THEOTY OF COMPUTATION

Similar documents
1.4 Nonregular Languages

1.3 Regular Expressions

Closure Properties of Regular Languages

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Theory of Computation Regular Languages

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

First Midterm Examination

Automata and Languages

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

CS 275 Automata and Formal Language Theory

Convert the NFA into DFA

This lecture covers Chapter 8 of HMU: Properties of CFLs

CSC 473 Automata, Grammars & Languages 11/9/10

For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir

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

Harvard University Computer Science 121 Midterm October 23, 2012

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

Lecture 08: Feb. 08, 2019

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.

Formal languages, automata, and theory of computation

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.

Lecture 6 Regular Grammars

Normal Forms for Context-free Grammars

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

CS375: Logic and Theory of Computing

Finite Automata-cont d

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

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

Context-Free Grammars and Languages

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)

Nondeterminism and Nodeterministic Automata

Minimal DFA. minimal DFA for L starting from any other

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

NFAs continued, Closure Properties of Regular Languages

Chapter 2 Finite Automata

NFAs continued, Closure Properties of Regular Languages

Non-deterministic Finite Automata

Non Deterministic Automata. Formal Languages and Automata - Yonsei CS 1

CS 330 Formal Methods and Models

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

1 Structural induction, finite automata, regular expressions

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

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

TREE AUTOMATA AND TREE GRAMMARS

Non-Deterministic Finite Automata

Tutorial Automata and formal Languages

Deterministic Finite Automata

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

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

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

CHAPTER 1 Regular Languages. Contents

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

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

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

Fundamentals of Computer Science

Formal Languages and Automata

First Midterm Examination

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa

Coalgebra, Lecture 15: Equations for Deterministic Automata

1 Nondeterministic Finite Automata

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

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

1 From NFA to regular expression

Parse trees, ambiguity, and Chomsky normal form

Designing finite automata II

CSCI FOUNDATIONS OF COMPUTER SCIENCE

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

Homework 3 Solutions

11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?

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

3 Regular expressions

Formal Languages Simplifications of CFGs

Finite-State Automata: Recap

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

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

Lecture 3 ( ) (translated and slightly adapted from lecture notes by Martin Klazar)

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.

CISC 4090 Theory of Computation

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

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

1 Structural induction

a b b a pop push read unread

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

Non-deterministic Finite Automata

CMSC 330: Organization of Programming Languages

CS 330 Formal Methods and Models

SWEN 224 Formal Foundations of Programming WITH ANSWERS

i 1 i 2 i 3... i p o 1 o 2 AUTOMATON q 1, q 2,,q n ... o q Model of a automaton Characteristics of automaton:

Let's start with an example:

ARITHMETIC OPERATIONS. The real numbers have the following properties: a b c ab ac

ɛ-closure, Kleene s Theorem,

CS 330 Formal Methods and Models

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. Comparing DFAs and NFAs (cont.) Finite Automata 2

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

Transcription:

Pushdown utomt nd Prsing lgorithms: Pushdown utomt nd context-free lnguges; Deterministic PDNondeterministic PD- Equivlence of PD nd CFG-closure properties of CFL. PUSHDOWN UTOMT ppliction: Regulr lnguges re those which re ccepted by finite utomt but lnguge such s l=( n b n /n>=1) cnnot be ccepted by regulr lnguge becuse it hs to precisely remember the number of s nd b s which would require infinite number of sttes. Hence push down utomt hs been designed to ccept context free lnguges. This is done by dding uxiliry memory in the form of stck. Definitions: The pushdown utomt formlly consist of 7 tuples given by M=(Q,,δ,,q 0,z 0,F) Where, Q: finite non empty set of sttes : finite non empty set of input symbols δ: the trnsition function from q ( U{^}) to the set of finite subsets Q * : finite non empty set of push down symbols q 0 : specil stte clled initil stte z 0 : specil push down symbols clled the initil symbols on the pushdown store denoted by z 0. In other words indictes the top of the stck F: the pushdown symbol denoting the finl stte. COMPONENTS OF PUSH DOWN UTOMT: The following digrm denotes the bsic model of pushdown utomt.. string detection removing direction finite stte control push down store J. Veerendeswri /IT/ RGCET Pge 1

