Applied Automata Theory

Size: px
Start display at page:

Download "Applied Automata Theory"

Transcription

1 Applied Automt Theory Prof. Dr. Wolfgng Thoms RWTH Achen Course Notes compiled y Thierry Ccht Kosts Ppdimitropoulos Mrkus Schlütter Stefn Wöhrle Novemer 2, 2005

2 2

3 i Note These notes re sed on the courses Applied Automt Theory nd Angewndte Automtentheorie given y Prof. W. Thoms t RWTH Achen University in 2002 nd In 2005 they hve een revised nd corrected ut still they my contin mistkes of ny kind. Plese report ny ugs you find, comments, nd proposls on wht could e improved to skript@i7.informtik.rwth-chen.de

4 ii

5 Contents 0 Introduction Nottion Nondeterministic Finite Automt Deterministic Finite Automt Automt nd Logicl Specifictions MSO-Logic over words The Equivlence Theorem Consequences nd Applictions in Model Checking First-Order Definility Str-free Expressions Temporl Logic LTL Between FO- nd MSO-definility Exercises Congruences nd Minimiztion Homomorphisms, Quotients nd Astrction Minimiztion nd Equivlence of DFAs Equivlence nd Reduction of NFAs The Syntctic Monoid Exercises Tree Automt Trees nd Tree Lnguges Tree Automt Deterministic Tree Automt Nondeterministic Tree Automt Emptiness, Congruences nd Minimiztion Logic-Oriented Formlisms over Trees Regulr Expressions MSO-Logic XML-Documents nd Tree Automt Automt over Two-Dimensionl Words (Pictures) iii

6 iv CONTENTS 3.6 Exercises Pushdown nd Counter Systems Pushdown nd Counter Automt The Rechility Prolem for Pushdown Systems Recursive Hierrchicl Automt Undecidility Results Retrospection: The Symolic Method Exercises Communicting Systems Synchronized Products Communiction vi FIFO Chnnels Messge sequence chrts Exercises Petri Nets Bsic Definitions Petri Nets s Lnguge Acceptors Mtrix Representtion of Petri Nets Decision Prolems for Petri Nets Exercises Index 181

7 Chpter 0 Introduction Automt re systems consisting of sttes, some of them designted s initil or finl, nd (usully) leled trnsitions. In clssicl utomt theory recognizle lnguges or sets of stte sequences hve een investigted. Non-clssicl theory dels with severl spects, e.g. infinite sequences nd non terminting ehvior, with isimultion, or with different kinds of input ojects, e.g. trees s input structures. Automt (more generlly: trnsition systems) re the min modeling tools in Computer Science. Whenever we wnt to design progrm, protocol or n informtion system, or even just descrie wht it is intended to do, its chrcteristics, nd its ehvior, we use these specil kinds of digrms. Consequently, there is vriety of pplictions of utomt in Computer Science, for exmple: s sequentil lgorithms (pttern mtching, see Figure 1) They implement exctly those tsks tht we normlly connect to utomt, nmely they ccept letters s n input, nd on termintion they rech stte, which descries whether or not the text tht hs een red possesses certin property. s models of the execution structure of lgorithms (flow digrms, see Figure 2.) Before ctully implementing n lgorithm in some progrmming lnguge, one usully descries it y using some 2-dimensionl model, tht represents the steps tht run of this lgorithm my tke nd the phses tht it my go through. s formlism to system description (see Figure 3) s formlism to system specifiction (see Figure 4) Before developing system, we wnt to express its potentil cpilities. 1

8 2 CHAPTER 0. INTRODUCTION 0 1 0,1 q q 1 1 q 2 0 q 3 1 q 4 0 Figure 1: Deterministic utomton serching for 1101 In this course we re lmost lwys concerned with finite utomt, which is the re of utomt theory where most questions re decidle. As we know, even Turing Mchines cn e seen s utomt, ut in this cse, ll min questions re undecidle. On the contrry, in the re of finite utomt, prcticlly ll interesting questions tht one my sk cn e nswered y n lgorithm; nd this is wht mkes them so specil nd useful in Computer Science. Considered s mthemticl ojects, utomt re simply leled, directed grphs. However, this view on utomt is not very interesting, since it cn only e used to nswer rther elementry questions like connectivity or rechility. Wht mkes utomt theory more complicted, is the fct tht these specil kinds of grphs hve certin ehvior, they express specil mening. This leds us to the semntics of finite utomt. Some typicl kinds of semntics re: the lnguge eing recognized (consisting of finite or infinite words) the word function eing computed (utomt with output) (i-)simultion clss prtil order of ctions (in Petri Nets) set of expressions (in tree utomt) By considering these semntics, we cn for exmple define n equivlence etween two completely different utomt in cse they recognize exctly the sme lnguge. Moreover one cn sk, which one of these two utomt is the est in terms of spce complexity (e.g. numer of sttes) nd whether there exists etter utomton. Furthermore, we cn sk whether there is wy even to compute the est possile utomton tht cn recognize this lnguge. Some other questions nd prolems tht rise re listed elow. Compre utomt with respect to their expressive power in defining lnguges, connect this with lterntive formlisms like regulr expressions or logic.

9 Figure 2: Flow digrm 3

10 4 CHAPTER 0. INTRODUCTION Figure 3: Trnsition digrm

11 5 Figure 4: SDL-digrm Descrie nd evlute lgorithms for trnsformtion nd composition of utomt nd evlute their complexity. Is it possile to find the simplest structure or expression to recognize given lnguge? In the cse of utomt, simplicity is mesured on the numer of sttes (minimiztion). In the cse of logic formuls it my e mesured e.g. on its length. Which questions out utomt re decidle nd, for those tht re, wht complexity do the corresponding lgorithms hve (e.g. concerning equivlence)? Consequently, utomt theory hs to intersect with other relted res of Computer Science like: computility nd complexity theory logic circuit theory lgorithmic grph theory

12 6 CHAPTER 0. INTRODUCTION The course nd therefore these course notes re structured s follows: Chpter 1 dels with the connection of utomt nd logic nd with the prdigm of model checking. In Chpter 2 equivlence issues including minimiztion nd isimultion re discussed. Chpter 3 focuses on tree utomt nd their pplictions. In Chpter 4 pushdown systems s first model with n infinite set of configurtions re investigted. The next two chpters del with utomt models which llow communiction nd concurrency etween different processes, nmely communicting finite stte mchines in Chpter 5, including the grphicl formlism of messge sequence chrts, nd Petri nets in Chpter Nottion An lphet is finite set. Its elements re clled symols. We usully denote n lphet y Σ, nd its elements y,, c,.... A word over n lphet Σ is finite sequence of letters n with i Σ for 1 i n. n is clled the length of n. Words re usully nmed u, v, w, u 1, u 2,.... By ɛ we denote the word of length 0, i.e. the empty word. Σ (Σ + ) is the set of ll (nonempty) words over Σ. The conctention of words u = 1... n nd v = 1... m is the word uv := 1... n 1... m. Finlly, we use cpitl clligrphic letters A, B,... to nme utomt. A set L Σ is clled lnguge over Σ. Let L, L 1, L 2 Σ e lnguges. We define the conctention of L 1 nd L 2 to e the set L 1 L 2 := {uv u L 1 nd v L 2 }, lso denoted y L 1 L 2. We define L 0 to e the lnguge {ɛ}, nd L i := LL i 1. The Kleene closure of L is the lnguge L := i 0 Li, nd the positive Kleene closure L + is the Kleene closure of L without dding the empty word, i.e. L + := i 1 Li. Regulr expressions over n lphet Σ re recursively defined:, ɛ, nd for Σ re regulr expressions denoting the lnguges, {ɛ}, nd {} respectively. Let r, s e regulr expressions denoting the lnguges R nd S respectively. Then lso (r + s), (r s), nd (r ) re regulr expressions denoting the lnguges R S, RS, nd R, respectively. We usully omit the prentheses ssuming tht hs higher precedence thn nd +, nd tht hs higher precedence thn +.We lso denote the regulr expression (r + s) y r s, nd r s y rs. 0.2 Nondeterministic Finite Automt Definition 0.1 A nondeterministic finite utomton (NFA) is tuple A = (Q,Σ, q 0,, F) where Q is finite set of sttes, Σ is finite lphet,

13 0.3. DETERMINISTIC FINITE AUTOMATA 7 q 0 Q is n initil stte, Q Σ Q is trnsition reltion, nd F Q is set of finl sttes. A run of A from stte p vi word w = 1... n Σ is sequence ϱ = ϱ(1)...ϱ(n+1) with ϱ(1) = p nd (ϱ(i), i, ϱ(i+1)), for 1 i n. We write A : p w q if there exists run of A from p vi w to q. We sy tht A ccepts w if A : q 0 w q for some q F. The lnguge recognized y n NFA A = (Q,Σ, q 0,, F) is L(A) = {w Σ A : q 0 w q for some q F }. Two NFAs A nd B re equivlent if L(A) = L(B). An NFA A = (Q,Σ, q 0,, F) is clled complete if for every p Q nd every Σ there is q Q such tht (p,, q). Exmple 0.2 Let A 0 e the NFA presented y the following trnsition grph.,, q 0 q 1 q 2 q 3 The lnguge ccepted y A 0 is L(A 0 ) = {w {, } w contins nd endswith }. The word is ccepted y A 0, ecuse there exists run, e.g , yielded y this word tht strts in the initil stte nd leds the utomton to finl one. We notice the nondeterminism in stte q 0, where on the occurrence of the utomton cn choose etween stying in the sme stte or proceeding to stte q 1, s well s in stte q 1, where n nlogous choice hs to e mde when reding n. 0.3 Deterministic Finite Automt Definition 0.3 (DFA) A deterministic finite utomton (DFA) is tuple A = (Q,Σ, q 0, δ, F) where Q is finite set of sttes, Σ is finite lphet, q 0 Q is n initil stte, δ : Q Σ Q is trnsition function, nd

14 8 CHAPTER 0. INTRODUCTION F Q is set of finl sttes. We cn extend the trnsition function δ to words y defining δ : Q Σ Q (p, w) q if A : p w q This cn lso e defined inductively y δ (p, ɛ) = p nd δ (p, w) = δ(δ (p, w), ). The lnguge ccepted y DFA A = (Q,Σ, q 0, δ, F) is L(A) := {w Σ δ (q 0, w) F }. To simplify nottion we often write δ insted of δ. Note tht y definition every DFA is complete. As every utomton with prtilly defined trnsition function cn esily e trnsformed in to DFA y dding n dditionl stte, we often lso consider utomt with prtil trnsition function s DFAs. Exmple 0.4 Consider the following DFA A 1., q 0 q 1 q 2 q 3 It is esy to evlute the extended trnsition function δ y following the corresponding pth in the utomton, e.g. δ (q 0, ) = q 1 or δ (q 0, ) = q 3. The lnguge ccepted y A 1 is L(A 1 ) = {w {, } w hs n infix } = Σ Σ. A 1 is indeed complete, ecuse from every stte, there is trnsition for every letter of the lphet.

15 Chpter 1 Automt nd Logicl Specifictions 1.1 MSO-Logic over words This chpter is concerned with the reltion etween finite utomt nd logicl formuls. In the first section we focus on the so clled Mondic Second-Order (MSO) Logic, y explining its chrcteristics nd expressiveness. Before going into the detils of the definition of this logic, we illustrte the motivtion tht leds us to study it s helping tool in the re of utomt. Exmple 1.1 We consider the following utomton over Σ = {,, c}:,,c,,c It is rther esy to see tht this nondeterministic utomton ccepts the words tht hve the following property: There re two occurrences of etween which only s occur. This cn lso e expressed in terms of logic y requiring the existence of two positions in the word (sy x nd y) leled with, such tht x is efore y, nd every position tht comes fter x nd efore y (if there is such position t ll) is leled y. A logicl formul ϕ tht expresses this kind of property is: x y(x < y P (x) P (y) z((x < z z < y) P (z))) A word w is ccepted y the ove utomton iff w stisfies ϕ. 9

16 10 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS x z s u Figure 1.1: A hlf-dder. Our finl gol is to find generl equivlence etween utomt nd logicl formuls. This mens tht the lnguge tht we choose to represent logicl formuls hs to e of exctly the sme expressive power s finite utomt. Furthermore, we wnt to find wy to construct for given utomton n equivlent logicl formul nd vice vers. This my hve een simple in the ove exmple ecuse we did not relly trnslte the utomton directly to the logicl formul. Wht we ctully did, ws, using our common sense, comprehend nd cpture in mind the lnguge tht is defined y the utomton, then intuitively express the properties of this lnguge in such colloquil English tht it cn e esily coded into logicl formul, nd finlly do the respective trnsltion. Unfortuntely, these trnsformtions cnnot (yet) e performed y mchine. A mchine needs explicitly defined instructions to trnslte one structure to nother. And in this cse it is not n esy tsk. On the one hnd logicl formuls cn e uild up y explicit prts; these prts re sic logicl formuls themselves, we cn prtilly order them in incresing complexity nd we cn comine them to result in new logicl formul tht somehow possesses the power of ll its components. In other words, logicl formuls cn e defined inductively. On the other hnd, we cnnot decompose n utomton to ny meningful sic prts; t lest not in the generl cse. Neither re there opertors in its definition tht lwys comine its components to construct the whole utomton. We cn of course disssemle n utomton to its sttes, ut ech one of these generlly does not hve ny mening nymore. It is the complex wy the sttes re connected over leled trnsitions wht mkes the utomton work in the desired wy. We know similr connection etween two different structures from Circuit Theory, nmely the equivlence etween Boolen Logic nd Circuits. Exmple 1.2 Consider the well known circuit (hlf-dder) of Figure 1.1: Its ehvior cn e descried y the following Boolen formuls: s = x z + x z, u = x z

17 1.1. MSO-LOGIC OVER WORDS 11 There is trnsltion from circuits to Boolen formuls nd vice vers. The min difference etween circuits nd utomt is tht the former re cyclic grphs. In the ove exmple we cn notice how dt flows from left to right. In the cse of utomt we my hve loops, consisting of one or more sttes, nd this is wht mkes them more complex to hndle. We lso know some other roughly speking logicl formuls tht descrie the ehvior of utomt, nmely regulr expressions over Σ. These re uilt up y the symols of Σ,, ɛ with + (for union), (for conctention) nd (for the itertion of conctention). Exmple 1.3 Consider the following utomton:,,c,,c The lnguge tht it recognizes cn e defined y the following regulr expression (the conctention symol is usully omitted): ( + + c) ( + + c), short Σ Σ. Theorem 1.4 (Kleene) A lnguge L is definle y regulr expression iff L is DFA or NFA recognizle. But if we lredy hve such n equivlence etween utomt nd regulr expressions why do we need more? Why re regulr expressions not enough nd wht is it tht mkes us need the logicl formuls? To relize the dvntges of logicl formuls, we consider Exmple 1.1 s well s two vritions of it, nmely: (Exmple 1.1) There re two occurrences of, etween which only s occur Exmple 1.5 There re no two occurrences of, etween which only s occur Exmple 1.6 Between ny two occurrences of only s occur We notice tht 1.5 is the complement of 1.1, wheres 1.6 turns the existentil sttement into universl sttement. These two reltions etween these exmples cn e esily expressed using logicl formuls (e.g. in the cse of 1.5): x y(x < y P (x) P (y) z((x < z z < y) P (z)))

18 12 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS On the other hnd, y using regulr expressions one cn conveniently descrie the occurrences of ptterns ut it tkes lot of effort to descrie the non-occurrence of ptterns. This holds even when defining lnguge y n utomton. The lnguge of Exmple 1.5 is defined y the following regulr expression: ( + c) (ɛ + )( c( + c) ) ( + c) So fr we hve used the following nottion in our logicl formuls: vriles x, y, z,... representing positions of letters in word (from 1 (= min) up the length n (= mx) of word) formuls P (x) ( t position x there is n ), x < y ( x is efore y ) Before extending the expressive power of our logicl formuls, we look t some further exmples: Exmple 1.7 Consider the lnguge consisting of words with the property: right efore the lst position there is n Regulr expression: Σ Σ Logicl formul: x (P (x) x + 1 = mx) Insted of the opertion +1 we use the successor reltion S(x, y) ( x hs y s successor ). Now the formul looks like this: x (P (x) S(x,mx)) Exmple 1.8 The property of even length: Even length, s property of non-empty words, is regulr: (ΣΣ) (ΣΣ) A corresponding logicl formul would e: x (x + x = mx) But introducing ddition of positions leds us outside the clss of regulr lnguges. In other words, the +-opertor provides us with too much

19 1.1. MSO-LOGIC OVER WORDS 13 expressive power. By using it we cn e.g. express the non-regulr lnguge { i i i > 0} y the formul x (x + x = mx y(y x P (y)) z(x < z P (z))) Is there wy to cpture the property of even length without using the +-opertor? To this purpose we consider set of positions of word nd require tht it: contins the first position, then lwys contins exctly every second position, does not contin the lst position We use X s vrile for sets of positions nd we write X(y) to express tht position y is in X. Now we re redy to express the property of even length in the following wy: X (X(min) y z (S(y, z) (X(y) X(z))) X(mx)) Definition 1.9 (Mondic Second Order Logic (MSO-Logic)) MSO formuls re uilt up from vriles x, y, z,... denoting positions of letters, constnts min nd mx vriles X, Y, Z,... denoting sets of positions the tomic formuls (with explicit semntics) x = y (equlity) S(x, y) x hs y s successor x < y x is efore y P (x) t position x there is n X(y) y X (insted of x, y min, or mx cn lso e used) the usul connectors,,,, nd nd the quntifiers, A non-empty word w = 1... m over the lphet Σ = { 1,..., n } defines the word model w = ( {1,...,m}, S w, < w, min w, mx w, P w }{{} 1,...,P w ) n =: dom(w) Where:

20 14 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS dom(w) is the set of (ll) positions 1,..., w S w is the successor- nd < w the smller-thn-reltion on dom(w) min w = 1 nd mx w = w P w i := {j dom(w) j = i } for i = 1,...,n Remrk 1.10 We decide to use only non-empty words for models for two resons. First, in mthemticl logic it is generlly convenient to use models tht hve t lest one element. Otherwise, we hve to other with some dditionl considertions nd specil cses. Second, in cse we ccept the empty word ɛ to define model, we re no longer le to mke use of the constnts min nd mx. MSO stnds for mondic second-order : Second-order ecuse it llows quntifiction not only over (first-order) position vriles ut lso over (second-order) set vriles. Mondic ecuse quntifiction is llowed t most over unry (mondic) reltions, nmely sets. For n lphet Σ we get the MSO Σ [S, <]-formuls. In the specil cse tht we use quntifiers only over first-order vriles (rnging over positions) we get the FO Σ [S, <]-formuls. Usully, the lowercse Greek letters φ, χ, ψ,... re used for formuls. A vrile x i or X i is free in formul if it does not occur within the scope of quntifier. The nottion φ(x 1,...,x m, X 1,...,X n ) for formul indictes tht t most the vriles x 1,...,x m, X 1,...,X n occur free in φ. Assume φ(x 1,...,x m, X 1,...,X n ) is given. To interpret the truth vlue of φ we need: word model w (with predictes P w for the symols Σ) positions k 1,...,k m s interprettions of x 1,...,x m sets K 1,...,K n of positions s interprettions of X 1,...,X n Consequently our complete model is: Now, (w, k 1,...,k m, K 1,...,K n ) (w, k 1,...,k m, K 1,...,K n ) = φ(x 1,...,x m, X 1,...,X n ) expresses the fct tht φ holds in w, if x i is interpreted y k i nd X i y K i. In short nottion we write: w = φ[k 1,...,k m, K 1,...,K n ]

21 1.1. MSO-LOGIC OVER WORDS 15 Exmple 1.11 Let Σ = {, }, w = nd 1. φ 1 (x 1, X 1 ) := P (x 1 ) y (x 1 < y X 1 (y) P (y)) 2. φ 2 (x 1, x 2 ) := z (x 1 < z z < x 2 P (z)) 3. φ 3 := x y (P (x) S(x, y) P (y)) Then: 1. (w, 1, {2, 3, 4}) = φ 1 (x 1, X 1 ) 2. (w, 2, 4) = φ 2 (x 1, x 2 ) 3. w = φ 3 The lst exmple-formul does not hve ny free vriles, nd cn therefore e interpreted given just word s model. Such formuls re clled sentences. If we collect ll words tht stisfy such sentence, nd put them into set, then this set is the lnguge defined y the sentence. Formlly, for n MSO Σ [S, <]-sentence φ, let L(φ) := {w Σ + w = φ} e the lnguge defined y φ. Such lnguge is clled MSO Σ [S, <]-definle (short: MSO-definle). In cse no set quntifiers re needed in φ, we cll the lnguge FO Σ [S, < ]-definle or just FO-definle. FO stnds for first-order, ecuse now quntifiers rnge only over position vriles. Exmple 1.12 For Σ = {,, c} Σ Σ is FO-definle, nmely y x y (x < y P (x) P (y) z ((x < z z < y) P (z))) Σ Σ is FO-definle, nmely y x (P (x) S(x,mx)) (ΣΣ) (ΣΣ) is MSO-definle, nmely y X (X(min) y z (S(y, z) (X(y) X(z))) X(mx)) Furthermore, we shll see in some future section tht this formul cnnot e expressed in FO-logic t ll. Remrk 1.13 In FO- nd MSO-formuls we cn eliminte min nd mx.

22 16 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS Exmple 1.14 Insted of x (P (x) S(x,mx)) we write x (P (x) y (S(x, y) z S(y, z))) In generl, sustitute ψ(mx), y: Anlogously for min. y(ψ(y) z y < z). Remrk 1.15 In MSO-formuls we cn eliminte <. Proof: Replce x < y y X [ X(x) z z (X(z) S(z, z ) X(z )) X(y) ] Exmple 1.16 Some more exmples over Σ = {,, c}: 1. {w Σ + in w every is followed only y s, until occurs} is definle y: x ( P (x) y ( x < y P (y) z (x < z z < y P (z)) )) 2. + is definle y x P (x). 3. () is definle y P (min) x y ( S(x, y) (P (x) P (y)) (P (x) P (y)) ) P (mx) 1.2 The Equivlence Theorem Now tht we hve defined the logic we re going to use, we shll present wy to trnslte ny given utomton to formul of this logic nd vice vers. To this purpose we do the following preprtion: A formul φ(x 1,...,X n ) is interpreted on word models (w, K 1,...,K n ) with K i dom(w). The set K i of positions serves s n interprettion of X i. To code such models y words tht cn e processed y n utomton we collect for every position k dom(w) the informtion if k K 1, k K 2,...,k K n in the form of it vector. Formlly, we represent word 1... m with sets of positions K 1,...,K n y word over the lphet Σ {0, 1} n :

23 1.2. THE EQUIVALENCE THEOREM 17 1 (c 1 ) 1. (c 1 ) n nd we set (c k ) j = 1 iff k K j. 2 (c 2 ) (c 2 ) n m (c m ) 1. (c m ) n Exmple 1.17 Let Σ = {, }, w =, K 1 =, K 2 = {2, 4, 5} nd K 3 = {1, 2}. w K K K Theorem 1.18 (Büchi, Elgot, Trkhtenrot 1960) A lnguge L Σ + is regulr if nd only if it is MSO-definle. The trnsformtion in oth directions is effective. For the proof we present regulr lnguges y NFAs. Let us give n exmple first. Exmple 1.19 Given the following utomton A:,, we hve to construct sentence φ A with w = φ A iff w L(A). In other words, φ A hs to express tht there exists n ccepting run of A on w. To this purpose, long with φ A we ssume the existence of three sets X 1, X 2, X 3, such tht: X i = set of positions, t which A is in stte i. Exmple An ccepting run for this word is We encode X 1, X 2, X 3 in the following wy (without the lst stte): w : X 1 : X 2 : X 3 :

24 18 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS Nturlly the utomton cn only e in one stte t ech point of time. Therefore there is just one 1 in every column of the run. How cn we descrie successful run? Tht is, how do we set constrints to X 1,...,X n? The formul we re looking for is conjunction over 4 sic properties: φ A := X 1 X 2 X 3 [ X1, X 2, X 3 form Prtition X 1 (min) x y (S(x, y) t x, y one of the trnsitions is pplied t mx the lst trnsition leds to finl stte ] Now let us explin ech one of these properties (except the second, which is ovious) nd give the respective MSO-formuls. X 1, X 2, X 3 form Prtition : Prtition is n expression for the ove mentioned unmiguity of the utomton stte. Since there is just one 1 in every X-itvector, X 1, X 2, X 3 hve to form prtition of dom(w). In terms of MSO-logic, we write: x (X 1 (x) X 2 (x) X 3 (x)) x (X 1 (x) X 2 (x)) x (X 2 (x) X 3 (x)) x (X 1 (x) X 3 (x)) t x, y one of the trnsitions is pplied : In other words, we need formul to represent the whole trnsition reltion : (X 1 (x) P (x) X 1 (y)) (X 1 (x) P (x) X 1 (y)) (X 1 (x) P (x) X 2 (y)) (X 2 (x) P (x) X 3 (y)) (X 3 (x) P (x) X 3 (y)) (X 3 (x) P (x) X 3 (y)) t position mx the lst trnsition leds to finl stte : Since we wnt the formul to e true if nd only if the word is ccepted y the utomton, we hve to force tht the run on w ends in finl stte of A: (X 2 (mx) P (mx)) (X 3 (mx) P (mx)) (X 3 (mx) P (mx)) Proof of Theorem 1.18: Let A = ({1,..., m}, Σ, 1,, F) e n NFA. The }{{} Q formul expressing tht there exists successful run of A on word w Σ + is then given y [ ( φ A = X 1... X m x X1 (x)... X m (x) ) i j x ( X i (x) X j (x) )

25 1.2. THE EQUIVALENCE THEOREM 19 X 1 (min) x y (S(x, y) (i,,j) (X i(x) P (x) X j (y))) (i,,j),j F (X i(mx) P (mx)) ] Then A ccepts w iff w = φ A. Remrk 1.21 φ A does not contin ny universl quntifiers over set vriles ut only existentil ones. Such n MSO-formul, nmely of the form X 1... X m ψ(x 1,...,X m ) where ψ does not contin ny set quntifiers t ll, is clled n existentil MSO-formul (EMSO-formul). Remrk 1.22 For m sttes, log 2 (m) set quntifiers suffice. Exmple 1.23 In the cse of 4 sttes: Insted of the sets X 1,...,X 4 it suffices to use X 1, X 2 long with the convention tht the sttes 1,...,4 correspond to the column vectors ( 0 0), ( 0 1), ( 1 0), ( 1 1), respectively. Suppose now tht we re given n MSO-formul φ nd wnt to construct n NFA A φ such tht L(A φ ) = L(φ). The min ide is to proceed y induction on the construction of φ(x 1,...,x m, X 1,...,X n ). First we show how to eliminte the first-order vriles x i nd get equivlent formuls contining only set vriles. To this purpose we represent the element x y the set {x} nd then work with formuls of the form φ(x 1,...,X n ). We cll such formuls MSO 0 -formuls. Atomic MSO 0 - formuls re: X Y nd X P Sing(X) S(X, Y ) X < Y ( X is singleton set ) ( X = {x}, Y = {y} nd S(x, y) ) ( X = {x}, Y = {y} nd x < y ) As usul, formuls re uilt up using,,,,,, nd. Lemm 1.24 (MSO 0 -Lemm) Every MSO-formul φ(x 1,...,X n ) is (over word models) equivlent to n MSO 0 -formul. Proof: We proceed y induction over the structure of the given MSOformul. In some of the intermedite steps we hve to hndle formuls with free first-order (element) vriles. As descried ove we trnsform these vriles into singleton set vriles. More formlly, y induction over

26 20 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS the structure of n MSO-formul ψ(y 1,...,y m, X 1,...,X n ), we construct corresponding MSO 0 -formul ψ (Y 1,...,Y m, X 1,...,X n ) with (w, k 1,...,k m, K 1,...,K n ) = ψ iff (w, {k 1 },...,{k m }, K 1,...,K n ) = ψ We omit the detils. The ide is illustrted in the exmple elow. Exmple 1.25 For construct φ(x 1 ) = x ( P (x) y (S(x, y) X 1 (y)) ) φ = X ( Sing(X) X P Y (Sing(Y ) S(X, Y ) Y X 1 ) ) Corollry 1.26 To trnslte formuls φ(x 1,...,X n ) to utomt it suffices to consider MSO 0 -formuls. A formul φ(x 1,...,X n ) defines lnguge over the lphet Σ {0, 1} n. Exmple 1.27 Let Σ = {, } nd φ(x 1 ) = x ( P (x) y (S(x, y) X 1 (y)) ) ( )( )( )( ) stisfies φ ( )( )( )( ) does not stisfy φ. L(φ) = the set of words over Σ {0, 1}, such tht fter every in the first component there is 1 in the second component. In the generl cse, for ech φ(x 1,...,X n ) we hve to inductively construct finite utomton over Σ {0, 1} n. For the se cse we consider the tomic MSO 0 -formuls. X 1 X 2 : Given word w (Σ {1, 0} n ) +, n utomton hs to check tht whenever the first component is 1, the second component is 1 s well. This is performed y the following NFA: # # # , , # tht is, it ccepts everything except 1 0, where # stnds for ritrry letters in Σ nd for ritrry it vectors in {0, 1} n 2.

27 1.2. THE EQUIVALENCE THEOREM 21 X 1 P : 1» 0,» 1,» 0 Sing(X 1 ):» # 0 1» # 1» # 0 2 S(X 1, X 2 ): 2 3 # # # # X 1 < X 2 : # # # # # For the induction step, we suppose tht for the formuls φ 1, φ 2 the corresponding NFAs A 1, A 2 re given nd we only consider the connectors, nd the quntifier. The other opertors (,, nd ) cn e expressed s comintion of the previous ones. Regrding the negtion, φ 1 is equivlent to the complement utomton of A 1. As we know, we cn construct it using the suset construction on A 1 nd then, in the resulting DFA, declre ll sttes Q \ F s finl ones. For the disjunction φ 1 φ 2 we construct the utomton tht recognizes L(A 1 ) L(A 2 ). As usully we do this y constructing the union utomton out of A 1 nd A 2. To hndle the existentil quntifier we need some preprtion. Lemm 1.28 (Projection Lemm) Let f : Σ Γ e projection of the lphet Σ into the lphet Γ extended to words y f( 1... m ) := f( 1 )...f( m ). If L Σ is regulr, then f(l) is regulr s well. 2 3 Proof: Given n NFA A = (Q,Σ, q 0,, F) tht recognizes L, we construct the NFA B = (Q,Γ, q 0,, F) with := {(p, f(), q) (p,, q) }.

28 22 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS Remrk 1.29 The NFA for the projection results y projecting the trnsition lels. Exmple 1.30 Consider the (incomplete) DFA over {, } {0, 1} tht recognizes L = ( ( 0) + ( 0) ) ( 1) (( 1)( 1)) : h i 0i,h 0 h 1i h 1i 1 2 h 1i 3 The projection f : ( c), ( c) yields the NFA:, which recognizes f(l). Now tht we hve defined the necessry notions of the projection, we cn del with the existentil quntifier. Lemm 1.31 (Quntifiers Lemm) Assume L (Σ {0, 1} n ) + is defined y φ(x 1,...,X n ). Let f : (Σ {0, 1} n ) (Σ {0, 1} n 1 ) e the cnonicl projection (, c 1,...,c n ) (, c 1,...,c n 1 ). Then the formul X n φ(x 1,...,X n ) defines the lnguge f(l). Corollry 1.32 If φ(x 1,...,X n ) defines the regulr lnguge L, then X n φ(x 1,...,X n ) defines regulr lnguge s well, nmely f(l). Remrk 1.33 The NFA for X n ϕ(x 1,...,X n ) is constructed from the utomton for ϕ(x 1,...,X n ) y omitting the lst component in the trnsition lels. Proof: (Quntifiers Lemm) w = 0... m 1 (Σ {0, 1} n 1 ) + stisfies X n φ(x 1,...,X n ) iff there exists K dom(w) such tht (w, K) = φ(x 1,...,X n ) iff there exist c 0,...,c m 1 {0, 1}, such tht [ ] [ ] 0 m 1... stisfies φ(x 1,...,X n ) c 0 c m 1

29 1.2. THE EQUIVALENCE THEOREM 23 iff 0... m 1 = f(u) for some u with u = φ(x 1,...,X n ), i.e. for some u L iff 0... m 1 f(l) Exmple 1.34 For the following formul we construct n equivlent utomton. ( ) ϕ = X 1 X1 (min) x y(s(x, y) (X }{{} 1 (x) X 1 (y))) z P }{{} (z) }{{} ψ 1 (X 1 ) ψ 2 (X 1 ) ψ 3 (X 1 ) We suppose tht we re directly given utomt A 1, A 2, A 3 for the su-formuls ψ 1 (X 1 ), ψ 2 (X 1 ), ψ 3 (X 1 ) respectively: A 1 : 1 A 2 : 1 A 3 : 1 [ ] [ [ 0] [ 1] 1] [ 0] 2 [ ] 2 3 [ 1] We consider the conjunctions directly (without eliminting them y using negtion nd disjunction). A 3 merely requires tht only s occur in the first component. Since A 1 nd A 2 mke no restrictions out the first component, we cn intersect A 3 with oth of them y lwys replcing the in the first component with n : A 1 : 1 A 2 : 1 [ [ 0] 1] [ 0] 2 [ ] 2 [ 1] [ 1] 3 Since A 1 only requires tht in the first position in the word model 1 occurs in the second component, we form the intersection of A 1 nd A 2 y removing the trnsition from 1 2. So for the formul ψ 1 (X 1 ) ψ 2 (X 1 ) ψ 3 (X 1 ) we get the following equivlent utomton: A 1 A 2 : 1 [ 0] 2 [ 1] [ 1] 3

30 24 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS The projection on Σ leds to the finl utomton A: Oviously L(A) = +, so (etter) equivlent utomton is: 1 2 The BET-Theorem llows the trnsformtion of n MSO-formul into n equivlent utomton nd vice vers. How effective re these trnsformtions? Let us focus on the computtionl effort (in terms of time complexity) tht is needed to perform the first one, ssuming tht we re given the utomt for the tomic formuls. If ech one of two NFAs A 1, A 2 hs t most n sttes, then the NFA recognizing the union lnguge hs t most 2n + 1 sttes (ecuse we crete new initil stte nd depending on the first letter tht is red, the new utomton rnches to one of the two initil ones) intersection lnguge hs t most n 2 sttes (ecuse we hve to construct the product utomton) complement lnguge hs t most 2 n sttes (ecuse we hve to use the suset construction nd turn the given NFAs to DFAs efore switching finl nd non-finl sttes) projection lnguge hs t most n sttes (ecuse we use the sme utomt nd omit one component) Does this men tht the trnsformtion requires exponentil time with respect to the numer of sttes of the utomt? Unfortuntely not. The fct tht the projection my turn DFA into n NFA nd the fct tht constructing the complement utomton requires to mke n utomton first deterministic (suset construction) mens tht, whenever n lterntion etween negtion nd projection occurs (e.g. when universl quntifier occurs), n dditionl exponentil urden is dded to our computtionl effort. So, in the generl cse, if k is the numer of logicl opertors in the formul, then the numer of sttes in the resulting utomton grows n } k like The following theorem shows tht we cnnot hope etter ound.

