if m dfa 1 2 0 1 2 0 l m 10 2 1 q q q 1 2 0 1 0
play

( ) ( ) if = M DFA 1 2 0 , 1 2 0 L ( M ) { 10 } - PDF document

Review Languages and Grammars Alphabets, strings, languages CS 301 - Lecture 3 Regular Languages NFA DFA Equivalence Deterministic Finite Automata Regular Expressions Nondeterministic Finite Automata Today: Fall 2008


  1. Review • Languages and Grammars – Alphabets, strings, languages CS 301 - Lecture 3 • Regular Languages NFA DFA Equivalence – Deterministic Finite Automata Regular Expressions – Nondeterministic Finite Automata • Today: Fall 2008 – Equivalence of NFA and DFA – Regular Expressions – Equivalence to Regular Languages Example of equivalent Equivalence of Machines machines M NFA 1 0 L M { 10 } * ( ) 1 = q q 1 M 0 M 1 Machine is equivalent to machine 1 2 L M L M ( ) ( ) if = M DFA 1 2 0 , 1 2 0 L ( M ) { 10 } * 2 = 1 q q q 1 2 0 1 0 1

  2. Convert NFA to DFA Convert NFA to DFA a M NFA a a M λ q q q 0 1 2 a λ q q q NFA b 0 1 2 DFA M ′ b a q { } q 1 , q { } 0 2 Begin with a set M ′ DFA of start states From the NFA start states, where could we get on a? q List the set of all possible states you can reach using { } DFA start state = 0 just an a. Union of NFA Start States Convert NFA to DFA Convert NFA to DFA a M NFA NFA a M a λ q q q 0 1 2 a λ q q q 0 1 2 b b M ′ DFA a a DFA { } q M ′ { q 1 , q } 0 2 a b q { } q 1 , q { } 0 2 How did we get from q0 to q2 b λ using only a? (think ) ∅ From new set, where could we get on a? From the NFA start states, where could we get on b? ∅ The set of all possible states you can reach may be empty! 2

  3. Convert NFA to DFA Convert NFA to DFA NFA a a M NFA M a a q q λ q λ q q q 0 1 2 0 1 2 b b a a b b DFA M ′ DFA M ′ a a q q { } { } q 1 , q q 1 , q { } { } 0 0 2 2 b b From empty set, From new set, where could we we can only get a , b get on b? back to empyt set. ∅ ∅ Convert NFA to DFA Could This Produce Infinite States? a M NFA If the NFA has states a λ q q q q , q , q ,... 0 1 2 0 1 2 b There are a finite number of NFA states by definition a b DFA M ′ the DFA has states in the powerset a q { } q 1 , q { } 0 2 , q , q , q , q , q , q , q ,.... { }{ }{ }{ } ∅ 0 1 1 2 3 4 7 b If a node has any Powerset of finite set can be big, but it is not infinite! NFA Final state, a , b mark the node as ∅ Final in the DFA. 3

  4. Procedure NFA to DFA Procedure NFA to DFA { q , q ,..., q } 2. For every DFA’s state i j m 1. Initial state of NFA: q 0 Compute in the NFA * q , a , ( ) δ i { q , q ,..., q } = ′ ′ ′ i j m q ( ) { } * q , a , Initial state of DFA: δ 0 j Add transition to DFA ... ( ) { q , q ,..., q }, a { q , q ,..., q } ′ ′ ′ δ = i j m i j m Procedure NFA to DFA Procedure NFA to DFA 3. For any DFA state { q , q ,..., q } i j m Repeat Step 2 for all letters in alphabet, q until no more transitions can be added. If some is a final state in the NFA j { q , q ,..., q } Then, i j m is a final state in the DFA 4

  5. Proof Theorem L ( M ) L ( M ) = ′ Take NFA M Apply procedure to obtain DFA M ′ L M L M L M L M ( ) ( ) AND ( ) ( ) ⊆ ′ ⊇ ′ M Then and are equivalent : M ′ L ( M ) L ( M ) ′ = w ∈ L ( M ) L M L M First we show: ( ) ( ) ⊆ ′ w ∈ L ( M ) Take arbitrary: w q q M : f 0 We will prove: w L ( M ) ′ ∈ w  = σ σ σ 1 2 k q σ σ σ q M : 1 2 k f 0 5

  6. More generally, we will show that if in : M We will show that if w ∈ L ( M ) v a a  a (arbitrary string) = 1 2 n w  = σ σ σ 1 2 k a a a q n q 1 q 2 q q M : 0 m i j l σ q σ σ q 1 2 k M : f 0 σ σ σ M ′ : 1 2 k a a a M ′ : n 1 2 { 0 q } { q , … } f w L ( M ) … { 0 q } … { q , } { q , … } { q , … } ′ { q , } ∈ j i l m Proof by induction on | v | Induction hypothesis: 1 | v ≤ | k ≤ v = a Induction Basis: 1 v a a  a = 1 2 k a a a q q k q 1 2 q q M : d 0 c a i j q 1 q M : 0 i a M ′ : 1 a a a M ′ : 1 2 k { 0 q } { q , … } i { 0 q } { q , … } { q , … } { q , … } { q , … } j c d i 6

  7. Induction Step: | v | = k 1 Induction Step: | v | = k 1 + + v a   a a a v a v a   a a a v a ′ ′ = = = = 1 2 k k 1 k 1 1 2 k k 1 k 1     + +     + + v v ′ ′ a a a a a a a q q k q q q k q q 1 q 2 q 1 q 2 q k 1 M : M : + d d 0 c 0 c e i j i j v ′ v ′ a a a a a a a M ′ : k M ′ : k k 1 1 2 1 2 + … … { 0 q } … { q , } { q , … } { q , … } { 0 q } … { q , } { q , … } { q , … } { q , … } { q , } { q , } j j i c d i c d e v ′ v ′ w ∈ L ( M ) Therefore if L ( M ) L ( M ) We have shown: ′ ⊆ w  = σ σ σ 1 2 k q σ σ σ q k M : 1 2 f 0 L ( M ) L ( M ) We also need to show: ′ ⊇ (proof is similar) σ σ σ M ′ : 1 2 k { 0 q } { q , … } f w L ( M ) ′ ∈ 7

  8. We will prove: Languages = Regular accepted NFAs Accept Regular Languages by NFAs Languages Languages accepted by DFAs NFAs and DFAs have the same computation power Step 1 Step 2 Languages Languages Regular Regular accepted accepted Languages Languages by NFAs by NFAs Proof: Any NFA can be converted to an Proof: Every DFA is trivially an NFA equivalent DFA L Any language accepted by a DFA L Any language accepted by an NFA is also accepted by an NFA is also accepted by a DFA 8

  9. Recursive Definition Regular Expressions Primitive regular expressions: , λ , ∅ α • Regular expressions describe regular r r Given regular expressions and 1 2 languages r r + 1 2 ( a b c ) * + ⋅ • Example: r r ⋅ 1 2 Are regular expressions describes the language r * 1 a , bc * , a , bc , aa , abc , bca ,... { } { } = λ r ( ) 1 Languages of Regular Examples Expressions A regular expression: L r r ( ) • : language of regular expression ( a b c ) * ( c ) + ⋅ ⋅ + ∅ • Example ( a + b ) Not a regular expression: + L ( ( a b c ) * ) { , a , bc , aa , abc , bca ,... } + ⋅ = λ 9

  10. Definition (continued) Formal Definition r r • For regular expressions and 1 2 • For primitive regular expressions: L r r L r L r ( ) ( ) ( ) + = ∪ 1 2 1 2 L ( ) ∅ = ∅ L ( r r ) L ( ) ( ) r L r ⋅ = 1 2 1 2 L ( ) { } λ = λ L r * L r ) * ( ) ( ( ) = 1 1 L ( ) { } a a = L r L r ( ( ) ) ( ) = 1 1 Example Example L a b L a * ( ( ) ) ( ) L ( ( a b ) a * ) = + + ⋅ L a b L a * ( ) ( ) = + • Regular expression ( L ( ) a L ( ) b ) ( L ( ) a ) * = ∪ r a b * a bb ( ) ( ) = + + a ∪ b a ) * ( { } { } ) { } ( = L ( ) { r a , bb , aa , abb , ba , bbb ,... } { a , b }{ , a , aa , aaa ,... } = = λ { a , aa , aaa ,..., b , ba , baa ,... } = 10

  11. What’s Next • Read – Linz Chapter 1, 2.1, 2.2, 2.3, (skip 2.4), Chapter 3 – JFLAP Startup, Chapter 1, 2.1, (skip 2.2) 3, 4 • Next Lecture Topics from Chapter 3.2 and 3.3 – Regular Expressions and Regular Languages – Regular Grammars and Regular Languages • Quiz 1 in Recitation on Wednesday 9/17 – Covers Linz 1.1, 1.2, 2.1, 2.2, 2.3, and JFLAP 1, 2.1 – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you like. – Quiz will take the full hour • Homework – Homework 2 is Due Thursday 11

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend