NFAs accept the Regular Languages 1 Equivalence of Machines Definition: Machine if M1 is equivalent to machine M 2 L M1 L M 2 2 Example of equivalent machines NFA LM1 {10} * 0 q0 q1 1 FA LM 2 {10} * M1 M2 0,1 0 q0 1 q1 1 q2 0 3 We will prove: Languages accepted by NFAs NFAs and FAs have the same computation power Regular Languages Languages accepted by FAs 4 We will show: Languages accepted by NFAs Regular Languages Languages accepted by NFAs Regular Languages 5 Proof-Step 1 Languages accepted by NFAs Regular Languages Proof: Every FA is trivially an NFA Any language L accepted by a FA is also accepted by an NFA 6 Proof-Step 2 Languages accepted by NFAs Regular Languages Proof: Any NFA can be converted to an equivalent FA Any language L accepted by an NFA is also accepted by a FA 7 Convert NFA to FA a NFA M q2 q0 a q1 b FA M q0 8 Convert NFA to FA a NFA M q2 q0 a q1 b FA M q0 a q1,q2 9 Convert NFA to FA a NFA M q2 q0 a q1 b FA M q0 a q1,q2 b 10 Convert NFA to FA a NFA M q2 q0 a q1 b FA a M q0 a q1,q2 b 11 Convert NFA to FA a NFA M q2 q0 a q1 b FA M a b q0 a q1,q2 b 12 Convert NFA to FA a NFA M q2 q0 a q1 b FA M a b q0 a q1,q2 b a, b 13 Convert NFA to FA a NFA M q2 q0 a q1 b LM L(M ) FA M a b q0 a q1,q2 b a, b 14 NFA to FA: Remarks We are given an NFA M We want to convert it to an equivalent FA M With LM L(M ) 15 If the NFA has states q0 , q1, q2 ,... the FA has states in the powerset , q0 , q1, q1, q2 , q3 , q4 , q7 ,.... 16 Procedure NFA to FA 1. Initial state of NFA: Initial state of FA: q0 q0 17 NFA Example a M q0 a q1 q2 b FA M q0 18 Procedure NFA to FA 2. For every FA’s state {qi , q j ,..., qm } Compute in the NFA * qi , a , * q j , a , } {qi , qj ,..., qm ... Add transition to FA } {qi , q j ,..., qm }, a {qi , qj ,..., qm 19 NFA Exampe a M q0 a q1 q2 b * (q0 , a) {q1, q2} FA M q0 a q1,q2 q0 , a q1, q2 20 Procedure NFA to FA Repeat Step 2 for all letters in alphabet, until no more transitions can be added. 21 NFA Example a M q0 a q1 q2 b FA M a b q0 a q1,q2 b a, b 22 Procedure NFA to FA 3. For any FA state If {qi , q j ,..., qm } q j is accepting state in NFA Then, {qi , q j ,..., qm } is accepting state in FA 23 NFA Example a M q0 a q1 q2 q1 F b FA M a b q0 a q1,q2 q1, q2 F b a, b 24 Take NFA Theorem M Apply procedure to obtain FA Then M and M M are equivalent : L M L M 25 Proof L M L M L M L M AND L M L M 26 First we show: L M L M Take arbitrary: w L(M ) We will prove: w L(M ) 27 w L(M ) M: w q0 qf w 1 2 k M: q0 1 2 k qf 28 qi i qj denotes qi i qj 29 We will show that if w L(M ) w 1 2 k M: q0 1 k 2 qf then M: 1 {q0 } 2 w L(M ) k {q f ,} 30 More generally, we will show that if in (arbitrary string) M: q0 a1 M: v a1a2 an qi a2 qj ql an qm then M: a1 {q0 } a2 {qi ,} {q j ,} an {ql ,} {qm ,} 31 Proof by induction on Induction Basis: M: |v| v a1 q0 M: a1 qi a1 {q0 } {qi ,} Is true by construction of M: 32 Induction hypothesis: 1 | v | k v a1a2 ak M: q0 M: a1 a1 {q0 } qi a2 qj a2 {qi ,} {q j ,} qc ak qd ak {qc ,} {qd ,} 33 Induction Step: | v | k 1 v a1a2 ak ak 1 vak 1 v M: q0 a1 qi a2 qj qc ak qd v M: a1 {q0 } ak a2 {qi ,} {q j ,} v {qc ,} {qd ,} 34 Induction Step: | v | k 1 v a1a2 ak ak 1 vak 1 v M: q0 a1 qi a2 qj qc ak qd ak 1 qe v M: a1 {q0 } ak a2 {qi ,} {q j ,} v ak 1 {qc ,} {qd ,} {qe ,} 35 Therefore if w L(M ) w 1 2 k M: q0 1 k 2 qf then M: 1 {q0 } 2 w L(M ) k {q f ,} 36 We have shown: L M L M We also need to show: L M L M (proof is similar) 37 Single Accepting State for NFAs 38 Any NFA can be converted to an equivalent NFA with a single accepting state 39 a Example NFA b a b Equivalent NFA a a b b 40 NFA In General Equivalent NFA Single accepting state 41 Extreme Case NFA without accepting state Add an accepting state without transitions 42 Properties of Regular Languages 43 For regular languages we will prove that: Union: Concatenation: L1 and L2 L1 L2 L1L2 Star: L1 * Reversal: R L1 Complement: L1 Intersection: L1 L2 Are regular Languages 44 We say: Regular languages are closed under Union: Concatenation: L1 L2 L1L2 Star: L1 * Reversal: R L1 Complement: L1 Intersection: L1 L2 45 Regular language LM1 L1 NFA M1 Single accepting state L1 Regular language L2 LM 2 L2 NFA M2 Single aceepting state 46 Example n0 L1 {a b} n M1 a b M2 L2 ba b a 47 NFA for L1 L2 Union M1 M2 48 Example NFA for L1 L2 {a b} {ba} n L1 {a b} n a b L2 {ba} b a 49 Concatenation NFA for L1L2 M1 M2 50 Example NFA for L1L2 {a b}{ba} {a bba} n L1 {a b} n n L2 {ba} a b b a 51 Star Operation NFA for L1 * L1 * M1 52 Example NFA for w w1w2 wk L1* {a b} * n wi L1 L1 {a b} n a b 53 Reverse NFA for L1 M1 L1 R M1 1. Reverse all transitions 2. Make initial state accepting state and vice versa 54 Example M1 a L1 {a b} n b a R L1 {ba } n M1 b 55 Complement L1 M1 M1 L1 1. Take the FA that accepts L1 2. Make final states non-final, and vice-versa 56 Example M1 a, b a L1 {a b} n b L1 {a, b} * {a b} n a, b M1 a, b a b a, b 57 Intersection L1 regular We show L2 regular L1 L2 regular 58 DeMorgan’s Law: L1 L2 L1 L2 L1 , L2 regular L1 , L2 regular L1 L2 regular L1 L2 regular L1 L2 regular 59 Example L1 {a b} regular n L2 {ab, ba} regular L1 L2 {ab} regular 60 Another Proof for Intersection Closure Machine FA for M1 L1 Construct a new FA Machine FA for M2 L2 M that accepts L1 L2 M simulates in parallel M1 and M 2 61 States in M qi , p j State in M1 State in M2 62 FA q1 FA M1 a q2 a p1 transition M2 p2 transition FA q1, p1 M a q2 , p2 transition 63 FA FA M1 M2 q0 p0 initial state initial state FA M q0 , p0 Initial state 64 FA FA M1 pj qi accept state pk accept states FA qi , p j M2 M qi , pk accept states Both constituents must be accepting states 65 Example: n0 m0 L1 {a b} L2 {ab } M1 M2 n a q0 b q2 m q1 p0 a, b b a, b a b p1 a p2 a, b 66 Automaton for intersection n n L {a b} {ab } {ab} a, b q0 , p0 a b q1, p2 q0 , p1 b q1, p1 a b a a b q0 , p2 q2 , p2 q2 , p1 a b a, b 67 M simulates in parallel M1 and M 2 M accepts string w if and only if M1 accepts string w M 2 accepts string w and L ( M ) L ( M1 ) L ( M 2 ) 68