It hs red only input tpe, input lphbet, finite stte control, set of finl sttes nd n initil stte s in the cse of finite utomt. ut in ddition to this it hs stck clled the pushdown store, it is red write pushdown store s we dd elements to the PDS or remove elements from PDS. finite utomt is in sme stte nd on reding n input symbol the top most symbol in PDS moves to new stte nd writes string of symbols in the PDS. DESIGN FOR PUSH DOWN UTOMT: Consider the context free lnguges n b n, n>=1, from this exmple it cn be concluded tht the lnguge consist of equl number of s s equl number of b s. Let us consider the cse where n=2, then we get the string bb, the following figure shows the structure of PD for the bove string. b b $ z 0 pushdown store finite stte control There re three sttes to be considered in this cse they re: q 0 : it is the stte tht recognizes the beginning lphbets(i.e)the symbol q 1: q 2 : it recognizes the second hlf of the strings (i.e)the symbol b it is the stte tht ccepts ll the lphbets now we strt the design of the pushdown utomt. Step1: δ (q 0,,z 0 ) b b $ finite stte control z 0 pushdown store J. Veerendeswri /IT/ RGCET Pge 2

in this cse of the beginning lphbet is pushed to the stck nd hed pointer is incremented. Step 2: δ (q 0,,z 0 ) b b $ finite stte control z 0 pushdown store the next lphbet is recognized by q0 nd pushed into the stck. Step 3: δ (q 1,b,z 0 ) b b $ finite stte control z 0 pushdown store in this cse we find tht we encounter new lphbet b upon this the lphbet is poped from the stck. Step 4: δ(q 1,b,zo) b b $ z 0 Finite stte control push down store Here gin we encountered b,so nother is poped from the stck. J. Veerendeswri /IT/ RGCET Pge 3

Step 5: δ(q 2,,zo) b b $ z 0 Finite stte control Push down store This is the finl stte in which we gin end up hving the stck empty becuse fter ll the s in the given string re dded to the stck. When the symbol b is encounter in the input string n is removed from stck bses. this confirms the sttement equl number of s nd equl number of b s in the string. PP P0 P1 P0P0 P1P1 context free grmmr for plindromes CONTEXT FREE GRMMERS: There re four importnt components in grmmticl description of lnguge: 1. There is finite set of symbols tht form the strings of the lnguge being defined. This set ws {0, 1} in the plindrome exmple we just sw. We cll this lphbet the terminls, or terminl symbols. 2. There is finite set of vribles, lso clled sometimes nonterminls or syntctic ctegories. Ech vribles represents lnguge; i.e., set of strings. In our exmples bove, there ws only one vrible, P, which we used to represent the clss of plindromes over lphbet {0, 1}. 3. One of the vribles represents the lnguge being defined; it is clled the strt symbol. Other vribles represent uxiliry clsses of strings tht re used to help define the lnguge of the strt symbol. In our exmples, P, the only vrible, is the strt symbol. 4. There is finite set of productions or rules tht represents the recursive definition of lnguge. Ech production consists of: ) vrible tht is being (prtilly) defined by the production. This vrible is often clled the hed of the production. b) The production symbol c) string of zero or more terminls nd vribles.this string, clled the body of the production, represents one wy to form strings in the lnguge of the production, represents one wy to form strings in the lnguge of the vrible of the hed. In so doing, we leve terminls unchnged nd J. Veerendeswri /IT/ RGCET Pge 4

substitute for ech vrible of the body ny string tht is known to be in the lnguge of tht vrible. The four components just described form context free grmmr, or just grmmr, or CFG. We shll represent CFG G by its four components, tht is, G= (V, T, P, S), where V is the set of vribles the terminls the set of productions, nd S the strt symbol. PPLICTION OF PUMPING LEM PPLICTION: 1. 1.check whether the given lnguge is context free lnguge or not. 2. 2.to check whether the string is finite or infinite. 3. Pumping level for cfl s sttes tht ther re lwys two short substrings close together tht cn be repeted, both the sme number of time s often we like. THEOREM Sttement: Let L be ny CFL (context free lnguge).then there is constnt n depending only on L, such tht z is in l nd z n,then we my write z=uvwxy such tht, ) ) vx 1 b) b) vwx n nd c) for ll i>0,uv i wx i y is in L. To Prove: To check whether uv i wx i y is in context free lnguge L or not Proof: Let G be Chomsky norml form grmmr generting L(G).observe tht if Z is in L(G) nd Z is long, then ny prse tree for x must contin long pth. more precisely we cn show by induction on i tht if the prse tree of word generted by Chomsky norml form grmmr hs no pth of length greter thn i, then the word is of length no greter thn 2 i-1. sis: For the pth i=1, the derivtion tree is of the form, s here n 2 i-1 where n=1,i=1 l 2 i-1 l 1 hence bsis is proved. Induction Prt: J. Veerendeswri /IT/ RGCET Pge 5

For this consider i>1.let the roots re s T1 T2 If there re no pth greter thn i,the words is of length no greter thn 2 i-1.if there re no greter thn 2 i-1.if there re no pths greter thn 2 i-1,the word is of length no greter thn 2 i-2 or fewer symbols. For proof ws the Chomsky norml form grmmr, G=({,,C},{,b},->C,C->,->,->b},) Where, V={,,C} T={,b} P={->C,->,C->,->b} S={} Consider string Z=bbbb in this grmmer.the derivtion nd derivtion tree is s follows. C C (replce ->) b C (replce ->b) b CC (replce ->C) bb CC (replce ->b) bbc (replce C->) bbbc (replce ->b) bbbc (replce ->C) bbb (replce C->) bbbb (replce ->b) bbbb (replce ->) Derivtion tree: C b C sub tree with prent vertex()v1: J. Veerendeswri /IT/ RGCET Pge 6

C b b sub tree with prent vertex()v2: In the prse tree, let p be pth tht is long or longer thn ny pth in the tree.then there must be two vertices v1 nd v2 on the pth stisfying the following conditions, 1. the vertices v1 nd v2 both hve sme lbel wy. 2. vertex v1 is closer to the root thn vertex v2. 3. the position of the pth v1 to the lef is of length lmost k+1. To use tht V1 nd V2 cn be lwys found,just proceed up pth p from the lef, keeping trck of the lbels encountered of the first k+2 vertices only the lef hs terminl lbel. Consider substring bb from the string bbbb contining the pth length i=3 C b b pth i=3 thus, =>bb=w Since pth length i=3 w 2 i-1 w =3 3 2 3-1 3 2 2 3 4 Which holds the condition w 2 i-1 for pumping lemm for CFL J. Veerendeswri /IT/ RGCET Pge 7

CLOSURE PROPERTIES OF CFL The closure properties of CFL re 1. CFL s re closed under union, conctention nd Kleene closure. 2. CFL s re closed under homomorphism 3. CFL s re closed under substitutions 4. If L is CFL nd R is regulr lnguge then, L/\R is CFL. 5. CFL s re not closed under intersection 6. CFL s re closed under complementtion. Theorem Context-free lnguges re closed under union, conctention nd kleene losure. Proof : let L1 nd L2 be CFL s generted by the CFG s G1={V1,T1,P1,S1) nd G2={V2,T2,P2,S2} Respectively. Since we my renme vribles t will without chnging the lnguge generted, we ssume tht V1 nd V2 re disjoint. ssume lso tht S2,S4 nd S5 re not in V1 or V2. For L1U L2 construct grmmr G3=(V1 U V2 U {S3},T1 U T2,P3,S3), where P3 is P1 U P2 plus the production S3 S1 S2. If w is in L1, then the derivtion S3=> S1=>w is derivtion in G3,s every production of G1 is production of G3. similrly, every word in L2 hs derivtion in G3 beginning with S3=>S2. Thus L1UL2 L(G3). For the converse, let w be in L(G3). Then the derivtion S3=>w begins with either S3=>S1=>w or S3=>S2=>w. In the former cse, s V1 nd V2 re disjoint, only symbols of G1 my pper in the derivtions S1=>w. s the only productions of P3 tht involve only symbols of G1 re those from P1, we conclude tht only productions of P1 re used in the derivtions S1=>w. Thus S1=>w, nd w is in L1. nlogously, if the derivtion strts S3=>S2, we my conclude w is in L2. Hence L(G2) L1UL2, so L(G3)= l1ul2 s desired. For conctention, let G4=(V1UV2U{S4},T1,P4,S4), where P4 is P1UP2 plus the production S4 S1 S2. proof tht L(G4)=L(G1)L(G2) is similr to the proof for union nd is omitted. For closure, let G2=(V1UV2U{S4}, T1,P2,S3), where P3 is P1 plus the productions S3 S1 S5 Є.We gin leve the proof tht L(G5)=L(G1)* to the reder. Theorem: The context-free lnguges re closed under substitution. Proof : Let L be CFL, L *, nd for ech in let L be CFL. Let L be L(G) nd for ech in let L be L(G). Without loss of generlity ssume tht the vribles of G nd the G S re disjoint. Construct grmmr G s follows the vribles of G re ll the vribles of G nd the G s, the terminls of G re the terminls of the G s. the strt symbol of G is the strt symbol of G. The productions of G re ll the productions of the G s together with those productions formed by tking production α of G nd substituting S, the strt symbol of Gn, for ech instnce of n in Σ ppering in α. Exmple : Let L be the set of words with n equl number of s nd b s L={0 1 n 1} nd L={ww r w is in (0+2)*}. For G we my choose S sbs bss є For G tke S 0S1 01 For Gb tke Sb 0Sb0 2Sb2 є If f is the substitution f()=l nd f(b)=lb, then f(l) is generted by the grmmr S S SSbS Sb SS S є J. Veerendeswri /IT/ RGCET Pge 8

S 0S1 01 Sb 0Sb0 2Sb2 є One should observe tht since {,b},{b}, nd CFL s the closure pf CFL s under substitute implies closure under union, conctention, nd *. The union of L nd Lb is simply the substitute of L nd Lb into {,b} nd similrly L Lb nd L* re tge substitute into{b} nd *, respectively. Thus theorem6.1 could be presented s corollry of theorem6.2. Since homomorphism is specil type of substitution we stte the following corollry. Corollry The CFL s re closed under homomorphism. Theorem : The context-free lnguge re closed under inverse homomorphism. Proof : s with regulr sets, mchine-bsed proof for closure under inverse homomorphism is esiest to understnd. Let h: be homomorphism nd L be CFL. Let L=L(M), where M is the PD (Q,,,δ,qo,Zo,F). In nlogy with the finite-utomton construction of theorem, we construct PD M ccepting h-1 (L) s follows. On input m M genertes the string h() nd simultes M on h(). if M were finite utomton, ll it could do on string h() would be to chnge stte, so M could simulte such composite move in one of its moves. However, in the PD cse, M could pop mny symbols on sting, or, since it is nondeterministic, mke moves tht push n rbitrry simulte M s moves on h() with one (or ny finite number of) moves of its own. Wht we do is give M buffer, in which it my store h(). then M my simulte ny є-moves of M it likes nd consume the symbols of h() one t time, s if they were M s input. s the buffer is prt of M s finite control, it cnnot be llowed to grow rbitrrily long. We ensure tht it does not, by permitting M to red n input symbol only when the buffer is empty. Thus the buffer holds suffix of h() for some t ll times. M ccepts its input w if the buffer is empty nd M is in finl stte. Tht is, M hs ccepted h(w). thus l(m )={w h(w)is in L}, tht is Input to M uffer Control of M Control Of M J. Veerendeswri /IT/ RGCET Pge 9