31 1.2. THE EQUIVALENCE THEOREM 25 Theorem 1.35 (Meyer, Stockmeyer 1971) There is no trnsltion of MSO-formuls ϕ to utomt in which the numer of sttes of the resulting utomton cn e ounded y function of the form n } k with constnt k. Empiricl oservtion (MONA system of Bsin, Klrlund): If ech DFA tht is produced y the trnsltion s n intermedite result is immeditely minimized, then even in the cse of long formuls the size of the utomton mostly remins moderte. But doesn t minimiztion dd nother computtionl urden? Not relly, ecuse we will see in the next chpter tht for the cse of DFA, minimiztion cn e done efficiently. Consequently, the exmples for n hyper-exponentil growth re not typicl. Exmple 1.36 We give to the MONA system the following formul: ϕ(x, Y, x) : X \ Y = {0, 1, 2, 4} ψ(x) X(x) with ψ(x) := Z(Z(0) Z(x) y(0 < y x ((Z(y) Z(y 1)) ( Z(y) Z(y 1))) MONA input: vr2 X,Y; X\Y = {0,4} union {1,2}; pred even(vr1 x) = ex2 Z: 0 in Z & x in Z & (ll1 y: (0 < y & y <= x) => (y in Z => y-1 notin Z) & (y notin Z => y-1 in Z)); vr1 x; even(x) & x notin X; The resulting utomton is (MONA output)

32 26 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS X X X X 1 0, X 0 1 X,1,X X 0 1 X,1,X X 0 1 X,1,X X 0 1 1,X,1 0 1 X 1 0,0 0 1 X 1 0, X 0 1 X,1,X X 0 1 1,X,1 0 X X 1 X,X X,1 1 0 X X X X 2 Now tht we hve connected utomt to logic, we cn mke comprison etween them, s well s consider the pplictions of this connection. Automt: opertionl, formuls: descriptive Automt: implementtion, formuls: specifiction Automt hve locl trnsitions, formuls hve glol opertors (in prticulr quntifiers) The semntics of utomt re defined over the ritrry construction of stte sequences, wheres the semntics of formuls re defined inductively (compositionl) lgorithmic questions on utomt re often efficiently solvle, wheres the ones on formuls re hrd to solve (non-emptiness vs. stisfiility) For utomt the minimiztion prolem is pprochle, for formuls it remins still incomprehensile. How does ll this relte to the logic of regulr expressions? These cn e enriched y further opertors tht mke them more convenient to use without incresing their expressive power. We dd (for the complement) nd (for the intersection). Definition 1.37 Generlized regulr expressions over Σ re uilt up y letters Σ nd, ɛ y using +,, (inry) nd, (unry). Exmple 1.38 The following property over words in Σ = {,, c}:

33 1.2. THE EQUIVALENCE THEOREM 27 there re no two occurrences of, etween which only s occur, nd t most three c s occur is defined y (Σ Σ ) (Σ cσ cσ cσ cσ ) Remrk 1.39 A lnguge is definle y generlized regulr expression if, nd only if, it is regulr. For the definition of word sets (lnguges) generlized regulr expressions re n lterntive to MSO-logic; they my e not so flexile, ut in mny cses they re much more convenient to use. Their trnsltion into utomt is of the sme computtionl complexity s the trnsltion of the formuls. Remrk 1.40 The BET-Theorem hs een extended to other types of models insted of finite words: 1. Automt on ω-words nd their equivlence to MSO-logic (Büchi 1960) 2. Automt on finite trees nd their equivlence to MSO-logic (Doner, Thtcher/Wright 1968) 3. Automt on infinite trees nd their equivlence to MSO-logic (Rin 1969) Appliction: Decidle theories. The initil motivtion to reduce formuls to utomt ws First-order rithmetics, i.e. the first-order theory of the structure (N, +,, 0, 1), which ws proven to e undecidle (Gödel 1931). Bsed on this result Trski formulted the following prolem: Wht is the result if in its signture we keep only +1, ut llow set quntifiers? Corollry 1.41 (of the Büchi, Elgot, Trkhtenrot Theorem) : The second-order theory of the structure (N, +1) in which the second-order quntifiers rnge only over finite sets is decidle. This theory is usully referred to s the wek second-order theory of one successor (WS1S). Theorem 1.42 The wek second-order theory of one successor (WS1S) is decidle. The use of tree utomt nd utomt on infinite trees led to further results: The theory S1S refers to the structure (N, +1) with ritrry set quntifiers.

34 28 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS The theory WS2S concerns the structure of the infinite inry tree (with two successor functions), in which the set quntifiers rnge only over finite sets. The theory S2S refers to the infinite inry tree with ritrry set quntifiers. All these theories re decidle using the corresponding utomt nd similr techniques s in the proof of Theorem Consequences nd Applictions in Model Checking First of ll, the Equivlence Theorem hs purely logicl consequence: Theorem 1.43 Every MSO-formul φ(x 1,...,X n ) is over word models equivlent to n EMSO-formul, i.e. to formul of the form where ψ is n FO-formul. Y 1... Y m ψ(x 1,...,X n, Y 1,...,Y m ) Proof: Use the BET-Theorem in oth directions: φ A φ Y 1... Y m ψ. So, given n MSO-formul φ(x), we first construct the equivlent NFA A φ over the lphet Σ {0, 1} n nd then trnsform it into n equivlent EMSO-formul Y 1... Y m ψ. Theorem 1.44 Stisfiility nd equivlence of MSO-formuls over word models re decidle prolems. Proof: Apply the trnsformtions into utomt: ϕ is stisfile iff L(ϕ) iff L(A ϕ ) ϕ ψ iff L(ϕ) = L(ψ) iff L(A ϕ ) = L(A ψ ) The constrints on the right cn e tested lgorithmiclly. We look t the terminting ehvior of finite stte systems. The model checking prolem is the following: Given finite stte system represented y n NFA A nd specifiction formulted s n MSO-formul φ, does every word ccepted y A stisfy the specifiction φ? This cn e succinctly restted s L(A) L(φ)?. To solve the model checking prolem we introduce error scenrios. A word w is n error scenrio if w L(A) ut w = φ, i.e. w L(A) L(A φ ).

35 1.3. CONSEQUENCES AND APPLICATIONS IN MODEL CHECKING29 The solution of model checking prolem consists of two steps. First we construct from formul φ n utomton A φ using the BET-Theorem. Then we construct the product utomton B of A nd A φ. B ccepts precisely the error scenrios. Hence, we pply the emptiness test for B. If L(B) turns out to e non-empty, then not every word ccepted y A stisfies the specifiction φ. In this cse the emptiness test returns counter-exmple to φ, which cn e used for deugging the system. So, given n utomton A nd n MSO-formul φ, to solve the model checking prolem we hve to do the following: 1. Construct the utomton A φ 2. Proceed to the product utomton A A φ tht recognizes L(A) L(A φ ). 3. Apply the non-emptiness test on the product utomton. 4. In cse of non-emptiness, return word tht is ccepted y the product utomton (error scenrio). Exmple 1.45 MUX (Mutul exclusion) protocol modeled y trnsition system over the stte-spce B 5. Proc0: loop (00) 0: Non_Criticl_Section_0; (01) 0: wit unless Turn = 0; (10) c0: Criticl_Section_0; (11) d0: Turn := 1; Proc1: loop (00) 1: Non_Criticl_Section_1; (01) 1: wit unless Turn = 1; (10) c1: Criticl_Section_1; (11) d1: Turn := 0; A stte is it-vector ( 1, 2, 3, 4, 5 ) B 5 (vlue of turn, line no. of process 0, line no. of process 1). On this protocol we cn define the system utomton A MutEx over the stte spce {0, 1} 5, with initil stte (00000), the lphet B 5 nd the following trnsitions: For process 0: For process 1: nlogously

36 30 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS If we dditionlly lel ech trnsition with its trget stte, nd declre ll rechle sttes s finl ones, the words eing ccepted y this utomton re exctly the system runs. Finlly, for mtters of system specifiction we cn represent the 5 its y predictes X 1,...,X 5 nd introduce revited compct stte properties tht cn e descried y MSO-formuls: t0(t) := X 2 (t) X 3 (t) (sttes of the form (X00XX) Turn(t) = 0 := X 1 (t) (sttes of the (0XXXX) The first formul specifies ll sttes where some prt of the system is t 0, which mens tht process 0 is in line 00. The second one specifies ll those sttes where the vlue of the synchroniztion vrile hppens to e 0. For the generl cse where stte properties p 1,...,p k re considered, frmework is used tht is clled Kripke structure. Definition 1.46 A Kripke structure over propositions p 1,...,p k hs the form M = (S,, s 0, β) with finite set S of sttes trnsition reltion S S (lterntively S Σ S) n initil stte s 0 leling function β : S 2 {p 1,...,p n} ssigning to ech s S the set of those p i tht re true in s Usully, we write vlue β(s) s it vector ( 1,..., n ) with i = 1 iff p i β(s). Some very essentil specifictions of the MUX System would e the sfety condition nd the liveliness condition. For the first we hve to specify tht no stte in which process 0 is in c0 nd process 1 is in c1 will ever e reched: ϕ := x ( tc0(x) tc1(x) ) According to our model, we hve to forid ll sttes of the form (X1010): ϕ(x 1,...,X 5 ) = x ( X 2 (x) X 3 (x) X 4 (x) X 5 (x) ) In the frmework of model checking, this is n inclusion test, nmely whether every (ccepting) run of the finite system is lso (correct) model for the MSO-specifiction: L(A MutEx ) L(ϕ(X 1,...,X 5 )). For n exmple specifiction of the second kind, we require tht whenever process 0 wnts to enter the criticl section (t 0), it will eventully indeed enter c0 : x ( t0(x) y(x < y tc0(y)) ) The MSO formultion of this condition ctully mkes sense when it comes to infinite system runs, which goes eyond the scope of these course notes.

37 1.4. FIRST-ORDER DEFINABILITY First-Order Definility For the most cses of specifiction the expressive power of FO[S, <]-formuls suffices. A nturl question to sk is wht re the exct limits of this power, i.e. which regulr lnguges cn e expressed y FO-formuls. To this purpose we re going to introduce two new formlisms, nmely str-free (regulr) expressions nd the temporl logic LTL ( liner time logic ), nd compre them with FO-logic. Without giving complete proof, we shll see tht ll three formlisms define exctly the sme clss of lnguges. Finlly, we will see tht this clss is proper suset of the clss of regulr lnguges, i.e. there is specil clss of lnguges tht is regulr (which mens MSO-definle) ut not FO-definle Str-free Expressions Definition 1.47 A str-free regulr expression is (generlized) regulr expression uilt up from the toms ɛ,, Σ using only the opertions for conctention, + for union, for intersection, nd for complementtion. The lnguge L(r) defined y such n expression r is lso clled str-free. Exmple 1.48 Let Σ = {,, c} 1. Σ is str-free, defined y 2. + is str-free, defined y ɛ (Σ ( + c)σ ) 3. () is str-free, defined y the constrint: never c, egin with, never nor, end with, i.e.: Remrk 1.49 (Σ cσ ) Σ (Σ ( + )Σ ) Σ. The use of complementtion is essentil. Indeed, complementtion is the opertion tht enles us to represent infinite lnguges ecuse y complementing finite lnguge we get n infinite one. With union, conctention, nd intersection we cn only produce finite lnguges strting from the finitely mny symols of the lphet.. The stndrd str-free expressions re produced out of Σ, ɛ, y using only + nd ; these expressions define exctly the finite lnguges. Theorem 1.50 Every str-free lnguge L Σ + is FO-definle.

38 32 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS This theorem follows from the more technicl lemm elow. Lemm 1.51 For every str-free expression r there is n FO-formul ϕ r (x, y) tht expresses tht the segment from x up to y is in L(r), tht is w L(r) iff w = ϕ r [min, mx] for ll w Σ +. Proof: By induction on the construction of the str-free expression. Bse cses: r = : Set ϕ r (x, y) := P (x) x = y r = : Set ϕ r (x, y) := z(x z z y (z = z)) Induction hypothesis: Let s, t e equivlent to ϕ s (x, y), ϕ t (x, y). Induction step: For r = s + t, r = s t nd r = ( s) ɛ set: ϕ r (x, y) := ϕ s (x, y) ϕ t (x, y), ϕ s (x, y) ϕ t (x, y), nd ϕ s (x, y), respectively. For r = s t we require the existence of two successive positions z, z tht re etween x nd y. From x up to z, ϕ s holds, nd from z up to y, ϕ t holds: ϕ r (x, y) := z z (x z z y x z z y ϕ s (x, z) S(z, z ) ϕ t (z, y)) Temporl Logic LTL The (propositionl) temporl logic LTL (liner time logic) ws first proposed in 1977 y A. Pnueli for purposes of system specifiction. Its min dvntges re: vrile-free compct syntx trnsformtion into utomt more efficiently thn in the cse of FOformuls equivlence to FO[S, <]-logic In this section we hndle LTL only over finite words. Definition 1.52 (LTL) Syntx: A temporl formul is uilt up from propositionl vriles p 1, p 2,... using the connectives,,,, nd the temporl opertors X (next), F (eventully), G (lwys), nd U (until). We write φ(p 1,...,p n ) for temporl formul φ to indicte tht t most the propositionl vriles p 1,...,p n pper in φ.

39 1.4. FIRST-ORDER DEFINABILITY 33 Semntics: A temporl formul φ(p 1,...,p n ) is evluted in model (w, j) where 1 j w is position in the word w, nd w is of the form w = ( 1 (1). n(1)... 1 ( w ). n( w ) The vlue i (k) {0, 1} codes the truth vlue of proposition p i t position k in w. We define the semntics of temporl formuls s follows: (w, j) = p i iff i (j) = 1 = Fφ iff k (j k w nd (w, k) = φ) = Gφ iff k (j k w (w, k) = φ) = Xφ iff { j < w nd (w, j + 1) = φ k1 (j k 1 w nd (w, k 1 ) = ψ = φu ψ iff nd k (j k < k 1 (w, k) = φ)) The Boolen connectives hve the stndrd semntics. Intuitively, (w, j) = φ mens tht φ is stisfied t position j in the word w. We write w = φ for (w, 1) = φ nd define the lnguge L(φ) ccepted y temporl formul contining the propositionl vriles p 1,...,p n to e L(φ) = {w ({0, 1} n ) + w = φ}. Exmple 1.53 The LTL-formul expresses the following property: ) ϕ := G(p 1 X(p 1 Up 2 )) Whenever p 1 holds, then from the next moment on the following holds: p 1 holds until eventully p 2 holds. Consider the model: [ ] [ ] [ ] [ ] [ ] [ ] [ ] w = The formul holds on position 2, ut not on position 1. Consequently, we write (w, 2) = ϕ ut w = ϕ. Exmple 1.54 G(p 1 X( p 2 Up 3 )) expresses in (w, j) with w ({0, 1} 3 ) + the following property:

40 34 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS From position j onwrds, whenever the first component is 1, then from the next position onwrds the second component is 0, until t some position the third component is 1. Exmple 1.55 Let n = 2 nd w = [ ][ ] [ ][ ] [ ][ ] w = G(p 1 Fp 2 ), w = G(p 2 Fp 1 ) w = X( p 2 Up 1 ), w = p 2 Up 1 w = p 1 U(p 1 p 2 ) Theorem 1.56 Every LTL-definle lnguge L Σ + is FO-definle. Lemm 1.57 For every LTL-formul ϕ one cn construct n equivlent FO[S, <]-formul ϕ (x) with (w, j) = ϕ iff (w, j) = ϕ (x) Proof: Inductive definition of ϕ (x): (p i ) (x) ( ϕ) (x) (Gϕ) (x) (Fϕ) (x) := X i (x) := (ϕ (x)), nlogously for,,, := y(x y ϕ (y)) := y(x y ϕ (y)) (Xϕ) (x) := y(s(x, y) ϕ (y)) (ϕuψ) (x) := y ( x y ψ (y) z(x z z < y ϕ (z)) ) Exmple 1.58 ϕ = G(p 1 X( p 2 Up 3 )) ϕ (x) = y(x y X 1 (y) z(s(y, z) s(z s X 3 (s) t(z t t < s X 2 (t))))) So fr we hve shown tht:

41 1.5. BETWEEN FO- AND MSO-DEFINABILITY 35 If L is str-free, then L is FO-definle. If L is LTL-definle, then L is FO-definle. The converses lso hold ut won t e proven in these course notes since this requires much igger technicl effort: Theorem 1.59 (McNughton 1969, Kmp 1968) The conditions FOdefinle, str-free, nd LTL-definle for lnguge L re equivlent. 1.5 Between FO- nd MSO-definility The question tht rises now is whether there is n MSO-definle lnguge tht is not FO-definle. Using the ove equivlences, this questions mens tht we re looking for regulr lnguges tht re not str-free. To this purpose we introduce the counting -property, y which regulr lnguges cn e distinguished from str-free ones. In prticulr, we show tht: There is t lest one regulr lnguge tht is counting. Every str-free lnguge is non-counting. Definition 1.60 Cll L Σ + non-counting if n 0 n n 0 u, v, w Σ : uv n w L uv n+1 w L. This mens for n n 0 either ll uv n w re in L, or none is. Remrk 1.61 The ove condition is strong pumping-property; nmely if for sufficiently lrge n the segment v n occurs in word of L, then we remin in L if we use higher powers of v. Furthermore, note tht the position of v n is ritrry. The stndrd Pumping Lemm gurntees only the existence of position to pump. Definition 1.62 L is not non-counting (short: L is counting) iff n 0 n n 0 u, v, w Σ : (uv n w L uv n+1 w L). Exmple 1.63 L 1 = () + is counting: Given n 0 tke some even numer n n 0 nd set u, w := ɛ, v :=. Then n L 1, ut n+1 / L 1. L 2 = ( ) is counting: Given n 0 tke some even numer n n 0 nd set u :=, v :=, w := ɛ. Then n L 2, ut n+1 / L 2. L 3 = ( + ) is non-counting ecuse it is FO-definle y:

42 36 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS P (min) P (mx) u(s(min, u) P (u)) x y( S(x, y) P (x) P (y) z(s(y, z) P (z) u(s(z, u) P (u)))). Theorems 1.65 nd 1.59 imply tht FO-definle lnguges re noncounting. Remrk 1.64 By counting we men modulo-counting successive occurrences of prticulr pttern (the word v in the definition). L = () is lso sort of counting lnguge since it contins only words of odd length, ut it is not modulo-counting in the ove sense. Theorem 1.65 Every str-free lnguge is non-counting. Proof: By induction on the structure of str-free expressions. Bse cses: For Σ,, ɛ tke n 0 = 2 respectively. Then, for ech of these lnguges L, for ech n n 0, nd for ll u, v, w Σ the following holds: uv n w L uv n+1 w L Induction step : If for suitle n 0 nd for every n n 0 uv n w L uv n+1 w L holds, then oviously this lso holds for the complement of L. Induction step : By induction hypothesis, for L 1, L 2 there re n 1, n 2, such tht for ll n n i uv n w L i uv n+1 w L i (i = 1, 2) Set n 0 = mx(n 1, n 2 ). Then for n n 0 the following holds: uv n w L 1 L 2 uv n+1 w L 1 L 2 Induction step : Tke the induction hypothesis s efore nd set n 0 = 2 mx(n 1, n 2 ) + 1. For n n 0 consider uv n w L 1 L 2. Consider the decomposition of uv n w in two segments, uv n w = z 1 z 2 with z 1 L 1, z 2 L 2 s illustrted in Figure 1.2. By the choice of n 0 one of the following cses pplies. Cse 1: z 1 contins t lest n 1 v-segments. Then y induction hypothesis z 1 (with one v-segment more thn z 1) is in L 1. Cse 2: z 2 contins t lest n 2 v-segments. Then y induction hypothesis z 2 (with one v-segment more thn z 2) is in L 2. In oth cses we get uv n+1 w L 1 L 2. The converse (from uv n+1 w L 1 L 2 to uv n w L 1 L 2 ) cn e proven nlogously.

43 1.5. BETWEEN FO- AND MSO-DEFINABILITY 37 v n u w n 1 n 2 z 1 L 1 z 2 L 2 Figure 1.2: Illustrtion Now tht we distinguished these clsses of lnguges on the level of logic, the nturl thing to sk is whether there is wy to do the sme on the level of utomt. Tht is, is there property of utomt tht chrcterizes the str-free expressions? This question is nswered positively in Section 2.4. In the following we introduce finer complexity scle for (stndrd) regulr expressions tht refers to the numer of occurrences of the str opertor, nd relte this mesure to property of utomt. Definition 1.66 The str-height of regulr expression is defined inductively s follows: sh() = sh( ) = sh(ɛ) = 0 sh(r + s) = sh(r s) = mx(sh(r), sh(s)) sh(r ) = sh(r) + 1 For regulr Lnguge L, the str-height of L is sh(l) = min{n there is regulr expression r with L = L(r) nd sh(r) = n} Remrk 1.67 L is finite iff sh(l) = 0. Theorem 1.68 (Eggn 1963) The str-height hierrchy is strict (over lphets with t lest two letters): For ech n 0 there exists lnguge L n with sh(l n ) = n. For L n we cn tke the fmily of lnguges, recognized y the following NFA (see exercises): n The property of NFAs tht corresponds to the str-height of expressions is the loop complexity (lso feedck numer ).

44 38 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS Definition 1.69 The loop complexity lc(a) of n NFA A is the minimum numer of steps of the following kind required to eliminte ll loops of A: remove one stte in ech strongly connected component of the current trnsition grph Exmple 1.70 Verify tht the following utomton hs loop complexity 2: st step: Remove 1 2nd step: Remove 0 nd 3 Exmple 1.71 lc(a 1 ) = 1, lc(a 2 ) = 2, nd lc(a 3 ) = 3.,, A 1 : 1 2 1st step: Remove 1 nd 2. A 2 : 1 2 1st step: Remove 1 (or 2) 2nd step: Remove 2 (or 1) A 3 : st step: Remove 4 2nd step: Remove 2 nd 6 3rd step: Remove 0 nd 7 Anlogously, we cn define the loop complexity of regulr lnguge. Definition 1.72 The loop complexity of regulr lnguge is lc(l) = min{n there exists n NFA A with L = L(A) nd lc(a) = n} Theorem 1.73 (Eggn 1963) For every regulr lnguge L, sh(l) = lc(l). The proof is refinement of the one for Kleene s theorem (Theorem 1.4). For further detils, plese refer to J.R. Büchi: Finite Automt, Their Algers nd Grmmrs, Sect Theorem 1.74 (Hshiguchi 1988) Given regulr lnguge L (sy defined y n NFA) the str-height cn e clculted lgorithmiclly. For the cse of generlized regulr expressions the generlized str-height gsh is defined nlogously to the one of the stndrd str-height.

45 1.6. EXERCISES 39 Remrk 1.75 gsh(l) sh(l) (i.e. we my e le to reduce the str-height y sustituting some strs y the extended opertors of the generlized regulr expressions) ut in generl we cnnot reduce it to 0 ecuse gsh(l) = 0 iff L is str-free (y definition). There exist regulr lnguges L with gsh(l) 1 (compre Exmple 1.63 on pge 35). Open prolem (since 1971): Are there regulr lnguges L with gsh(l) 2? We suspect tht in cse there is solution, it goes to the direction of nesting modulo-counting since this is the identifying property of non-strfree expressions. We define the lnguges: E = (00) 1 ( even lock ) O = (00) The suggestion of using the lnguge 01 ( odd lock ) specifying n even numer of even locks (((O E)(O E)) O ) filed fter few yers. Theorem 1.76 (Thoms., Theor. Comput. Sci. 13 (1981)) gsh(((o E)(O E)) E ) = 1 Another proposed lnguge L s cndidte for lnguge with gsh(l) = 2 ws (O + E + O + E + ). Also for this lnguge it ws lter proven tht gsh(l) = 1. For detils, plese refer to M. Roson, More lnguges of generlized str height 1, Theor. Comput. Sci. 106 (1992), Exercises Exercise 1.1 Give FO- or MSO-formuls for the lnguges tht re defined y the following regulr expressions or descriptions in colloquil lnguge: () +, (), (c) there re t lest three occurrences of, nd efore the first there re t most two occurrences of. Exercise 1.2 Consider the following NFA A:

46 40 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS In the lecture it ws shown how to construct n equivlent formul ϕ A with four set vriles X 1,, X 4. According to the hint of the lecture, give formul with only two set vriles. (The sttes 1, 2, 3, 4 should correspond to the vectors [ 0 0 ], [ 0 1 ], [ 1 0 ], [ 1 1 Exercise 1.3 () For the MSO-formul give n equivlent MSO 0 -formul. ] ). Is L(A) FO-definle? x y(x < y P (y)) () Let Σ = {, }. The following MSO 0 -formul defines lnguge over Σ {0, 1} 3. Give (y direct construction) n equivlent NFA. (X 1 X 2 ) (X 1 < X 3 ) (X 3 P ). Exercise 1.4 Show tht every regulr lnguge L Σ + is definle y n EMSO-sentence with only one single set quntifier. Exercise 1.5 Let Σ = {, } nd ϕ(x 1, y) := ( P (y) X 1 (y) ), ψ(x 1 ) := y ϕ(x 1, y) nd χ := X 1 ψ(x 1 ). () Write ϕ s n MSO 0 -formul ϕ(x 1, Y ). () Construct n NFA over Σ {0, 1} 2 recognizing L(ϕ(X 1, Y )). (c) Using () construct n NFA over Σ {0, 1} recognizing L(ψ(X 1 )). (d) Using (c) construct n NFA over Σ recognizing L(χ). Exercise 1.6 Consider the following two decidility prolems: () Given n MSO-sentence ϕ, does ϕ hold for ll nonempty word models? () Given n MSO-sentence ϕ, does ϕ hold for ll nonempty word models of even length? Descrie lgorithms for solving these prolems. Exercise 1.7 Consider the word model [ ] w := nd the formuls

47 1.6. EXERCISES ϕ = p 2 U(p 1 p 2 ) nd 2. ψ = G(p 1 Xp 2 ) () For ech j = 1,, 6 nswer whether the formuls hold in (w, j) or not. () Give equivlent FO-formuls nd str-free expressions. Exercise 1.8 For n 1 let A n e the following NFA: n () Show tht L(A n ) is str-free. () Show tht for L(A 2 n) there exists conventionl regulr expression (i.e. only using +,, ) of str-height n. (The str-height of n expression is the mximl numer of nested strs. Exmple: (() + () ) hs str-height 2) (c) Give n LTL-formul for L(A n ). Hint: For (),() it is useful, to consider next to A n lso the utomt A + n, A n ; A + n hs initil stte 0, finl stte n, A n hs initil stte n, finl stte 0. Exercise 1.9 Give str-free expressions for the {[ lnguges ] [ ] [ ] defined [ ]} y the following LTL-formuls. The lphet is Σ =,,,. Write [ ] [ ] [ ] for +, etc. 0 1 () XX(p 1 G p 2 ) () FG(p 1 Xp 2 ) (c) F(p 1 X( p 2 Up 1 )) Exercise 1.10 Decide whether the following lnguges re counting nd verify your ssumption. () () () ()

48 42 CHAPTER 1. AUTOMATA AND LOGICAL SPECIFICATIONS

49 Chpter 2 Congruences nd Minimiztion In this chpter we re interested in reducing the size of utomt while keeping their functionlity. For finite utomt (on words or on trees) the size usully refers to the numer of sttes. The sttes of n utomton or system represent the distinctions tht re mde in order to fulfill certin tsk. The gol is to mke this numer of distinctions s smll s possile. For this purpose we now tke the grph theoretic view (s opposed to the logicl view from the previous chpter) of utomt. As we will see, there re elegnt techniques tht llow us to compre nd improve utomt on the system level, rther thn on the specifiction level. 2.1 Homomorphisms, Quotients nd Astrction There re cses in the nlysis nd design of system, where we re interested only in rough view of its structure nd wnt to spre ourselves the locl detils. In this cse, we ctully represent y model only the topology nd interconnection etween the susystems nd strct wy from their own functionlity. Exmple 2.1 The NFA A 2 on the right-hnd side of Figure 2.1 is rough view on the NFA A 2 on the left-hnd side, where the susystem of the sttes 1, 2, nd 3 (counting s modulo 3) is represented y stte B. This merging of sttes corresponds to the following homomorphism: 0 A, 1 B, 2 B, 3 B Definition 2.2 Let A = (A, R A, f A, c A ), B = (B, R B, f B, c B ) e two structures, with 43

50 44 CHAPTER 2. CONGRUENCES AND MINIMIZATION A B 3 Figure 2.1: Merging sttes in n NFA universes A, B, inry reltions R A A A, R B B B, inry functions f A : A A A, f B : B B B nd distinguished elements ( constnts ) c A A, c B B. A homomorphism from A to B is function h : A B with for x 1, x 2 A: If (x 1, x 2 ) R A, then (h(x 1 ), h(x 2 )) R B for x 1, x 2 A: h(f A (x 1, x 2 )) = f B (h(x 1 ), h(x 2 )) h(c A ) = c B The definition is nlogous for reltions nd functions of other rity. Exmple 2.3 The Prikh-mpping : A = ({, },, ɛ), B = (N N, +, (0, 0)) h(w) = ( w, w ) (Numers of s nd s in w) E.g.: h() = (3, 2) The function h is homomorphism ecuse: for w 1, w 2 {, } : h(w 1 w 2 ) = ( w 1 w 2, w 1 w 2 ) = ( w 1 + w 2, w 1 + w 2 ) = ( w 1, w 1 ) + ( w 2, w 2 ) = h(w 1 ) + h(w 2 ) h(ɛ) = ( ɛ, ɛ ) = (0, 0) Exmple 2.4 Consider gin the NFAs A 1 nd A 2 from Figure 2.1: ({0, 1, 2, 3}, 0, R, 1 R 1, {1}) with R 1 = {(1, 2), (2, 3), (3, 1)} nd R 1 = {(0, 0), (0, 1)} ({A, B}, A, R, 2 R 2, {B}) with R 2 = {(B, B)} nd R 2 = {(A, A), (A, B)}

51 2.1. HOMOMORPHISMS, QUOTIENTS AND ABSTRACTION 45 The domin of this homomorphism h is the stte set of A 1 nd hs the following discrete vlues: h(1) = h(2) = h(3) = B, h(0) = A. It is indeed homomorphism, ecuse every trnsition from R 1 is mpped to trnsition in R. 2 Anlogously for R 1 nd R2. Definition 2.5 Let A 1 = (Q 1, Σ, q 1 0, 1, F 1 ) nd A 2 = (Q 2, Σ, q 2 0, 2, F 2 ) e NFAs. An NFA-homomorphism from A 1 to A 2 is function h : Q 1 Q 2 with h(q 1 0 ) = q2 0 (p,, q) 1 (h(p),, h(q)) 2 q F 1 h(q) F 2 Remrk 2.6 This is covered lso y the generl definition of homomorphism if 1 is decomposed into inry reltions R 1 for ech Σ with: nd nlogously for 2. (p, q) R 1 iff (p,, q) 1 Remrk 2.7 Let h e n NFA-homomorphism from A 1 to A 2. Then the following holds: If A 1 ccepts the word w, then so does A 2. Hence, L(A 1 ) L(A 2 ). In other words strction y homomorphism produces n NFA tht recognizes super-lnguge of the one defined y the initil NFA. Exmple 2.8 Consider A 1 nd A 2 from Exmple 2.4: L(A 1 ) = + () L(A 2 ) = + Remrk 2.9 An NFA-homomorphism h of A yields mtching (or equivlence) of the sttes of A: p, q re h-equivlent iff h(p) = h(q). In short terms: A homomorphism yields stte equivlence. The converse of Remrk 2.9 lso holds, nmely: A stte equivlence yields homomorphism. To this purpose we consider prtitioning of the sttes of the NFA A = (Q,Σ, q 0,, F) nd we write p q if p, q re in the sme clss q/ = {p Q p q} (i.e. they re equivlent ). Definition 2.10 The quotient utomton A/ of A is defined y A/ = (Q/, Σ, q 0 /, /, F/ ) with Q/ = set of -clsses q/ for q Q

52 46 CHAPTER 2. CONGRUENCES AND MINIMIZATION (P,, R) / -clsses P, R P F/ iff there is p P, r R with (p,, r), for iff there exists p P with p F Then: h : q q/ is homomorphism from A to A/. Exmple 2.11 In the following utomton we merge the pirs of sttes (0, 5), (1, 2) nd (3, 4) nd otin the utomton on the right-hnd side., A B C Note tht we drw -trnsition from A to B, lthough there is such trnsition only from 0 to 1 (ut not from 5 to 1) in the initil utomton. This is ecuse the definition requires only the existence of memer in ech clss tht re linked with ech other over such trnsition. Exmple 2.12 On the sme utomton s efore we cn merge the pirs (1, 5) nd (0, 4): 1, 5 2,, 0, 4 3 In oth previous exmples we oserved tht if B results from A y merging sttes, then L(A) L(B). If we could find wy to merge the correct sttes, so tht the resulting utomton recognizes exctly the sme lnguge s the initil one (L(A) = L(B)), then we would hve improved the initil utomton y reducing its numer of sttes, without ffecting its

53 2.1. HOMOMORPHISMS, QUOTIENTS AND ABSTRACTION 47 functionlity. Furthermore, the est possile merging of sttes would led us to n equivlent utomton with the minimum numer of sttes. This is wht we cll the minimiztion prolem of NFAs; nmely given n NFA A, to find n equivlent NFA B tht hs the minimum numer of sttes. But cn we relly chieve this y merging sttes? The following two exmples give n nswer to this question. Exmple 2.13 Let A e n NFA nd cll A q the sme NFA s A ut with different initil stte, nmely q. To minimize A we suggest to merge two sttes p, q, if L(A p ) = L(A q ). Tht is, if A ccepts the sme lnguge oth strting from p nd from q, then we shll merge p nd q., A B C In the utomton ove there is no pir tht cn e merged in wy descried efore: A vs. C: From A, is ccepted, from C not, A vs. B: From B, ɛ is ccepted, from A not, B vs. C: From B, ɛ is ccepted, from C not. But still, it is ovious tht the utomton cn e minimized since sttes A nd B suffice to ccept the sme lnguge, nmely Σ. Unfortuntely, things re even worse since there re cses where even if we try ll possile mergings (without following specific rule s in the previous exmple), we will not find the miniml NFA. Exmple 2.14 Consider the lnguge L = Σ Σ, over Σ = {, }. Oviously the miniml utomton A tht recognizes L is the following:,, Another (not miniml) utomton B recognizing L is the following:

54 48 CHAPTER 2. CONGRUENCES AND MINIMIZATION We oserve tht there is no proper quotient utomton of B tht recognizes L. This mens tht in the generl cse of the minimiztion of n NFA it does not suffice to merely merge the existing sttes. 2.2 Minimiztion nd Equivlence of DFAs We first look t the minimiztion prolem for DFAs. In this cse we cn successfully pply the techniques tht we studied in the previous section nd furthermore we hve n efficient lgorithmic solution. Before strting, we hve to dopt more strct view on DFAs, nmely consider them s lgers. Definition 2.15 Let Σ = { 1,..., n }. A DFA A = (Q,Σ, q 0, δ, F) cn e represented s structure A = (Q, q 0, δ 1,...δ n, F) with δ i : Q Q, defined y δ i (p) := δ(p, i ). This is n lger with distinguished suset F. Every word w = 1... m induces function δ w : Q Q, which is defined s composition of δ 1,...,δ m : δ w (p) = δ m (δ m 1 (...δ 1 (p)...)). A ccepts w iff δ w (q 0 ) F. We re going to pply the homomorphisms on the structures A. Exmple A B 4 3 Looking t the utomton on the right-hnd side we oserve tht with we remin t the sme stte, wheres with we switch from A to B nd vice vers. So, δ 2 is the identity function nd δ 2 is the permuttion A B, B A. To the utomton on the left-hnd side we pply homomorphism h defined y h(1) = h(4) = A, h(2) = h(3) = B. To ensure tht it is indeed

55 2.2. MINIMIZATION AND EQUIVALENCE OF DFAS 49 homomorphism we hve to check for ech p {1, 2, 3, 4} the homomorphism condition: or in stndrd syntx: h(δ 1 (p)) = δ 2 (h(p)), h(δ 1 (p)) = δ2 (h(p)) h(δ 1 (p, x)) = δ 2 (h(p), x) for x Σ. Next, we dpt the definition of NFA-homomorphism introduced in the previous section to the cse of DFAs. Definition 2.17 Let A 1 = (Q 1, Σ, q 1 0, δ1, F 1 ) nd A 2 = (Q 2, Σ, q 2 0, δ2, F 2 ) e DFAs. A DFA-homomorphism from A 1 to A 2 is homomorphism h : Q 1 Q 2 etween the corresponding lgers. This mens: h(q0 1) = q2 0 h(δ 1 (p, )) = δ 2 (h(p), ) h(f 1 ) F 2 If h is ijective function nd h(f 1 ) = F 2, then h is clled n isomorphism. Exmple 2.18 From the left utomton we proceed to the right one y merging 1 with 3 nd 2 with A B C This corresponds to homomorphism h with: h(0) = A, h(1) = h(3) = B, h(2) = h(4) = C. This homomorphism is lso DFA-homomorphism, ecuse oth the initil nd the resulting utomt re DFAs. Exmple 2.19 On the sme utomton s in the previous exmple we mke different merging of sttes, nmely 1 with 2 nd 3 with 4.

56 50 CHAPTER 2. CONGRUENCES AND MINIMIZATION, A B 4 3 C The mpping h(0) = A, h(1) = h(2) = B, h(3) = h(4) = C yields n NFA-homomorphism, ut not DFA-homomorphism. We oserve tht if we wnt to preserve determinism in the resulting utomton, we cnnot merge ny pirs of sttes, even if this dheres to the conditions of the NFAhomomorphism. There must e some dditionl reltion etween the two sttes efore they re merged. Remrk 2.20 Every DFA-homomorphism induces n NFA-homomorphism; the converse does not hold. This mens tht if DFA-homomorphism from A to B exists, then L(A) L(B) holds (s result of the induced NFAhomomorphism). Remrk 2.21 A prtitioning of sttes with corresponding equivlence defines DFA-homomorphism iff is congruence with respect to the trnsition functions δ for ech Σ nd preserves the distinction etween finl nd non-finl sttes. Formlly: p q δ (p) δ (q) nd p q (p F q F) Definition 2.22 A DFA-homomorphism from A = (Q,Σ, q 0, δ, F) to B defines quotient-dfa of A in the following wy: We set p q iff h(p) = h(q) nd define A/ = (Q/, Σ, q 0 /, δ/, F/ ) with Q/ = the set of -clsses q/ for q Q δ/ (p/, ) = δ(p, )/ p/ F/ iff p F Explntion: The definition of δ/ (p/, ) is independent of the representtive p. This goes lso for F/. Definition 2.23 For DFA A = (Q,Σ, q 0, δ, F), where w.l.o.g. we suppose tht ll sttes re rechle from q 0 we define p A q, if L(A p ) = L(A q ). Equivlently: δ w (p) F iff δ w (q) F for ll w Σ.,

57 2.2. MINIMIZATION AND EQUIVALENCE OF DFAS 51 Remrk 2.24 ) A is right congruence, i.e. n equivlence reltion nd if p A q nd Σ, then δ (p) A δ (q). ) The DFA A/ A is clled the reduced DFA of A, short A red nd L(A) = L(A red ). Definition 2.25 (Nerode congruence) Let L Σ. u L v iff for ll w Σ uw L vw L. This mens tht for ny future w, u nd v need not e distinguished with respect to L. We often use the negtion of this equivlence to prove tht two words elong in different equivlence clsses, nmely u L v iff there exists some w with uw L nd vw L (or uw L nd vw L). Exmple 2.26 Consider the lnguge L = (). nd re not equivlent: Tke w = ɛ, then w = L ut w = L.,,,... re for exmple equivlent. ɛ,,, re pirwise not equivlent. Remrk 2.27 L is right congruence with respect to conctention, which mens tht if u L v, then u L v nd generlly uw L vw. Proof: Show tht u L v, i.e. uy L vy L for ll y Σ : uy L u(y) L y ssumption v(y) L vy L Nottion: For the L -clss of u we write [u] L or just [u]. In DFA A tht recognizes L, we oserve tht if oth u nd v led to the sme stte, then u L v. This holds ecuse from δ(q 0, u) = δ(q 0, v) we imply δ(q 0, uw) = δ(q 0, vw) nd consequently uw L vw L. This mens tht there cn e t most tht mny L -clsses s there re sttes: Remrk 2.28 If DFA A recognizes the lnguge L, then: Numer of L -clsses numer of A-sttes. It follows tht if L is regulr, then L hs finite index, i.e. there re finitely mny equivlence clsses. Definition 2.29 (Cnonicl DFA) Let L e lnguge with finite index( L ). The cnonicl DFA A L = (Q L, Σ, q 0L, δ L, F L ) for L is defined s follows: Q L := { [u] L u Σ } the (finite) set of L -clsses, q 0L := [ε],

58 52 CHAPTER 2. CONGRUENCES AND MINIMIZATION δ L ([u], ) := [u] nd F L := {[u] u L}. Exmple 2.30 Let L = {, } {, }. There re four different L - clsses: [ε] L, [] L, [] L, [] L. Since [ε] L = [] L, [] L = [] L = [] L, [] L = [] L = [] L we otin the following cnonicl utomton for L: [ε] L [] L [] L [] L, Proposition 2.31 The cnonicl utomton A L ccepts L. Proof: A L ccepts w δ(q 0L, w) F L [w] L F L w L A L hs index( L ) mny sttes. So A L is DFA ccepting L with the minimum possile numer of sttes. The following theorem shows tht A L is unique up to isomorphism. Theorem 2.32 (Min DFA-Minimiztion Theorem) If the DFA A = (Q,Σ, q 0, δ, F) recognizes L, then the DFA A red is isomorphic to A L. Proof: We hve to show tht for A red = (Q,Σ, q 0, δ, F) there is ijection f : Q Q L with f(q 0 ) = q 0L, f(f) = F L nd f(δ(q, )) = δ L (f(q), ). Definition of f: Pick for ny stte q of A red word u q with δ(q 0, u q ) = q nd let f(q) := [u q ] L. Oviously f is n isomorphism etween A red nd A L. Exmple 2.33 Consider the following utomton, which is oviously the miniml one tht cn recognize the lnguge L = (). To mp this utomton to cnonicl one, we choose the following isomorphism: 1 [ɛ] 2 [] = [] 3 [] 4 [] = []

59 2.2. MINIMIZATION AND EQUIVALENCE OF DFAS 53, Our im is to compute from ny DFA A DFA B s in Theorem 2.32, nd thus otin miniml deterministic utomton. Given DFA A = (Q,Σ, q 0, δ, F) we hve to determine the equivlence clsses of A. But to fix two equivlent sttes, we hve to exmine ll possile words tht the utomton my red from those sttes, nd exmine whether they led the utomton to finl stte or not. Tht is why we prefer the converse: we identify ll pirs of sttes tht re not A -equivlent. In other words, we identify those pirs p, q for which the following holds: there exists w, such tht one of the two sttes δ(p, w) nd δ(q, w) is in F nd the other one not To fix n pproprite w we proceed stepwise on its length. In the first step we tke w = ɛ nd seprte ll finl sttes from the non-finl ones: (F, Q\F). In the next step (ecuse p A q δ(p, ) A δ(q, )) we declre two (not yet seprted) sttes p nd q s non-equivlent, if for some Σ, δ(p, ) nd δ(q, ) re non-equivlent s well. According to this concept we refine the clssifiction (F, Q \ F) s long s this is possile. Formlly, the prtition Q \ F hs to e split in two with respect to F if: there exist p, q Q \ F nd letter, with δ(p, ) F nd δ(q, ) F; then the prtition Q \ F is split into {p Q \ F δ(p, ) F } nd {p Q \ F δ(p, ) F }. For every following step nd currently ville prtition (B 1,...,B k ) the tsk is generlly descried s follows: B i is eing split in two with respect to B j nd, if there exist p, q in B i, such tht δ(p, ) B j, ut δ(q, ) B j This prtitioning splits B i into ( ) {p B i δ(p, ) B j } nd {p B i δ(p, ) B j }

60 54 CHAPTER 2. CONGRUENCES AND MINIMIZATION A B C D E F G AD BG E C F Figure 2.2: Prtition refinement Prtition refinement lgorithm: 1. Initiliztion: B 1 = F, B 2 = Q \ F 2. While there exist B i, B j, with ( ), prtition B i with respect to B j nd. Exmple 2.34 We wnt to find equivlence clsses in the utomton from the left-hnd side of Figure 2.2. The initil prtition is (ABDEFG, C) nd we now stepwise split these locks ccording to ( ): 1st step: Splitting ABDEFG w.r.t. C nd yields BG nd ADEF. 2nd step: Splitting ADEF w.r.t. BG nd yields AD nd EF. 3rd step: Splitting EF w.r.t. C nd yields E nd F. initiliztion ABDEF G C 1st step BG ADEF 2nd step AD EF 3rd step E F The resulting minimized utomton is shown on the right-hnd side of Figure 2.2. Q

61 2.2. MINIMIZATION AND EQUIVALENCE OF DFAS 55 Complexity of the lgorithm: There cn e t most Q 1 splits. Every loop requires t most to clculte δ(q, ) for q Q nd Σ (for checking condition ( )). Altogether this sums up to O( Σ Q 2 ). We conclude tht the minimiztion of DFA cn e done in second-order polynomil time with respect to the numer of sttes. This cn e improved y the lgorithm of Hopcroft, which requires only O( Q log Q ) time. Now tht we know n efficient lgorithm to minimize DFAs, we cn use it to construct n efficient equivlence test, ccording to the following corollry. Corollry 2.35 (of the Min Minimiztion Theorem) Two DFAs over Σ re equivlent, if nd only if the corresponding reduced utomt re isomorphic. This mens tht we cn use the following lgorithm to check, whether two DFAs re equivlent: 1. Given two DFAs A, B construct their reduced versions A red, B red. 2. Strting from the initil stte perform redth-first serch in A red, B red nd nme ech reched stte q with the smllest word tht leds to it, ccording to the cnonicl order. 3. Check whether the trnsition tles nd the finl sttes re identicl. Time complexity: O(n log n), like for the minimiztion. Exmple 2.36 We consider the cnonicl utomton of Exmple 2.33 nd pply the equivlence test lgorithm. With redth-first serch we first visit, [ε] [] [] [] [ɛ] [] [] [] [] [] [] [] [] [] [] [] the initil stte [ɛ] nd write it into the trnsition tle. In the next loop we visit [] nd from there []. We enter oth under [ɛ]. In the next loop we rech gin [], ut tke no ction, ecuse we hve lredy seen this stte. In the lst loop we visit [] nd write it down into the trnsition tle. We complete the trnsition tle for every stte tht we reched

62 56 CHAPTER 2. CONGRUENCES AND MINIMIZATION nd every symol of the lphet. If we follow the sme procedure on the reduced version of ny other utomton, we cn find out whether it recognizes the sme lnguge s the one ove, y simply compring the resulting trnsition tles. To end up the minimiztion of DFAs we consider specil cse of lnguges, nmely the ones with specific word length over the lphet Σ = {0, 1}. It is oviously out finite lnguges L {0, 1} n, i.e. the sets of ll it sequences of length n. Remrk 2.37 A lnguge L {0, 1} n specifies oolen function f : {0, 1} n {0, 1} ccording to the following mpping: nd vice vers. f( 1,..., n ) = 1 iff 1... n L Such lnguges cn e defined y specil kind of DFA, nmely one tht hs no cycles, ut rther the form of decision tree. The nturl question to sk now, is whether we cn pply some similr kind of prtition refinement in this kind of DFA to construct reduced digrm. We illustrte this ide y the following exmple. Exmple 2.38 Consider the formul (x y) z. We write the corresponding decision tree, where continuous line denotes trnsition with 1 (s n interprettion of the strting node) nd dotted one, trnsition with 0. A doule line mens tht the sme trnsition is tken either with 0 or with 1. y x z z z z Becuse the oolen function cn tke only two vlues, nmely 0 or 1, we only need two leves. By merging similr leves, we get the following digrm, which is not tree nymore: y x y z z z z 0 1 We oserve tht the 3 leftmost z s hve the sme view on the prt of the tree tht is elow them, i.e. they see 1 through trnsition with 0, nd 0 through trnsition with 1. Tht is why we cn merge these nodes nd get the following digrm (left): y

63 2.3. EQUIVALENCE AND REDUCTION OF NFAS 57 x y y z z 0 1 x y z 0 1 Finlly, node tht leds to its (only) successor with oth 0 or 1 cn e eliminted, ecuse it does not ffect the finl result. This leds us to the finl minimized digrm ove (right). Formlly the procedure cn e descried y the following reduction rules: 1. Merge two nodes p, q if they hve isomorphic structures. (This corresponds to the reltion p A q for DFA A) 2. In cse there exist trnsitions p q nd q 0 r, q 1 r, strike out q nd introduce the trnsition p r. Note tht the second rule mkes use of the fct tht the nodes re leled y the nmes of the vriles. This wy, striking out node does not led to processing the wrong its. If we pply these reduction rules on decision tree, until no rules cn e pplied nymore, then the resulting digrm is clled Reduced Ordered Binry Decision Digrm (ROBDD). Theorem 2.39 (Min Theorem on ROBDDs) The ROBDD for oolen function does not depend on the order, in which the reduction rules re pplied: it is unmiguously defined up to isomorphism. Corollry 2.40 The equivlence test for definitions of oolen functions cn e reduced on the isomorphism test of ROBDDs. 2.3 Equivlence nd Reduction of NFAs In this section we exmine whether the prolems tht we efficiently solved in the lst section on DFAs re likewise efficiently solvle in the cse of NFAs. The min motivtion towrds this gol is the fct tht miniml NFAs cn e exponentilly smller thn equivlent miniml DFAs with respect to the numer of sttes. Exmple 2.41 Consider the lnguge L n = the set of words over {, } hving n on the n-th position efore the end. A miniml NFA cn recognize this lnguge with n + 1 sttes y guessing when the n-th lst position is eing red nd initite run of n trnsitions to the finl stte. On the contrry, miniml DFA would lwys hve to memorize the lst n letters tht it hs processed y hving uilt in pth for ech possile comintion. This needs oviously 2 n sttes.

64 58 CHAPTER 2. CONGRUENCES AND MINIMIZATION By this exmple we relize tht the minimiztion of NFAs cn sve up lot of spce when modeling system. Unfortuntely, this does not come without cost. In prticulr, in this section we del with the following issues: The PSPACE-hrdness of the equivlence prolem nd the minimiztion prolem for NFAs An efficient reduction of NFAs using the isimultion equivlence etween sttes The Universl NFA nd the serch for miniml NFA We ddress only the decision prolems of minimiztion, equivlence nd non-universlity nd show tht even these re PSPACE-hrd. NFA Minimiztion Prolem Given: NFAs A, B over the sme lphet Question: Is B miniml NFA equivlent to A? NFA Equivlence Prolem Given: NFAs A, B over the sme lphet Question: Are A nd B equivlent? NFA Non-Universlity Prolem Given: NFA A over the lphet Σ. Question: Does L(A) Σ hold? At the first glnce this lst prolem looks very similr to our firly known (nd y the wy very efficiently solvle) non-emptiness prolem. However, we will see tht there is ig difference etween them. Before we strt, let us refresh our memory with some issues out of Complexity Theory. We know tht decision prolem is P, NP or PSPACE if it cn e solved y Turing Mchine (TM) in polynomil time non-deterministic TM in polynomil time TM using t most polynomil spce respectively. Remrk 2.42 We code decision prolem y lnguge L s follows: L contins the word codings of those instnces, for which the expected nswer is yes.

65 2.3. EQUIVALENCE AND REDUCTION OF NFAS 59 Furthermore, we lso know tht P NP PSPACE nd we strongly suspect tht the inclusions re proper. Definition 2.43 A lnguge L 0 is PSPACE-complete, if 1. L 0 elongs to PSPACE 2. Every lnguge L PSPACE, sy over the lphet Σ, is reducile in polynomil time to L 0 (short: L p L 0 ), i.e. there exists function F on Σ, such tht it is computle in polynomil time nd for ll w Σ w L iff F(w) L 0 holds. In colloquil English, this mens tht prolem tht hs this property is t lest s hrd s ny other prolem in PSPACE. L 0 is PSPACE-hrd, if the second condition holds. Exmple 2.44 QBF, nmely the evlution prolem for quntified oolen formuls is PSPACE-complete. Our im is now to prove tht ll three decision prolems mentioned ove re PSPACE-hrd, i.e. they re not efficiently solvle like in the cse of DFAs. (It cn e lso shown tht they elong to PSPACE, ut we re not going to del with tht prt of the proof.) For the cse of the Non- Universlity Prolem of NFAs we hve to prove tht for every L in PSPACE L p NFA Non-Universlity Prolem holds. Lemm 2.45 For n ritrry lnguge L Σ tht elongs to PSPACE, there exists trnsformtion F tht is computle in polynomil time, such tht F : Σ set of ll NFAs over Σ with ( ) w L iff NFA F(w) does not ccept ll words over Σ. Proof: Let M e Turing Mchine tht decides L using polynomil spce. We define M y tuple M = (Q,Σ, Γ, q 0, δ, F) with stte set Q, initil stte q 0 Q, finl stte set F Q working lphet Γ, input lphet Σ Γ (with distinguished lnk symol in Γ \ Σ) trnsition function δ : (Q \ F) Γ Γ {N, L, R} Q A trnsition δ(p, ) = (, L/R/N, q) implies: when eing in stte p nd reding n on the working cell, write there, move the hed to the left / move the hed to the right / don t move the hed nd go to stte q. Now ssume the TM M decides L nd is spce-ounded y some polynomil p(n). The computtionl sitution, in which M is, is descried y its configurtion, which is defined y the word tht is written on the left of the

66 60 CHAPTER 2. CONGRUENCES AND MINIMIZATION working cell, the current stte nd the word tht is written on the right of the working cell. So, configurtion of M hs the form uqv. Let w = 1... n. An ccepting computtion M, w is word over Γ Q {#} of the following form: u 0 q 0 v 0 # u 1 q 1 v 1 #... # u s q s v s #, where 1. u 0 =... nd v 0 = w..., nd u 0, v 0 hve een chosen in such wy tht throughout the whole computtion M visits only the cells occupied y u 0, v 0, so u i + v i = p(n) 2. u i+1 q i+1 v i+1 is successor configurtion of u i q i v i 3. u s q s v s is configurtion with q s F The purpose of the reduction is to find trnsformtion F computle in polynomil time with F : Σ set of ll NFAs over the lphet Σ hving the property: ( ) w L iff NFA F(w) does not ccept ll words in (Σ ) We choose Σ = Γ Q {#} nd we define the NFA F(w) in such wy tht it ccepts exctly the words tht re not n ccepting M, w-computtion. Then ( ) holds! To chieve this, the NFA F(w) hs to check whether on the input u one of the constrints 1. to 3. is indeed violted. In other words, the NFA hs to verify tht: 1. The input word does not egin with u 0 q 0 v 0 #, 2. OR there re two consecutive segments u i q i v i #u i+1 q i+1 v i+1 #, such tht u i+1 q i+1 v i+1 is not successor configurtion of u i q i v i 3. OR tht the lst configurtion does not contin finl stte. The first condition cn e tested with p(n)+2 sttes (ecuse u 0 v 0 = p(n)). The second condition cn e tested y guessing 3 consecutive cells, whose updte (fter p(n) + 2 positions) is not correct. O(p(n) + 2) sttes suffice for this test. Explntion: Assume tht the trnsition function of the Turing Mchine implies δ(p, ) = (, L, q) nd consider the following two consecutive configurtions (without the squre rckets):...[][p]...#...[][q] }{{} p(n)+2 The utomton my compre the three consecutive cells in the first squre rckets with the ones tht re p(n) + 2 positions wy. In the cse tht none of these cells is currently (or in the previous step) occupied y the

67 2.3. EQUIVALENCE AND REDUCTION OF NFAS 61 hed of the Turing Mchine, one cell would suffice for the comprison. But in cse one of the cells contins the stte of the Turing Mchine (like in the second squre rckets) three cells re required. In the exmple ove the NFA verifies tht the Turing Mchine chnged from stte p to q, moving the hed to the left (tht is why the q is now written on the left of the tht ws previously on the left of the p) nd printing n on the. In this exmple the cells dhere to the trnsition function. In the generl cse the Turing Mchine hs to guess such pir of triples where this does not hold. It is now ovious tht O(p(n) + 2) sttes suffice for this test, where the constnt represents the spce tht is required to sve triple of cells like it ws mentioned ove. The lst condition cn e trivilly tested y using memory stte to rememer the informtion no finl stte hs een seen etween the lst two #. Consequently, from M nd w we cn construct the pproprite NFA F(w) s union-nfa from the three utomt mentioned ove with p(n)+2, const (p(n)+2) nd 5 sttes respectively. Altogether, this NFA hs polynomilly mny sttes with respect to n = w, which lso mens tht the trnsformtion w F(w) is computle in polynomil time. Thus, we hve proven the following theorem: Theorem 2.46 The NFA-Non-Universlity Prolem is PSPACE hrd. Now tht we hve extensively delt with the non-universlity prolem on NFAs, let us compre it with much more esily solvle prolem tht looks (t lest t the first glnce) similr to it, nmely the non-emptiness prolem for NFAs. So, given n NFA A we compre the following questions: 1. L(A) =? or the negtion L(A)? 2. L(A) = Σ? or the negtion L(A) Σ? The first question is out the existence of n pproprite w nd the existence of some corresponding ccepting run on it, which, s we know, is solvle in liner time (y performing redth-first or depth-first serch). On the contrry, the second prolem is out the existence of n ccepting run for ech possile w, or for the existence of such w tht ll possile runs on it re rejecting. Now we cn see tht there is ig difference in terms of logic etween the two prolems. The first one contins two consecutive existentil quntifiction wheres the second is expressed y universl quntifiction followed y n existentil one (or vice vers in the cse of the negtion). The PSPACE hrdness of the second prolem relies exctly on this lterntion of the existentil nd the universl quntifier. It is esy to see tht the universlity prolem of n NFA A over Σ is specil cse of the equivlence prolem etween A nd the stndrd NFA A 0 with just one stte tht is lso finl one (oviously ccepting Σ ). Likewise,

68 62 CHAPTER 2. CONGRUENCES AND MINIMIZATION it is specil cse of the minimiztion prolem is A 0 miniml NFA for A?. Hence, oth the NFA-equivlence prolem nd the NFA-minimiztion prolem hve to e t lest s hrd s the NFA-universlity prolem. Theorem 2.47 NFA-equivlence prolem nd the NFA-minimiztion prolem re PSPACE hrd. Since we hve proven tht we cnnot minimize NFAs in n efficient wy, we try to find wy t lest to reduce them, e.g. y merging two sttes tht hve een found to e equivlent. For this reson we consider the reduction of NFAs, y using the stte equivlence: p A q ( whether strting from p or from q the sme lnguge is recognized ). For NFAs there re still two prolems: 1. As it ws shown efore: The quotient NFA does not hve to e the miniml NFA. 2. Fixing pirs of equivlent sttes is hrd, ecuse it requires n NFA equivlence test. The question now is, whether there exists stte equivlence tht is oth efficiently computle nd lnguge preserving (i.e. such tht the quotient NFA is equivlent to the originl one). To define this equivlence we need to introduce specil kind of NFAs with the convention tht the finl sttes re exctly those sttes without outgoing trnsitions. Definition 2.48 (Leled Trnsition System) A Leled Trnsition System (LTS) is tuple A = (Q,Σ, ), where Q is set of sttes, Σ is n lphet nd is trnsition reltion. By dding n initil stte q Q, we get (A, q), pointed LTS. We consider pointed LTS (A, q 0 ) s usul NFA, where the set of finl sttes F A is implicitly defined s {q Q there is no (q,, q ) }. Definition 2.49 (Bisimultion gme) A isimultion gme BG(A, p 0, B, q 0 ) is plyed etween plyers I (proposer) nd II (responder) on leled trnsition systems A = (Q A, Σ, A ) nd B = (Q B, Σ, B ). A configurtion is pir (p, q) Q A Q B. The initil configurtion is (p 0, q 0 ). A round of gme hs two steps. From configurtion (p, q) plyer I picks trnsition (p,, p ) A or (q,, q ) B nd plyer II responds with trnsition (q,, q ) B or (p,, p ) A respectively. The new configurtion is now (p, q ). If plyer I cnnot choose trnsition he loses. If plyer II cnnot respond correctly he loses. If ply goes on forever, plyer II wins.

69 2.3. EQUIVALENCE AND REDUCTION OF NFAS 63 A strtegy is mpping σ : (Q A Q B ) + (Q A Q B ) for plyer I nd similrly σ : (Q A Q B ) + (Q A Q B ) (Q A Q B ) for plyer II. A winning strtegy for plyer II ensures tht for every configurtion (p, q) tht is reched while II plys ccording to this strtegy, plyer I will not win the BG(A, p, B, q). (A, p 0 ) nd (B, q 0 ) re clled isimilr, (A, p 0 ) (B, q 0 ), if plyer II hs winning strtegy in BG(A, p 0, B, q 0 ). In the specil cse tht (A, p) (A, q) we cll p nd q -equivlent (p q). Proposition 2.50 (A, p 0 ) (B, q 0 ) L(A p0 ) = L(B q0 ) Proof: By ssumption plyer II hs winning strtegy in BG(A, p 0, B, q 0 ). We show L(A p0 ) L(B q0 ). (The other direction is similr to this one.) Assume w L(A p0 ). We pply the winning strtegy of plyer II to ply where plyer I moves in A from p 0 to F A y pth leled w. Plyer II relizes pth in B strting from q 0 nd leled with w. We hve to check tht the lst stte of this pth is in F B. But this is cler, ecuse otherwise plyer II would lose in the next step. The following exmple shows tht the converse direction of proposition 2.50 fils. Exmple 2.51 Consider the following two NFAs: c c They ccept the sme lnguge, ut they re not isimilr (oth strted on their leftmost stte). Remrk 2.52 Bisimultion equivlence is finer thn lnguge equivlence. This mens tht it results to correct ut not optiml reduction of n NFA. To compute the isimultion equivlence etween two LTS we hve to check for ll sttes p, q whether (A, p) (B, q). Agin, similr to the minimiztion lgorithm for DFAs, we determine the pirs p, q where plyer I hs winning strtegy (showing non-equivlence). Remrk If p F A nd q F B, or vice vers, plyer I wins fter his first move.

70 64 CHAPTER 2. CONGRUENCES AND MINIMIZATION Input: LTS A = (Q A,Σ, A ), B = (Q B,Σ, B ) 1. Mrk p,q Q A Q B if p F A q F B 2. while some sttes hve een mrked in the lst itertion do 3. Mrk ech pir p,q previously unmrked for which there is (p,,p ) A such tht for ll (q,,q ) B (p,q ) is mrked 4. Mrk ech pir p,q previously unmrked for which there is (q,,q ) B such tht for ll (p,,p ) A (p,q ) is mrked. 5. od Output: All mrked pirs. Figure 2.3: Bisimultion Mrking Algorithm 2. If plyer I cn pick (p,, p ) A such tht for ll (q,, q ) B tht plyer II cn choose, plyer I wins from (p, q ), then from (p, q) plyer I wins. Similrly, if plyer I cn pick (q,, q ) B such tht for ll (p,, p ) A tht plyer II cn choose, plyer I wins from (p, q ), then from (p, q) plyer I wins. The Remrk 2.53 motivtes the mrking lgorithm for mrking pirs (p, q) with (A, p) (B, q) shown in Figure 2.3. Exmple 2.54 We pply the mrking lgorithm to reduce the NFA shown elow. According to our convention, the finl sttes re 4 nd 6. Tht is why efore entering the loop, we mrk ll pirs, where exctly one of those two sttes occurs. In the first loop we mrk the pir (2, 1) ecuse we cn choose to move from 2 with, ut we cnnot move with the sme letter from stte 1. We lso mrk the pir (5, 2) ecuse there exists trnsition with from 5 tht leds to stte 6 tht is lredy mrked with every stte tht is rechle from 2 with the sme trnsition (nmely 3, since it is the only stte rechle with nd (6, 3) is mrked). Continuing like this, the lgorithm termintes leving the pirs (5, 3) nd (6, 4) unmrked.

71 2.3. EQUIVALENCE AND REDUCTION OF NFAS X X X X X X X X X X X : It is not necessry to look t this field. 0 : This field ws mrked efore entering the loop (finl nd non-finl sttes). i : This field ws mrked in the i-th loop (i = 1, 2,...). This mens tht we cn merge these sttes in the reduced utomton. The resulting NFA is shown elow nd it hppens to e lso miniml one , 5 4, 6 The lgorithm termintes fter Q A Q B loops (ll possile pirs of sttes). Every loop requires the considertion of ech previously unmrked pir (p, q) y checking the corresponding outgoing trnsitions, i.e. computtionl effort tht is proportionl to Q A A + Q B B. Altogether, if A, B hve Q A + Q B = n sttes nd A + B = m trnsitions, then the mrking lgorithm termintes in time O(n 3 m). Better lgorithms re known working in time O(n log 2 (n)) (Pge nd Trjn, 1987). NFA A PTIME NP-hrd smllest NFAs A 0, A 1,...,A k gp in size A isimultion quotient of A There is vrint of BG(A, p, B, q) tht results to wider equivlence clsses, nd is therefore often considered s more pproprite. It is clled the lternting simultion nd the min difference to isimultion is tht this time plyer I hs to sty in the NFA tht he chose in his first move, i.e. he cnnot ritrrily switch etween the two NFAs. In this cse the quotient NFA is gin lnguge equivlent nd efficiently computle. Exmple 2.55 For the following NFAs the lternting simultion holds, ut not the isimultion.

72 66 CHAPTER 2. CONGRUENCES AND MINIMIZATION Finlly, there is n lterntive technique tht leds not only to the reduced, ut even to the miniml NFA. The ide relies on the fct tht given n NFA with n sttes, there re only finitely (of course exponentilly) mny NFAs with less thn n sttes. The following procedure illustrtes, how we cn construct (in most cses huge) NFA tht contins ll equivlent smller NFAs nd in which we cn restrict our ttention only to those NFAs who relly hve the possiility to e miniml ones. Given regulr lnguge L, there is indeed cnonicl NFA, in which we cn serch for the miniml one; it is constructed s follows: 1. Determine the miniml DFA A L (powerset construction nd DFA-minimiztion) 2. In A L invert ll trnsitions nd switch ll finl sttes to initil ones nd vice vers nd thus otin the NFA A L. 3. Once gin pply the powerset construction to otin D(A L ) (deterministic). 4. Invert this DFA too nd otin D(A L ). 5. The Universl-NFA C is constructed out of the stte sets of the lst NFA. The NFA D(A L ) hs sttes A 1,...,A k, ech of them consisting of A L - sttes. The sttes of the Universl-NFA C re sets of the form {A i1,...,a im }, where A i1... A im must hold. For further detils, plese refer to O. Mtz, A. Potthoff, Computing Smll Nondeterministic Automt. Theorem 2.56 The Universl-NFA of L contins ech miniml NFA recognizing L s n induced NFA for n pproprite suset of its sttes. This confirms our initil clim, nmely tht the miniml NFA cn e found within the Universl-NFA.

73 2.4. THE SYNTACTIC MONOID The Syntctic Monoid In this section we introduce structure tht chrcterizes regulr lnguge ut lso contins neutrl element nd enles us to perform inry opertions just like in the cse of nturl numers. The reson why we find such structure very useful to descrie lnguge, is tht the set of ll words follows the sme concept (neutrl element, inry opertions) ut utomt don t. In other words we shll see tht using this structure we cn directly identify chrcteristics of lnguge tht cnnot e directly hndled y utomt, like for exmple whether lnguge is str-free (i.e. FO-definle or LTL-definle) Exctly s the miniml DFA is cnonicl cceptor for regulr lnguge L, we define further cnonicl cceptor M(L), the syntctic monoid for L, with the sme signture s for ll words over Σ, nmely (Σ,, ɛ). There is close reltion etween the monoid structure nd the trnsition structure of the miniml DFA A L. This reltion is presented in the following. First, we refine the Nerode congruence y mking it symmetric: Definition 2.57 For lnguge L Σ we define: u L v if x, y Σ : xuy L xvy L. Remrk 2.58 L is right congruence with respect to conctention, i.e. L is n equivlence reltion nd u L v, u L v uu L vv. If u L v nd u L v, then xuu y L iff xvv y L for ll words x nd y. Remrk 2.59 u L v implies u L v (tke x = ε). The converse does not hold in generl. Exmple 2.60 Consider the lnguge L =. L, ecuse for ll w Σ : w / L nd w / L. But L, ecuse ɛ / L, nd ɛ L. Nottion: The L -clss of u Σ is denoted y u L. Let Σ / L e the set of ll L -clsses. A multipliction (conctention) etween L -clsses is defined y representtives: u L v L := uv L. The product is well-defined ecuse L is right congruence. Remrk 2.61 (Σ,, ɛ) is monoid (i.e. is ssocitive, nd ɛ is the neutrl element).

74 68 CHAPTER 2. CONGRUENCES AND MINIMIZATION The structure M(L) := (Σ / L,, ɛ ) is lso monoid, nmely the syntctic monoid of L. But how cn we construct the correct monoid for lnguge? We do this y pplying specific trnsformtions on the utomton (we tke the cnonicl one) tht recognizes this lnguge. Let A = (Q,Σ, q 0, δ, F) e DFA. Every word w Σ induces stte trnsformtion w A : Q Q tht is defined y w A (q) := δ(q, w). Note tht ɛ A = id Q (identity function). The composition goes s follows: u A v A is the function (uv) A : u A v A (q) = v A (u A (q)). Remrk 2.62 The structure T(A) = ({u A u Σ },, id Q ) is monoid, nmely the trnsition monoid of A. Note tht over Q, there re t most Q Q mny functions. This mens tht the trnsition monoid of DFA is finite. If Q = {0,...,n}, then we represent the stte trnsformtion u A y the sequence u A (0),..., u A (n) of vlues on the sttes of the DFA. Exmple 2.63 Consider the following utomton nd the trnsformtions eside ɛ A : (0 1 2) A : (1 2 0) A : (2 0 1) One cn esily see tht there re no other (different) trnsformtions on this DFA, e.g. A = ɛ A or A = A. But of course this is no proof tht we hve indeed found ll possile trnsformtions. There is forml method to determine ll functions u A nd it goes s follows: 1. Go through ll words u in cnonicl order, until no new functions occur. 2. Drw n -leled rrow from u A to (u) A Exmple 2.64 Let L 1 := { w Σ w 0 (mod 3) }. The DFA A L1 is shown elow:

75 2.4. THE SYNTACTIC MONOID ε Hving determined the functions from the previous exmple, we drw the trnsition monoid (on the right). Exmple 2.65 Consider the lnguge L 2 := { w Σ w 0 (mod 2) } recognized y the following utomton A L2 :, 0 1, 3 2, 0123 ɛ ,,,, The corresponding trnsition monoid T(A L2 ) is drwn on the right. Exmple 2.66 L 3 := () is recognized y the following utomton A L3 : 0 1 2, The corresponding trnsition monoid T(A L3 ) is drwn on the right. Now we cn proceed to constructing the syntctic monoid. For this purpose we prove the following theorem. 012 ε , Theorem 2.67 Let L e regulr nd A L the miniml utomton recognizing L. The syntctic monoid M(L) is isomorphic to the trnsition monoid of A L, short: M(L) = T(A L ).

76 70 CHAPTER 2. CONGRUENCES AND MINIMIZATION Hence, y constructing the trnsition monoid (y using the previously illustrted method) nd y pplying the lst theorem, we otin the syntctic monoid. Proof: Define f : M(L) T(A L ) y f( u ) := u A L. f is the pproprite isomorphism. f is well-defined nd injective ecuse Verifiction: u = v iff x, y: xuy L xvy L u = v iff u A L = v A L. iff x: [xu] = [xv] (y definition) iff x: u A L([x]) = v A L([x]) (Note tht [x] is stte of A L nd u A L([x]) = [xu]) iff u A L = v A L f is surjective, ecuse u A L = f( u ) for ll u A L T(A L ) Finlly, f is homomorphism, ecuse f( u v ) = f( uv ) = (uv) A L = u A L v A L = f( u ) f( v ) Now we cn use these results to identify the clss, in which lnguge elongs. For exmple, in the previous chpter we hve shown tht the strfree lnguges re non-counting. In the following we show tht it cn e identified, whether lnguge is non-counting, y the property group-free of the syntctic monoid. Furthermore, we show tht for regulr lnguges, the properties non-counting nd str-free coincide. Definition 2.68 An element m of monoid M is clled idempotent, if m m = m. Every suset of M tht forms group through multipliction, hs exctly one idempotent element. This is the neutrl element of the group. We cll monoid M group-free if the only occurring susets tht form groups re the trivil ones {m} with n idempotent m. Exmple 2.69 We look t the monoid of previous exmple.

77 2.4. THE SYNTACTIC MONOID ε 120 ɛ ɛ ɛ ɛ ɛ Oviously the whole monoid represents non-trivil group, since it is counting modulo-3. The two multipliction nd ddition tles show the correspondence etween this monoid nd the group (Z 3, +) respectively. Exmple 2.70 Consider the following two monoids ɛ ,,,, ɛ 122 The left one hs two groups, ech one of the type Z 2, while the right one does not hve ny non-trivil groups, i.e. it is group-free. Theorem 2.71 (Schützenerger 1965) Let L e regulr. L is str-free if nd only if M(L) is group-free. According to this theorem, one cn lgorithmiclly decide, whether given regulr lnguge is str-free , Exmple 2.72 According to the previous exmples: 1. L 1 := { w Σ w 0 (mod 3) } is not str-free. 2. L 2 := { w Σ w 0 (mod 2) } is not str-free. 3. L 3 := () is str-free. Theorem 2.71 llows even the genertion of str-free expression out of given group-free monoid. This is implemented in the AMoRE system. We cn lso determine whether monoid M(L) is group-free y directly nlyzing the corresponding miniml DFA A L. The required property is given in the following definition.

78 72 CHAPTER 2. CONGRUENCES AND MINIMIZATION Definition 2.73 A DFA A = (Q,Σ, q 0, δ, F) llows permuttions, in cse there exist suset Q 0 Q nd word w Σ +, such tht w A Q0 represents non-trivil permuttion on Q 0. In the opposite cse A is clled permuttion-free. Exmple 2.74 We exmine the miniml deterministic utomt recognizing the three lnguges of the previous exmples. A L1 : This DFA llows permuttions. Tke Q 0 = {0, 1, 2} nd w =. Then A L 1 {0,1,2} represents non-trivil permuttion on {0, 1, 2} ( ). 0 1 A L2 :, 3, 2, This DFA llows permuttions. Tke Q 0 = {1, 2} nd w =. Then A L 2 {1,2} represents non-trivil permuttion on {1, 2} ( ). A L3 : 0 1 2, This DFA is permuttion-free. Finlly, we gther ll the previous properties of regulr lnguge in the following theorem. Theorem 2.75 For regulr lnguge L the following conditions re equivlent: () L is non-counting.

79 2.4. THE SYNTACTIC MONOID 73 () The miniml DFA A L is permuttion-free. (c) The syntctic monoid M(L) is group-free. (d) L is str-free. According to the theorem of Schützenerger (c) (d). In the following we show not (c) not (), not () not (), not () not (c). Proof (from group to permuttion): Assume M(L) is not group-free, sy hving group G. Choose g G other thn the neutrl element of G nd consider the cyclic group {g, g 2,...,g k } with g k s neutrl element. g = u corresponds vi the isomorphism M(L) = T(A L ) to the trnsformtion u A L. Then g i = u i, nd the following holds: 1. (u k ) A L = (u 2k ) A L 2. (u k ) A L (u k+1 ) A L Now choose q, such tht δ(q, u k ) δ(q, u k+1 ). Set Q 0 = {δ(q, u k ), δ(q, u k+1 ),...,δ(q, u 2k 1 )}. Then u A L is permuttion on Q 0. Proof (from permuttion to modulo-counting): Let the trnsformtion v A L e permuttion π on Q 0. Choose q Q 0 nd otin the elements q, π(q), π 2 (q),..., π m (q) = q. Then δ(q, v km ) = q, δ(q, v km+1 ) = q q. Choose u, w such tht δ(q 0, u) = q, nd not δ(q, w) F δ(q, w) F. Now we hve to show tht for ny ritrrily lrge n: u, v, w: not uv n w L uv n+1 w L Tke n = km where k is ritrry. Then it does not hold tht δ(q 0, uv km w) F δ(q 0, uv km+1 w) F Proof (from modulo-counting to group): Note tht in every finite monoid ech element m hs power m k tht is idempotent. Now set K = the smllest common multiple of these k-vlues. For every element m of monoid m K = m 2K ( ). By hypothesis there re ritrrily lrge n s (lso > K), such tht for pproprite u, v, w: uv n w L ut uv n+1 w L For such n n then v n v n+1. Becuse of ( ), v K = v 2K. Then v K v K+1 must hold. Now v K+1 forms group in M(L).

80 74 CHAPTER 2. CONGRUENCES AND MINIMIZATION 2.5 Exercises Exercise 2.1 Find fmily (L n ) n>0 of lnguges over {, }, such tht L n is recognized y DFA with O(n) sttes, nd every DFA tht recognizes L R n hs t lest 2 n mny sttes. Hint: The first utomton of Exmple 2.14 points to the right direction. (L R n = { n 1 1 n L} is the lnguge of the flipped words.) Exercise 2.2 Consider the following lgorithm tht is pplied on DFA A (over Σ = {, }): 1. Invert A, i.e. turn the A-trnsitions to the opposite direction nd switch the initil sttes with the finl ones. Otin A R. (Note tht the utomton my hve severl initil sttes.) 2. Apply the powerset construction (construct only the rechle sttes). Otin D(A R ). (The initil stte of this utomton is the set of initil sttes of the NFA.) 3. Invert D(A R ), otin (D(A R )) R. 4. Apply the powerset construction s in (2), otin D((D(A R )) R ). Show tht the resulting utomton is the miniml utomton for A. Exercise 2.3 Consider the lnguge L = ( + ) over the lphet {, }. () Give representtives for the five L -clsses. () Verify tht the representtives re pirwise not lnguge equivlent, i.e. for ny pir u, v, u L v holds (construct tle, where for ech pir seprting word w is entered). (c) Using () give the miniml utomton A L for L. Exercise 2.4 () Apply the minimiztion lgorithm (pge 54) in order to minimize the following DFA (descrie the steps s in Exmple 2.34): ,

81 2.5. EXERCISES 75 () Construct the isimultion quotient à of the following NFA A: 8,, 5,, 4, Exercise 2.5 Consider the DFA A without finl sttes s given y the following trnsition grph: Choose finl sttes such tht A is miniml, or show tht this is impossile. Exercise 2.6 Show tht there exists fmily of regulr lnguges lnguges (L n ) n>0 such tht L n is recognized y n different (not isomorphic) miniml NFAs. Hint: The editors do not know the solution yet. Exercise 2.7 () determine the trnsition monoid of the following utomton ccording to the method presented in the lecture:, Mrk with circle the idempotent elements. () Determine the trnsition monoid (with 13 elements) of the following utomton: Give non-trivil group.

82 76 CHAPTER 2. CONGRUENCES AND MINIMIZATION Exercise 2.8 Give fmily of DFAs A n = (Q n, Σ, q n 0, δ n, F n ), n > 0, with Q n = n over the lphet Σ = {,, c}, such tht the trnsition monoid of A n hs exctly n n elements. Hence, every mpping f : Q n Q n hs to e implemented y word in Σ.

83 Chpter 3 Tree Automt In the lst two chpters we delt with two fundmentl issues in the world of finite utomt, nmely estlishing connection to logicl (or logic-like ) expressions nd discovering lgeric ides nd methods to solve typicl prolems on finite utomt. In this chpter we re going to generlize the model of finite utomton itself, nd use it for processing generlized inputs (i.e. not only finite words). This cn e done in two different dimensions. One is to lift the constrint of finiteness nd consider infinite inputs such s the run of non-terminting procedure. In this cse we re not nymore interested in reching some finl stte ut rther in ensuring stility, e.g. y pssing gin nd gin through certin stte. The other is to consider (finite) inputs tht re rnching rther thn eing linerly ordered (i.e. letters follow one nother). The first dimension goes eyond the scope of this course nd is the core of the next semester s course out utomt over infinite ojects. The second dimension leds to the tree utomt nd tree lnguges, which re our min suject in this chpter. Our primry motivtion relies on the fct tht trees model structured ojects, which hppen to e very frequent in computer science. Even the finite words we were deling with in the previous chpters re specil cse in this ctegory; they represent liner trees (only one successor). The fundmentl questions we re going to nswer re ccordingly generliztion of the ones we considered in the lst two chpters, i.e.: Which techniques cn we orrow from the re of finite words? How cn we construct utomt tht descrie the properties of trees? How cn we define equivlent formlisms like regulr expressions nd logicl formuls? Are there efficient lgorithms for the fundmentl prolems (nonemptiness, equivlence nd minimiztion of utomt)? 77

84 78 CHAPTER 3. TREE AUTOMATA Finlly, we exmine some pplictions in the re of descriing structured ojects such s context-free lnguges nd XML-Documents. 3.1 Trees nd Tree Lnguges Trees rise nturlly s structured dt, s terms, or s processes with rnching ehvior. Exmple 3.1 The term x (π + z) corresponds to tree: x + π z A Boolen term (x y) 1 corresponds to tree: 1 x y A context-free grmmr (CF): S AA, A c AB, B induces derivtion tree: S A A c A B In the cse of context-free syntx of progrmming lnguge, derivtion tree cptures the structure of progrm. Exmple 3.2 Consider the mini-lnguge of WHILE-progrms. An exmple progrm in this lnguge would e the Eucliden lgorithm for the gretest common divider: {Input in x 1, x 2 } x3 := x1; x4 := x2; WHILE x3 <> x4 DO

85 3.1. TREES AND TREE LANGUAGES 79 IF x3 < x4 THEN x4 := x4 - x3 ELSE x3:= x3 - x4 END END {the vlue of x 3 is gcd(x 1, x 2 )} A forml definition of the WHILE-progrms includes: terminl lphet: Σ keyord non-terminl symols: S for progrm W for ssignmentofvlue V for vrile D for deciml numer Z for positive digit F for sequence of deciml digits B for condition O for comprison opertor E for rithmetic expression grmmr S W S; S IF B THEN S ELSE S END WHILE B DO S END W V := E V XD D 0 Z ZF F 0 Z 0F ZF Z E D V (E + E) (E E) (E E) B EOE O = < > <> =< => According to this definition possile syntx tree of the gcd-progrm looks s follows: S S ; S W S ; S W W HILE B DO S EN D... IF B THEN S ELSE S END We know tht it is very importnt to point out the hierrchicl structure of progrm even in its norml text representtion. Tht is why progrmmers use indents to show how expressions re nested in ech other. A similr

86 80 CHAPTER 3. TREE AUTOMATA wy to represent the structure of derivtion tree in norml text form is the use of specil rcketing. For every non-terminl symol X the rckets ( X nd ) X re introduced. Then, the derivtion tree t for w is coded y the word w t tht is produced y inserting rcketing symols into w. Exmple 3.3 The derivtion tree on the left cn e coded y the word on the right. A S A A B c ( S ( A ( A c ) A ( B ) B ) A ( A ) A ) S XML-documents re lso coding trees in norml text form. Here, the rcketing nottion is slightly modified: X is used for ( X nd /X is used for ) X. Exmple 3.4 Consider the following XML-document: <ProfileOfStudies> <fculty> Computer Science </fculty> <semester> 3 </semester> <courses> <title> PROGRAMMING </title> <title> COMPUTER STRUCTURES </title> <title> DATA STRUCTURES </title> </courses> </ProfileOfStudies> The min difference etween the previous exmples nd XML-documents is tht in the ltter the rnching degree is generlly unlimited. For exmple there is no restriction on the numer of titles tht the courses -g my contin. This cse is considered in further detil lter. Definition 3.5 A rnked lphet is non-empty finite set Σ of symols, where every symol is ssigned finite set rk() N (the set of ll rnks or rities of ). Σ i := { Σ i rk() } Σ = Σ 0 Σ m (where m = mx{rk() Σ}) Note tht the Σ i need not e disjoint.

87 3.1. TREES AND TREE LANGUAGES 81 Exmple 3.6 The rnked lphet for the term x (π + z) from Exmple 3.1 is Σ = {, +,, x, π, z} with Σ 2 = {+, }, Σ 1 = { } nd Σ 0 = {x, π, z}. Exmple 3.7 The rnked lphet for the term (x y) 1 from Exmple 3.1 is Σ = {0, 1,,, } with Σ 0 = {0, 1}, Σ 1 = { }, Σ 2 = {, }. Exmple 3.8 The rnked lphet for the context-free grmmr from Exmple 3.1 is Σ = {,, c, A, B, S} with Σ 0 = {,, c}, Σ 1 = {A, B}, Σ 2 = {S, A}. We first define trees in term-like fshion. Definition 3.9 Let Σ = Σ 0... Σ n e rnked lphet. The set T Σ of trees (or terms) over Σ is defined inductively y: Ech symol Σ 0 is tree T Σ. For f Σ k nd t 1...t k T Σ, f(t 1...t k ) is tree in T Σ depicted y f A set T T Σ is clled tree-lnguge. t 1 t 2... t k 1 t k Remrk 3.10 This definition of trees llows inductive definitions of functions on the set of Σ-trees proofs y induction over the construction of Σ-trees. Exmple 3.11 Inductive definitions: 1. The frontier word yield(t) of tree t (the lelling of the leves of t red from left to right) is inductively defined y yield() = for Σ 0, yield((t 1,...,t i )) = yield(t 1 ) yield(t i ) for Σ i (i > 0). 2. Semntics of WHILE-progrms Let WHILE n e the set of WHILE-progrms with the vrilesx1,...,xn. Ech such progrm computes prtil function f : N n N n. Let F n e the set of these functions. Then, the semntics of progrm is function σ : WHILE n F n tht is defined inductively over the structure of the progrm. Exmple 3.12 An inductive proof for the rithmeticl terms over {0, 1, +, }:

88 82 CHAPTER 3. TREE AUTOMATA Hypothesis: 0 or 1. The modulo-3 vlue of term t with t most one 1, is either Inductive proof: 1. Induction strt: Verify the hypothesis for the terms 0 nd Induction step: Assume the hypothesis is fulfilled for t 1, t 2. Show tht the hypothesis holds for (t 1 + t 2 ) nd (t 1 t 2 ) (y simply distinguishing the possile cses). An lterntive, ut equivlent, definition of trees distinguishes the treedomin, which is the set of underlying nodes, from their vlues under n evlution function. Exmple 3.13 Below the tree ssocited to the term (x y) 1 nd its underlying domin is shown. The evlution function vl stisfies vl(ɛ) = ; vl(1) =,... 1 ɛ 1 2 x y Definition 3.14 Let Σ = Σ 0... Σ n e rnked lphet. A Σ- vlued tree is tuple t = (dom t, vl t ) where dom t is prefix closed suset of {1,...n} stisfying ui dom t uj dom t for every j < i, nd vl t : dom t Σ mps node u with k successors to symol in Σ k. 3.2 Tree Automt Deterministic Tree Automt Definition 3.15 A deterministic tree utomton (DTA) is tuple A = (Q,Σ, δ, F) where Q is finite set of sttes, Σ is rnked lphet,

89 3.2. TREE AUTOMATA 83 F Q is set of finl sttes, nd δ : i 0 (Qi Σ i ) Q is trnsition function. By convention Q 0 Σ 0 := Σ 0. The evlution function δ : T Σ Q is defined inductively y δ () = δ() for Σ 0, nd δ (f(t 1...t i )) := δ(δ (t 1 ),...,δ (t i ), f) for f Σ i nd t 1,...,t i T Σ. A DTA A ccepts tree t T Σ if δ (t) F. The tree-lnguge recognized y A is T(A) = {t T Σ A ccepts t}. Exmple 3.16 We define tree utomton ccepting ll true Boolen expressions over Σ = {,,, 0, 1}. Let Q = {q 0, q 1 } e the stte set, F = {q 1 } e the set of finl sttes, nd δ e defined y δ(0) = q 0 δ(1) = q 1 δ(q i, ) = q i 1 δ(q i, q j, ) = q min(i,j) δ(q i, q j, ) = q mx(i,j) Definition 3.17 T is clled DTA-recognizle or regulr, if there exists DTA A with T = T(A). Exmple 3.18 The set of the true logicl expressions (the ones tht cn e evluted to 1) is regulr. Exmple 3.19 (on rithmetic expressions) Let Σ = Σ 0 Σ 2 with Σ 0 = {0, 1}, Σ 2 = {+, }. We construct tree utomton tht recognizes the tree lnguge T = {t T Σ vlue of t = 0 (mod 3)}. A tree tht elongs to this lnguge is shown in the picture elow. On the sme picture, the run of the utomton, which we intend to construct, is shown; nmely we use 3 sttes to distinguish the 3 different cses in modulo-3 counting. + q 0 q2 + q 1 1 q 1 + q 2 0 q 0 1 q 1 1 q 1 1 q 1 Formlly: We use stte set Q = {q 0, q 1, q 2 }, where q i mens tht the modulo-3 reminder of the evluted term is i. Oviously, q 0 is the only finl stte. The trnsition function is defined explicitly for ech possile vlue

90 84 CHAPTER 3. TREE AUTOMATA of its rguments, using prmetric formultion for mtters of compctness: δ(0) = q 0, δ(1) = q 1 δ(q i, q j, +) = q i+j mod 3, δ(q i, q j, ) = q ij mod 3 In the following we consider 3 further exmples of lnguges, in order to get more fmilir with constructing DTAs. Exmple 3.20 Let Σ = Σ 0 Σ 1 Σ 2 with Σ 0 = {0, 1}, Σ 1 = {g},nd Σ 2 = {f}. We define tree utomt for the lnguges T 1 = {t T Σ there is n odd numer of f s in t} T 2 = {t T Σ there re t lest two f s in t} T 3 = {t T Σ on the frontier of t there is no 1 efore 0} For T 1 let Q = {q 0, q 1 } nd F = {q 1 }. q 0 signls n even numer of f s nd q 1 n odd numer of f s in the sutree elow the current node. This induces the following trnsition function: δ(0) = δ(1) = q 0 δ(q i, g) = q i δ(q i, q j, f) = q (i+j+1) mod 2 For T 2 let Q = {q 0, q 1, q 2 } (signling respectively no, one nd t lest two occurrences of n f in the sutree elow the current node) nd F = {q 2 }. This induces the following trnsition function: δ(0) = δ(1) = q 0 δ(q i, g) = q i δ(q i, q j, f) = q min(i+j+1,2) For T 3 let Q = {q 0, q 1, q 01, q 10 } nd F = {q 0, q 1, q 01 }. A node of the tree is leled with stte q 01 if ll 0 s re efore the first 1 in the frontier word of the sutree elow this node. q 10 signls tht there is 1 somewhere left of 0 on the frontier, nd q 0, q 1 signl tht only 0 s, respectively 1 s, pper on the frontier of the corresponding sutrees. The mening of the sttes is implemented in the following trnsition function: δ(0) = q 0, δ(1) = q 1, δ(q, g) = q for ll q Q, δ(q 0, q 0, f) = q 0 δ(q 01, q 0, f) = q 10 δ(q 1, q 1, f) = q 1 δ(q 01, q 1, f) = q 01 δ(q 0, q 1, f) = q 01 δ(q 0, q 01, f) = q 01 δ(q 1, q 0, f) = q 10 δ(q 1, q 01, f) = q 10, nd δ(p, q, f) = q 10 for ll other comintions of sttes p, q Q.

91 3.2. TREE AUTOMATA 85 Tree lnguges cn lso e defined y the rules of context-free grmmrs. How do these lnguges relte to the regulr lnguges we illustrted so fr? Definition 3.21 If G = (N, T, P, S) is context-free grmmr, then let T(G) e the set of ll derivtion trees generted y G (with frontier words consisting of T-symols). For this definition we ssume tht ɛ is not used in the grmmr. Exmple 3.22 The derivtion tree on the right elongs to the lnguge defined y the grmmr on the left. S AA A c AB B S A A c A B The following theorem shows tht this kind of tree lnguges forms proper suset of the regulr ones. Theorem 3.23 ) If G is context-free grmmr, then T(G) is regulr. ) Not every regulr tree lnguge cn e represented s lnguge T(G) for context-free grmmr G. Proof: (prt ) Given grmmr G = (N, T, P, S) we construct DTA with stte set N T { } nd finl stte S. The tree utomton should e le to copy the tree symols into its sttes, s long s the tree is uilt up (in ottom-up fshion) ccording to the rules of G. Hence, the input lphet consists of Σ 0 = T nd Σ i = {X N there exists rule X α with α = i} (for i > 0). The trnsition function is defined s follows: δ() = for Σ 0 δ(σ 1,...,σ i, X) = X for X σ 1... σ i P for i > 0, X Σ i δ(σ 1,...,σ i, X) = otherwise ( error stte) δ(σ 1,...,σ i, ) = Proof: [prt ] It suffices to show tht there exists tree lnguge tht cnnot e represented s lnguge of derivtion trees. For this reson we consider the set T contining ll trees with the following property: ( ) On every pth there re t most two A s nd there exists t lest one pth with two A s.

92 86 CHAPTER 3. TREE AUTOMATA Looking t this property, on the one hnd we oserve tht T is regulr lnguge ecuse ( ) is conjunction of two properties tht cn e esily recognized y DTA. On the other hnd we lso oserve tht in cse symol A occurs twice in pth of derivtion tree t (s result of sequence of grmmr rules), then it is possile to produce trees with n ritrry numer of A s on the sme pth (using the sme sequence of rules gin nd gin). Consequently, T is recognizle y DTA ut cnnot e of the form T(G) for grmmr G. Finlly, we illustrte n exmple of lnguge tht elongs to higher clss in the sense tht it is not recognizle y DTA. Exmple 3.24 Let Σ = Σ 0 Σ 2 with Σ 0 = {}, Σ 2 = {}. We show tht the lnguge T := { (t, t) t T Σ } is not recognizle. By (t, t) we men wht is shown in the picture elow, where t is (su)tree. t t When reding the root of tree, the only informtion DTA cn get from the two sutrees elow, is the sttes it reches t the top of ech sutree. Hence, the ide to prove this ssumption (s well s other similr ones) is to show tht the finitely mny sttes of the DTA do not suffice to compre the infinitely mny different sutrees. Proof: Towrds contrdiction, we ssume tht the DTA A = (Q,Σ, δ, F) recognizes T. Since we do not hve restriction on the length of the tree, there re oviously infinitely mny trees over Σ. But ecuse Q is finite, there exist two different trees t, t with δ (t) = δ (t ) nd hence lso δ ((t, t)) = δ ((t, t )) (t this point the utomton cnnot distinguish etween t nd t nymore, since oth led it to the sme stte). Now, since δ ((t, t)) F lso δ ((t, t )) F, which mens tht (t, t ) T. Contrdiction. In cse we wnt to generte similr repetition of sttes, this time only on the sme pth, we use nother method tht relies on the pumping lemm. To chieve this we first hve to formlly descrie how we cn conctente trees to get longer nd longer pths. In the cse of finite words no specil definition ws required, ecuse it is ovious tht we ppend word t the (only) end of nother one. In the cse of finite trees we do not hve one specific end, ut insted numer of leves; hence we hve to lwys declre t which one of them we ppend new tree when conctenting. Definition 3.25 Let Σ e rnked lphet nd c new symol of rnk 0. A specil tree over Σ is tree over Σ {c}, where c occurs exctly once (s lef). We cll S Σ the set of ll specil trees over Σ. For t T Σ or

93 3.2. TREE AUTOMATA 87 t S Σ nd s S Σ let t s e the tree, tht results from s y replcing c y t. Theorem 3.26 (Pumping Lemm) Let T e regulr tree lnguge. Then, for n pproprite n (nmely the numer of sttes of tree utomton recognizing T) the following holds: If the height of t T is n, then there re two nodes on pth of t tht cn split t in three pieces t 0, s 1, s 2, such tht n itertion (ritrrily often) of s 1 c results in trees tht lso elong to T. In short nottion: t = t 0 s 1 s 2 with t 0 (s 1 ) i s 2 T for every i 0. Proof: Assume T is recognized y some tree utomton with n sttes. If the height of t is n, then on some pth of the run tree of t there hve to e two positions, where stte repetition occurs. Define the split t = t 0 s 1 s 2 on these two positions. Now we cn pply this theorem to show the non-recognizility for further exmples of tree lnguges, where n equlity not etween sutrees, ut etween the lengths of ll pths in the whole tree (complete trees) is required. Exmple 3.27 Let Σ = Σ 0 Σ 2 with Σ 0 = {e}, Σ 2 = {, }. The lnguge T = {t T Σ t is complete } is not regulr. (A tree t is complete iff ll its pths hve the sme length). Proof: Towrds contrdiction, ssume tht T is regulr (i.e. recognized y some DTA). Then, consider split ccording to the Pumping Lemm. By repeting the middle prt twice, we get tree tht is ccepted, lthough it is not complete. Contrdiction. By the previous two exmples we relized tht DTAs re not powerful enough to solve some fundmentl questions over trees. There re still some other interesting prolems reducile to recognizing tree properties tht cn e chrcterized y finitely mny sttes. The prolem of type checking tht is emedded in every modern progrmming lnguge represents such n issue. Exmple 3.28 Consider the type informtion of functions elow on the left. A compiler hs to check whether term like the one represented y the tree on the right, is dhering to these rules. 0 nt 1 nt + : nt nt nt + : int int int s : int nt nt int + s

94 88 CHAPTER 3. TREE AUTOMATA To nswer this purpose, DTA is used tht hs stte for ech one of the types (finitely mny). The DTA evlutes the term using the type rules s trnsitions nd ssumes n error stte in cse of type mismtch. The run tree of the utomton is shown elow: nt nt nt int nt nt nt Becuse the s-function is not defined on nt, the lst rule (nmely tht nt is sutype of int) hs to e pplied first. This corresponds to the implicit type csting in progrmming lnguges nd is implemented y ɛ-trnsitions in the tree utomton Nondeterministic Tree Automt Definition 3.29 A nondeterministic tree utomton (NTA) is tuple A = (Q,Σ,, F) where Q is finite stte set, Σ = Σ 0... Σ m is rnked lphet, F Q is set of finl sttes, nd m i=0 (Qi Σ i Q) is trnsition reltion. By convention Q 0 Σ 0 Q = Σ 0 Q. A run of A on tree t T Σ is mpping ρ : dom t Q such tht for lef nodes u dom t we hve (vl t (u), ρ(u)), nd for nodes u with successors u1,...,ui we hve (ρ(u1),...,ρ(ui), vl t (u), ρ(u)). An NTA A ccepts tree t T Σ if for some run ρ of A on t ρ(ɛ) F. The tree-lnguge recognized y A is T(A) = {t T Σ A ccepts t}. Exmple 3.30 Let Σ = Σ 0 Σ 1 Σ 2 with Σ 0 = {0, 1}, Σ 1 = {g}, nd Σ 2 = {f}. Let T = {t T Σ some pth through t hs even length }.

95 3.2. TREE AUTOMATA 89 We construct n NTA tht guesses pth through t, counts modulo-2 the length of this pth, nd lels ll other nodes with dummy symol. Let Q = {q 0, q 1, } nd F = {q 0 }. The trnsition reltion implements the ide ove. := { (0, ), (1, ), (0, q 0 ), (1, q 0 ), (q 0, g, q 1 ), (q 1, g, q 0 ), (, g, ), (q 0,, f, q 1 ), (q 1,, f, q 0 ), (, q 0, f, q 1 ), (, q 1, f, q 0 ) (q 0, q 0, f, ), (q 1, q 1, f, ), (,, f, ) } In the cse of utomt over finite words, nondeterminism does not offer ny dditionl expressive power. The following theorem shows tht the sme hppens in the cse of tree utomt. Theorem 3.31 For ech NTA one cn construct n equivlent DTA. Proof: For given NTA A = (Q,Σ,, F) we construct DTA A = (Q, Σ, δ, F ) where Q = 2 Q, F = {P Q F P }, δ() = {q Q (, q) } for Σ 0, nd δ(p 1,...,P i, f) = {q Q q 1 P 1... q i P i : (q 1,...,q i, f, q) } for f Σ i. It remins to show tht for every t T Σ, δ (t) is the set of those sttes q Q, for which run of A on t exists reching q t the root of t. By induction on the construction of t, one cn esily see tht: Then: A ccepts t iff δ (t) F iff q δ (t) F q rechle y A on the root of t iff q δ (t). iff q run ρ of A on t with ρ(ɛ) = q nd q F iff A ccepts t. The closure properties lso hold, s they do for NFAs.

96 90 CHAPTER 3. TREE AUTOMATA Theorem 3.32 The clss of regulr tree lnguges is closed under the Boolen opertions (,, complement) nd under projection. This cn e esily shown y copying the following well-known proofs: intersection nd union y product utomton, complement s with norml NFAs, for the projection f : Σ Γ (ssumed s rnk preserving) chnge from trnsition (q 1, q 2,, q) to (q 1, q 2, f(), q). A nturl thing to sk is whether there re ny results tht cnnot e directly trnsferred from word utomt to tree utomt. Unfortuntely, the nswer to this question is positive. Until now, we were using tree utomt tht process trees from the leves to the root (ottom-up). We cn lso introduce utomt tht evlute their input in the opposite direction (top-down) nd show tht in this cse reduction from nondeterminism to determinism is not possile. Definition 3.33 A nondeterministic top-down tree utomton ( NTA) over Σ = Σ 0 Σ m is of the form A = (Q,Σ, Q 0, ) with finite stte set Q, Q 0 Q s set of initil sttes, m i=0 (Q Σ i Q i ) (The pirs in (Q Σ 0 ) re lso clled finl comintions ). An ccepting run of A on t is mpping ρ : dom t Q with ρ(ɛ) Q 0, for ech node u of t with i > 0 successors, we hve ( ρ(u), vlt (u), ρ(u1),..., ρ(ui) ), for ech lef u of t, ( ρ(u), vl t (u) ) is finl comintion. A ccepts t if nd only if there exists run on t. Remrk 3.34 Norml NTAs cn e directly trnsformed to NTAs nd vice vers. A DTA is specil NTA tht hs singleton set {q 0 } s n initil stte set Q 0, trnsition functions δ 1,...,δ m with δ i : Q Σ i Q i insted of nd finl comintions exctly like NTA. A tree t is ccepted y the unmiguous run on t. This lso mens tht stte ssumed on position of the run tree cn only depend on the nodes of the pth ck to the root. The exmple lnguge considered elow shows tht DTA cn recognize less thn NTA (in contrst to wht hppens in the cse of ottom-up tree utomt).

97 3.2. TREE AUTOMATA 91 Remrk 3.35 The douleton set { T := f } f, is recognizle y NTA (nd n NTA s well), ut not y DTA. Proof ( NTA recognizility): The following NTA recognizes T: Q := {q 0, q, q } Q 0 := {q 0 } := {(q 0, f, q, q ), (q 0, f, q, q ), (q, ), (q, )} Proof ( DTA non-recognizility): Towrds contrdiction we ssume tht the DTA A recognizes T. Then, A ccepts f, with the unmiguous run f q 0 q 1 q 2 This mens tht δ(q 0, f) = (q 1, q 2 ) nd (q 1, ) nd (q 2, ) re finl comintions. A likewise ccepts f with the run f q 0 q 1 q 2 Consequently, (q 1, ) nd (q 2, ) re lso finl comintions. Hence A lso ccepts f(, ). Contrdiction Emptiness, Congruences nd Minimiztion Theorem 3.36 The emptiness prolem for nondeterministic tree utomt is decidle in polynomil time. Proof: Given n NTA A, the min ide for the proof is to consider the set E A of ll sttes tht re rechle on the roots of input trees nd note tht T(A) iff E A contins finl stte. Then, E A is computed in the following wy: For h = 0, 1, 2,... determine the sttes tht re rechle on trees of height h, until no new sttes rise. Now verify whether the computed set contins finl stte.

98 92 CHAPTER 3. TREE AUTOMATA Emptiness lgorithm: Input: A = (Q,Σ,, F) E 0 := {q Q (, q) for some Σ 0 } n := 0 Repet n := n + 1 E n := E n 1 {q Q there exists q 1,...,q i E n 1, Σ i with (q 1,...,q i,, q) } Until E n = E n 1 If E n F = output( empty ) else output( non-empty ) Note tht since Q is finite, the lgorithm termintes. The effort in terms of time complexity is O( Q ( Q )). Correctness: It hs to e shown tht E n = E A for the smllest n with E n = E n 1. The inclusion E n E A cn e esily shown y induction over n. To prove the opposite inclusion E A E n, we hve to show tht if q is rechle on tree of height i, then q E i (induction). Now i N E i = E n holds nd hence, if q E A, then lso q E n. The Nerode congruence for trees is defined using the notion of specil trees introduced previously. Herey, when ppending tree t T Σ to specil tree s S Σ, to construct t s, s is clled the context of t in t s. Definition 3.37 (Nerode congruence) Define T T Σ T Σ for T T Σ y: t 1 T t 2 for ech specil tree s S Σ : t 1 s T t 2 s T Exmple 3.38 Let Σ = Σ 0 Σ 2 with Σ 0 = Σ 2 = {, } nd the lnguge T with T = { t T Σ on every rnch of t there re two consecutive occurrences of n }. Consider the trees t = (, ), t = (, ) nd t = (, ). Then, t T t nd t T t. The first cn e shown y choosing the specil tree s = (c, ). Then t s T ut t s / T s it cn e seen elow (the letter in rckets is the one tht ws sustituted for the ske of the conctention).

99 3.2. TREE AUTOMATA 93 (c) (c) Definition 3.39 For given DTA A = (Q,Σ, δ, F) (w.l.o.g. ssume ll sttes re rechle) define p 1 A p 2 y: If δ (t 1 ) = p 1 nd δ (t 2 ) = p 2 then for every specil tree s δ (t 1 s) F δ (t 2 s) F Remrk 3.40 In the specil cse tht Σ = {c} Σ 1 the reltions T nd A re identicl to the corresponding congruences for the cse of finite words. Remrk 3.41 ) T nd A re right congruences. ) If p A p with δ (t) = p nd δ (t ) = p, then t T t. c) index of T index of A. d) If T is recognizle, then T hs finite index. e) If T hs finite index, then T is recognizle; moreover, the T -clsses form the stte spce of the (up to isomorphism unmiguous) miniml DTA A T tht recognizes T. The proofs re nlogous to the ones in the word cse nd re therefore skipped. Only for the lst remrk we give the forml definition of the miniml DTA s well s the method for computing it. Definition 3.42 For given T with finite index we define the DTA A T = (Q T, Σ, δ T, F T ) with Q T = T Σ / T (the set of equivlence clsses [t]) δ T () = [] for Σ 0, δ T ([t 1 ],...,[t i ], ) = [(t 1,...,t i )] for Σ i, i > 0, F T = { [t] t T } Note tht δ T is well-defined, since t 1 T t 1,...,t i T t i implies tht (t 1,...,t i ) T (t 1,...,t i ). To compute this miniml DTA, s in the cse of finite words, strting from n ritrry DTA we first eliminte ny non-rechle sttes nd then we merge the equivlent sttes (i.e. two sttes q, q with q A q ) into one.

