Download presentation

Published byHassan Willits Modified over 2 years ago

1
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer Science University of Virginia

2
**Closure Properties of CFLs**

Theorem: The context-free languages are closed under union. Hint: Derive a new grammar for the union. Let G1 =(V1, Σ,R1, S1), G2 =(V2, Σ,R2, S2) Then G1+2 =(V1 +V2 +{S}, Σ, R1 + R2 +{S→ S1 | S2}, S) S→ S1 | S2 S1 →… S2 →…

3
**Closure Properties of CFLs**

Theorem: The CFLs are closed under Kleene closure. Hint: Derive a new grammar for the Kleene closure. Let G =(V, Σ,R, S) Then G* =(V, Σ,R+ {S → SS|ε}, S) S → SS|ε|…

4
**Closure Properties of CFLs**

Theorem: The CFLs are closed under Ç with regular langs. Hint: Simulate PDA and FA in parallel. Let FSA Mfsa=(Qf, S, df, qf, Ff), PDA Mpda =(Qp, S, G, dp, qp, Fp) Then M∩=(Qf ×Qp, S, G, d, (qf ,qp), Ff ×Fp) d: Qf ×Qp ´(SÈ{e})´G ® 2Q´G* s.t. d (qf, qp, s, g) = df(qf, s) ´ dp(qp, s, g) Mpda a b stack × Mfsa

5
**Closure Properties of CFLs**

Theorem: The CFLs are not closed under intersection. Hint: Find a counter example. L={an bn cn} is not context free (Involves pumping lemma of CFLs, we’ll get to it) Let L1={ai bj cj}, L2 ={ai bi cj} L1 ∩L1 = L

6
**Closure Properties of CFLs**

Theorem: The CFLs are not closed under complementation. Hint: Use De Morgan’s law. Assume FSORC that CFLs are closed under complementation. Since we know that they are closed under union we can find

7
**Decidable PDA / CFG Problems**

Given an arbitrary pushdown automata M the following problems are decidable (i.e., have algorithms): Q1: Is L(M) = Ø ? Q5: Is L(G) = Ø ? Q2: Is L(M) finite ? Q6: Is L(G) finite ? Q3: Is L(M) infinite ? Q7: Is L(G) infinite ? Q4: Is w Î L(M) ? Q8: Is w Î L(G) ? (or CFG G) ≡ Extra-credit: prove each!

8
**Undecidable PDA / CFG Problems**

Theorem: the following are undecidable (i.e., there exist no algorithms to answer these questions): Q: Is PDA M minimal ? Q: Are PDAs M1 and M2 equivalent ? Q: Is CFG G minimal ? Q: Is CFG G ambiguous ? Q: Is L(G1) = L(G2) ? Q: Is L(G1) Ç L(G2) = Ø ? Q: Is CFL L inherently ambiguous ? ≡ Extra-credit: prove each!

9
**Extra-credit: prove each!**

PDA Enhancements Theorem: 2-way PDAs are more powerful than 1-way PDAs. Hint: Find an example non-CFL accepted by a 2-way PDA. Theorem: 2-stack PDAs are more powerful than 1-stack PDAs. Hint: Find an example non-CFL accepted by a 2-stack PDA. Theorem: 1-queue PDAs are more powerful than 1-stack PDAs. Hint: Find an example non-CFL accepted by a 1-queue PDA. Theorem: 2-head PDAs are more powerful than 1-head PDAs. Hint: Find an example non-CFL accepted by a 2-head PDA. Theorem: Non-determinism increases the power of PDAs. Hint: Find a CFL not accepted by any deterministic PDA. Extra-credit: prove each!

10
**PDA = CFG Loop start Var S end**

Theorem: If a Language is derivable by some context free grammar then it is accepted by some PDA Proof idea: Construct a PDA which checks if there is a way of reversing the substitution rules of the grammar to produce the start variable. Machine description: Put the symbol ‘$’ onto the stack Put the start symbol onto the stack Repeat the following: If the top of the stack has a variable V, nondeterministically choose a substitution rule . Pop the V and push the rhs of the rule onto the stack If the top is a terminal symbol ‘a’ then check if the next input symbol is also ‘a’ . If so then pop the ‘a’, if not then reject. If the top of the stack is ‘$’ then enter the accept state, accept if all input has been read. ε, ↓$ Var S ε, ↑V↓R ε, ↓S Loop ε, ↑$ a, ↑a end

11
**PDA = CFG Loop start Var S end Example: S→aSb|ε ε, ↓$ ε, ↑S↓bSa ε, ↓S**

b, ↑b a, ↑a ε, ↑$ end

12
**PDA = CFG Loop start Var S end Example: S→aSaa|B B→bB|ε ε, ↓$**

ε, ↑S↓aaSa ε, ↓S b, ↑b Loop ε, ↑S↓B a, ↑a ε, ↑B ε, ↑B↓Bb ε, ↑$ end

