0
Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Theory of Computation: Lecture 35

1,966

Published on

Published in: Education, Technology
1 Comment
2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• sir please enable the save option for ppt

Are you sure you want to  Yes  No
Views
Total Views
1,966
On Slideshare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
0
1
Likes
2
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. CS 5000: Theory of Computation Lecture 35 Vladimir Kulyukin Department of Computer Science Utah State Universitywww.youtube.com/vkedco
• 2. Outline ● Review ● Regular Grammars ● Right Linear Grammars ● Left Linear Grammars ● Regular Grammars and Regular Languageswww.youtube.com/vkedco
• 3. Review: Pumping Lemma Let L = L( M ) , where M is a DFA with n states. Let x ∈ L and x ≥ n. Then we can write x = uvw, where 1 ≤ v and uv w ∈ L, for i ≥ 0. iwww.youtube.com/vkedco
• 4. Review: Pumping Lemma Use ● Pumping Lemma is not used to prove that languages are regular ● Pumping Lemma states that if a language is regular, then its strings have a specific property (pumping property) ● Pumping Lemma is used to show that languages are not regular: assume that a language is regular and then show that a specific string does not satisfy the pumping propertywww.youtube.com/vkedco
• 5. Review: Finite Automata Applications ● Text Processors – Computational Linguistics – Compilers – Bioinformatics ● Roboticswww.youtube.com/vkedco
• 6. Review: Derivation w ⇒ z ( w derives z ) if and only if 1) there exist strings u , x, y, v ∈ ( Σ ∪ V ) , x ≠ ε , * 2) w = uxv, z = uyv, and ( x → y ) ∈ P. w ⇒ z if and only if there is a derivation * of zero or more steps that starts with w and ends with z.www.youtube.com/vkedco
• 7. Language Generated by Grammar Let G be a grammar. { Then L( G ) = x ∈ Σ | S ⇒ * * } x.www.youtube.com/vkedco
• 8. Example Consider G = ( { S , X } , { a, b}, S , { S → aS , S → X , X → bX , X → ε } ). Let us write the rules out for ease of reference : 1) S → aS ; 2) S → X ; 3) X → bX ; 4) X → ε Is aaab ∈ L( G ) ? By definition, aaab ∈ L( G ) iff S ⇒ * aaab. Let us try to find a derivation. S ⇒ aS (Rule 1) ⇒ aaS (Rule 1) ⇒ aaaS (Rule 1) ⇒ aaaX (Rule 2) ⇒ aaabX (Rule 3) ⇒ aaab (Rule 4) .www.youtube.com/vkedco
• 10. Regular Grammars ● Two types of regular grammars: – Right linear grammars – Left linear grammars ● They are called regular, because they generate regular languages ● Regular grammars can be viewed as a bridge from regular expressions to context-free grammars (or from finite state automata to stack machines)www.youtube.com/vkedco
• 11. Right Linear Grammar A grammar G = (V , Σ , S , P ) is right linear iff every production in P has one of the two forms : 1. X → zY ; 2. X → z; where X ∈ V , Y ∈ V , and z ∈ Σ * .www.youtube.com/vkedco
• 12. Regular Linear Grammars and Regular Languageswww.youtube.com/vkedco
• 13. Right Linear Grammars & Regular Languages Theorem: If G is a right linear grammar, L(G) is regular. Proof Insight: Construct an NFA M such that L(M) = L(G).www.youtube.com/vkedco
• 14. Proof For every production of the form X  a1a2a3...akY, add the following transitions to the NFA: a1 a2 a3 ak X … Ywww.youtube.com/vkedco
• 15. Proof Note that if X  Y, then we add the following production: ε X Ywww.youtube.com/vkedco
• 16. Proof For every production of the form X  a1a2a3...ak, add the following transitions to the NFA. F is the symbol that we use to designate the final state. a1 a2 a3 ak X … Fwww.youtube.com/vkedco
• 17. Proof For every production of the form X  ε, no additional transitions need to be added to the NFA. ε X is the same as Xwww.youtube.com/vkedco
• 18. Example ● Consider the following grammar: – S  1S | 0T | ε – T  1T | 0U – U  1U | 0Swww.youtube.com/vkedco
• 19. Example 1 S Modeling Production S  1Swww.youtube.com/vkedco
• 20. Example 1 0 S T Modeling Production S  0Twww.youtube.com/vkedco
• 21. Example 1 0 S T Modeling Production S  ε S becomes a final statewww.youtube.com/vkedco
• 22. Example 1 1 0 S T Modeling Production T  1Twww.youtube.com/vkedco
• 23. Example 1 1 0 0 S T U Modeling Production T  0Uwww.youtube.com/vkedco
• 24. Example 1 1 1 0 0 S T U Modeling Production U  1Uwww.youtube.com/vkedco
• 25. Example 1 1 1 0 0 S T U 0 Modeling Production U  0Swww.youtube.com/vkedco
• 27. Language Reversals If x ∈ Σ * , then x R is the reversal of x. Examples : x = ab, x R = ba; x = 011, x R = 110. { If L is a language, then L = x | x ∈ L . R R } Examples : L = { 01,010,110,011}, LR = {10,010,011,110}; L = 01* , LR = 1*0.www.youtube.com/vkedco
• 28. Left Linear Grammar A grammar G = (V , Σ , S , P ) is left linear iff every production in P has one of the two forms : 1. X → Yz; 2. X → z; where X ∈ V , Y ∈ V , and z ∈ Σ . *www.youtube.com/vkedco
• 29. Left Linear Grammars and Regular Languageswww.youtube.com/vkedco
• 30. Left Linear Grammars & Regular Languages Theorem: If G is a left linear grammar, then L(G) is regular. Proof Insight: Convert G to a right linear grammar GR such that L(G) = [L(GR)]R.www.youtube.com/vkedco
• 31. Proof ● Given a left-linear grammar G, construct a right-linear grammar GR by reversing its rules ● L(GR) = LR ● Construct an NFA for GR with a single start state and a single final state (this is always possible with ε-moves) ● Reverse the NFA by reversing the direction of the arcs and making the old start state the new final state and the old final state the new start statewww.youtube.com/vkedco
• 32. Proof If G has a production of the form X → Yz, then GR has a production X → z Y . If G has R a production X → z , then GR has a production X → z . Then if x ∈ L( G ) , then x ∈ L( GR ). R R Thus, x = ( x ) ∈ [ L( G ) ] R R R R .www.youtube.com/vkedco
• 33. Regular Grammars & Regular Languages Left - linear Grammars = Right - linear Grammars Regular Grammars ⊆ Regular Languageswww.youtube.com/vkedco
• 34. From Regular Languages to Regular Grammarswww.youtube.com/vkedco
• 35. From Regular Languages to Regular Grammars Theorem: If L is a regular language, there is a right linear grammar G such that L(G) = L. Proof Insight: Take an NFA M such that L(M) = L and construct a right linear grammar G from its transitions such that L(G) = L.www.youtube.com/vkedco
• 36. Proof Let M be an NFA such that L( M ) = L. We construct a right linear G as follows. For every transition of the form δ ( q, a ) = { r1 ,..., rn } , n ≥ 1, add the productions q → ar1 | ... | arn . For every final state q ∈ F , add the production q → ε . By induction on the length of x, x ∈ L( M ) iff x ∈ L( G ).www.youtube.com/vkedco
• 37. Example a c NFA M b ε Q0 Q1 Q2 Q0  aQ0 Q0  bQ1 Right Linear Grammar G: Q1  cQ1 Q1  Q2 Q2  εwww.youtube.com/vkedco
• 38. Regular Languages & Regular Grammars Regular Languages ⊆ Regular Grammarswww.youtube.com/vkedco
• 39. Regular Languages = Regular Grammars Regular languages ⊆ Regular grammars Regular grammars ⊆ Regular languages Regular grammars = Regular languageswww.youtube.com/vkedco