100 94 CHAPTER 3. TREE AUTOMATA Only the wy we identify two equivlent sttes (given two other sttes tht hve een lredy found to e equivlent) is little more complicted thn in the cse of finite words. This is ecuse, s stted efore, in trees we hve to explicitly stte t which lef we conctente tree with nother. Formlly: q A q, Σ i δ(q 1,...,q j 1, q, q j+1,...,q i, ) A δ(q 1,...,q j 1, q, q j+1,...,q i, ) for ll j {1,...,i} nd ll q 1,...,q j 1, q j+1,...,q i Q. Trnslted into n lgorithm, the procedure tkes the following steps: 1. Mrk ll pirs (q, q ), such tht exctly one stte elongs to F. 2. While new pir ws mrked in the lst step: mrk ll yet nonmrked pirs (q, q ), for which there exists n Σ i nd sttes q 1,...,q j 1, q j+1,...,q i, such tht the pir (δ(q 1,...,q j 1, q, q j+1,...,q i, ), δ(q 1,...,q j 1, q, q j+1,...,q i, )) is lredy mrked. As in the cse of conventionl DFAs, this lgorithm cn lso e pplied to test the equivlence etween two given tree utomt y minimizing them nd compring them with respect to isomorphism. 3.3 Logic-Oriented Formlisms over Trees In this section we look t the two kinds of logic-oriented formlisms tht we studied in the first chpter out words, nmely regulr expressions nd MSO-logic. We only focus on issues tht hve to e extended or refined to meet the specil chrcteristics of trees, skipping wht cn e directly trnsferred from the re of finite words Regulr Expressions Regulr expressions re uilt up using three min opertions, nmely union, conctention nd str-opertion. For the first one, no specil explntion needs to e given. For the other two some further considertion is necessry. The wy we defined conctention in the previous section (specifying exctly one lef where specil tree is ppended to the root of nother tree) mkes it rther wek to express ll lnguges tht re recognizle y tree utomt. Definition 3.43 T 1 c T 2 is the set of ll trees tht re formed from some t T 1, y replcing ech c-leled lef y some tree from T 2. Note tht from now on we re conctenting trees in top-down mnner, in contrst to wht we did in Section 3.2. This is nturl thing to do t this point, since we now ppend more thn one tree to n existing one. Also note