13
PDA = CFG Theorem: If a Language is accepted by some PDA then it is derivable by some CFG Proof idea: For every pair of states (p,q) in the machine construct a variable. This variable generates all strings that cause the machine to transition from p with an empty stack to q on an empty stack. The variable for (start, accept) is the start variable. Machine restrictions: There is a unique accept state The stack is empty before accepting Each transition performs at most 1 stack operation Construction: There are two cases for states (p,q): The last item popped is the same as the first item pushed, apply the rule Vpq →a Vrs b where ‘a’ matches the transition out of p to state r, and ‘b’ matches the transition out of state s to state q. The stack was emptied previously in in the path. For the latter we add rule Vpq →Vpr Vrq where r is the state where the stack becomes empty.

14
**PDA = CFG start a‘s b‘s Va,a → ε Va,b → b Va,end →ba Vb,b → ε**

Example: Vstart,start → ε Vstart,a → a Vstart,b →ab Vstart,end → a Va,b a a b a start a‘s b‘s end Va,a → ε Va,b → b Va,end →ba Vb,b → ε Vb,end →a Vend,end → ε

15
**PDA = CFG a‘s b‘s start Va,b → a Va,b b|a Va,ab Va,end → Vb,start →**

Example: Vstart,start → ε Vstart,a → Vstart,b → Vstart,end → ε| ε Va,b ε Va,start → Va,a → ε a‘s ε, ↓$ end b‘s a, ↓a start b, ↑a ε, ↑$ ε Va,b → a Va,b b|a Va,ab Va,end → Vb,start → Vb,a → Vb,b → ε Vb,end → Vend, start → Vend,a → Vend,b → Vend,end → ε

16
**PDA = CFG a‘s b‘s start Va,b → a Va,b a| b Va,b b| ε Va,end →**

Example: Vstart,start → ε Vstart,a → Vstart,b → Vstart,end → ε Va,b ε Va,start → Va,a → ε a‘s ε, ↓$ end b‘s a, ↓a b, ↓b start ε ε, ↑$ a, ↑ a b, ↑ b Va,b → a Va,b a| b Va,b b| ε Va,end → Vb,start → Vb,a → Vb,b → ε Vb,end → Vend, start → Vend,a → Vend,b → Vend,end → ε

17
**Parse Tree Describes derivation of a string from a CFG Examples:**

S→aSaa|B B→BB|b|ε S B a aa b S ® a for each aÎSL S ® (S) | SS | S* | S+S S ( a + b ) *

18
**Pumping Lemma for Context Free Languages**

If L is a CFL then there is some number p such that for any string s in L where |s|>p we can divide s into 5 substrings s=uvxyz in a way to satisfy all of the following: For each i≥0, |vy|>0 |vxy|≤p

19
**Pumping Lemma for Context Free Languages**

For each i≥0, |vy|>0 |vxy|≤p Proof: Consider the CFG for L. The grammar has a finite number of production rules. If a string is long enough, some variable must have been reached twice. S u z R v y x S R u v x y z S R u x z

20
**Pumping Lemma for Context Free Languages**

For each i≥0, |vy|>0 |vxy|≤p Example: Consider: If any of a,b,c are not part of vy then we definitely fail rule 1. Because of rule 3 if v contains the letter ‘a’ then y cannot contain the letter ‘b’

21
**Pumping Lemma for Context Free Languages**

For each i≥0, |vy|>0 |vxy|≤p Example:. Consider: If neither a,c or b,d are not part of vy then we definitely fail rule 1. Because of rule 3 if v contains the letter ‘a’ then y cannot contain the letter ‘c’ If v contains the letter ‘b’ then y cannot contain the letter ‘d’

22
**Pumping Lemma for Context Free Languages**

For each i≥0, |vy|>0 |vxy|≤p Example: Consider: If I modify the first set of ‘a’s then I must also modify the second set. If v contains one of the first set of ‘a’s then y cannot contain one of the second set due to rule 3. The case for the ‘b’s is similar.

23
Here Be an extra slide

24
**Pumping Lemma for Context Free Languages**

For each i≥0, |vy|>0 |vxy|≤p Proof: Consider the CFG for L. The grammar has a finite number of production rules. If a string is long enough, some rule must have been applied twice. S R u v x y z S R u x z S R u v x y z

Similar presentations

Presentation is loading. Please wait....

OK

Theory of Computation Automata Theory Dr. Ayman Srour.

Theory of Computation Automata Theory Dr. Ayman Srour.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Seminar ppt on secure atm by image processing Problem solution reading ppt on ipad Ppt on models of business communication Decoding in reading ppt on ipad Ppt on porter's five forces model Free ppt on history of cricket Maths ppt on binomial theorem Ppt on viruses and antiviruses Ppt on asian continental divide Ppt on operating system concepts