nfa - NONDETERMINISM 0, 1 0 0 0 q0 q1 q2 q3 NONDETERMINISM...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: NONDETERMINISM 0, 1 0 0 0 q0 q1 q2 q3 NONDETERMINISM 0, 1 0 0 0 q0 q1 q2 q3 Allows zero, one or more edges labeled ”0” (or ”1”) from any state q . NONDETERMINISM 0, 1 0 0 0 q0 q1 q2 q3 Allows zero, one or more edges labeled ”0” (or ”1”) from any state q . • Important concept in the Theory of Computer Science. NONDETERMINISM 0, 1 0 0 0 q0 q1 q2 q3 Allows zero, one or more edges labeled ”0” (or ”1”) from any state q . • Important concept in the Theory of Computer Science. • Allows many computational paths to be followed simultaneously. NONDETERMINISTIC FINITE AUTOMATA (NFA) M accepts w if and only if there exists a path from q0 labeled w to some final state. NONDETERMINISTIC FINITE AUTOMATA (NFA) M accepts w if and only if there exists a path from q0 labeled w to some final state. M = (Q, Σ, δ, q0 , F ) NONDETERMINISTIC FINITE AUTOMATA (NFA) M accepts w if and only if there exists a path from q0 labeled w to some final state. M = (Q, Σ, δ, q0 , F ) Q, Σ, q0 , F : same as for DFA NONDETERMINISTIC FINITE AUTOMATA (NFA) M accepts w if and only if there exists a path from q0 labeled w to some final state. M = (Q, Σ, δ, q0 , F ) Q, Σ, q0 , F : same as for DFA δ : Q × Σ → 2Q : (power set of Q) NONDETERMINISTIC FINITE AUTOMATA (NFA) M accepts w if and only if there exists a path from q0 labeled w to some final state. M = (Q, Σ, δ, q0 , F ) Q, Σ, q0 , F : same as for DFA δ : Q × Σ → 2Q : (power set of Q) set of possible next states from state q on input a: δ (q, a) ⊆ Q FORMALLY Extension of δ : ˆ δ : Q × Σ ∗ → 2Q FORMALLY Extension of δ : ˆ δ (q, ￿) = {q } ˆ δ : Q × Σ ∗ → 2Q FORMALLY Extension of δ : ˆ δ : Q × Σ ∗ → 2Q ˆ δ (q, ￿) = {q } ￿ ˆ ˆ δ (q, va) = r∈δ(q,v) δ (r, a) = {p : ∃r ∈ δ (q, v ), p ∈ δ (r, a)} ˆ FORMALLY Extension of δ : ˆ δ : Q × Σ ∗ → 2Q ˆ Note: δ agrees with δ on Q × Σ, so it extends δ . ˆ δ (q, ￿) = {q } ￿ ˆ ˆ δ (q, va) = r∈δ(q,v) δ (r, a) = {p : ∃r ∈ δ (q, v ), p ∈ δ (r, a)} ˆ FORMALLY Extension of δ : ˆ δ : Q × Σ ∗ → 2Q ˆ Note: δ agrees with δ on Q × Σ, so it extends δ . ˆ δ (q, ￿) = {q } ￿ ˆ ˆ δ (q, va) = r∈δ(q,v) δ (r, a) = {p : ∃r ∈ δ (q, v ), p ∈ δ (r, a)} ˆ FORMALLY Extension of δ : ˆ δ : Q × Σ ∗ → 2Q ˆ Note: δ agrees with δ on Q × Σ, so it extends δ . L(M ) = {w : δ (q0 , w) ∩ F ￿= ∅} ˆ δ (q, ￿) = {q } ￿ ˆ ˆ δ (q, va) = r∈δ(q,v) δ (r, a) = {p : ∃r ∈ δ (q, v ), p ∈ δ (r, a)} ˆ FORMALLY Extension of δ : ˆ δ : Q × Σ ∗ → 2Q ˆ Note: δ agrees with δ on Q × Σ, so it extends δ . L(M ) = {w : δ (q0 , w) ∩ F ￿= ∅} ˆ δ (q, ￿) = {q } ￿ ˆ ˆ δ (q, va) = r∈δ(q,v) δ (r, a) = {p : ∃r ∈ δ (q, v ), p ∈ δ (r, a)} ˆ M accepts w iff there is a final state that M could end up in upon reading w. EXAMPLE 0, 1 1 0,1 0,1 q0 q1 q2 ... ... 0,1 qn EXAMPLE 0, 1 1 0,1 0,1 q0 q1 q2 ... ... 0,1 qn 0, 1 0 1 0 0 q0 1 1 DFA VS. NFA Q: Is a DFA an NFA? DFA VS. NFA Q: Is a DFA an NFA? A: Well ... almost. DFA VS. NFA Q: Is a DFA an NFA? A: Well ... almost. Theorem. If L is accepted by a DFA, then L is accepted by an NFA. DFA VS. NFA Q: Is a DFA an NFA? A: Well ... almost. Theorem. If L is accepted by a DFA, then L is accepted by an NFA. Theorem. Regular languages = {L : ∃ DFA accepting L} = {L : ∃ NFA accepting L}. DFA VS. NFA Q: Is a DFA an NFA? A: Well ... almost. Theorem. If L is accepted by a DFA, then L is accepted by an NFA. Theorem. Regular languages = {L : ∃ DFA accepting L} = {L : ∃ NFA accepting L}. Idea: From the NFA build a DFA that keeps track of all the states that the NFA could be in at any time while reading the input. EXAMPLE 0 0 0 1 q0 q1 1 1 q3 FORMAL CONSTRUCTION Let M = (Q, Σ, δ, q0 , F ) be an NFA FORMAL CONSTRUCTION Let M = (Q, Σ, δ, q0 , F ) be an NFA ￿ Define DFA M ￿ = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) by: FORMAL CONSTRUCTION Let M = (Q, Σ, δ, q0 , F ) be an NFA ￿ Define DFA M ￿ = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) by: Q￿ = 2Q power set of Q FORMAL CONSTRUCTION Let M = (Q, Σ, δ, q0 , F ) be an NFA ￿ Define DFA M ￿ = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) by: Q￿ = 2Q ￿ q0 = {q0 } power set of Q FORMAL CONSTRUCTION Let M = (Q, Σ, δ, q0 , F ) be an NFA ￿ Define DFA M ￿ = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) by: Q￿ = 2Q ￿ q0 = {q0 } power set of Q F ￿ = {q ￿ ∈ Q￿ : q ￿ ∩ F ￿= ∅} FORMAL CONSTRUCTION Let M = (Q, Σ, δ, q0 , F ) be an NFA ￿ Define DFA M ￿ = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) by: Q￿ = 2Q ￿ q0 = {q0 } power set of Q F ￿ = {q ￿ ∈ Q￿ : q ￿ ∩ F ￿= ∅} δ ￿ ({qi1 , qi2 , . . . , qin }, a) = δ (qi1 , a) ∪ δ (qi2 , a) ∪ · · · ∪ δ (qin , a) CORRECTNESS OF CONSTRUCTION Goal: Show L(M ￿ ) = L(M ). CORRECTNESS OF CONSTRUCTION Goal: Show L(M ￿ ) = L(M ). ∀w : δ ￿ ({q0 }, w) ∈ F ￿ ⇔ δ (q0 , w) ∩ F ￿= ∅ CORRECTNESS OF CONSTRUCTION Goal: Show L(M ￿ ) = L(M ). ∀w : δ ￿ ({q0 }, w) ∈ F ￿ ⇔ δ (q0 , w) ∩ F ￿= ∅ ∀w : δ ￿ ({q0 }, w) ∩ F ￿= ∅ ⇔ δ (q0 , w) ∩ F ￿= ∅ CORRECTNESS OF CONSTRUCTION Goal: Show L(M ￿ ) = L(M ). ∀w : δ ￿ ({q0 }, w) ∈ F ￿ ⇔ δ (q0 , w) ∩ F ￿= ∅ ∀w : δ ￿ ({q0 }, w) ∩ F ￿= ∅ ⇔ δ (q0 , w) ∩ F ￿= ∅ Subgoal: ∀w, δ ￿ ({q0 }, w) = δ (q0 , w) NFAS WITH ￿ -TRANSITIONS Allow change-of-state without reading input. NFAS WITH ￿ -TRANSITIONS Allow change-of-state without reading input. δ : Q × (Σ ∪ {￿}) → 2Q NFAS WITH ￿ -TRANSITIONS Allow change-of-state without reading input. δ : Q × (Σ ∪ {￿}) → 2Q 0 1 0 1 ￿ q0 q1 q3 ￿ q2 0 NFAS WITH ￿ -TRANSITIONS Allow change-of-state without reading input. δ : Q × (Σ ∪ {￿}) → 2Q 0 1 0 1 ￿ q0 q1 q3 ￿ q2 0 M , an NFA with ￿ transitions, accepts w = a1 . . . an iff: NFAS WITH ￿ -TRANSITIONS Allow change-of-state without reading input. rowsQ × (Σ ∪ { abxδ :Arrows￿}) →Arrows 03: mathabx 2Q 0 1 \nwarrow 0 \nwarrow \nw \nwarrow row \leftarrow 1 ￿ ws \restriction \re ftarrows \restriction \leftleftarrows q q \restrictio q ow \rightarrow \ri ghtarrow \rightarrow \rightarrow \leftrightarrow ￿ 0 q ows \rightleftarrows ghtarrows \rightleftarrows \ri \rightlefta \leftrightarrows M , an NFA with \rightrightarrowsff: ￿ transitions, accepts w = a1 . . . an i ow igarrow ghtsquigarrow \rightrightarrows \rightright \leftrightsquigarrow \ri ￿ ￿ ￿ a1 a2 ￿ an q . . .\rightsquig ow \rightsquigarrow uigarrow \rightsquigarrow \ri \leftsquigarrow 0 1 3 2 0 THE POWER OF ￿ -TRANSITIONS ￿ Construct M = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) is an NFA without ￿-transitions. THE POWER OF ￿ -TRANSITIONS ￿-transitions do not increase power! ￿ Construct M = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) is an NFA without ￿-transitions. THE POWER OF ￿ -TRANSITIONS ￿-transitions do not increase power! M = (Q, Σ, δ, q0 , F ) is an NFA with ￿-transitions. ￿ Construct M = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) is an NFA without ￿-transitions. THE POWER OF ￿ -TRANSITIONS ￿-transitions do not increase power! M = (Q, Σ, δ, q0 , F ) is an NFA with ￿-transitions. ￿ Construct M = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) is an NFA without ￿-transitions. THE POWER OF ￿ -TRANSITIONS ￿-transitions do not increase power! M = (Q, Σ, δ, q0 , F ) is an NFA with ￿-transitions. ￿ Construct M = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) is an NFA without ￿-transitions. Q￿ = Q THE POWER OF ￿ -TRANSITIONS ￿-transitions do not increase power! M = (Q, Σ, δ, q0 , F ) is an NFA with ￿-transitions. ￿ Construct M = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) is an NFA without ￿-transitions. Q￿ = Q ￿ q0 = q0 THE POWER OF ￿ -TRANSITIONS ￿-transitions do not increase power! M = (Q, Σ, δ, q0 , F ) is an NFA with ￿-transitions. ￿ Construct M = (Q￿ , Σ, δ ￿ , q0 , F ￿ ) is an NFA without ￿-transitions. Q￿ = Q ￿ q0 = q0 F￿ = F bx Arrows THE POWER OF ￿ -TRANSITIONS 0 ow ￿-transitions do not increase power! \nwarrow tarrows, δ, q , F ) is an NFA with ￿-transitions. \restriction M = (Q, Σ htarrowM = (Q , Σ, δ , q , F ) is an NFA\rightarrow Construct without ￿-transitions. htarrows \rightleftar Q =Q htsquigarrow \rightrighta q =q ￿ F =F igarrow Unless q \rightsquiga in which case F = F ∪ {q }. ightarrow \righttoleft owdownleft \Rsh owdownright \searrow ￿ ￿ ￿ 0 ￿ ￿ ￿ 0 0 ￿ 0 ￿ 0 bx Arrows THE POWER OF ￿ -TRANSITIONS 0 ow ￿-transitions do not increase power! \nwarrow tarrows, δ, q , F ) is an NFA with ￿-transitions. \restriction M = (Q, Σ htarrowM = (Q , Σ, δ , q , F ) is an NFA\rightarrow Construct without ￿-transitions. htarrows \rightleftar Q =Q htsquigarrow \rightrighta q =q ￿ F =F igarrow Unless q \rightsquiga in which case F = F ∪ {q }. ightarrow to compensate for the lack of ￿-edges. \righttoleft δ has extra edges owdownleft \Rsh owdownright \searrow ￿ ￿ ￿ 0 ￿ ￿ ￿ 0 0 ￿ 0 ￿ 0 ￿ bx Arrows THE POWER OF ￿ -TRANSITIONS 0 ow ￿-transitions do not increase power! \nwarrow tarrows, δ, q , F ) is an NFA with ￿-transitions. \restriction wsM = (Q, Σ htarrowM = \nwarrowan NFA\rightarrow Construct (Q , Σ, δ , q , F ) is without ￿-transitions. \nwarrow htarrows \restriction \rightleftar s Q =Q \restriction htsquigarrow \rightrighta q =q \rightarrow w \rightarrow ￿ F =F igarrow Unless q \rightsquiga \rightleftarrows ws \rightleftarrows in which case F = F ∪ {q }. ightarrow\rightrightarrows \righttoleft w δ has extra edges to compensate for the lack of ￿-edges. garrow \rightrightarrows ￿ aq owdownleft￿ q (in M ) ⇒ p\Rsh (in M ￿) a p \rightsquigarrow w \rightsquigarrow owdownright \searrow ￿ ￿ ￿ 0 ￿ ￿ ￿ 0 0 ￿ 0 ￿ 0 ￿ \restriction CORRECTNESS OF CONSTRUCTION \rightarrow Goal: Prove L(M ￿ ) = L(M ). \rightleftarrows Lemma: rrow ∀p, q ∀w such that |w| ≥ 1: \rightrightarrows w p q (in M ) ⇒ p w q (in M ￿ ) \rightsquigarrow w \righttoleftarrow ft \Rsh ght \searrow \swarrow \updownarrows POWER OF NONDETERMINISM Let L be regular. Define: 1 2 (L) = {x| ∃y, |x| = |y | ∧ xy ∈ L} POWER OF NONDETERMINISM Let L be regular. Define: 1 2 (L) = {x| ∃y, |x| = |y | ∧ xy ∈ L} is regular. Show that 1 2 (L) POWER OF NONDETERMINISM Let L be regular. Define: 1 2 (L) = {x| ∃y, |x| = |y | ∧ xy ∈ L} is regular. 0 Show that 0 1 1 2 (L) 1 q0 1 1 q1 0 q2 q3 0 POWER OF NONDETERMINISM Let L be regular. Define: 1 2 (L) = {x| ∃y, |x| = |y | ∧ xy ∈ L} is regular. 0 string left finger right finger Show that 0 1 1 2 (L) 1 ￿ q2 q0 q1 q3 q2 q2 q2 q1 q3 q0 1 1 q1 0 1 10 100 q3 0 ...
View Full Document

Ask a homework question - tutors are online