101 3.3. LOGIC-ORIENTED FORMALISMS OVER TREES 95 tht these trees ( T 2 ) cn e different. If we represent tree y tringle nd mrk the c-leled leves y dot, conctented tree elonging to T 1 c T 2 my look like where the upper tree elongs to T 1 nd the lower ones to T 2. Since the str-opertor induces specil kind of conctention it hs to e defined in similr wy. Definition 3.44 T c := T 0 T 1 T 2 with T 0 := {c}, T i+1 := T i c (T {c}) { f Exmple 3.45 Consider the singleton tree lnguge T := c c of the trees elonging to T c re schemticlly shown elow: }. Some Definition 3.46 (Regulr Expressions) T T Σ is definle y regulr expression, if there exist n n 0 nd 0-ry symols c 1,...,c n, such tht T is constructed from finitely mny trees over Σ {c 1,...,c n } y finitely often pplying the opertors, ci nd c i (i {1,...,n}). Exmple 3.47 Let Σ = Σ 0 Σ 2 with Σ 2 := { 1,..., m }, Σ 0 := { 1,..., k }. T Σ is definle y regulr expression: T Σ := ( 1 c c + + m c c ) c c ( k ) Tke for exmple the following tree tht oviously elongs to T Σ :

102 CHAPTER 3. TREE AUTOMATA This tree cn e generted ccording to the ove mentioned regulr expression y twice pplying the str-opertor ( c ) nd once the conctention ( c): c 1 c c c c c c c c c c 1 c c c Exmple 3.48 Let Σ 2 = {}, Σ 0 = {}. 1. If T is the set of ll trees with height igger thn 1, then T = ( 2. If T is the set of ll left-coms, then c c c + c c c ( ) c T = c c ) c T Σ 3. If T is the set of ll trees whose pths re ll of even length, then T = ( c c c c ) c c 4. If T is the set of ll left-coms of even length, then ( ) c2 T = c1 c 2 c 1 c 2