Stck Of M nd M' Construction of PD ccepting h 1(L) L(M )=h 1(L(M)).The rrngement is depicted in fig ;the forml construction follows. Let M =(Q,,Γ,δ,[q0, ],Zo,F { }),where Q consists of pir [q,x] such tht q is in Q nd x is (not necessrily proper)suffix of some h()for in.δ is defined s follows: 1. δ ([q,x],,y) contins ll ([p,x],γ) such tht δ(q,,y) contins(p,γ).simulte -moves of M independent of the buffer contents. 2. δ ([q,x],,y) contins ll([p,x],γ) such tht δ(q,,y) contins(p,γ). Simulte moves of M on input in, removing from the front of the buffer. 3. δ ([q, ],,Y) contins(q,h()],y) for ll in nd Y in Γ. Lod the buffer with h (), reding from M s input ; the stte of M remin unchnged. To show tht L(M )=h 1 (L(M))first observe tht by one ppliction of rule (3), followed by ppliction of rules(1)nd(2),if(q,h(),α)*/m(p,,β). Theorem:The CFL S re not closed under intersection. Proof: we showed the lnguge L1={ i b i c i i 1 } ws not CFL. We clim tht L2= { i b i c i i 1 nd L3={ i b i c i i 1 nd j 1} re both CFL s. For emple PD to recognize L2 stores the s pm its stck nd cncels them ginst b s, then ccepts its input fter seeing one or mors c s. lterntively L2 is generted by the grmmr S-> ->b b ->c c Where genertes ^ib^i nd genertes c^i. similr grmmr S->CD C->C D->bDc bc Genertes L3. However, L2^L3 =L1. If the CFL s were closed under intersection. L1 would thus be CFL. Corollry : The CFL s re not closed under complementtion. Proof: we know the CFL s re closed under union. If they were closed under complementtion, they would, by DeMorgn s lw, L1^L2=L1UL2, be closed under intersection. Theorem : If L is CFL nd R is regulr set, then L R is CFL. Proof: Let L be L(M) for PD M=(Qm,,,ᵟ,[p0,qo],z0,f fm), nd let R be L()for DF =( q,,ᵟ,p0,f ). We construct PD M for L R by running M nd in prllel, M simultes moves of M on input without chnging the stte of. when M mkes move on input symbol, M simultes tht move nd lso simultes s chnge of stte on input. M ccepts if nd only if both nd M ccept. Formlly, let M'=(Q Qm,,,ᵟ,[p0,q0],z0,F Fm) J. Veerendeswri /IT/ RGCET Pge 10

Input to,mndm' Control of M uffer Control Of M Stck of M nd M DECISION LGORITHM FOR CFL Sttement: Decision lgorithm for CFL is minly used to check whether the given lnguge is finite, empty or non finite(infinite). To Prove: To check whether the lnguge is finite, infinite or empty. ssumptions: 1. the grmmr should be in Chomsky norml form(cnf) without ᶓ production. 2. if s is the strt symbol nd r is the rnk of the symbol, then the string length will be greter then or equl to 2 r. If is the reverse vertex ssocited with s is the root node,then the string length will not be greter thn 2 r-1. If is the reverse vertex ssocited with s is the root node, then the string length will not be greter thn 2 r-2. sis : (r=0) Consider production,it is directed cyclic grph denoted by.y the ssumption non terminl with rnk r cnnot generte string of length greter thn 2 r. Here, the rnk of is 0.i.e(r=0) y the condition l 2 r, substitute r vlue, We get l 2 0 L 1 Hence it is proved by considering the form ->,we my derive only string of length 1,which is finite. Induction : J. Veerendeswri /IT/ RGCET Pge 11

If we use production of the form,we my derive only string of length 1.if we begin with C, then s nd C re of rnk r-1 or less, by the inductive hypothesis, they derive only strings of length 2 r-1 or less. Thus C cnnot derive string of length greter thn 2r. Since s is of finite rnk r0,nd in fct, is of rnk no greter thn the number of vribles derives strings of length no greter thn the number of vribles derives strings of length no greter thn 2 r0.thus the lnguge is finite. Consider n exmple, S C CC C S r (s)=3 r()=2 r()=1 r(c)=0 C Rnk of strting symbol s (r(s)=3). Rnk,r() depends on root node s, it should be less thn s nd rnk of b,r() depends on both S nd,it should be less thn both S nd. From, the figure check the condition l 2 r r (s)=3, l 2 3 l 8 r()=2, l 2 2 l 4 r() =1, l 2 1 l 2 r(c) =0, l 2 0 l 1 hence the finite length for ech string is derived..hence it proved. Now, consider the directed cyclic grph, s C For the figure, the rnk cnnot be specified. Hence for the cyclic grph the lnguge is infinite. For cyclic grph the lnguge is finite. Hence the sttement is proved. J. Veerendeswri /IT/ RGCET Pge 12