103 3.3. LOGIC-ORIENTED FORMALISMS OVER TREES 97 Remrk 3.49 Note tht c is considered s non-terminl symol tht cn pper in the construction ut not in the trees of the lnguge. Theorem 3.50 (Kleene-Theorem for Tree Lnguges) A tree lnguge T T Σ is recognizle y tree utomton if nd only if it is definle y regulr expression. Proof ( ): We suppose tht we re given lnguge, defined y regulr expression. By definition the expression contins finitely mny trees. Hence, we cn proceed y induction on the construction of regulr expressions. Induction strt: By the definition of regulr expressions, we strt with lnguges contining finitely mny trees. These cn e uilt up from singleton lnguges y finitely often pplying the union opertor. And since we re going to hndle this opertor in the induction step nywy, it suffices now to construct n utomton recognizing singleton lnguge, i.e. exctly one tree. Exmple 3.51 Given the following tree t = c c c dom t = ɛ we construct n NTA over the stte set dom t, such tht in successful run stte i is ssumed on reding node i. The trnsitions re: (c,111), (c,21), (c,22), (111,, 11), (21, 22,,2), (11,, 1), (1, 2,, ɛ). Generlly given tree t, the utomton recognizing it is A = (dom t, Σ,, {ɛ}) with := { (u1,...,ui,vl t (u), u) u dom t }. Induction step: Given utomt A i = (Q i, Σ, i, F i ) for i = 1, 2 with Q 1 Q 2 =, T(A 1 ) T(A 2 ) is recognized y the NTA A := (Q 1 Q 2, Σ, 1 2, F 1 F 2 ) T(A 1 ) ct(a 2 ) is recognized y the NTA A := (Q 1 Q 2, Σ,, F 1 ) with = ( 1 \ { (c, q) q Q 1 }) 2 { (q (2) 1,...,q(2) i,, q (1) ) q F 2 : (q (2) 1,...,q(2) i,, q ) 2 nd (c, q (1) } ) 1

104 98 CHAPTER 3. TREE AUTOMATA T(A 1 ) +c is recognized y the NTA A := (Q 1, Σ,, F 1 ) with := 1 { (q 1,...,q i,, q) q F 1 : (q 1,...,q i,, q ) 1 nd (c, q) 1 } Proof (( )): We suppose tht T is recognized y the NTA A = (Q,Σ,, F). First of ll we hve to choose some distinguished 0-ry symols to enle conctention ( c-symols ). For this purpose we misuse the stte set of the utomton nd extend Σ to Σ Q, where the symols from Q hve rity 0. Exmple 3.52 Let Σ = Σ 0 Σ 2 with Σ 0 = {}, Σ 2 = {} nd Q = {, 0, 1}. An exmple tree over this extended lphet would e 0 After hving extended the lphet we construct A from A y dding the trnsitions (p, p) for every p Q, to llow the utomton to red the new 0-ry symols on the leves nd synchronously ssume the corresponding stte (hving the sme nme). Next we define set T(R, S, q) for R, S Q tht contins ll trees over Σ Q, on which there exists run of A, whose leves tht re leled y Q-symols in the input tree, re leled with sttes from R whose root is leled y the stte q nd whose remining nodes re occupied y sttes from S We cll the elements of R the source sttes, q the trget stte nd the elements of S the intermedite sttes. Exmple T({0, }, {1, }, 0)

105 3.3. LOGIC-ORIENTED FORMALISMS OVER TREES 99 By the definition of T(R, S, q) the following holds: T(A) = T(, Q, q). q F Hence, it suffices to show tht ll sets T(R, S, q) re regulr, which we prove y induction over the size of S. Induction strt: S =. In this cse T(R, S, q) contins only trees of length 0 or 1. These re finitely mny, so T(R, S, q) is regulr. Induction step: S > 0: Let S = S 0 {s} (with s / S 0 ), where for S 0 the induction hypothesis holds. A tree t T(R, S, q) iff there exists run on t with source sttes in R, q s trget stte nd intermedite sttes in S 0 {s}. If we decompose t y splitting it on the nodes where s occurs q s s s s s then y induction hypothesis we cn uild regulr expression for the decomposed prts, since ll their intermedite nodes re in S 0. Using the following eqution we cn then construct regulr expression for T(R, S, q). T(R, S 0 {s}, q) = T(R, S 0, q) T(R {s}, S 0, q) s ( T(R {s}, S 0, s) ) s s T(R, S 0, s) MSO-Logic In this susection we introduce wy to descrie the properties of trees using the Mondic Second-Order Logic. Furthermore, s we did in the cse of finite words, we compre the expressive power of this logic to the tree utomt, this time without giving proof. Definition 3.54 (MSO-Logic over trees) Let Σ = Σ 0 Σ m e rnked lphet. A tree t corresponds to structure t = ( dom t, S t 1,...,S t m, t, (P t ) Σ ) with S t i the i-th successor reltion on dom t (etween two positions, where the second is on the i-th rnch strting from the first, when counted from left to right )

106 100 CHAPTER 3. TREE AUTOMATA t the prefix reltion on dom t (etween two positions in t tht re on the sme pth) P t := {u dom t vl t (u) = } (i.e. the set of ll positions of t leled with n ) The syntx of MSO-Logic over trees follows the one over words, though with the tomic formuls x = y, S 1 (x, y),..., S m (x, y), x y, P (x), X i (x) Given formul ϕ(x 1,...,X n ) the expression ( domt, S1, t...,sm, t t, (P) t ) }{{ Σ, K } 1,...,K n = ϕ(x1,...,x n ) t sttes tht s n interprettion for X i, t with K i dom t stisfies ϕ. A sentence ϕ defines the tree lnguge T(ϕ) := {t T Σ t = ϕ}. Such lnguges re clled MSO-definle. Exmple 3.55 For the tree t over Σ = Σ 0 Σ 1 Σ 2, with Σ 0 = Σ 1 = Σ 2 = {, } depicted elow, P = {ɛ, 11, 2}, P = {1, 12, 21, 211} nd oviously Exmple 3.56 We express three min properties of trees y mens of MSOformuls nd use these in following exmples. Consider n lphet with mximl rnk m = 2. Then: 1. We cn express tht node x is the root of tree (i.e. it does not hve ny predecessors) y Root(x) = y(s 1 (y, x) S 2 (y, x)) 2. We cn express tht node x is on the frontier of tree (i.e. it does not hve ny successors) y Fr(x) = y(s 1 (x, y) S 2 (x, y))

107 3.3. LOGIC-ORIENTED FORMALISMS OVER TREES We cn express tht set X of nodes of tree is closed under predecessors (i.e. if some node elongs to X, then so does its predecessor) y y z(x(y) (S 1 (z, y) S 2 (z, y)) X(z)) Exmple 3.57 Now consider some more complicted issues: 1. The prefix opertor cn e eliminted. Tht is, we cn express x y y: X(X(y) X is closed under predecessors X(x)) 2. occurs twice on the sme pth : x y( x = y x y P (x) P (y)) 3. occurs twice not on the sme pth : x y( y x x y P (x) P (y)) 4. there exists sutree leled only with s : x y(x y P (y)) 5. the frontier word contins n infix : To express this property we first express the reltion, which is prtil order mening tht node is on the left of nother, for the cse of mximl rnk m = 2: x y = x 0 y 0 z(s 1 (z, x 0 ) S 2 (z, y 0 ) x 0 x y 0 y) Then, the quoted property cn e expressed y: x y(fr(x) Fr(y) P (x) P (y) x y z(fr(z) x z z y)) The following theorem sserts the equivlence etween tree utomt nd MSO-logic. Theorem 3.58 (Doner, Thtcher-Wright 1968) T T Σ is regulr if nd only if T is MSO-definle. The proof is completely nlogous to the one of the theorem of Büchi, Elgot, Trkhtenrot, nmely: for the direction from formuls to tree utomt we consider n induction over the construction of MSO-formuls nd mke use of the closure properties of tree utomt for the direction from tree utomt to formuls we descrie the existence of run y n existentil MSO-formul.

108 102 CHAPTER 3. TREE AUTOMATA 3.4 XML-Documents nd Tree Automt In this section we consider XML-Documents, which re specil kinds of trees s we experienced in the very eginning of this chpter. Compred to the conventionl trees we were deling with y now, these ones my e slightly more complicted, ut re therefore nowdys extremely significnt for pplictions. The dditionl compliction relies on the fct tht ritrry rnching is llowed. But let us recll Exmple 3.4. Exmple 3.59 We know tht n XML-Document, like the one shown elow, is word tht codes tree using rcketing X nd /X to signl the eginning nd the end of rnch. <ProfileOfStudies> <fculty> Computer Science </fculty> <semester> 3 </semester> <courses> <title> PROGRAMMING </title> <title> COMPUTER STRUCTURES </title> <title> DATA STRUCTURES </title> </courses> </ProfileOfStudies> This XML-Document codes the following tree: PS F S C TXT TXT T T T TXT TXT TXT Note tht the rnching under Courses is ritrry, i.e. we could s well list more thn three courses. This unlimited rnching is lredy known from other res. In rithmetics for exmple, lthough we formlly define + s inry opertion, we re used to writing sum of ritrrily mny numers (n n m ) ecuse we know tht the order is not importnt. In this sense we could s well sy tht the + -opertion hs ritrry rity (t lest 2). The following exmple illustrtes similr cse in the re of oolen expressions. Exmple 3.60 In generlized oolen expressions ritrrily long conjunctions nd disjunctions cn e formed (β 1... β n nd β 1... β n with n > 0). In this sense the expression ((1 0) (1 0 0) (0 1 0))

109 3.4. XML-DOCUMENTS AND TREE AUTOMATA 103 represents the ritrrily (ut finitely) rnching tree: Considering the previous exmples it ecomes ovious tht the rnked lphets we introduced in the eginning of this chpter re not pproprite nymore. Insted, we introduce leling lphet Σ tht does not restrict the rnching of node. Definition 3.61 A Σ-vlued tree over the lphet Σ is of the form t = (dom t, vl t ), where dom t N + is tree domin vl t : dom t Σ is the leling function. A tree domin D stisfies the following conditions: 1. D is closed under prefixes (wj D w D) 2. D is closed under left rother (wj D, 1 i < j wi D) A node with rnk i must hve exctly i successors. The model of Σ-vlued tree is defined similrly to the one over rnked lphet. The min difference is tht in this cse it is rther inpproprite to use n indexed successor reltion, ecuse the index could e ritrry. Insted, we only use simple (not indexed) reltion of the immedite successor nd dditionlly we introduce n ordering reltion etween the immedite successors of node. Definition 3.62 (Model of Σ-vlued tree) Let t e Σ-vlued tree. Then t = (dom t, S t, t, < t, (P t ) Σ ) with S t = successor reltion (edge reltion) without indexing t = prefix reltion on dom t < t = n ordering reltion etween ll immedite successors of the sme node, i.e., u < t v iff u is n elder rother of v in t

110 104 CHAPTER 3. TREE AUTOMATA P t = {u dom t vl t (u) = } MSO-definility is defined s in the previous cse. XML-documents re such Σ-vlued trees nd their models cn e used to interpret MSO-formuls. However, it is quite inconvenient to use MSO-logic to descrie (groups of) XML-documents. Insted, nother specil kind of document description is used. Definition 3.63 (Document-Type Definition (DTD)) A Document- Type Definition (DTD) is system S of rules for the cretion of set of XML-documents. Ech rule in this system hs the form of rule of generlized context-free grmmr, nmely X r, where r is regulr expression. The resulting derivtion trees (if coded into words using the specil XML-rcketing) re the XML-documents creted y S. Recll tht such systems hve exctly the sme expressive power s conventionl context-free grmmrs. Theorem 3.64 By using generlized context-free grmmrs, exctly the contextfree lnguges cn e constructed. Exmple 3.65 A context-free grmmr to crete the XML-document (tree) of Exmple 3.59 is defined y the following rules ProfileOfStudies fculty semester courses fculty terminl word semester terminl word courses title title terminl word The corresponding (equivlent) DTD would e: <!DOCTYPE ProfileOfStudies [ <!ELEMENT ProfileOfStudies (fculty, semester, courses)> <!ELEMENT fculty (\# PCDATA)> <!ELEMENT semester (\# PCDATA)> <!ELEMENT courses (title*)> <!ELEMENT title (\# PCDATA)> ]> where the keyword \# PCDATA stnds for prsed chrcter dt to llow words over the the terminl lphet. We use the keyword TEXT insted. An lterntive wy to descrie sets of XML-documents is to use specil tree utomton tht is le to process them. Of course, such kind of utomton should e defined in wy tht it hs exctly the sme expressive power s DTDs.

111 3.4. XML-DOCUMENTS AND TREE AUTOMATA 105 Definition 3.66 (XML Tree Automton) For n lphet Γ let Reg(Γ) e the set of regulr lnguges over Γ. An XML-Automton is nondeterministic tree utomton of the form A = (Q,Σ,, F) with finite stte set Q, leling lphet Σ, trnsition reltion Reg(Q) Σ Q, finl stte set F Q. Note tht ecuse of the ritrry rnching of the trees, there my e infinitely mny different comintions of son-nodes llowed, in order to proceed to certin prent node. Nevertheless, the trnsition reltion is still presented s finite set y ech time specifying regulr expression or n NFA over Q for the first component of trnsition tuple. Definition 3.67 (Run nd cceptnce of n XML-utomton) A run of A on t is function ρ : dom t Q with the following conditions: for every node u dom t of rnk n there exists (L,vl t (u), ρ(u)) with ρ(u1)...ρ(un) L ρ(ɛ) F (i.e. the stte ssumed on the root hs to e finl one) A ccepts t if there exists such run of A on t (i.e. run fulfilling oth conditions). By T(A) we denote the set of ll trees ccepted y A. We cll such tree lnguge regulr. Note tht, ccording to the first condition of the run function, for n - vlued lef node the trnsition reltion of n XML-utomton must contin trnsition (L,, q) with ɛ L. Exmple 3.68 We construct n XML-utomton tht ccepts the generlized Boolen expressions (s they were illustrted in Exmple 3.60) tht evlute to true. Not surprisingly we hve to use set of two sttes Q = {q 0, q 1 } denoting tht the sutree evlutes to flse or true, respectively. The utomton ccepts if the true stte is ssumed t the root (F = {q 1 }). The trnsition reltion contins the following trnsitions: (ɛ, 0, q 0 ), (ɛ, 1, q 1 ) (Q q 0 Q,, q 0 ), (q + 1,, q 1) (Q q 1 Q,, q 1 ), (q + 0,, q 0)

112 106 CHAPTER 3. TREE AUTOMATA To show tht the definition of XML-utomt is correct one, we hve to show our primry requirement, which ws to crete n lterntive formlism tht hs the sme expressive power s DTDs. Theorem 3.69 Every DTD is equivlent to n XML-utomton. Proof: Simply use the non-terminl symols of the rule system S s sttes in the XML-utomton (cf. Theorem 3.23). One should note tht for the other direction (the trnsltion from XMLutomt to DTDs) the sitution is s in Theorem This cn e voided y llowing severl instnces A 1, A 2,...,A k of ech non-terminl symol A nd considering the derivtion trees with the indices of these instnces removed (the detils re omitted). Note tht the utomton defined in Exmple 3.68 hppens to hve t most one run on given tree. This holds ecuse the trnsitions re defined in mutully exclusive wy, i.e. ll lnguges defined y the -trnsitions do not hve common elements (nd the sme goes for the -trnsitions). This kind of determinism results from the specific trnsitions of the utomton, ut is still not integrted into its structure. In the following we define vrition of the conventionl XML-utomton with uilt-in determinism. Definition 3.70 (Deterministic XML-Automton) A deterministic XML-utomton hs the form A = (Q,Σ, δ, (S ) Σ, F), where: Q,Σ, F re s in the conventionl cse, δ : Σ Q (to initilize the run), for ech Σ, S is DFA over Q with n output in Q. The unmiguous run ρ of A on t is specified s follows: for lef node u: ρ(u) = δ(vl t (u)), for node u of rnk n > 0 nd vl t (u) = : ρ(u) is the (unmiguous) output of S on the input ρ(u1)...ρ(un) (i.e. upon reding the ordered sequence of the sttes of the immedite successors of n -vlued node, S returns the stte tht hs to e ssigned to the node) Now tht we hve defined oth the deterministic nd the non-deterministic version of XML-utomt it is nturl to question ourselves out their expressive power. The following theorem sserts tht, s with utomt on rnked trees, nondeterminism does not offer the ility to descrie more lnguges. Theorem 3.71 A nondeterministic XML-utomton is equivlent to deterministic XML-utomton.

113 3.4. XML-DOCUMENTS AND TREE AUTOMATA 107 Furthermore, ll min issues tht were considered for the cse of utomt on rnked trees (nd lso on finite words) hold in exctly the sme wy for XML-utomt. These issues minly include the following points: 1. The regulr sets of vlued trees re closed under the Boolen opertions nd under projection. 2. A set of vlued trees is regulr if nd only if it is MSO-definle. 3. The emptiness prolem, the inclusion prolem nd the equivlence prolem for XML-utomt re ll decidle. All these sttements cn e proved y simply copying nd dpting the results tht we know from the previous cses. Alterntively, we cn code the Σ-vlued trees y inry trees nd use the results of the previous sections directly. The mentioned properties of XML-utomt cn e used for vrious pplictions concerning XML-documents. Among these re: 1. Testing DTDs for comptiility: For the XML-utomt A, B corresponding to the given DTDs, check whether T(A) T(B). 2. Query evlution: Given query expressed in logic (e.g. XPthexpression, MSO-formul), extrct ll documents stisfying the following condition: For the XML-utomton A construct query representtion B nd check whether T(A) T(B). Remrk 3.72 ) Another very essentil ppliction in XML technologies is the trnsformtion of n XML-document into nother tree structure. This prolem cnnot e hndled y the XML-utomt tht we introduced in this section; it requires the definition of XML-utomt with output, the so-clled tree trnsducers, which construct new tree while processing n XML-document s input. ) It is very common in current pplictions to use identifiers to estlish links etween XML-documents. This leds to structures tht cnnot e considered (nd processed) s trees nymore. The resulting grphs re much more difficult to hndle thn the initil XML-documents nd require more complex methods. As stted efore, the model tht we used for processing XML-documents, ctully, ws intentionlly defined in such wy tht it provides exctly the sme expressive power s DTDs. In fct, when trying to figure out wy to red nd vlidte tree with ritrry (ut still finite) rnching, nother ide comes first into mind; tht is, to nvigte through the tree in verticl nd horizontl mnner y visiting exctly one position of the tree t time.

114 108 CHAPTER 3. TREE AUTOMATA (This is similr to the wy NFAs red the input of finite words letter y letter, lthough in this cse we cnnot relly spek of nvigtion since the movement tkes plce only in one direction). In the following we construct nd riefly study such pth-oriented utomton tht is lwys t one node of tree t time, nd from there it cn move to the prent node ( ), to the first immedite successor ( ), to the next immedite successor of the immedite predecessor node (i.e. to the next rother node) ( ) nd nlogously to the previous one ( ), or remin t the sme position (sttionry move: s). To void the cse tht this utomton gets out of ounds we extend the input tree t to t +, y dding order nodes leled y,,,. Exmple 3.73 The simple tree on the left must e extended to the one on the right efore it is given s n input to the new utomton. c d c d Now, let us descrie this new utomton formlly. Definition 3.74 (Tree Wlking Automton) A Tree Wlking Automton (TWA) hs the form A = (Q,Σ, q 0,, q f ) with finite stte set Q, n initil stte q 0, n ccepting stte q f, trnsition set Q (Σ {,,, }) D Q where D = {,,,, s}. A tuple (p,, d, q) sys tht, when eing in stte p nd currently reding the symol, perform movement d nd proceed to stte q, in cse this is possile. A configurtion of A on the input tree t is pir (u, q), where u dom t is the current position nd q the current stte of the TWA. The initil configurtion is (ɛ, q 0 ) nd the ccepting one is (ɛ, q f ). A ccepts the input t, if A cn rech the ccepting configurtion (ɛ, q f ) from the initil configurtion (ɛ, q 0 ) y processing t. The lnguge T(A) recognized y A is defined s T(A) = {t t is Σ-vlued tree nd A ccepts t + }. Exmple 3.75 Let Σ = {,, c} nd consider the lnguge T of ll Σ- vlued trees hving t lest one -leled node with oth -leled nd c-leled descendnt. A nondeterministic TWA tht recognizes T hs

115 3.5. AUTOMATA OVER TWO-DIMENSIONAL WORDS (PICTURES)109 stte set Q = {q, q, q c, q r, q f }, where q, q, q c men tht the utomton is currently serching for n, or c respectively, q r tht the pttern ws found nd the utomton is on the wy ck to the root, nd q f is the ccepting stte. We choose q 0 = q, i.e. we first nvigte down the tree to find node with lel, from there node with lel on the pth ck to the root, nd from there node with lel c somewhere in the sutree. Trnslted into trnsitions this procedure is coded s follows: serch for n pproprite (i.e. the utomton hs to guess tht this hs n -leled predecessor) with trnsitions (q, σ, /, q ) on visiting switch to stte q nd serch for n y using trnsitions (q,, s, q ) nd (q, σ,, q ) on visiting n proceed to q c nd serch for c-leled node in the sutree with the trnsitions (q,,, q c ) nd (q c, σ, /, q c ) hving visited c proceed to q r nd return to the root y pplying the trnsitions (q c, c, s, q r ) nd (q r, σ,, q r ) ccept with the trnsition (q r,, s, q f ) Regrding the reltionship etween XML-utomt nd TWAs nd etween deterministic nd nondeterministic TWAs, the following results hve een shown up to now. Theorem 3.76 ) Any TWA cn e trnslted into n equivlent (nondeterministic) XML-utomton. ) There exists lnguge tht is recognizle y n XML-utomton ut not y ny (nondeterministic) TWA. c) There exists lnguge tht is recognizle y nondeterministic TWA ut not y ny deterministic TWA. There re, still, some fundmentl questions concerning TWAs tht remin open to computer science; one of those is concerned with complementtion: Is the complement of the tree lnguge recognized y nondeterministic TWA lso recognizle y nondeterministic TWA? We suspect tht the nswer is negtive, though. 3.5 Automt over Two-Dimensionl Words (Pictures) In this lst section of the chpter we re going to tke one more further step in generlizing our models y considering two-dimensionl words s elements of lnguges nd inputs for utomt. Strictly speking, this slightly

116 110 CHAPTER 3. TREE AUTOMATA generlized model does not relly elong to the re of trees. The essentil distinction etween them is the fct tht trees re the kind of directed grphs where two pieces of informtion flow from the root to the leves in spreding mnner, i.e. without eing le to converge gin into some node. In other words, in trees node hs lwys t most one predecessor wheres in two-dimensionl words it hs t most two. Still, we re going to study pictures s generlized model in this chpter ecuse this very step of generliztion is the one tht leds us out of the convenient world of decidility nd efficient computility s fr s it concerns the most fundmentl prolems on descriing nd processing input models. In prticulr, fter introducing utomt nd MSO-formuls over leled grids, we re going to verify tht ) the clss of recognizle picture lnguges is not closed under complement nd ) the emptiness prolem is undecidle. Definition 3.77 (Picture) A picture over Σ is pir p = (dom p, vl p ) with dom p = {1,...,m} {1,...,n} for m, n > 1 nd vl p : dom p Σ. In this cse we re speking of picture of size (m, n). Exmple 3.78 Below we cn see picture of size (2, 3). Definition 3.79 (Picture Lnguge) Let Σ ++ e the set of ll pictures over Σ. Any B Σ ++ is clled picture lnguge over Σ. If Σ is singleton set, then we spek of grids [m, n] nd grid lnguges. Exmple 3.80 Below we list three sic picture lnguges tht we re going to consider in further detil lter. 1. for Σ = {, }: B 1 = {p Σ ++ p(3, 3) =, otherwise p(i, j) = } 2. for Σ = { }: B 2 = {[n, n] n > 0} (squre grids)

117 3.5. AUTOMATA OVER TWO-DIMENSIONAL WORDS (PICTURES) for Σ = {, }: B 3 = {pp p Σ ++, p is squre} As usul we re going to introduce model over these pictures tht llows us fterwrds to define MSO-formuls, descriing lnguges like the ones mentioned ove. Models of pictures elonging to lnguge should then serve s n interprettion for the corresponding MSO-formul. Definition 3.81 (Pictures s Models) For picture p of size (m, n) over Σ let p := ( dom p, S p 1, Sp 2, ( P p ) ) Σ with S p ( ) 1 (i, j), (i + 1, j) (lower successor), S p ) 2( (i, j), (i, j + 1) (right successor) for ll suitle i, j nd P p = {u dom p vl p (u) = }. Definition 3.82 (MSO-Logic over Pictures) The MSO-Logic over pictures (over Σ) is s previously defined with the tomic formuls: x = y S 1 (x, y) S 2 (x, y) P (x) X(y) The semntics (p, K 1,...,K r ) = ϕ(x 1,...,X r ) where K i dom p is defined s usully. For sentence ϕ we cll B(ϕ) = {p Σ ++ p = ϕ} the picture lnguge defined y ϕ. Exmple 3.83 Consider the lnguge B 1 of Exmple First we construct n uxiliry formul to specify the symol t position (0, 0) of the picture: topleft(x) = ys 1 (y, x) ys 2 (y, x) Now B 1 cn e defined y the following formul: x 1, y 1, x 2, y 2, x 3 (topleft(x 1 ) S 1 (x 1, y 1 ) S 2 (y 1, x 2 ) S 1 (x 2, y 2 ) S 2 (y 2, x 3 ) P (x 3 ) y( y = x 3 P (y))) i.e. y expressing the fct tht in the picture there must e top left position from which, fter moving twice right nd twice down, we rech n -leled position wheres ll other positions re leled y letter. Exmple 3.84 Consider the lnguge B 2 of Exmple In squre grid, deprting from the top left position we cn rech the ottom right position y continuously moving once to the right nd once down in n

118 112 CHAPTER 3. TREE AUTOMATA lternting fshion. In this sense we cn sy tht squre grid is ctully picture in which every set X tht contins the top left position nd is closed under digonl successors lso contins the ottom right position. This is exctly wht we express y the following MSO-formul: X [ x(topleft(x) X(x)) x y z(x(x) S 1 (x, y) S 2 (y, z) X(z)) x(ottomright(x) X(x)) ] where ottomright(x) := ys 1 (x, y) ys 2 (x, y) Now tht we hve defined logicl formlism to descrie picture lnguges it is time to construct corresponding utomton-oriented model. To this purpose we first recll the construction we dopted in the cse of conventionl trees. The run of tree utomton is mpping of sttes to the nodes of the input tree. This mpping, long with the lels of the nodes, hs to comply with the trnsitions tht the utomton is llowed to perform. (q 0, ) tree trnsition (q 1, ) (q 2, ) (q 2, ) (q 0, ) (q 1, ) (q 0, ) Figure 3.1: Run tree of tree utomton. This wy, run is composed y mtching the prescried tringles (llowed trnsitions) to tringle of nodes (leled tree node long with oth its immedite successors). Picture cceptors (Tiling-Systems) re nondeterministic systems tht function in similr fshion. They guess the ssignment of sttes to the input picture nd then verify the locl correctness of the ssignment y mtching it with the llowed trnsitions. But this time trnsitions re represented y (2 2)-squres insted of tringles, s illustrted y Figure 3.2. Ech such possile squre of the filled-out picture hs to correspond to trnsition of Tiling-System. To e le to distinguish those squres tht include some oundry nodes (i.e. elonging to the first or the lst row or column) of the picture, we extend the input y mrginl symols #, s illustrted y the following exmple:

119 3.5. AUTOMATA OVER TWO-DIMENSIONAL WORDS (PICTURES)113 trnsitions p p p q q r Figure 3.2: Verifiction of mtching trnsitions on n ssignment of sttes # # # # # # # # # # # # # # Definition 3.85 (Tiling-Systems (T-Systems)) A Tiling-System (T- System) for pictures over Σ hs the form A = (Q,Σ, ) with finite set of sttes Q nd [ (Σ {#}) Q ] 4. In other words, trnsition is tuple of four pirs of the type (input symol, ssigned stte). To hve etter overview we represent trnsition ( 1, q 1, 2, q 2, 3, q 3, 4, q 4 ) y is m- ( ) 1,1... 1,n 1 q mtrix 1 2 q 2. A run of A on p =. 3 q 3 4 q m,1... m,n q 0,0... q 0,n+1 trix ρ =..... q m+1,0... q m+1,n+1 i,n+1 := #, the following holds, for ll suitle i, j: such tht, with 0,j = i,0 = m+1,j = ( ) i,j q i,j i,j+1 q i,j+1. i+1,j q i+1,j i+1,j+1 q i+1,j+1 A ccepts p if nd only if there exists such run of A on p. As usul we cll the set B(A) := {p Σ ++ A ccepts p} the lnguge recognized y the t-system A. Now we re going to consider once gin the lnguges presented in Exmple 3.80 nd this time descrie them y t-systems. Exmple 3.86 To recognize B 1 (the set of ll pictures with n t (3,3) nd everywhere else) we construct t-system with sttes Q = {0, 1, 2} (1 to e ssigned to the first nd 2 to the second digonl element) nd

120 114 CHAPTER 3. TREE AUTOMATA ( ) ( ) ( ) #0 # the trnsitions,,, long with ll other # ones tht re required to fill-out the rest of the picture with stte 0. An exmple run could e (sttes re denoted s exponents, nd stte 0 is ssumed whenever no stte is mentioned): # 0 # # # # # 1 # # 2 # # 0 # # # # # # # # Exmple 3.87 To recognize the squre grids required y lnguge B 2 = {[m, m] m > 0} from Exmple 3.80 we use lmost the sme trick s when we were looking for n pproprite MSO-formul. The ide is to emit signl-stte from the top left corner nd trnsmit it through the grid in the digonl direction. To this purpose we choose stte set Q = {0, 1} nd require the trnsitions to fit to the picture elow (stte 0 is ssumed whenever no stte is mentioned): #1 # # # # # 1 # # 1 # # 1 # # # # # #1 The t-system ( ccepts ) the grid only if it cn mtch its specil verifiction 1 #0 trnsition with some prt of the input, i.e. if the 1 tht ws #0 #1 emitted from the top-left corner is received y the ottom-right corner. Remrk 3.88 If two lnguges B 1, B 2 re oth recognizle y t-systems, then the sme holds for the lnguges B 1 B 2 nd B 1 B 2. The ide for the proof of B 1 B 2 is to construct union of the two t- systems tht should hve disjoint stte sets. For B 1 B 2 the usul product construction hs to e pplied in order to uild t-system with stte set Q 1 Q 2. The lst exmple tht we study right wy is more complicted one nd is sed on the lnguge B 3 of Exmple 3.80.

121 3.5. AUTOMATA OVER TWO-DIMENSIONAL WORDS (PICTURES)115 Exmple 3.89 Let Σ = {, } nd consider the lnguge B 3, nmely the set of ll pictures over Σ tht do not hve the form pp for some squre p. A picture p elongs to this lnguge if either 1. p is not of size (n, 2n), or 2. p is indeed of size (n, 2n), ut there exist some 1 i, j n such tht vl p (i, j) vl p (i, j + n). It suffices to construct one t-system for ech cse ecuse fterwrds, y Remrk 3.88, we cn construct t-system for the union of these two, which oviously recognizes B 3. Cse 1: Let us first find out how we cn ccept pictures of size (n, 2n). This cn e done y extending the ide of Exmple 3.87, nmely s soon s the signl stte 1 is received y some ottom position it hs to e reflected to the up-right digonl direction (renmed s signl stte 2 to void ny confusion). Now we shll expect to receive the signl stte 2 in the top-right corner of the grid. Below we cn see n ccepting run tht lso shows the other trnsitions tht re required in order to fill out the grid correctly: #1 #0 #0 #0 #0 #0 #0 #0 #0 #0 #0 #2 # #0 # #0 # #0 # #0 # #0 #0 #0 #0 #0 #0 #0 #0 #0 #0 #0 #0 #0 However, in this exmple we ctully wnt to ccept everything ut this kind of grids. For this purpose, we keep the sme t-system nd refuse to receive the signl stte 2 t the top-right corner y striking out the trnsition ( #0 #2 2 #0 ). Insted, we my receive the signl stte 2 everywhere else on ( ) ) #0 #0 ( 0 #0 the right or top order y dding the trnsitions, (in #0 cse the numer of columns is greter or less thn 2n, respectively), or we my receive only the signl ) ( stte 1 somewhere ) on the ) right order y dding ( 1 #0 1 #0 ( 0 #0 the trnsitions,, (in cse the numer of 0 #0 #0 #0 1 #0 columns is n). Of course ( we expect ) stte 0 in the criticl top-right corner #0 #0 y dding the trnsition. Finlly, some extr considertion hs 0 #0 to e done for the sizes (1, 1) nd (1, n), which we skip t this point.

122 116 CHAPTER 3. TREE AUTOMATA Cse 2: The second t-system hs to ccept pictures p of size (n, 2n) (we lredy know from the previous cse how this cn e done) tht hve t lest one pir of positions (i, j), (i, j +n) such tht vl p (i, j) vl p (i, j +n). First of ll the t-system hs to guess such position (i, j), which cn e done esily y using nondeterminism. Then, it hs to count n positions to the right to verify tht the symol t (i, j + n) is different. Of course counting cnnot e done y using n different sttes ecuse n is not fixed. The ide is depicted elow (we ssume tht (i, j) is -leled nd (i, j + n) is -leled): ( ) 1 3 The position (i, j) is guessed y using the trnsition. From 1 0 there the signl stte 1 is emitted verticlly towrds the ottom order nd the signl stte 3 (the stnds for the letter tht hs een red; it is perfectly in order to do this ecuse the lphet is finite nd given) is emitted horizontlly towrds position (i, j + n). How do we know tht stte 3 just reched this position to perform the comprison with (i, j)? As soon s stte 1 hits the ottom order, it is renmed to 2 nd further trnsmitted ( to the ) upper( right digonl ) direction, minly with the trnsitions nd. When stte 2 crosses the horizontl #0 #0 2 0 trnsmission of stte 3, they( re renmed ) to 5( nd 4, respectively. ) The corresponding trnsitions re nd. When stte hits the top order, it is renmed to 6 nd further ( trnsmitted ) ( verticlly ) #0 #0 5 6 towrds the ottom order, using trnsitions, nd ( ) 0 6. Note tht this hppens t column j + n ecuse the picture hs 0 6 n rows nd stte 2 (lter stte 5 nd 6) took s mny steps to the right s to the top. When stte 6 crosses the horizontl ( trnsmission ) ( of stte ) 4, the letter comprison is done y trnsitions,. In

123 3.5. AUTOMATA OVER TWO-DIMENSIONAL WORDS (PICTURES)117 cse the letters re different n OK signl is trnsmitted (y using stte 7) ( to the ) ottom ( nd ) finlly ( to the ) ottom-right ( ) corner with trnsitions #7,,,. 0 7 #0 #7 #7 #7 #7 #7 But wht out the lnguge B 3 of Exmple 3.80? Is it lso recognizle y t-system s it is the cse with its complement? If not, then we would hve proven tht the closure property under complement does not hold for picture lnguges recognizle y t-systems. Theorem 3.90 The picture lnguge B 3 = {pp p Σ ++, p is squre} is not recognizle y t-system. Proof: Towrds contrdiction we ssume tht A = (Q, {, }, ) recognizes B 3. Set k := Q nd consider the runs of A on pictures of size (n, 2n). The numer of ll possile centrl stripes (the prt of the run consisting of columns n nd n+1) in such runs is t most (Σ {#}) Q 2(n+2) = (3k) 2n+4. The numer of ll possile pictures of size (n, n) over Σ is 2 n2. Becuse the second term grows fster thn the first one (with respect to n), we cn find suitle n such tht 2 n2 > (3k) 2n+4. For such n n, there exist two pictures pp nd qq with p q tht re oth ccepted y A with two runs tht hve the sme centrl stripes: ϱ p ϱ p ϱ q ϱ q Comining the left prt of the left picture with the right prt of the right one, we cn compose run tht ccepts pq: ϱ p ϱ q Contrdiction. The following theorem summrizes the closure properties tht we studied ove. Theorem 3.91 The clss of picture lnguges recognizle y t-systems is closed under union nd intersection, ut not under complement. As fr s it concerns the reltion of t-systems to MSO-logic the following holds:

124 118 CHAPTER 3. TREE AUTOMATA Theorem 3.92 (Gimmrresi, Restivo, Seiert, Ths. 1994) A picture lnguge is t-system recognizle if nd only if it is EMSO-definle. Theorem 3.93 (Mtz, Schweikrdt, Ths. 1997) As the numer of lterntions etween second-order quntifiers grows we otin n infinite hierrchy of igger nd igger clsses of picture lnguges. Compre the ltter result with the cse of finite words, where EMSO-logic cn provide the sme expressive power s MSO-logic. We conclude this section (nd the whole chpter out trees) y proving tht even the most fundmentl decision prolem on utomt is not solvle within the re of pictures. Theorem 3.94 The emptiness prolem for t-systems is undecidle. Proof: To prove undecidility, s usul, we consider reduction of the hlting prolem for Turing mchines. In other words, we trnsform Turing mchine (TM) M to t-system A M, such tht M hlts on the empty tpe B(A M ). This should suffice to prove tht it is not possile to hve method to decide the emptiness prolem for t-systems ecuse, if we hd one, then we would e le to decide the hlting prolem for TMs s well (through the ove mentioned trnsformtion), which hs een proven to e impossile. We construct A M in such wy tht B(A M ) codes (in its elements) exctly the terminting computtions of M when strted on the empty tpe. Let M = (Q,Σ, q 0,, q f ) with Σ. contins trnsitions of the form (q,,, l/r, q ). We suppose tht the tpe is left ounded. The configurtion words re of the form 1... i 1 (q i ) i+1... n (denoting tht M is currently in stte q, reding letter nd the rest of the symols re written on the tpe to the left nd the right of the hed). For trnsitions (q, i,, l, q ) nd (q, i,, r, q ) the successor configurtions re 1... (q i 1 ) i+1... n nd 1... i 1 (q i+1 )... n, respectively. If we write the sequence of configurtions one fter the other into the rows of tle, we otin picture of size (m, n), for sufficiently lrge m, n. This wy, terminting computtion of M strted on the empty tpe cn e represented y picture over Σ (Q Σ): with 1,1... 1,n = (q 0 )..., 1,1... 1,n.. m,1... m,n

125 3.5. AUTOMATA OVER TWO-DIMENSIONAL WORDS (PICTURES)119 i+1,1... i+1,n is the word coding successor configurtion of i,1... i,n for 1 i < m, nd in m,1... m,n letter (q f ) occurs. In the trnsitions of A M no sttes re needed ecuse the t-system only needs to verify the correctness of the picture y compring two consecutive rows nd two consecutive positions on the tpe (ecuse the Turing mchine cn move the hed only y one position). For this comprison the 2 2 tiles of the t-system suffice. Hence, the t-system needs the following trnsitions (we hve to ssume tht the TM is deterministic nd complete; otherwise, we hve to check tht on ech row the control stte ppers only once, which is possile using 2 sttes in the system): For the initil configurtion: ( ) # #, # (q 0 ) ( ) # #, (q 0 ) ( ) # #, ( ) # # # For the intermedite configurtions: ( ) (q), ( ) # (q) #, ( ) (q) (q, for (q,, ), r, q ) ( ) (q), ( ) (q) #, # ( ) (q) (q ), for (q,,, l, q ) ( ) #, # (q) ( ) #, (q) # ( ) #, # ( ) #, for Σ, q Q # ( ), ( ) (q, ) ( ) (q), for, Σ, q Q. For the finl configurtion: ( ) #, # # ( ), # # ( ) ( # (qf ) (qf ), ), # # # # ( ) #, # # ( (qf ) ), # # ( ) (qf ) # # # for, Σ.

126 120 CHAPTER 3. TREE AUTOMATA 3.6 Exercises Exercise 3.1 Let Σ = Σ 0 Σ 2 with Σ 0 = Σ 2 = {f, g} e rnked lphet. Give tree utomt for the following lnguges: () { t T Σ on some pth in t there re two consecutive occurrences of f } () { t T Σ on every pth in t there re two consecutive occurrences of f } Remrk: pth is lwys strts t the root nd ends t lef. Exercise 3.2 Let the tree lnguges T 1, T 2 T Σ e recognized y the tree utomt A 1, A 2, where A i = (Q i, Σ, δ i, F i ) for i = 1, 2. Give tree utomt recognizing the following lnguges: () T Σ \T 1, () T 1 T 2. Exercise 3.3 Let Σ = Σ 0 Σ 2 e rnked lphet with Σ 0 = {c}, Σ 2 = {, }. Show tht () T 1 := { t T Σ in t there re more s thn s } is not regulr, () T 2 := { t T Σ in t there re more c s thn s } is regulr. Exercise 3.4 Let Σ 2 = {f}, Σ 0 = {, }, nd T := { t T Σ the frontier word of t is in () + }. Give DTA tht recognizes T. Provide lso n explntion. Alterntively: Solve the exercise for ny regulr lnguge L {, } + insted of () +. Exercise 3.5 () Which lnguge is generted y the following regulr expression over Σ 0 = Σ 2 = {0, 1}? ( 0 c 0 c 0 ) c0 c 0 [ 1 c 1 c 1 c1 ( 0 c 0 c 0 ) c0 c 0 {0}] () Give regulr expression over Σ = Σ 0 Σ 2 with Σ 0 = {0, 1} nd Σ 2 = {f} tht genertes the lnguge T := { t T Σ the frontier word of t contins n infix 01 }. Exercise 3.6 Let n lmost-deterministic top-down tree utomton e defined like deterministic top-down tree utomton, ut with set Q 0 of initil sttes. A run is successful if one of these sttes is ssumed t the root. Show tht there exists recognizle tree lnguge tht cnnot e recognized y n lmost-deterministic top-down tree utomton.

127 3.6. EXERCISES 121 Exercise 3.7 Consider the generlized rithmetic expressions with constnts 0, 1 nd the functions + nd with ritrry rities n 2. Give n XML-utomton tht recognizes the set T 0 of ll generlized expressions tht hve the vlue 0 (modulo 3). Exercise 3.8 () Give deterministic (!) TWA tht ccepts those input trees over Σ = {,, c} where n occurs. Hint: Progrm run through the whole input tree. () Give deterministic TWA for the lnguge T presented in the lecture, nmely the set of ll Σ-vlued trees hving t lest one -leled node with oth -leled nd c-leled successor. Provide n explntion for ech prt. Exercise 3.9 Give t-system tht ccepts exctly those pictures p over the singleton lphet { } whose domin dom p contins n even numer of elements. Provide n explntion. Exercise 3.10 Show tht the set of squre grids [m, m] where m is prime numer is recognizle y t-system.

128 122 CHAPTER 3. TREE AUTOMATA

129 Chpter 4 Pushdown nd Counter Systems In this chpter we re entering the re of systems whose sets of configurtions re infinite. This mkes it hrder to find lgorithmic solutions to certin prolems, ecuse we cnnot nymore hope to gther ll required informtion y tking finitely mny steps throughout the trnsition grph of such system. Nevertheless, we present some methods tht successfully solve the most fundmentl prolems. We then pply our results to systems tht re sed on recursive structures nd gin some significnt results. Finlly, we identify nd prove decidility limits towrds more complex systems. 4.1 Pushdown nd Counter Automt It is well known tht pushdown utomt ccept precisely the context-free lnguges. Words re ccepted using finite set of control sttes nd stck s n uxiliry memory. A glol stte or configurtion of such n utomton is pir consisting of control stte nd stck content. Hence, different from the finite stte systems treted so fr, the set of configurtions of pushdown utomton cn e infinite, nd therefore new questions rise. Definition 4.1 A pushdown utomton (PDA) is tuple A = (Q,Σ, Γ, q 0, Z 0, ) where Q is finite set of control sttes, Σ is finite input lphet, Γ is finite stck lphet, q 0 Q is the initil stte, 123

130 124 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS Z 0 Γ is the initil stck symol, nd Q (Σ {ɛ}) Γ Γ Q is the trnsition reltion. A trnsition (p, /ɛ, Z, β, q) is interpreted in the following wy: If A is in stte p, reding letter or no input letter respectively, with Z on top of the stck, it replces Z y β nd enters control stte q. A configurtion is pir (stte q, stck content u) nd is often represented y single word qu, where the first letter of u represents the top stck symol. An extended configurtion is triple (stte, stck content, remining input). With trnsition (p, /ɛ, Z, β, q) we rech successor of the current extended configurtion (p, Zu, w) (q, βu, w) or (p, Zu, w) (q, βu, w) in cse the empty word is red. In terms of conventionl configurtions this is written s pzu qβu. Hence, we oserve tht the configurtions of PDA induce prefix rewriting system. An input word w is ccepted y PDA A if there is computtion of A on w tht strts in q 0 with Z 0 on the stck, reds ll letters of w, nd reches the empty stck t the end of w. In other words, PDA ccepts w if from (q 0, Z 0, w) n extended configurtion (q, ɛ, ɛ) cn e reched in finitely mny steps: (q 0, Z 0, w) (q, ɛ, ɛ) for some q Q. We cll L(A) = {w Σ A ccepts w} the lnguge recognized y A. Theorem 4.2 (Min Theorem) A lnguge L is context-free (i. e. cn e constructed y context-free grmmr) iff L is recognizle y PDA. We recll three fundmentl results from the re of context-free grmmrs. Given context-free grmmr (or two for the third result) G: 1. The word prolem does w elong to L(G)? is decidle (CYKlgorithm). 2. The emptiness prolem Is L(G) =? is decidle (mrking of the vriles from which terminl word cn e derived). 3. The inclusion nd the equivlence prolem re oth undecidle. Since PDAs descrie the sme clss of lnguges s context-free grmmrs, there must e wy to gin nlogous results for the former y some reduction to the ltter. However, ecuse in computer science PDAs often occur independently (i. e. not relted to some grmmr), we solve the first two prolems directly for PDAs. Pushdown utomt ply centrl role in vrious topics in computer science. In compilers the stck serves s the centrl dt structure. In prticulr, it is used s n uxiliry memory in the implementtion of recursive

131 4.1. PUSHDOWN AND COUNTER AUTOMATA 125 procedures. In the specil cse tht the stck lphet consists of single symol, prt from the initil stck symol, stck ctully implements counter. If the stck contins only the initil stck symol, the numer 0 is represented. Any other numer is represented y the numer of occurrences of the (only) stck symol on top of the initil one. This gin shows tht the set of ll possile stck contents is infinite, s nturl numers re too. Exmple 4.3 The depth-first serch in grph G = (V, E), strting from node v 0, cn conveniently e implemented y the following recursive procedure DFS(v): Mrk v For ll non-mrked successors w of v: DFS(w) We illustrte this process on the grph elow, where v 0 = 1, nd denote the nested clls of the lgorithm on the left. DFS(1) DFS(2) DFS(4) DFS(6) DFS(5) To implement this y n itertive progrm we hve to store the procedure clls in reverse direction. This cn e done y the following lgorithm tht uses stck s n uxiliry memory: Initilize stck with v 0 Mrk v 0 As long s the stck is not empty, ssume the top symol is v: if there exists non-mrked neighor of v: mrk the first non-mrked neighor w of v nd push w onto the stck otherwise, delete v from the stck If we pply this lgorithm to the exmple grph from ove, the stck content evolves s follows: ɛ. Exmple 4.4 According to Theorem 4.2, if lnguge L cn e generted y context-free grmmr, then L is recognizle y PDA. Suppose L is generted y grmmr G. Then w L iff there exists derivtion tree t for w in G. While reding w, this cn e verified y guessing left derivtion tht corresponds to depth-first serch through the derivtion tree. A stck once gin serves s n uxiliry memory for this kind of depth-first serch.

132 126 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS Given the following grmmr S AA, A AB c, B, we suppose tht the tree shown elow is guessed y nondeterministic utomton. On the right we cn see how the stck content evolves fter ech step of the depth-first serch. S A A A B c S AA ABA BA BA A A c By defining the configurtions of PDA s sttes of trnsition system, we cn extend the PDA to n infinite utomton, since there re in generl infinitely mny configurtions. This shows gin tht PDAs cn ccept wider clss of lnguges thn finite utomt. Definition 4.5 [Configurtion grph of PDA] If A is PDA, then the configurtion grph of A is defined s G A = (V, (E ) Σ {ɛ} ), where V is the set of ll configurtions rechle from q 0 Z 0, nd (pzu, qβu) E or (pzu, qβu) E ɛ if there is trnsition (p, Z, /ɛ, β, q). A pushdown grph is the configurtion grph of PDA without ɛ-trnsitions. Exmple 4.6 We define PDA A for the lnguge L = { n n n > 0}. Let A = ({q 0, q 1 }, {, }, {Z 0, Z}, q 0, Z 0, ) with (q 0,, Z 0, ZZ 0, q 0 ), (q 0,, Z, ZZ, q 0 ), = (q 0,, Z, ɛ, q 1 ), (q 1,, Z, ɛ, q 1 ),. (q 1, ɛ, Z 0, ɛ, q 1 ) The configurtion grph of A is shown elow. q 0 Z 0 q 0 ZZ 0 q 0 ZZZ 0... ɛ q 1 q 1 Z 0 q 1 ZZ 0 q 1 ZZZ 0...

133 4.1. PUSHDOWN AND COUNTER AUTOMATA 127 The wy we defined PDA t the eginning of the section llows to replce the top symol of the stck y severl ones (i. e. word β) in one step. We sy tht PDA is in norml form, if it hs only trnsitions (p, /ɛ, Z, β, q) with β 2. Tht is, in one step the length of the stck cn e incresed or reduced y t most 1. Lemm 4.7 For every PDA there exists n equivlent PDA in norml form. Proof: For ech trnsition with β > 2 dd β 2 intermedite trnsitions. Every PDA induces pushdown system, where we suppress the specil roles of q 0 nd Z 0, nd ignore the input letters. Definition 4.8 A pushdown system (PDS) P is tuple P = (P, Γ, ), where P is finite set of sttes, Γ is finite stck lphet, nd (P Γ P Γ ) is finite set of trnsition rules, written p qv. A configurtion (or glol stte) of pushdown system P is word pw P Γ, where the first letter of w represents the top symol of the stck. We write pw p w if w = w 0, w = vw 0, nd p p v, pw i p w if there exists p 0 w 0,...,p i w i with pw = p 0 w 0, p i w i = p w, nd p j w j p j+1 w j+1 for 0 j < i, nd pw p w if pw i p w for some i 0. The configurtion grph of pushdown system P = (P, Γ, ) is the grph with vertex set {c c PΓ } nd n edge etween c 1 nd c 2 if c 1 c 2. Exmple 4.9 Let P = (P, Γ, ) e PDS, where P = {p 0, p 1, p 2 }, Γ = {,, c} nd = {(p 0 p 1 ), (p 1 p 2 c), (p 2 c p 0 ), (p 0 p 0 ɛ)}. A sequence of configurtions rechle from p 2 c is shown elow. p 2 c p 0 p 0 p 0 p 0 p 1 p 2 c... In the following we consider n extension of pushdown systems to systems tht hve more thn one stck. Definition 4.10 [n-pushdown System] An n-pushdown system is defined nlogously to PDS ut with n stcks. Wht needs to e redefined is the wy trnsitions re executed. By [n] we denote the set {1,...,n}. Then,

134 128 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS the trnsition reltion is Q [n] Γ Γ Q. A trnsition (p, i,, v, q) mens tht eing in stte p with s the top symol of stck i, the system is llowed to replce this y v nd proceed to stte q. The configurtions re nlogous to the ones of PDS. We recll the specil cse of counter systems nd extend them to more thn one counters y giving nlogous forml definitions. Definition 4.11 [Counter System] A counter system is pushdown system whose stck lphet contins one single symol Z prt from the initil stck symol Z 0. Hence, the stck content is Z m Z 0 nd represents the numer m. A trnsition (p, Z, v, q) with v Z mens the following: for v > 1: ddition of v 1 nd chnge to stte q; for v = 1: chnge to stte q; for v = 0: sutrction of 1 nd chnge to stte q. A counter system is deterministic if the corresponding PDS is. An n-counter system is n n-pushdown system where the stck lphet for ll stcks contins one single symol Z prt from the initil stck symol Z 0. A configurtion hs the form (p, i 1,...,i n ), denoting the current stte nd the numer currently represented y ech of the n counters. Counter systems pper in progrmming lnguges, however under different nme nd formt. To study the computtion limits on functions over N, register mchines were introduced s model of progrmming lnguge. Definition 4.12 [Register Mchines (Shepherdson, Sturgis 1963)] An n- register mchine is sequence of instructions 1 I 1 ; 2 I 2 ;...;k I k (i. e. progrm) with progrm vriles X 1,...,X n. For j < k n instruction I j hs one of the following forms: INC X i (increse the vlue of X i y 1 nd proceed to the next instruction); DEC X i (decrese the vlue of X i y 1, if possile, nd proceed to the next instruction); IF X i = 0 GOTO m (if the vlue of X i = 0, jump to instruction I m, otherwise proceed to I j+1 ). I k is the instructionstop. A configurtion (j,vlueof(x 1 ),...,vlueof(x n )) contins the numer j of the instruction tht is executed in the next step, nd the vlues currently ssigned to ech of the n vriles.

135 4.1. PUSHDOWN AND COUNTER AUTOMATA 129 Exmple 4.13 Consider the register mchine R 0 : 1 IF X 2 = 0 GOTO 5; 2 INC X 1 ; 3 DEC X 2 ; 4 IF X 3 = 0 GOTO 1; 5 STOP Becuse (1, x, y,0) (5, x+y, 0, 0), R 0 cn e used to perform the ddition of two nturl numers. Even if register mchines re llowed to perform only the three sic instructions mentioned ove, it cn e shown tht they possess the sme expressive power s Turing mchines. Tht is, using only these three instructions nd finite numer of vriles one cn compute ll functions in numer theory. Insted of proving this directly, we conclude this section y showing tht register mchines re indeed only different formultion of counter systems, nd in lter section we reduce Turing mchines to counter systems. Proposition 4.14 Deterministic counter systems Z in norml form cn simulte register mchines R nd vice vers. More specificlly, given counter system Z, there exists register mchine R tht comprises the sttes of Z such tht: Z : (p, i 1,...,i n ) (q, j 1,...,j n ) iff R : (p, i 1,...,i n ) (q, j 1,...,j n ) The converse direction cn e expressed in n nlogous wy. Proof (from register mchines to counter systems): Given R construct Z y using the instruction numers 1,...,k s sttes nd dd the following trnsitions: for I j = INC X i : (j, i, Z, ZZ, j + 1), (j, i, Z 0, ZZ 0, j + 1); for I j = DEC X i : (j, i, Z, ɛ, j + 1), (j, i, Z 0, Z 0, j + 1); for I j = IF X i = 0 GOTO m: (j, i, Z 0, Z 0, m), (j, i, Z, Z, j + 1). Proof (from counter systems to register mchines): For the ske of simplicity we exclude complex cses in the trnsitions of the counter system. We ssume tht trnsitions either do not depend on whether the current top stck symol is Z or Z 0, or they leve the stck unchnged (ech counter system cn esily e trnsformed into one stisfying these restrictions).

136 130 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS Given deterministic n-counter system Z in norml form, we construct n n + 1-register mchine R where we use the lst vrile s constnt X n+1 = 0 to e le to express sttic GOTO instructions (i. e. not depending on the dynmic vlue of vrile). Before proceeding to the construction we mke the counter system complete y dding trnsitions such tht for every possile control stte nd top stck symol the counter system cn tke step. If Z hs the sttes 1,...,k, introduce the instruction numers 1,...,2k + 1 (instruction 2k + 1 is STOP). We denote the sttic instruction j IF X n+1 = 0 GOTO m y j GOTO m. The trnsition reltion is then trnsformed to register specific instructions ccording to the following cses: for (j, i, Z/Z 0, ZZ/ZZ 0, m): 2j 1 INC X i ; 2j GOTO 2m 1 for (j, i, Z, ɛ, m) nd (j, i, Z 0, Z 0, m): 2j 1 DEC X i ; 2j GOTO 2m 1 for (j, i, Z, Z, m) nd (j, i, Z 0, Z 0, m ): 2j 1 IF X i = 0 GOTO 2m 1; 2j GOTO 2m The Rechility Prolem for Pushdown Systems Configurtion grphs of pushdown systems re (in generl) infinite. Hence the question whether one cn rech from configurtion c 1 configurtion c 2 ecomes more interesting. We cll this the rechility prolem. Let C e set of configurtions. We define nd post (C) := {c c 0 c for some c 0 C} pre (C) := {c c c 0 for some c 0 C}. With this nottion the rechility prolem for two configurtions cn e restted in two versions: Forwrd rechility prolem: Given c nd the definition of C, does c post (C) hold? Bckwrds rechility prolem: Given c nd the definition of C, does c pre (C) hold? These formultions cn e shrpened to meet generlized version of the rechility prolem. Tht is, given the definition of some configurtion set C, we wnt to determine the definitions of the configurtion sets post (C) nd pre (C). Note tht such result is very helpful for testing certin sfety conditions in system design.

137 4.2. THE REACHABILITY PROBLEM FOR PUSHDOWN SYSTEMS131 Theorem 4.15 (Büchi 1964) Let P = (P, Γ, ) e PDS nd C PΓ regulr set of configurtions. Then pre (C) nd post (C) re gin regulr. Moreover, from n NFA A ccepting C we cn compute n NFA Ā ccepting pre (C) nd n NFA Ã ccepting post (C). Before proceeding to the proof, we look t some very significnt results tht emnte from this theorem. Corollry 4.16 The stck contents tht re rechle from the initil configurtion q 0 Z 0 of PDA form regulr set. Corollry 4.17 The point-to-point rechility prolem for pushdown systems is decidle. Proof: Let c 1, c 2 e two configurtions. Oviously {c 2 } is regulr set. By using Theorem 4.15 we cn determine DFA tht recognizes pre ({c 2 }). Then we only need to check whether c 1 is ccepted y this DFA, in order to decide if c 2 is rechle from c 1. Since counter systems (nd register mchines equivlently) re speciliztion of pushdown systems, the sme sttement s Corollry 4.17 must hold for this cse too. Theorem 4.18 The point-to-point rechility prolem for 1-counter systems (equivlently for 1-register mchines) is decidle. Corollry 4.19 The emptiness prolem for context-free lnguges is decidle. Proof: We use PDAs (insted of grmmrs) to prove this corollry. For the lnguge recognized y PDA A the following holds: L(A) iff q 0 Z 0 (q, ɛ) for some q Q. This mens tht the context-free lnguge is non-empty iff q 0 Z 0 pre (Qɛ), which cn e decided y Theorem Proof (of Theorem 4.15): First we hve to clrify how we will give definitions for sets of configurtions. We use specil NFAs to represent such regulr sets. Let P = (P, Γ, ) e PDS nd C PΓ regulr set of configurtions. A P-utomton for C is n NFA A = (Q,Γ, P, A, F) tht ccepts from n initil stte p P exctly the words w Γ such tht pw C. The control sttes of P re used s initil sttes of A. Additionlly, it is not llowed in A to hve trnsition to n initil stte.

138 132 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS Input: A P-utomton A, PDS P = (P, Γ, ) 1. A 0 := A, i := 0 2. repet : 3. if p p v nd A i : p v q 4. then dd (p,,q) to A i to otin A i+1 5. i := i until no more trnsitions cn e dded. 7. Ā := A i Output: Ā Figure 4.1: First Sturtion Algorithm Exmple 4.20 Consider the pushdown system from Exmple 4.9 nd the configurtion C = {p 0 }. The P-utomton for C is the following: A : p 2 p 0 s 1 s 2 p 1 The ide tht we use (proposed y Boujjni, Esprz, Mler, Hnsel, Rossmnith, Schwoon) is trnsformtion of such n NFA. We consider the regulr trget set C of configurtions of PDS nd suppose tht the NFA A(C) ccepts qvw with run q v r w F. If there exists rule p qv in the pushdown system, then pw must e ccepted y the NFA s well. Therefore we dd trnsition p r to its trnsition reltion. Let P = (P, Γ, ) e PDS nd C PΓ regulr set of configurtions represented y P-utomton A = (Q,Γ, P, A, F). We present two sturtion lgorithms to compute P-utomt Ā nd à ccepting the sets pre (C) nd post (C), respectively. The first sturtion lgorithm is shown in Figure 4.1. Exmple 4.21 shows the P-utomton computed y the first sturtion lgorithm with the pushdown system from Exmple 4.9 nd the P-utomton from Exmple 4.20 s inputs. Since the numer of trnsitions tht cn e dded to P-utomton is finite, the lgorithm termintes. For the correctness we hve to prove tht pw pre (C) Ā : p w F.

139 4.2. THE REACHABILITY PROBLEM FOR PUSHDOWN SYSTEMS133 For the direction from left to right we show for n 0: pw n ru C Ā : p w F. For n = 0 there is nothing to show. Suppose now tht pw n ru nd ru C. We cn decompose this sequence into pw p vw n 1 ru where w = w nd p p v is trnsition of the pushdown system. By the induction hypothesis we know tht Ā : p vw F, i.e. there is stte q such tht Ā : p v w q F. Hence the sturtion rule ensures tht there is trnsition (p,, q) Ā, nd thus pw is ccepted y Ā. For the converse we hve to show more generl clim to mke the induction work. We show tht for ll pw nd ll q we hve Ā : p w q p w : A : p w q nd pw p w (*) For q F this yields the originl clim ecuse A : p w q then mens tht p w C, nd thus pw p w implies tht pw pre (C). If Ā : p w q, then there exists i such tht A i : p w q. We prove (*) y induction on i. For i = 0 the clim oviously holds with p w = pw s A 0 = A. For i > 0 let (p 1,, q 1 ) e the trnsition tht ws dded y the lgorithm to A i 1 to otin A i. This trnsition is used j times in the run A i : p w q for some j 0. We prove the induction step for i y nother induction, this time on j. If j = 0, then we get A i 1 : p w q nd we cn directly pply the induction hypothesis for i. If j > 0, then we cn split the run A i : p w q t the first position where the new trnsition is used s follows (where w = u 1 u 2 ): A i 1 : p u 1 p }{{} 1, A i : p 1 q1, }{{} u A i : q 1 2 q. }{{} (1) (2) (3) We cn pply the induction hypothesis for i to (1) (i. e. to pu 1 nd p 1 ). This mens tht there is p 1 u 1 such tht A : p u 1 1 p 1 nd pu 1 p 1 u 1. As P-utomton does not hve ny trnsitions leding to n initil stte, the only possiility for A : p u 1 1 p 1 is u 1 = ɛ nd p 1 = p 1. We get pu 1 p 1. Considering (2), the trnsition (p 1,, q 1 ) ws dded y the lgorithm v ecuse there is pushdown rule p 1 p 2 v with A i 1 : p 2 q1. Conctenting this run with (3) we otin the run A i : p 2 v u 2 q1 q in which the trnsition (p 1,, q 1 ) is used only j 1 times. The induction hypothesis on j yields p w such tht A : p w q nd p 2 vu 2 p w. Comining this with pu 1 p 1 (derived from (1)) nd the rule p 1 p 2 v we get pw p 1 u 2 p 2 vu 2 p w, proving (*). For the prt of Theorem 4.15 concerning post (C) we use the sme ide. We suppose we re given PDS P = (P, Γ, ), this time in norml form,

140 134 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS Input: A P-utomton A nd PDS P = (P,Γ, ) 1. Set A 0 := A nd i := 0 2. For ech rule r : p p c dd new stte r nd trnsition (p,,r) 3. repet (Sturtion steps): 4. if p p nd A i : p q then dd (p,ɛ,q) 5. if p p nd A i : p q then dd (p,,q) 6. if r : p p nd A i : p q then dd (r,,q) 7. i := i until no more trnsitions cn e dded. 9. Ã := A i Output: Ã Figure 4.2: Second Sturtion Algorithm i.e. contining only rules p q or p q or p qc. We use P- utomton tht recognizes the (regulr) configurtion set C of P. Suppose tht the NFA A(C) ccepts pw with run p w F. If there exists rule p qv in the pushdown system, then we must e le to construct run q vw F in the NFA. If the first trnsition of the run p w F is p r, then we distinguish three cses for rule p qv of the PDS. 1. v = ɛ: dd trnsition q ɛ r (now qvw = qw is ccepted y the run q ɛ r w F); 2. v = : dd trnsition q r (now qvw = qw is ccepted y the run q r w F); 3. v = c: we hve to dd some trnsition q c r. But since the NFA cn process only one letter t time, we need n intermedite stte r ρ for ech such rule ρ with v = 2. In this cse, efore strting the procedure we should first hve extended the NFA y trnsition q r ρ. Now we cn dd the trnsition r ρ c r, so tht the NFA finlly ccepts qvw = qcw y the run q r ρ c r w F. The second sturtion lgorithm is shown in Figure 4.2. Exmple 4.21 shows the P-utomton computed y this lgorithm with the sme inputs s ove. Since the correctness proof is similr to the one for the first sturtion lgorithm, it hs een dropped here.

141 4.2. THE REACHABILITY PROBLEM FOR PUSHDOWN SYSTEMS135 Exmple 4.21 Let P e the pushdown system from Exmple 4.9. Applying the first sturtion lgorithm for the P-utomton from 4.20, we otin the utomton Ā ccepting pre (p 0 ). Ā : p 2 c p 0 s 1 s 2 p 1 The utomton à otined y pplying the second sturtion lgorithm nd ccepting post (p 0 ) is shown elow. à : p 0 s 1 s 2 p 1 r 1,ɛ p 2 c r 2 Complexity estimtion of the first sturtion lgorithm: For the ckwrds rechility prolem we re given PDS P = (P, Γ, ) in norml form nd P-utomton A = (Q,Γ, P, A, F). Hence, the length of the input for the lgorithm is P + + Q + A. In the first step of ech loop (see Figure 4.1) we exmine the existence of oth rule of the pushdown system (there re mny) nd mtching run (with some v) in the P- utomton. Becuse v 2 (norml form), such run cn comprise t most two trnsitions. Hence, for ech rule in we hve to exmine t most Q 2 runs, which in the worst cse sums up to Q 2 checks in ech loop. Now ecuse trnsition is comintion of pir of sttes nd letter of the input lphet, the loop cn e executed t most P Q Γ times; more trnsitions cnnot e dded to the P-utomton. All in ll we get (polynomil) complexity of P Q 3 Γ. Complexity estimtion of the second sturtion lgorithm: The input is the sme s efore. In this lgorithm we hve n dditionl computtionl effort tht must e crried out efore entering the loop (see Figure 4.2), in order to extend the P-utomton for ech rule tht increses the

142 136 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS stck y one symol. This cn e done s mny times s there re rules, nmely times. In ech loop nd for ech rule in we hve to find out in which of the three cses it elongs (t most 3 comprisons) nd then find mtching trnsition (not run!). In the worst cse this cn e done in 3 Q steps. For similr reson s efore the loop cn e executed t most ( P + ) Q Γ times. All in ll we get (polynomil) complexity of + 3 ( P + ) Q 2 Γ. We conclude this section y reclling wht holds out the equivlence tests etween two PDAs. Theorem 4.22 The prolem Given two PDAs A, B, do A nd B recognize the sme lnguge? is undecidle. However, it is decidle for deterministic PDAs. Theorem 4.23 The prolem Given two PDAs A, B, re A nd B isimilr? is decidle. 4.3 Recursive Hierrchicl Automt In the previous section we thoroughly studied the rechility prolem for PDSs. In this section we consider kind of system whose nlysis depends on the ppliction of this rechility test. These re the so clled recursive hierrchicl systems which consist of components K 0,...,K n tht cn cll one nother or even themselves (recursion). The sttes of such system re either norml ones or clls of component K j. Figure 4.3 shows the system K 0 tht comprises three norml sttes nd two clls, one to itself nd one to component K 1. Clls to components re usully represented s oxes, like in the picture. Unlike the cse of Figure 4.3, oxes my hve K 0 K 0 K 1 Figure 4.3: A recursive hierrchicl system.

143 4.3. RECURSIVE HIERARCHICAL AUTOMATA 137 severl inputs nd outputs. For the ske of simplicity, we only consider the cse of single input nd output in the following. The concept which recursive hierrchicl systems rely on is of course well-known to us from the context-free grmmrs. The ide of replcing component with severl ones (including itself) is represented y the rules tht imply sustitution of some letter y severl ones (including itself). Exmple 4.24 Consider the context-free grmmr G, defined y the following rules: S AB ASB SS, A ca, B cb. S genertes the rcket words over {A, B}, e.g. AABABBAB. If we imgine A s ( nd B s ), then this word corresponds to (()())(). A derivtion tree of this word is shown elow. S S S A S B A B S S A B A B Finlly A is replced y words in c nd B y words in c. The rules of this grmmr induce recursive hierrchicl system S (Figure 4.4) tht cn sequentilly cll the components A, B or the components A, S, B or the components S, S. S A B A S B S S Figure 4.4: A recursive hierrchicl system corresponding to the grmmr of Exmple The component A is shown in Figure 4.5, where either c is selected nd A is recursively clled, or the cll is completed y n. The component B is constructed similrly.

144 138 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS A c A Figure 4.5: A component of the recursive hierrchicl system of Figure 4.4. Definition 4.25 [Recursive Hierrchicl Automton] A recursive hierrchicl utomton over Σ hs the form A = (K 0,...,K n ), where every component K j = (Q j, BX j, BI j, i j, j, o j ) consists of the following: finite stte set Q j ; finite set of oxes BX j ; specifiction of the ox content BI j : BX j {0,...,n}. In prticulr, BI j (B) = i mens tht in the component K j the ox B is cll to the component K i ; n input stte i j nd n output stte o j ; trnsition reltion j with trnsitions of the form (p,, q), (p, ɛ, B), (B, ɛ, q), (B, ɛ, B ) for p, q Q j, Σ, nd B, B BX j. Definition 4.26 [Run of Recursive Hierrchicl Automton] A run of A is sequence p 0, 1, p 1, 2, p 2,..., m, p m of sttes p i from Q = n j=0 Q j nd lels i Σ {ɛ}. For ech segment p i, i+1, p i+1 of the sequence there is j {0,...,n} such tht the following holds: (p i, i+1, p i+1 ) j (norml trnsition), or (p i, i+1, B) j with B BX j, BI j (B) = m, nd p i+1 = i m ( cll to component K m ), or (B, i+1, p i+1 ) j with B BX j, BI j (B) = m, nd p i = o m (return from component K m ), or (B, i+1, B ) j with B, B BX j, BI j (B) = m, BI j (B ) = m, p i = o m, p i+1 = i m (cll to component K m, while returning from component K m ).

145 4.3. RECURSIVE HIERARCHICAL AUTOMATA 139 An ccepting run on w is run from i 0 to o 0, leled y the word w. A ccepts w, if there exists n ccepting run of A on w. Exmple 4.27 Consider the word cc nd the recursive hierrchicl systems of Figures 4.4 nd 4.5. By following the upper rnch of system S nd twice the lower nd then once the upper rnch of component A, we get the following ccepting run of cc (of course we lso follow once the upper rnch of component B, which is nlogous to A): i S ɛ ia c q ɛ ia c q ɛ ia oa ɛ oa ɛ oa ɛ ib ob ɛ os. Theorem 4.28 Recursive hierrchicl utomt recognize exctly the contextfree lnguges. We skip the proof, since it merely goes y direct trnsformtion of grmmrs to recursive hierrchicl utomt nd vice vers. The trnsformtion of the first direction ws illustrted in Exmple Nturlly, the run of the recursive hierrchicl utomton illustrted in the lst exmple motivtes the question out the rechility prolem; nmely, given two sttes of such n utomton, is there sequence of trnsitions to rech one from the other? The following theorem nswers this question indirectly y giving n equivlence etween recursive hierrchicl utomt nd pushdown utomt. It is then ovious tht we cn solve the rechility prolem, since we hve found n efficient solution for the cse of pushdown utomt. Theorem 4.29 For every recursive hierrchicl utomton A n equivlent pushdown utomton cn e constructed. Remrk Theorem 4.29 is vrint of the trnsltion from grmmrs to pushdown utomt. 2. With some dditionl effort we otin vrints of Theorem 4.29 with severl input nd output sttes. Proof (of Theorem 4.29): Given recursive hierrchicl utomton A = (K 0,...,K n ) with K j = (Q j, BX j, BI j, i j, j, o j ), we construct pushdown utomton with stte set Q = n j=0 Q j nd stck lphet {Z 0 } n j=0 BX j. The min ide of the construction is to store the current K j -stte in the control stte of the PDA, nd to store on the stck the oxes tht re clled in LIFO fshion. This mens tht the ox tht is clled is stored on top of the stck. This wy, the correct informtion out where to return when cll is completed is lwys ville. If only the initil stck symol Z 0

146 140 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS is stored on the stck, then no ox cll is currently ctive, nd furthermore the current stte is in Q 0. A PDA-trnsition (p,, Z, v, q) is dded in the following cses: For norml trnsition (p,, q) j, we set v = Z (the stck remins unchnged). For n entrnce trnsition (p, ɛ, B) j into ox B from p Q j, we set = ɛ, v = BZ (the ox tht is clled is dded on top of the stck for lter use), nd q is the initil stte of K m, where m = BI j (B). For return trnsition (B, ɛ, q) j from ox B BX j, we set = ɛ, Z = B, v = ɛ (the ox tht finished its cll is ersed from the stck), nd p is the finl stte of K m where BI j (B) = m. For jump -trnsition (B, ɛ, B ) j from ox B to ox B, oth in BX j, we set = ɛ, Z = B, v = B, p is the finl stte of K m, where BI j (B) = m, nd q is the initil stte of K m, where BI j (B ) = m. Remrk 4.31 ) We re often not interested in the recognized lnguge, so we suppress the lphet Σ nd merely study recursive hierrchicl systems. ) As discussed efore, the theorem leds to the solution of the (forwrd nd ckwrd) rechility prolem for recursive hierrchicl systems. c) The theorem holds even when using isimultion equivlence insted of lnguge equivlence. 4.4 Undecidility Results Up to this point we hve shown tht the rechility prolem is decidle oth for single pushdown nd counter systems. We hve lso introduced n-pushdown systems tht mke use of more thn one uxiliry memory to perform their computtions. To proceed further we cn tke generliztion step towrds two different directions. One wy is to extend the 1-CS with second counter nd the other wy is to dd second stck to the 1-PDS. The following schem illustrtes this ide y representing generliztion y n rrow. 2-PDS 1-PDS 2-CS 1-CS

147 4.4. UNDECIDABILITY RESULTS 141 As fr s the rechility prolem is concerned, the system tht is most likely to led us to n undecidility result is the most complex one, nmely the 2-PDS. In the following we first show tht this sttement indeed holds, nd then proceed to proving the sme even for 2-CS, y showing tht it hs the sme expressive power s 2-PDS. Hence, we gin the insight tht oth extensions cross the oundries of decidility nd led us to Turing complete systems. Theorem 4.32 The rechility prolem is undecidle for oth 2-pushdown systems nd 2-counter systems. Proof: The proof involves three min steps: 1. From TM to 2-PDS: Given TM M we construct 2-PDS P M nd configurtions c 0, c 1, such tht M hlts when strted on the empty tpe iff P M : c 0 c From 2-PDS to 4-counter systems: Given 2-PDS P nd configurtions c 0, c 1, we construct 4-counter system Z nd configurtions c 0, c 1 tht simulte P, nmely: P: c 0 c 1 iff Z : c 0 c From 4-counter systems to 2-counter systems: Given 4-counter system Z nd configurtions c 0, c 1, we construct 2-counter system Z nd configurtions c 0, c 1 tht simulte Z, nmely: Z : c 0 c 1 iff Z : c 0 c To simulte TM we use the two stcks of 2-PDS to store the tpe content on the left nd on the right of the current working cell. Only the immedite (left nd right) neighors of the working cell will e directly ccessile, since they will e the current top symols of the stcks. Lemm 4.33 Given TM M one cn construct 2-PDS P M nd configurtions c 0, c 1, such tht M hlts when strted on the empty tpe iff P M : c 0 c 1. Proof: Consider TM M = (Q,Γ, q 0,, q f ) with trnsitions of the form (p,,, R/L/N, q), expressed in colloquil lnguge: If in stte p nd reding n on the working tpe, print letter there, move the hed to the right / to the left / don t move, nd ssume stte q. An M-configurtion is of the form [ 1 m p 1 n ] with left nd right end mrkers [ nd ] respectively. The corresponding configurtion of the 2-PDS would then e (p, 1 n ], m 1 [). Hence, we construct 2-PDS P M = (Q (Q Γ), Γ, ) with ] nd [ s the initil stck symol of the first nd the second stck respectively, nd llow the following trnsitions:

148 142 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS for ech non-moving trnsition (p,,, N, q) dd PDS trnsition (p, 1,,, q); for ech right-moving trnsition (p,,, R, q) dd the PDS trnsitions (p, 1,, ɛ,(q, )) nd ((q, ), 2, c, c, q) for ll c Γ; for ech left-moving trnsition (p,,, L, q) dd the PDS trnsitions (p, 2, c, ɛ,(p, c)) nd ((p, c), 1,, c, q) for ll c Γ. Furthermore we hve to ensure tht in the end oth stcks of the PDS re empty, so tht it ccepts exctly when the TM reches finl stte. Hence, we hve to dd trnsitions tht force the PDS to repetedly erse the top symols in oth stcks, until it reches the initil ones ( ] nd [ ), nmely: (q f, 1,, ɛ, q f ) for ] nd (q f, 2,, ɛ, q f ) for [. Now we hve ensured tht M cn rech certin configurtion from nother one if nd only if P M cn do the sme for the corresponding configurtions. Formlly: M : [upv] [u qv ] iff P M : (p, v ], u R [) (q, v ], (u ) R [). This holds lso if one configurtion is the initil one (with n empty tpe) nd the other is finl one: M : [q 0 ] [u q f v ] for some u, v iff P M : (q 0, ], [) (q f, ], [). In other words, M termintes when strted on the empty tpe if nd only if P M cn rech the configurtion c 1 := (q f, ], [) from the configurtion c 0 := (q 0, ], [). 2. To simulte 2-PDS y 4-counter system, we simulte ech pushdown stck y 2-counter system. The following lemm proves tht this is possile. Lemm 4.34 Given PDS P nd configurtions c 0, c 1, one cn construct 2-counter system Z P nd configurtions c 0, c 1, such tht P : c 0 c 1 iff Z P : c 0 c 1. Proof: To simulte pushdown stck y two counters we code stck content over stck lphet with k elements y k +1-dic 0-free numer n, crrying the code of the ottom most symol t the leding position. We only illustrte the proof for the cse k = 9. Then we cn relte ech of the letters in Γ to (different) deciml digit (except 0) nd mp the stck content i 0 i r to the numer with the deciml representtion i r i 0.

149 4.4. UNDECIDABILITY RESULTS 143 Exmple 4.35 Consider n initil stck content Then the stck content 3511 is coded y the numer z = 1153; the top symol is the reminder of z fter dividing it y 10; ersing the top symol of the stck corresponds to division y 10 without reminder; replcing the top symol of the stck e. g. y 7 corresponds to: division y 10 without reminder, multipliction y 10 nd ddition of 7; replcing the top symol of the stck e. g. y 27 corresponds to: division y 10 without reminder, multipliction y 10 nd ddition of 7, multipliction y 10 nd ddition of 2. These rithmetic opertions cn esily e crried out y using second counter. We ssume tht the PDS P = (P, Γ, ) is given in norml form. To simplify the construction of the 2-counter system Z, we continue using Γ = 9. Every P-trnsition is crried out y lock of Z-trnsitions (which we will represent y pseudo progrm p): Ersing the top symol of the stck (with trnsition p q) is simulted y: p: if rem(z 1 ) = then z 1 := z 1 div 10, goto q Replcing the top symol of the stck y nother symol (with trnsition p q) is simulted y: p: if rem(z 1 ) = then z 1 := z 1 div 10; z 1 := z 1 10; z 1 := z 1 + ; goto q Replcing the top symol of the stck y two symols (with trnsition p qc) is simulted y: p: if rem(z 1 ) = then z 1 := z 1 div 10; z 1 := z 1 10; z 1 := z 1 + c; z 1 := z 1 10; z 1 := z 1 + ; goto q We give the counter opertions only for the second cse. The other two re nlogous. We descrie (lmost) ll of the four opertions of this cse elow: The computtion of rem(z 1 ) cn e done with the uxiliry counter y 1 s follows: Sutrct 1 from z 1 nd dd 1 to y 1, going through the sttes 0,...,9 in cyclic mnner.

150 144 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS z 1 ecomes 0 on reching stte i iff rem(z 1 ) = i. Hence we get the reminder in the index of the stte. Now the initil vlue of z 1 is stored in y 1, nd we cn write it ck to z 1 with the opposite opertion, ut without chnging the stte. Multipliction y 10: We use 10 uxiliry sttes nd repet the following until z 1 = 0: z 1 := z 1 1 nd ten times y 1 := y In other words, we decrese the first counter one y one until it reches 0, nd for ech decrese we perform 10 increses of the second counter. Agin, we cn copy the vlue of y 1 ck to z 1, simultneously resetting the uxiliry counter to 0. Addition of is esy. Division y 10 without reminder is left s n exercise to the reder. Finlly, for the initil configurtion c = (p, i 0 i r ) of the PDS, the corresponding configurtion of the 2-counter system is c = (p, (i r i 0 ) 10, 9), where 9 is used s the initil stck (counter) symol. Then, since we hve coded ll possile trnsitions of the PDS y corresponding ones for the 2- counter system, the following holds: P : c 0 c 1 iff Z P : c 0 c 1. It follows directly from Lemm 4.34 tht ny 2-PDS P cn e simulted y 4-counter system Z P (ctully 3 counters would suffice, since we only need one uxiliry counter). For the initil configurtion c = (p, i 0 i r, j 0 j s ) of P, the corresponding configurtion of Z P is then c = (p, (i r i 0 ) 10, 9, (j s j 0 ) 10, 9). 3. The following lemm shows tht we cn in fct further reduce the numer of counters we need. Lemm 4.36 For every 4-counter system Z nd configurtions c 0, c 1, one cn construct 2-counter system Z nd configurtions c 0, c 1, such tht Z : c 0 c 1 iff Z : c 0 c 1. Proof: To simulte four counters (ech with content k i ) y two, we code (k 1,...,k 4 ) y ˆk := 2 k1 3 k2 5 k3 7 k 4 nd store this numer in one of the counters. Adding, respectively deleting, 1 to k 1 then corresponds to multiplying, respectively dividing, ˆk y 2, nd nlogously for k 2,...,k 4.

151 4.5. RETROSPECTION: THE SYMBOLIC METHOD 145 Agin these opertions cn e computed using the second counter s n uxiliry memory. Now tht we cn simulte TM y counter system with two counters, this suffices to show tht the rechility prolem is undecidle even for 2-counter systems. A consequence of Theorem 4.32 is tht progrmming lnguge with two integer vriles X 1, X 2, instructions X i := X i +1, X i := X i 1, nd IF X i = 0 THEN JUMP TO (line) s is lredy Turing complete, i.e. powerful enough to simulte every Turing mchine. 4.5 Retrospection: The Symolic Method In this section we look ck t the wy we solved the rechility prolem for the different models of utomt theory, ut this time in more strct sense. First of ll, it is interesting to note why the rechility prolem is so importnt in system design. The typicl prolem tht we fce in such cses is tht we re given trnsition system (e. g. grph) nd some set of sttes or configurtions (e. g. vertices) in this system. Then, we wnt to find the trnsitive closure under predecessor of this set, i. e. we wnt to extend this set in order to dditionlly include ll those sttes from which, fter finite numer of steps, we cn rech the initil designted set. Imgine tht the designted set includes ll those sttes tht we wnt run to void (dedlocks, endless loops, conflicts, etc.). Then of course we lso wnt to void the sttes from which visit to the mlicious sttes cn e forced. This is typicl kind of sfety constrint tht is checked in the frmework of Model Checking. Returning once gin to the exmple of grph, we know tht there is very efficient wy to solve this prolem, nmely y ckwrds redth-first serch in time O( V + E ), where V nd E re the sets of vertices nd edges of the grph respectively. In fct we cnnot hope for more efficient result. However, if we consider for exmple circuit with 100 flip-flops (nothing extrordinry nowdys), the numer of different sttes in this system is 2 100, which is lso the numer of steps tht our very efficient lgorithm hs to tke efore issuing the result. Hence, even if our method is s good s it gets, it is still not stisfctory enough for lrge systems. Since we cnnot improve the lgorithm itself, our only wy out is to improve the input. Strictly speking, we hve to find wy to improve the method y which the systems re coded efore they re given s n input to n lgorithm. This is exctly the ide of the symolic method; insted of enumerting set of sttes we cn descrie it (e. g. y some logic formlism or n utomton) using significntly less spce. Then, we cn perform rechility nlysis y successively computing the descriptions of C, pre(c), pre 2 (C) etc., until no new sttes cn e dded nymore. Note

152 146 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS tht this is definitely going to e the cse sometime, ecuse the overll numer of ville sttes in the system is finite nywy. In the lgorithm tht is presented elow we ctully mnipulte formul or n utomton until it descries exctly the set tht we re looking for. We denote y β n strct description (formul or utomton), nd y [β] the set defined y β. The symolic lgorithm for ckwrds rechility tkes the following steps: 1. β := description of C; 2. β := description of [β] {q Q there is trnsition from q to [β]}; 3. if [β] = [β ], terminte with output β s description of pre (C); otherwise β := β nd ck to 2. We lredy know tht in the cse of finite systems on the stte spce {0, 1} n, it is very convenient to descrie sets y oolen formuls β(x 1,...,x n ). Exmple 4.37 Consider the stte set Q = {0, 1} 5 nd the designted set of configurtions C = {q Q 3rd or 5th component = 0}. The set C cn e descried y β = x 3 x 5. In Section 2.2 we studied wy to construct miniml cyclic utomton for such oolen formul, nmely OBDDs. The OBDD for (the description of) C is shown elow. x 5 x It is ovious tht it is much esier to pply the rechility lgorithm on the level of OBDDs thn to pply it on enumerted sets. To chieve this, two steps of the lgorithm presented ove still remin to e implemented: 1. β := description of [β] {q Q there is trnsition from q to [β]}; 2. the equivlence test ( [β] = [β ]? ). At this point let us recll tht this is exctly wht we were striving towrds when we were trying to solve the rechility prolem for pushdown systems. To descrie the given set C we used P-utomton. To implement the extension to the trnsitive closure (under predecessor) of C, we

153 4.6. EXERCISES 147 grdully exhusted the sttes elonging strictly to pre (C) y dding new trnsitions to the P-utomton. Furthermore, ecuse we used such structure, we were not concerned with n equivlence test. The termintion of the lgorithm depended on whether it ws possile to dd new trnsitions to the utomton. Wht we finlly oserve is tht the rechility nlysis of pushdown systems is performed ccording to the symolic method, y using NFAs for the representtion of stte sets. We conclude this chpter out pushdown systems y noting tht these re first essentil step in the verifiction of infinite systems. In such systems we look t two words u, v, e. g. representing two configurtions, nd we wnt to exmine ll wys tht my led from the first to the second. To chnge the first letter of one word nd replce it y nother (or two) is only specil cse. 4.6 Exercises Exercise 4.1 Show tht every PDA A is (lnguge) equivlent to PDA B tht uses only purely expnding nd purely reducing trnsitions. Exercise 4.2 Let P := (P, Γ, ) e pushdown system with P := {p 0, p 1 }, Γ := {,, c} nd the following set of trnsitions: p 0 p 0 p 0 c p 1 p 0 p 1 c p 1 c p 0 Consider the configurtion c 1 = p 0 c. As in the lecture {c 1 } is ccepted y n NFA A with sttes p 0, p 1, s 1, s 2, s 3. Apply the sturtion procedures to compute the utomt Ā nd à ccepting pre {c 1 } nd post {c 1 }, respectively. Exercise 4.3 A 1-register mchine R decides set M N, if R, initilized with x N, lwys termintes nd moreover with vlue 1 ssigned to X 1 in cse x M, nd with vlue 0 ssigned to X 1 in cse x M. Show tht if M is eventully periodic, then M is decided y 1-register mchine. (M is eventully periodic, if for suitle k 0, p the following holds: for ll x k 0 : x M x + p M.) Exercise 4.4 Show tht the following prolem is decidle: Given pushdown utomton A, does there exist sequence q 0 Z 0 q 1 w 1 q 2 w 2... of configurtions such tht the length of the configurtions is unounded, i.e. for every n N there is n i such tht q i w i > n? Hint: Consider the repetitions nd the following prmeters: The numer of sttes n, the numer of symols in the stck lphet m, nd the mximl length of word v in trnsition (p, /ɛ, Z, v, q).

154 148 CHAPTER 4. PUSHDOWN AND COUNTER SYSTEMS Exercise 4.5 In the lecture we pplied the sturtion lgorithm to compute the set pre (C) to P-utomt whose sttes from P hve no incoming trnsitions. Show tht this ssumption is necessry. For this purpose, find pushdown system P := (P, Γ, ), set C of configurtions nd P-utomton A tht recognizes C nd hs incoming trnsitions into sttes in P, such tht the sturtion lgorithm computes no utomton for the set pre (C) when pplied to A. Exercise 4.6 Construct recursive utomton tht recognizes the lnguge generted y the following context-free grmmr: S A B B A S AA S BB Give run of the utomton on the word. Exercise 4.7 Show tht the following prolem is undecidle. Given: A 2-pushdown system P nd configurtion c of P. Question: Does numer n exist, such tht c < n holds for ll configurtions c post (c)? The length of the configurtion is the sum of the lengths of oth stck contents. Hint: For reduction the hlting prolem for offline Turing mchines is recommended, which cn e ssumed to e undecidle. (An offline Turing mchine hs red-only input tpe nd red-write working tpe.)

155 Chpter 5 Communicting Systems In this chpter different types of utomt re introduced which llow to model prllel nd distriuted computtions directly rther thn encoding the ehvior of such system into single finite stte device. We gin succinct representtion of prllel processes, ut lso show tht one hs to e creful not to include too powerful communiction possiilities to mintin the nice properties of finite stte mchines. 5.1 Synchronized Products Recll the product construction for NFAs. We generlize this construction y distinguishing which ctions re relevnt for which utomt. Definition 5.1 (Synchronized product) Let A i = (Q i, Σ i, q 0i, i, F i ) e NFAs for 1 i n.. The synchronized product of A 1,...,A n is the utomton A 1... A n := (Q 1... Q n, Σ 1... Σ n, (q 01,...,q 0n ),, F 1... F n ) with ( (p1,...,p n ),,(q 1,...,q n ) ) : { (p i,, q i ) i for Σ i nd p i = q i for Σ i. In inry products we usully emphsize the synchronizing lphet Σ 0 := Σ 1 Σ 2 y writing A 1 Σ0 A 2. Exmple 5.2 We model producer consumer system y synchronized product. 1st process: This process models shipuilder with two sites for storing ships. Possile ctions re: produce ship, check the qulity, sell ship, nd retke ship. This process cn e implemented y the following 149

156 150 CHAPTER 5. COMMUNICATING SYSTEMS NFA, where the upper three sttes indicte whether there re 0 (left), 1 (middle), or 2 ships (right) redy to e sold. s s P 1 : r r p q p q q q 2nd process: This process models very cutious ship owner who uses ship only if she possesses two. Possile ctions re: uy (sell for 1st process), return ship (retke for 1st process), use ship, nd lose ship. This process cn e implemented y the following NFA. r r,l P 2 u s s The synchronized product P 1 {r,s} P 2 of these utomt models the interction etween the shipuilder nd the ship owner. It hs 15 sttes nd thus cnnot e represented s succinct s the component utomt. Exmple 5.3 In this exmple we model mutul exclusion protocol clled Peterson s Protocol where two processes need ccess to criticl section. The processes re the following ones: P 0 : repet 1. (non-criticl section) 2. d 0 := 1 3. turn := 0 4. wit (d 1 = 0 or turn = 1) 5. (criticl section) 6. d 0 := 0 P 1 : repet : 1. (non-criticl section) 2. d 1 := 1 3. turn := 1 4. wit (d 0 = 0 or turn = 0) 5. (criticl section) 6. d 1 := 0 The protocol uses the Boolen vriles d i nd turn. Process P i sets d i to 1 nd turn to i iff it request the criticl section. The vrile turn ensures tht ccess to the criticl section lterntes if oth processes repetedly pose requests. We represent the protocol y synchronized product using two-stte utomton B for ech Boolen vrile :=1 :=0 B : 0 =0? :=0 1 :=1 =1?

157 5.1. SYNCHRONIZED PRODUCTS 151 nd the following utomton for P 0 (P 1 is defined nlogously): P 0 : 1 non-criticl section 0 2 d 0 :=1 3 d 0 :=1 6 criticl section 0 5 d 1 =0? 4 turn:=0 turn=1? Peterson s Protocol is modeled y the synchronized product P 0 P 1 D 0 D 1 T. Note tht the expnded product utomton hs = 288 sttes! Exmple 5.4 We model the fmous Dining Philosophers Prolem s synchronized product. The prolem is the following: 5 philosophers re sitting t tle, nd there is fork in etween two of them (s shown elow). Ech philosopher either thinks or ets, nd to et she needs oth of her neighoring forks, i.e. philosopher i needs forks i nd i + 1 (mod 5). F 1 P 1 P 5 F 2 F 5 P 2 P 4 F 3 F 4 P 3 A simplified version where we ssume tht every philosopher picks oth forks simultneously cn e modeled y the synchronized product of downforks i,i+1 downforks i,i+1 downforks i 1,i P i : think et nd F i : down up. upforks i,i+1 upforks i,i+1 upforks i 1,i The synchronized product of the trnsition systems presented in the previous exmple is only model for ll possile ctions (trnsitions) tht cn occur nd for ll possile situtions (sttes), in which the group of philosophers cn find itself t ny moment in time. To relly descrie the prolem of the dining philosophers (there re severl versions of it) we hve to construct protocol tht specifies code of ehvior etween them y llowing nd foridding certin ctions. Such protocol would for exmple force the following constrints:

158 152 CHAPTER 5. COMMUNICATING SYSTEMS A dedlock must not occur; tht is from every rechle sitution, n ction of t lest one philosopher is llowed. Every philosopher will gin nd gin otin the forks tht re ccessile y him (liveliness condition). By introducing n intermedite stte hungry we my require tht whenever philosopher gets hungry, he will eventully otin his forks. Conditions like the ones ove re not modeled in the trnsition rules of the system. They re posed on the ehvior of the system, i.e. on the possile pths through the grph. A pth cn e coded y word, nd thus the condition will specify suset of ll possile words, i.e. lnguge. The first condition stted ove is for exmple typicl rechility condition nd hence cn e expressed y the techniques on finite words tht we hve lerned so fr. For the lst condition ove one hs to exmine infinite executions of the system nd thus this cnnot e expressed y the sme techniques. In the generl cse the solution nd verifiction of such prolems is relized in three different levels. The synchronized product is constructed to descrie lnguge L over the ction lphet representing the possile ehvior. The required ehvior of the communicting components is descried y n utomton for some lnguge K. A solution (protocol) is nother utomton recognizing su-lnguge L 0 K. Usully L nd K re given, nd we hve to follow n efficient method to determine L 0. Although the synchronized product offers very compct description of system with sy k components of n sttes ech, the stte spce explosion to the numer n k is generlly inevitle. Techniques like the symolic method re unfortuntely not lwys helpful, nd this is one of the min prolem of system verifiction nowdys. 5.2 Communiction vi FIFO Chnnels In this section we introduce finite stte mchines which communicte with ech other vi chnnels. A chnnel implements FIFO queue, i.e messges re processed in first-in first-out order. We represent the content of queue y word 1... n where letters dded to the queue re ppended to the left nd red from the right. The sic ide for two utomt A 1 nd A 2 nd chnnels c 12 nd c 21 is the following: A 1 sends messges to A 2 vi chnnel c 12 nd, vice vers, mthcla 2 sends messges to A 1 using chnnel c 12. The content of chnnel c ij is word over messge lphet Γ. In generl utomt A 1,...,A n communicte with ech other vi set of chnnels CN CN n := ({1,...,n} {1,...,n})\{(1, 1),...,(n, n)}. For exmple, if CN =

159 5.2. COMMUNICATION VIA FIFO CHANNELS 153 {(1, 2), (3, 1), (3, 2)(2, 3)} we otin the following communiction structure: A 1 c 12 A2 c 31 c 32 A 3 c 23 Definition 5.5 A communicting finite stte mchine (CFSM) is tuple A = (A 1,...,A n, Γ, CN) where CN CN n, Γ is messge lphet, nd for 1 i n A i = (Q i, Σ i, q 0i, i, F i ) is finite utomton with trnsitions of the form (p,, q) Q i Σ i Q i, (p, m!j, q) where p, q Q i, m Γ, (i, j) CN, nd (p, m?j, q) where p, q Q i, m Γ, (j, i) CN. (locl) (write) (red) A configurtion of CFSM A is tuple ( (p 1,...,p n ), (w ij ) (i,j) CN ) where p i Q i nd w ij Γ is content of chnnel c ij. A configurtion of A is lso clled glol stte. The semntics of the trnsitions is defined s follows: ( p, (w ij )) ( q, (u ij )) : there exists k such tht p (p k,, q k ) k nd i = q i for i k, u ij = w ij for (i, j) CN p (p k, m!j, q k ) k nd i = q i for i k, u kj = mw kj, u ii = w ii for (i, i ) (k, j) (p k, m?j, q k ) k nd p i = q i for i k, u jk m = w jk, u ii = w ii for (i, i ) (j, k) A trnsition (p,, q) of n utomton A i is interpreted s usul, the trnsitions (p, m!j, q) nd (p, m?j, q) re used to write, respectively red, letter from the corresponding chnnel. Note tht with this definition of CFSM only one component utomton A i is ctive t time. However this cn e esily generlized to rel prllel processing. Remrk 5.6 IF CFSM hs ounded chnnels, i.e. in every execution of the system the length of the chnnel contents is ounded y some l N, then the numer of configurtions is ounded y Q 1... Q n ( Γ + 1) CN l. Hence such CFSM is equivlent to n NFA. A configurtion c of CFSM A is rechle from the initil configurtion ( q 0, ɛ) (where q 0 = (q 01,...,q 0n )) if ( q 0, ɛ)... c. Let C e set of configurtions of CFSM A. If the lnguges of the chnnel contents from

160 154 CHAPTER 5. COMMUNICATING SYSTEMS C re regulr, then C cn e finitely represented y tuples consisting of control stte nd regulr expression r ij for the content of chnnel c ij. We cll such set regulr set of configurtions. The rechility prolem for CFSMs is the following: Input: Prolem: A CFSM A, regulr set C of configurtions. Is configurtion c C rechle from ( q 0, ɛ)? Theorem 5.7 The rechility prolem for CFSMs is undecidle. Proof: We reduce the hlting prolem for Turing Mchines to the rechility prolem for CFSMs. Rememer tht instructions of Turing mchine M re of the form (s,,,, s ) where s, s re sttes of M,, re symols from the tpe lphet, nd {L, R, N} is the direction in which the hed of M moves. A configurtion of M is word usv$ where nd $ re the left nd right end mrkers of the tpe inscription, u is the word to the left of the hed of M, v is the word to the right of it (including the symol eneth the hed), nd s is the current stte of M. We ssume tht M only stops if specil stte s fin is reched. We define n effective trnsformtion of Turing mchine M into CFSM A M where A M = (A M 1, AM 2, {(1, 2), (2, 1)}) such tht M stops when strted on the empty tpe iff A M reches configurtion in set C to e defined lter on. The ide is tht A M 1 puts the current configurtion of M into chnnel c 12. A M 2 reds this configurtion, pplying chnges to it ccording to the instructions of M nd sends the new configurtion ck to A M 1 using chnnel c 21. More precisely: To strt the simultion of M, A M 1 puts the initil configurtion s 0 $ into chnnel c 12, nd proceeds to stte p 0. From thereon A M 1 will write every letter red from c 21 to chnnel c 12. A M 2 ehves s follows 1. Strting from the initil stte red the first three letters 1, 2, 3 from c 12 nd store them in stte [ 1, 2, 3 ]. 2. If 2 is not stte symol then if 3 = $ write 1, 2, 3 to c 21 nd enter the initil stte gin. else write 1 to c 21, red letter from c 12 nd updte the stte to [ 2, 3, ]. 3. If [ 1, 2, 3 ] = [, s, ] then 0 if = $ write to c 21 nd enter stte [s,, $] else if (i) (s,,, N, s ) M proceed to stte [, s, ]

161 5.2. COMMUNICATION VIA FIFO CHANNELS 155 (ii) (s,,, R, s ) M proceed to stte [,, s ] (iii) (s,,, L, s ) M proceed to stte [s,, ] if, else write to chnnel c 21 nd enter stte [s,, ]. Let now C e the set of configurtions of the communiction stte mchine A M in which s fin occurs in chnnel c 12. This set is oviously regulr. We otin tht the TM M strted on the empty tpe reches the stop stte s fin iff A M reches from the initil configurtion ((q 01, q 02 ), ɛ, ɛ) configurtion in C. Hence the rechility prolem for CFSMs is undecidle. This proof cn e esily modified such tht one single utomton with chnnel to itself suffices to simulte Turing mchines. We therefore conclude tht the rechility prolem is decidle for systems with n unounded LIFO memory (stck), ut undecidle for systems with n unounded FIFO chnnel. For the oundedness prolem we experience likewise sitution. In exercise 4.4 we proved tht this prolem is decidle for pushdown systems. This is unfortuntely not the cse for FIFO-communicting utomton. Theorem 5.8 The prolem, whether FIFO-communicting utomton hs ounded chnnels strting from configurtion c, is undecidle. The ide is to consider the decidility of the oundedness prolem for the cse of Turing mchine. Since we hve lredy found wy to simulte TMs y CFSMs, the prolem is decidle for the former if nd only if it is decidle for the ltter. Lemm 5.9 The oundedness prolem for Turing Mchines Given TM M nd TM-configurtion c, is M ounded strting from c? is undecidle. Proof: We cll TM M ounded strting from c, in cse M reches only finitely mny cells of the working tpe, when strting from c. This my hppen ecuse of two resons; either M will eventully hlt if strted from c, or it will not hlt ut will move in ounded re y visiting gin nd gin the sme cells. We know tht the first cse in undecidle, ut we re not sure out the second. For this reson we construct new TM M tht simultes M in such wy tht M termintes strting from c iff M is ounded strting from c. This cn e done esily y instructing M to work exctly s M nd dditionlly replce the right end mrker $ y $ fter ech step. Then oviously M hlts strting from c iff M is ounded strting from c. Proof of Theorem 5.8: We use the previous lemm nd the construction from the proof of Theorem 5.7. Thus, given M nd c we cn construct FIFO-communicting utomton A M such tht M is ounded strting from

162 156 CHAPTER 5. COMMUNICATING SYSTEMS c iff A M is ounded strting from configurtion where initilly c is stored in chnnel c Messge sequence chrts Messge sequence chrts re simple formlism for the nottion of synchronous communicting processes, their syntx settled in the Interntionl Stndrd Z120. Definition 5.10 A Messge Sequence Chrt (MSC) C is given y finite set {P 1,...,P n } of processes, finite set M = {m 1,...,m k } of messges, where ech m i involves send event s i nd receive event r i nd E = {s 1,...,s k, r 1,...,r k } is the set of ll events, lel function l : E {P 1,...,P n }, ssigning to ech event process such tht l(s i ) l(r i ), nd for every 1 i n totl order < i defined on the set E i := {e E l(e) = i} of ll events elonging to process i (clled visul order) Exmple 5.11 An MSC is shown in Figure 5.1. In this MSC P = {P 1, P 2, P 3 } nd e.g. E 2 = {r 1, s 2, s 3, r 4, s 5 } with r 1 < 2 s 2 < 2 s 3 < 2 r 4 < 2 s 5. msc C P 1 P 2 P 3 m s 1 1 r 1 m s 2 2 r 2 m s 3 3 r 3 m r 4 4 s 4 m r 5 5 s 5 m r 6 6 s 6 Figure 5.1: MSC from Exmple 5.11

163 5.3. MESSAGE SEQUENCE CHARTS 157 Our im is to ssign semntics to MSCs y defining prtil order on the send nd receive events. To do this we need some fcts on prtil orders s preprtion. Definition 5.12 A prtil order over set A is reltion < A A such tht ( < ) for ll A (< is irreflexive), ( < ) ( < c) < c for ll,, c A (< is trnsitive), nd ( ( < ) ( < ) ) for ll, A (< is cyclic). Oviously every prtil order gives rise to n cyclic grph. Conversely, every cyclic grph (A, ) induces prtil order (A, <) with < : there is non-empty -pth from to. Definition 5.13 Let (A, <) e prtil order. The Hsse digrm (A, < ) of (A, <) is the cyclic grph defined y < : < nd there exists no c A : < c < A lineriztion of prtil order (A, <) is totl order (A, ) such tht <. A lineriztion of prtil order cn e otined lgorithmiclly y topologicl sort sed on depth-first serch. Exmple 5.14 Let A := {pnts, trousers, socks, shoes, wtch, elt, shirt, tie, jcket}. Figure 5.2 shows Hsse digrm for A such tht the ssocited prtil order llows to dress correctly. The ssocited prtil order is defined y < iff there exists nonempty pth from to in the Hsse digrm for A. A possile lineriztion of this prtil order is the following: wtch < shirt < tie < pnts < trousers < elt < jcket < socks < shoes. Definition 5.15 Let C e n MSC. The semntics of C is the prtil order on the send nd receive events of C induced y the cyclic grph (E, ) defined y e e : e = s j nd e = r j, or e < i e nd t lest one of them is send event, or e = r j, e = r k with l(r j ) = l(r k ) nd s j < i s k. A rce of n MSC C is pir of receive events r, r such tht r < i r for some i, ut not r < r in the prtil order induced y (E, ).

164 158 CHAPTER 5. COMMUNICATING SYSTEMS pnts socks trousers shirt wtch shoes elt tie jcket Figure 5.2: Hsse Digrm for Exmple 5.14 Exmple 5.16 Figure 5.3 shows the Hsse digrm of the prtil order defined y the MSC C from Figure 5.1. Note tht r 5 nd r 6 re not ordered in the prtil order induced y (E, ), ut r 5 < 1 r 6, i.e. r 5 nd r 6 re rce of C. An importnt tsk when deling with MSCs is to find ll rces. The stndrd procedure is to construct the cyclic grph (E, ) from Definition 5.15, then compute its trnsitive closure (E, <), nd compre this with the visul orders < i. MSCs cn e generlized to higher level messge sequence chrts (HM- SCs), where HMSC is directed grph composed of MSCs. A HMSC defines fmily of MSCs, otined from pths in the HMSC grph y conctenting the component MSCs. Exmple 5.17 Let HMSC e given y the following grph with component MSCs s shown in Figure 5.4: C 1 C 2 C 3 An expnsion of this HMSC is shown in Figure 5.5, where the dshed lines indicte tht the prt etween lel 1 nd 2 cn e repeted ritrrily often fterwrds. We otin fmily of MSCs with n unounded set of rces (for process P 3 ). The previous exmple leds us to prtil orders with lrger nd lrger numer of nodes. There is specil theory tht dels with such prtil

165 5.3. MESSAGE SEQUENCE CHARTS 159 s 1 r 1 s 2 r 2 s 3 r 3 s 4 r 4 s 6 s 5 r 5 r 6 Figure 5.3: Hsse Digrm for the MSC of Figure 5.1 msc C 1 msc C 2 P 1 P 2 P 3 P 1 P 2 P 3 msc C 3 P 1 P 2 P 3 Figure 5.4: Component MSCs for Exmple 5.17

166 160 CHAPTER 5. COMMUNICATING SYSTEMS P 1 P 2 P Figure 5.5: Expnded HMSC from Exmple 5.17 orders s trce lnguges. These represent generliztion of words to leled prtil orders. They re defined y n independence reltion on concurrency lphet. Such n lphet is of the form (Σ, I) with set of letters Σ nd n irreflexive reltion I Σ Σ. A pir (, ) I implies tht two consecutive occurrences of nd cn e switched. Then, every word w Σ defines n equivlence clss [w] which is the set of words which cn e otined from w y sequence of switches of neighoring letters, with (, ) I. We cll [w] trce ( Mzurkiewicz trce ). Exmple 5.18 Let D e the reltion (Σ Σ) \ I. D descries the dependency reltion nd contins ll pirs (, ) whose order must not e switched. (Σ, D) cn y given s n undirected grph, e.g. y d c In this cse, if w = dcd, then dcd [w] nd dcd [w].

167 5.4. EXERCISES Exercises Exercise 5.1 Consider the following utomt A 1 over {.} nd A 2 over {, c}. A 1 : 1 2 A 2 : 4 5 c 3 6 c () Drw the grph of the synchronized product A 1 A 2, disregrding the sttes tht re not rechle from the initil stte (1, 4). () Descrie (informlly or y regulr expression) the lnguge ccepted y A 1 A 2. Exercise 5.2 Consider the synchronized product modeling the five philosophers, with utomt P 1,...,P 5 nd F 1,...,F 5 s explined in this chpter. Determine the numer of sttes of this synchronized product. Give n upper ound (s smll s you cn justify) on the numer of rechle sttes from the initil sttes think for the philosophers nd down for the forks. Exercise 5.3 () Consider the lnguge L defined y the regulr expression ( + c + ). Find n NFA A 1 over {, } nd n NFA A 2 over {, c} such tht L is ccepted y the synchronized product A 1 A 2. () Show tht no NFAs A 1, A 2 s in () exist such tht the lnguge ( + c + ) + (c + + ) is ccepted y their synchronized product A 1 A 2. Exercise 5.4 Let A 1 nd A 2 e synchronized products of NFAs, ech consisting of m fctor NFAs with n sttes ech. Descrie procedure to test the equivlence of A 1 nd A 2 nd give ound on the time complexity in terms of m nd n. Exercise 5.5 () Develop CFSM A tht models the Five Philosophers Prolem. A shll consist of component utomt P 1,...,P 5 for the philosophers nd F 1,...,F 5 for the forks, which re lifted seprtely here. P i shll e connected vi forwrd nd ckwrd chnnels to oth F i nd F i+1. In prticulr your model hs to ensure tht (i) no fork cn e lifted y two philosophers simultneously,

168 162 CHAPTER 5. COMMUNICATING SYSTEMS (ii) philosopher cn et iff she possesses oth of her forks, (iii) philosopher cn think iff she possesses no fork, nd (iv) once fork is requested, philosopher is not in stte think nymore. Explin your construction. () Modify your CFSM such tht philosopher is llowed to drop her request for fork (ecuse the fork is in use) nd go ck to stte think. Exercise 5.6 In the course it ws shown tht CFSMs consisting of single component utomton A with chnnel to itself induces n undecidle rechility prolem. ( Given such n A, cn it rech from n initil configurtion (q, ɛ) configurtion (p, w) with control stte p nd chnnel content w? ) Anlyze this prolem for the restricted cse of CFSM with n one-letter messge lphet Γ = {m}. Justify your nswer. Exercise 5.7 Consider the messge sequence chrt from Figure 5.6. msc C P 1 P 2 P 3 P 4 Id 1 Id 2 Req Ack1 Interr Disconn 1 Disconn 2 Inf Check Figure 5.6: MSC for Exercise 5.7 We denote the send events y s(id 1 ), s(id 2 ),... nd the receive events y r(id 1 ), r(id 2 ),.... () Drw the Hsse digrm for the prtil order ssocited with C.

169 5.4. EXERCISES 163 () List the rces occurring in C. (c) Give three lineriztions of the events of C.

170 164 CHAPTER 5. COMMUNICATING SYSTEMS

171 Chpter 6 Petri Nets 6.1 Bsic Definitions Petri nets re models for concurrent systems nd their ehvior. Definition 6.1 A Petri net is tuple N = (P, T, F) where P nd T re nonempty, finite nd disjoint sets of plces nd trnsitions, respectively, nd F P T T P is flow reltion. A mrking of Petri net N = (P, T, F) is function m : P N tht ssigns numer of tokens to plce. If P = {p 1,...,p n } we lso write m = (m 1,...,m n ) for the mrking m where m i is the numer of tokens on plce p i. A trnsition t cn e fired (or executed) if there is token on every plce with n incoming edge to t. When t is fired, one token is removed from every plce with n incoming edge to t, nd one token is put on every plce connected to t y n outgoing edge. In figures we represent plces y circles nd trnsitions y rs. Tokens re represented y dots inside plce. In the context of concurrent systems the plces re clled resource holders, nd tokens re resources. Exmple 6.2 The following Petri net models mutul exclusion protocol 165

172 166 CHAPTER 6. PETRI NETS where two processes ccess criticl section. noncriticl section criticl section Definition 6.3 Let N = (P, T, F) e Petri net. The preset of trnsition t T is the set t := {p P (p, t) F }, the postset is the set t := {p P (t, p) F }. The preset p nd postset p of plce p P re defined nlogously. The definitions ove generlize to sets of trnsitions nd sets of plces in the usul wy, e.g., for set S T of trnsitions we set S := {p P (t, p) F for some t S}. Let m, m e mrkings of Petri net N = (P, T, F). We write m m : p P m(p) m (p), nd m > m : p P m(p) m (p) nd p : m(p) > m (p). Let m e mrking of Petri net N = (P, T, F) nd t T. We define m t m : p t : m(p) > 0 nd m(p) 1 p P : m (p) = m(p) + 1 m(p) if p t, p / t if p / t, p t otherwise We write m m if there is trnsition t with m t m. A firing sequence from m to m is sequence τ = t 1,...,t n of trnsitions such tht there re mrkings m 0,...m n with m 0 = m, m n = m nd m i 1 ti m i for 1 i n. We write m τ m if τ is firing sequence from m to m nd m m if such sequence exists. We cll mrking m dedlock for N if for ll t T there exists p t with m(p) = 0, i.e., no trnsition of N cn e fired. A Petri net with initil mrking m 0 is clled unounded (or unsfe) if for ll K N there exists sequence m 0 m 1 m 2... of mrkings such tht there is n i with p P m i(p) > K.

173 6.1. BASIC DEFINITIONS 167 Exmple 6.4 The following picture illustrtes the firing of trnsition. m : m : Exmple 6.5 The following Petri net illustrtes the modeling power of Petri nets. 1 2 c d Trnsitions nd re in conflict, only one of them cn e fired t time. We cll such trnsitions nondeterministic. Trnsition c cn e fired independently of nd. We cll c concurrent to nd. If trnsitions, c fire, the Petri net ends up in dedlock. If, c nd d fire repetedly, more nd more tokens re collected t plce 1, i.e., the Petri net is unounded. Exmple 6.6 The following Petri net models two production lines A nd B with two intermedite steps ech; the min mnufcturing phse nd the reset ck to the idle stte. Production line A requires resources p nd q,

174 168 CHAPTER 6. PETRI NETS Figure 6.1: A Petri net modeling the prolem of five dining philosophers. wheres production line B needs only q. p q A B Exmple 6.7 Consider the prolem of the dining philosophers s it ws descried in Exmple 5.4. The Petri net depicted in Figure 6.1 represents snpshot of possile modeling of the system, when only the first philosopher holds his forks nd ets. Exmple 6.8 Consider smll computer network where three PCs hve to shre two printers. These two printers cn e represented y n uxiliry

Lecture 9: LTL and Büchi Automata

Lecture 9: LTL and Büchi Automata Lecture 9: LTL nd Büchi Automt 1 LTL Property Ptterns Quite often the requirements of system follow some simple ptterns. Sometimes we wnt to specify tht property should only hold in certin context, clled

More information

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck. Outline Automt Theory 101 Rlf Huuck Introduction Finite Automt Regulr Expressions ω-automt Session 1 2006 Rlf Huuck 1 Session 1 2006 Rlf Huuck 2 Acknowledgement Some slides re sed on Wolfgng Thoms excellent

More information

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages Deprtment of Computer Science, Austrlin Ntionl University COMP2600 Forml Methods for Softwre Engineering Semester 2, 206 Assignment Automt, Lnguges, nd Computility Smple Solutions Finite Stte Automt nd

More information

Convert the NFA into DFA

Convert the NFA into DFA Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm:

More information

Lecture 08: Feb. 08, 2019

Lecture 08: Feb. 08, 2019 4CS4-6:Theory of Computtion(Closure on Reg. Lngs., regex to NDFA, DFA to regex) Prof. K.R. Chowdhry Lecture 08: Fe. 08, 2019 : Professor of CS Disclimer: These notes hve not een sujected to the usul scrutiny

More information

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true. York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech

More information

Regular expressions, Finite Automata, transition graphs are all the same!!

Regular expressions, Finite Automata, transition graphs are all the same!! CSI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 7: Kleene s Theorem Chpter 7: Kleene s Theorem Regulr expressions, Finite Automt, trnsition grphs re ll the sme!! Dr. Neji Zgui CSI3104-W11 1

More information

1 Nondeterministic Finite Automata

1 Nondeterministic Finite Automata 1 Nondeterministic Finite Automt Suppose in life, whenever you hd choice, you could try oth possiilities nd live your life. At the end, you would go ck nd choose the one tht worked out the est. Then you

More information

Coalgebra, Lecture 15: Equations for Deterministic Automata

Coalgebra, Lecture 15: Equations for Deterministic Automata Colger, Lecture 15: Equtions for Deterministic Automt Julin Slmnc (nd Jurrin Rot) Decemer 19, 2016 In this lecture, we will study the concept of equtions for deterministic utomt. The notes re self contined

More information

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014 CMPSCI 250: Introduction to Computtion Lecture #31: Wht DFA s Cn nd Cn t Do Dvid Mix Brrington 9 April 2014 Wht DFA s Cn nd Cn t Do Deterministic Finite Automt Forml Definition of DFA s Exmples of DFA

More information

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4 Intermedite Mth Circles Wednesdy, Novemer 14, 2018 Finite Automt II Nickols Rollick nrollick@uwterloo.c Regulr Lnguges Lst time, we were introduced to the ide of DFA (deterministic finite utomton), one

More information

Chapter 2 Finite Automata

Chapter 2 Finite Automata Chpter 2 Finite Automt 28 2.1 Introduction Finite utomt: first model of the notion of effective procedure. (They lso hve mny other pplictions). The concept of finite utomton cn e derived y exmining wht

More information

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1 Chpter Five: Nondeterministic Finite Automt Forml Lnguge, chpter 5, slide 1 1 A DFA hs exctly one trnsition from every stte on every symol in the lphet. By relxing this requirement we get relted ut more

More information

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science CSCI 340: Computtionl Models Kleene s Theorem Chpter 7 Deprtment of Computer Science Unifiction In 1954, Kleene presented (nd proved) theorem which (in our version) sttes tht if lnguge cn e defined y ny

More information

Harvard University Computer Science 121 Midterm October 23, 2012

Harvard University Computer Science 121 Midterm October 23, 2012 Hrvrd University Computer Science 121 Midterm Octoer 23, 2012 This is closed-ook exmintion. You my use ny result from lecture, Sipser, prolem sets, or section, s long s you quote it clerly. The lphet is

More information

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton 25. Finite Automt AUTOMATA AND LANGUAGES A system of computtion tht only hs finite numer of possile sttes cn e modeled using finite utomton A finite utomton is often illustrted s stte digrm d d d. d q

More information

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38 Theory of Computtion Regulr Lnguges (NTU EE) Regulr Lnguges Fll 2017 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of Finite Automt A finite utomton hs finite set of control

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 CMSC 330 1 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All exmples so fr Nondeterministic

More information

Formal Languages and Automata

Formal Languages and Automata Moile Computing nd Softwre Engineering p. 1/5 Forml Lnguges nd Automt Chpter 2 Finite Automt Chun-Ming Liu cmliu@csie.ntut.edu.tw Deprtment of Computer Science nd Informtion Engineering Ntionl Tipei University

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2 CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt

More information

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Lexicl Anlysis nd These slides re sed on slides copyrighted y Keith Cooper, Ken Kennedy & Lind Torczon t Rice University First Progrmming Project Instruction Scheduling Project hs een posted

More information

Designing finite automata II

Designing finite automata II Designing finite utomt II Prolem: Design DFA A such tht L(A) consists of ll strings of nd which re of length 3n, for n = 0, 1, 2, (1) Determine wht to rememer out the input string Assign stte to ech of

More information

Theory of Computation Regular Languages

Theory of Computation Regular Languages Theory of Computtion Regulr Lnguges Bow-Yw Wng Acdemi Sinic Spring 2012 Bow-Yw Wng (Acdemi Sinic) Regulr Lnguges Spring 2012 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of

More information

3 Regular expressions

3 Regular expressions 3 Regulr expressions Given n lphet Σ lnguge is set of words L Σ. So fr we were le to descrie lnguges either y using set theory (i.e. enumertion or comprehension) or y n utomton. In this section we shll

More information

Minimal DFA. minimal DFA for L starting from any other

Minimal DFA. minimal DFA for L starting from any other Miniml DFA Among the mny DFAs ccepting the sme regulr lnguge L, there is exctly one (up to renming of sttes) which hs the smllest possile numer of sttes. Moreover, it is possile to otin tht miniml DFA

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb. CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt

More information

Parse trees, ambiguity, and Chomsky normal form

Parse trees, ambiguity, and Chomsky normal form Prse trees, miguity, nd Chomsky norml form In this lecture we will discuss few importnt notions connected with contextfree grmmrs, including prse trees, miguity, nd specil form for context-free grmmrs

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS The University of Nottinghm SCHOOL OF COMPUTER SCIENCE LEVEL 2 MODULE, SPRING SEMESTER 2016 2017 LNGUGES ND COMPUTTION NSWERS Time llowed TWO hours Cndidtes my complete the front cover of their nswer ook

More information

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz University of Southern Cliforni Computer Science Deprtment Compiler Design Fll Lexicl Anlysis Smple Exercises nd Solutions Prof. Pedro C. Diniz USC / Informtion Sciences Institute 4676 Admirlty Wy, Suite

More information

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata CS103B ndout 18 Winter 2007 Ferury 28, 2007 Finite Automt Initil text y Mggie Johnson. Introduction Severl childrens gmes fit the following description: Pieces re set up on plying ord; dice re thrown or

More information

Tutorial Automata and formal Languages

Tutorial Automata and formal Languages Tutoril Automt nd forml Lnguges Notes for to the tutoril in the summer term 2017 Sestin Küpper, Christine Mik 8. August 2017 1 Introduction: Nottions nd sic Definitions At the eginning of the tutoril we

More information

Bases for Vector Spaces

Bases for Vector Spaces Bses for Vector Spces 2-26-25 A set is independent if, roughly speking, there is no redundncy in the set: You cn t uild ny vector in the set s liner comintion of the others A set spns if you cn uild everything

More information

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.) CS 373, Spring 29. Solutions to Mock midterm (sed on first midterm in CS 273, Fll 28.) Prolem : Short nswer (8 points) The nswers to these prolems should e short nd not complicted. () If n NF M ccepts

More information

Homework 3 Solutions

Homework 3 Solutions CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 3 Solutions 1. Give NFAs with the specified numer of sttes recognizing ech of the following lnguges. In ll cses, the lphet is Σ = {,1}.

More information

CHAPTER 1 Regular Languages. Contents

CHAPTER 1 Regular Languages. Contents Finite Automt (FA or DFA) CHAPTE 1 egulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, euivlence of NFAs nd DFAs, closure under regulr

More information

Formal languages, automata, and theory of computation

Formal languages, automata, and theory of computation Mälrdlen University TEN1 DVA337 2015 School of Innovtion, Design nd Engineering Forml lnguges, utomt, nd theory of computtion Thursdy, Novemer 5, 14:10-18:30 Techer: Dniel Hedin, phone 021-107052 The exm

More information

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh Lnguges nd Automt Finite Automt Informtics 2A: Lecture 3 John Longley School of Informtics University of Edinburgh jrl@inf.ed.c.uk 22 September 2017 1 / 30 Lnguges nd Automt 1 Lnguges nd Automt Wht is

More information

Closure Properties of Regular Languages

Closure Properties of Regular Languages Closure Properties of Regulr Lnguges Regulr lnguges re closed under mny set opertions. Let L 1 nd L 2 e regulr lnguges. (1) L 1 L 2 (the union) is regulr. (2) L 1 L 2 (the conctention) is regulr. (3) L

More information

Deterministic Finite Automata

Deterministic Finite Automata Finite Automt Deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion Sciences Version: fll 2016 J. Rot Version: fll 2016 Tlen en Automten 1 / 21 Outline Finite Automt Finite

More information

Nondeterminism and Nodeterministic Automata

Nondeterminism and Nodeterministic Automata Nondeterminism nd Nodeterministic Automt 61 Nondeterminism nd Nondeterministic Automt The computtionl mchine models tht we lerned in the clss re deterministic in the sense tht the next move is uniquely

More information

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018 CS 301 Lecture 04 Regulr Expressions Stephen Checkowy Jnury 29, 2018 1 / 35 Review from lst time NFA N = (Q, Σ, δ, q 0, F ) where δ Q Σ P (Q) mps stte nd n lphet symol (or ) to set of sttes We run n NFA

More information

CS 267: Automated Verification. Lecture 8: Automata Theoretic Model Checking. Instructor: Tevfik Bultan

CS 267: Automated Verification. Lecture 8: Automata Theoretic Model Checking. Instructor: Tevfik Bultan CS 267: Automted Verifiction Lecture 8: Automt Theoretic Model Checking Instructor: Tevfik Bultn LTL Properties Büchi utomt [Vrdi nd Wolper LICS 86] Büchi utomt: Finite stte utomt tht ccept infinite strings

More information

Finite Automata-cont d

Finite Automata-cont d Automt Theory nd Forml Lnguges Professor Leslie Lnder Lecture # 6 Finite Automt-cont d The Pumping Lemm WEB SITE: http://ingwe.inghmton.edu/ ~lnder/cs573.html Septemer 18, 2000 Exmple 1 Consider L = {ww

More information

More on automata. Michael George. March 24 April 7, 2014

More on automata. Michael George. March 24 April 7, 2014 More on utomt Michel George Mrch 24 April 7, 2014 1 Automt constructions Now tht we hve forml model of mchine, it is useful to mke some generl constructions. 1.1 DFA Union / Product construction Suppose

More information

Software Engineering using Formal Methods

Software Engineering using Formal Methods Softwre Engineering using Forml Methods Propositionl nd (Liner) Temporl Logic Wolfgng Ahrendt 13th Septemer 2016 SEFM: Liner Temporl Logic /GU 160913 1 / 60 Recpitultion: FormlistionFormlistion: Syntx,

More information

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9. Regulr Expressions, Pumping Lemm, Right Liner Grmmrs Ling 106 Mrch 25, 2002 1 Regulr Expressions A regulr expression descries or genertes lnguge: it is kind of shorthnd for listing the memers of lnguge.

More information

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-* Regulr Expressions (RE) Regulr Expressions (RE) Empty set F A RE denotes the empty set Opertion Nottion Lnguge UNIX Empty string A RE denotes the set {} Alterntion R +r L(r ) L(r ) r r Symol Alterntion

More information

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Converting Regular Expressions to Discrete Finite Automata: A Tutorial Converting Regulr Expressions to Discrete Finite Automt: A Tutoril Dvid Christinsen 2013-01-03 This is tutoril on how to convert regulr expressions to nondeterministic finite utomt (NFA) nd how to convert

More information

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016 CS125 Lecture 12 Fll 2016 12.1 Nondeterminism The ide of nondeterministic computtions is to llow our lgorithms to mke guesses, nd only require tht they ccept when the guesses re correct. For exmple, simple

More information

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010 CS 311 Homework 3 due 16:30, Thursdy, 14 th Octoer 2010 Homework must e sumitted on pper, in clss. Question 1. [15 pts.; 5 pts. ech] Drw stte digrms for NFAs recognizing the following lnguges:. L = {w

More information

Revision Sheet. (a) Give a regular expression for each of the following languages:

Revision Sheet. (a) Give a regular expression for each of the following languages: Theoreticl Computer Science (Bridging Course) Dr. G. D. Tipldi F. Bonirdi Winter Semester 2014/2015 Revision Sheet University of Freiurg Deprtment of Computer Science Question 1 (Finite Automt, 8 + 6 points)

More information

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers 80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES 2.6 Finite Stte Automt With Output: Trnsducers So fr, we hve only considered utomt tht recognize lnguges, i.e., utomt tht do not produce ny output on ny input

More information

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute Victor Admchik Dnny Sletor Gret Theoreticl Ides In Computer Science CS 5-25 Spring 2 Lecture 2 Mr 3, 2 Crnegie Mellon University Deterministic Finite Automt Finite Automt A mchine so simple tht you cn

More information

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true. York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 Automt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Problem (II) Chpter II.6.: Push Down Automt Remrk: This mteril is no longer tught nd not directly exm relevnt Anton Setzer (Bsed

More information

State Minimization for DFAs

State Minimization for DFAs Stte Minimiztion for DFAs Red K & S 2.7 Do Homework 10. Consider: Stte Minimiztion 4 5 Is this miniml mchine? Step (1): Get rid of unrechle sttes. Stte Minimiztion 6, Stte is unrechle. Step (2): Get rid

More information

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 4 1. UsetheproceduredescriedinLemm1.55toconverttheregulrexpression(((00) (11)) 01) into n NFA. Answer: 0 0 1 1 00 0 0 11 1 1 01 0 1 (00)

More information

Lecture 3: Equivalence Relations

Lecture 3: Equivalence Relations Mthcmp Crsh Course Instructor: Pdric Brtlett Lecture 3: Equivlence Reltions Week 1 Mthcmp 2014 In our lst three tlks of this clss, we shift the focus of our tlks from proof techniques to proof concepts

More information

p-adic Egyptian Fractions

p-adic Egyptian Fractions p-adic Egyptin Frctions Contents 1 Introduction 1 2 Trditionl Egyptin Frctions nd Greedy Algorithm 2 3 Set-up 3 4 p-greedy Algorithm 5 5 p-egyptin Trditionl 10 6 Conclusion 1 Introduction An Egyptin frction

More information

Java II Finite Automata I

Java II Finite Automata I Jv II Finite Automt I Bernd Kiefer Bernd.Kiefer@dfki.de Deutsches Forschungszentrum für künstliche Intelligenz Finite Automt I p.1/13 Processing Regulr Expressions We lredy lerned out Jv s regulr expression

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 utomt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Prolem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) nton Setzer (Bsed on ook drft y J. V. Tucker nd K. Stephenson)

More information

First Midterm Examination

First Midterm Examination Çnky University Deprtment of Computer Engineering 203-204 Fll Semester First Midterm Exmintion ) Design DFA for ll strings over the lphet Σ = {,, c} in which there is no, no nd no cc. 2) Wht lnguge does

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automt Theory nd Forml Lnguges TMV027/DIT321 LP4 2018 Lecture 10 An Bove April 23rd 2018 Recp: Regulr Lnguges We cn convert between FA nd RE; Hence both FA nd RE ccept/generte regulr lnguges; More

More information

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh Finite Automt Informtics 2A: Lecture 3 Mry Cryn School of Informtics University of Edinburgh mcryn@inf.ed.c.uk 21 September 2018 1 / 30 Lnguges nd Automt Wht is lnguge? Finite utomt: recp Some forml definitions

More information

Lexical Analysis Finite Automate

Lexical Analysis Finite Automate Lexicl Anlysis Finite Automte CMPSC 470 Lecture 04 Topics: Deterministic Finite Automt (DFA) Nondeterministic Finite Automt (NFA) Regulr Expression NFA DFA A. Finite Automt (FA) FA re grph, like trnsition

More information

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA) Finite Automt (FA or DFA) CHAPTER Regulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, equivlence of NFAs DFAs, closure under regulr

More information

NFAs continued, Closure Properties of Regular Languages

NFAs continued, Closure Properties of Regular Languages Algorithms & Models of Computtion CS/ECE 374, Fll 2017 NFAs continued, Closure Properties of Regulr Lnguges Lecture 5 Tuesdy, Septemer 12, 2017 Sriel Hr-Peled (UIUC) CS374 1 Fll 2017 1 / 31 Regulr Lnguges,

More information

CISC 4090 Theory of Computation

CISC 4090 Theory of Computation 9/6/28 Stereotypicl computer CISC 49 Theory of Computtion Finite stte mchines & Regulr lnguges Professor Dniel Leeds dleeds@fordhm.edu JMH 332 Centrl processing unit (CPU) performs ll the instructions

More information

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont. NFA DFA Exmple 3 CMSC 330: Orgniztion of Progrmming Lnguges NFA {B,D,E {A,E {C,D {E Finite Automt, con't. R = { {A,E, {B,D,E, {C,D, {E 2 Equivlence of DFAs nd NFAs Any string from {A to either {D or {CD

More information

CS 330 Formal Methods and Models

CS 330 Formal Methods and Models CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2017 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 2 1. Prove ((( p q) q) p) is tutology () (3pts) y truth tle. p q p q

More information

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science CSCI 340: Computtionl Models Trnsition Grphs Chpter 6 Deprtment of Computer Science Relxing Restrints on Inputs We cn uild n FA tht ccepts only the word! 5 sttes ecuse n FA cn only process one letter t

More information

Finite-State Automata: Recap

Finite-State Automata: Recap Finite-Stte Automt: Recp Deepk D Souz Deprtment of Computer Science nd Automtion Indin Institute of Science, Bnglore. 09 August 2016 Outline 1 Introduction 2 Forml Definitions nd Nottion 3 Closure under

More information

Fundamentals of Computer Science

Fundamentals of Computer Science Fundmentls of Computer Science Chpter 3: NFA nd DFA equivlence Regulr expressions Henrik Björklund Umeå University Jnury 23, 2014 NFA nd DFA equivlence As we shll see, it turns out tht NFA nd DFA re equivlent,

More information

Surface maps into free groups

Surface maps into free groups Surfce mps into free groups lden Wlker Novemer 10, 2014 Free groups wedge X of two circles: Set F = π 1 (X ) =,. We write cpitl letters for inverse, so = 1. e.g. () 1 = Commuttors Let x nd y e loops. The

More information

FABER Formal Languages, Automata and Models of Computation

FABER Formal Languages, Automata and Models of Computation DVA337 FABER Forml Lnguges, Automt nd Models of Computtion Lecture 5 chool of Innovtion, Design nd Engineering Mälrdlen University 2015 1 Recp of lecture 4 y definition suset construction DFA NFA stte

More information

Handout: Natural deduction for first order logic

Handout: Natural deduction for first order logic MATH 457 Introduction to Mthemticl Logic Spring 2016 Dr Json Rute Hndout: Nturl deduction for first order logic We will extend our nturl deduction rules for sententil logic to first order logic These notes

More information

Ehrenfeucht-Fraïssé Games: Applications and Complexity. Department of Mathematics and Computer Science University of Udine, Italy ESSLLI 2010 CPH

Ehrenfeucht-Fraïssé Games: Applications and Complexity. Department of Mathematics and Computer Science University of Udine, Italy ESSLLI 2010 CPH Ehrenfeucht-Frïssé Gmes: Applictions nd Complexity Angelo Montnri Nicol Vitcolonn Deprtment of Mthemtics nd Computer Science University of Udine, Itly ESSLLI 2010 CPH Outline Introduction to EF-gmes Inexpressivity

More information

Non-deterministic Finite Automata

Non-deterministic Finite Automata Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd T. vn Lrhoven Institute for Computing nd Informtion Sciences Intelligent

More information

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014 CS125 Lecture 12 Fll 2014 12.1 Nondeterminism The ide of nondeterministic computtions is to llow our lgorithms to mke guesses, nd only require tht they ccept when the guesses re correct. For exmple, simple

More information

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages 5//6 Grmmr Automt nd Lnguges Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn Regulr Lnguges Context Free Lnguges Context Sensitive

More information

Name Ima Sample ASU ID

Name Ima Sample ASU ID Nme Im Smple ASU ID 2468024680 CSE 355 Test 1, Fll 2016 30 Septemer 2016, 8:35-9:25.m., LSA 191 Regrding of Midterms If you elieve tht your grde hs not een dded up correctly, return the entire pper to

More information

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun: CMPU 240 Lnguge Theory nd Computtion Spring 2019 NFAs nd Regulr Expressions Lst clss: Introduced nondeterministic finite utomt with -trnsitions Tody: Prove n NFA- is no more powerful thn n NFA Introduce

More information

2.4 Linear Inequalities and Interval Notation

2.4 Linear Inequalities and Interval Notation .4 Liner Inequlities nd Intervl Nottion We wnt to solve equtions tht hve n inequlity symol insted of n equl sign. There re four inequlity symols tht we will look t: Less thn , Less thn or

More information

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1 Tle of Contents: Week 1: Preliminries (set lger, reltions, functions) (red Chpters 1-4) Weeks

More information

Let's start with an example:

Let's start with an example: Finite Automt Let's strt with n exmple: Here you see leled circles tht re sttes, nd leled rrows tht re trnsitions. One of the sttes is mrked "strt". One of the sttes hs doule circle; this is terminl stte

More information

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings... Tle of contents: Lecture N0.... 3 ummry... 3 Wht does utomt men?... 3 Introduction to lnguges... 3 Alphets... 3 trings... 3 Defining Lnguges... 4 Lecture N0. 2... 7 ummry... 7 Kleene tr Closure... 7 Recursive

More information

Review of Gaussian Quadrature method

Review of Gaussian Quadrature method Review of Gussin Qudrture method Nsser M. Asi Spring 006 compiled on Sundy Decemer 1, 017 t 09:1 PM 1 The prolem To find numericl vlue for the integrl of rel vlued function of rel vrile over specific rnge

More information

First Midterm Examination

First Midterm Examination 24-25 Fll Semester First Midterm Exmintion ) Give the stte digrm of DFA tht recognizes the lnguge A over lphet Σ = {, } where A = {w w contins or } 2) The following DFA recognizes the lnguge B over lphet

More information

Thoery of Automata CS402

Thoery of Automata CS402 Thoery of Automt C402 Theory of Automt Tle of contents: Lecture N0. 1... 4 ummry... 4 Wht does utomt men?... 4 Introduction to lnguges... 4 Alphets... 4 trings... 4 Defining Lnguges... 5 Lecture N0. 2...

More information

Model Reduction of Finite State Machines by Contraction

Model Reduction of Finite State Machines by Contraction Model Reduction of Finite Stte Mchines y Contrction Alessndro Giu Dip. di Ingegneri Elettric ed Elettronic, Università di Cgliri, Pizz d Armi, 09123 Cgliri, Itly Phone: +39-070-675-5892 Fx: +39-070-675-5900

More information

DFA minimisation using the Myhill-Nerode theorem

DFA minimisation using the Myhill-Nerode theorem DFA minimistion using the Myhill-Nerode theorem Johnn Högerg Lrs Lrsson Astrct The Myhill-Nerode theorem is n importnt chrcteristion of regulr lnguges, nd it lso hs mny prcticl implictions. In this chpter,

More information

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS CS 310 (sec 20) - Winter 2003 - Finl Exm (solutions) SOLUTIONS 1. (Logic) Use truth tles to prove the following logicl equivlences: () p q (p p) (q q) () p q (p q) (p q) () p q p q p p q q (q q) (p p)

More information

CDM Automata on Infinite Words

CDM Automata on Infinite Words CDM Automt on Infinite Words 1 Infinite Words Klus Sutner Crnegie Mellon Universlity 60-omeg 2017/12/15 23:19 Deterministic Lnguges Muller nd Rin Automt Towrds Infinity 3 Infinite Words 4 As mtter of principle,

More information

Non-deterministic Finite Automata

Non-deterministic Finite Automata Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion

More information

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30 Tlen en Automten Test 1, Mon 7 th Dec, 2015 15h45 17h30 This test consists of four exercises over 5 pges. Explin your pproch, nd write your nswer to ech exercise on seprte pge. You cn score mximum of 100

More information

Context-Free Grammars and Languages

Context-Free Grammars and Languages Context-Free Grmmrs nd Lnguges (Bsed on Hopcroft, Motwni nd Ullmn (2007) & Cohen (1997)) Introduction Consider n exmple sentence: A smll ct ets the fish English grmmr hs rules for constructing sentences;

More information

Lecture 09: Myhill-Nerode Theorem

Lecture 09: Myhill-Nerode Theorem CS 373: Theory of Computtion Mdhusudn Prthsrthy Lecture 09: Myhill-Nerode Theorem 16 Ferury 2010 In this lecture, we will see tht every lnguge hs unique miniml DFA We will see this fct from two perspectives

More information

1.3 Regular Expressions

1.3 Regular Expressions 56 1.3 Regulr xpressions These hve n importnt role in describing ptterns in serching for strings in mny pplictions (e.g. wk, grep, Perl,...) All regulr expressions of lphbet re 1.Ønd re regulr expressions,

More information

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research Speech Recognition Lecture 2: Finite Automt nd Finite-Stte Trnsducers Mehryr Mohri Cournt Institute nd Google Reserch mohri@cims.nyu.com Preliminries Finite lphet Σ, empty string. Set of ll strings over

More information

Farey Fractions. Rickard Fernström. U.U.D.M. Project Report 2017:24. Department of Mathematics Uppsala University

Farey Fractions. Rickard Fernström. U.U.D.M. Project Report 2017:24. Department of Mathematics Uppsala University U.U.D.M. Project Report 07:4 Frey Frctions Rickrd Fernström Exmensrete i mtemtik, 5 hp Hledre: Andres Strömergsson Exmintor: Jörgen Östensson Juni 07 Deprtment of Mthemtics Uppsl University Frey Frctions

More information