Homework • Homework #1 returned today Kleene Theorem • Homework #2 due today Homework Before We Start • Speaking of Homework • Any questions? – Here’s Homework #3 (Due April 4) • From the textbook – 4.15b.c (No need to use proof of Kleene Theorem) – 4.16a,d – 4.29a – 4.35a,b (Do not simplify) – 4.38a (Must use proof of Kleene) Languages Regular Languages • Recall. • Regular languages – What is a language? – Means of defining: Regular Expressions – What is a class of languages? – Machine for accepting: Finite Automata 1
Finite Automata Did I happen to mention? • Steven Cole Kleene • A finite automaton (finite-state machine) is – 1909-1994 a 5-tuple ( Q , Σ , q o , δ , A ) where – b. Hartford, Conn. – Q is a finite set (of states) – Σ is a finite alphabet of symbols – PhD – Princeton (1934) – q o ∈ Q is the start state – Prof at U of Wisc at Madison (1935 – 1979) – A ⊆ Q is the set of accepting states – δ is a function from Q x Σ to Q (transition – Introduced Kleene Star op function) – Defined regular expressions Kleene Theorem Proving Kleene Theorem A language L over Σ is regular iff there • Approach • – Define 2 variants of the Finite Automata exists an FA that accepts L. • Nondeterministic Finite Automata (NDFA) 1. If L is regular there exists an FA M such that • Nondeterministic Finite Automata with Λ transitions (NDFA- Λ ) L = L(M) – Prove that FA, NDFA, and NDFA- Λ are equivalent 2. For any FA, M, L(M) is regular w.r.t. the languages they accept – For a regular expression, build a NDFA- Λ that accepts L(M), the language accepted by the FA can be the same language expressed as a regular expression. – For an FA build a regular expression that describes the language accepted by the FA. Tonight Equivalence • Last time we defined these two FA variants: If L is a language over Σ * , then the • – Nondeterministic Finite Automata (NDFA) following 3 statements are equivalent: – Nondeterministic Finite Automata with Λ 1. L is accepted by a FA transitions (NDFA- Λ ) 2. L is accepted by a NDFA • In part 1 we show they are equivalent 3. L is accepted by a NDFA- Λ • Questions? 2
Equivalence Step 1: NDFA->FA • How we will show this • Given NDFA find FA 1. Given an NDFA that accepts L, create an FA – Let M = (Q, Σ , q 0 , A, δ ) be a NDFA then that also accepts L • There exists a FA, M 1 = (Q 1 , Σ , q 1 , A 1 , δ 1 ) 2. Given an NDFA- Λ that accepts L, create an • Such that L(M) = L(M 1 ) NDFA that also accepts L 3. Given an FA that accepts L, create a NDFA- Λ that also accepts L. Are we ready? Step 1: NDFA -> FA Step 1: NDFA -> FA • Basic idea • Formal definition – M = (Q, Σ , q 0 , A, δ ) be a NDFA – Recall that for a NDFA, δ : Q x Σ → 2 Q – We define FA, M 1 = (Q 1 , Σ , q 1 , A 1 , δ 1 ) – Use the states of M 1 to represent subsets of Q. • Q 1 = 2 Q – If there is one state of M 1 for every subset of Q, • q 1 = {q 0 } then the non-determinism of M can be • For q ∈ Q 1 and a ∈ Σ , δ = U δ eliminated. ( q , a ) ( p , a ) • 1 ∈ p q – This technique, called subset construction, is a • A 1 = {q ∈ Q 1 | q ∩ A ≠ ∅ } primary means for removing non-determinism – Note that we need only include states on M 1 (subsets of from an NDFA. Q) if the state is reachable. Step 1: NDFA -> FA Step 1: NDFA -> FA • Algorithm for building M 1 • Example – Add {q 0 } to Q 1 – While there are states of Q 1 whose transitions are yet to be defined • Let q ∈ Q 1 • For each a ∈ Σ , determine the set of states, P, in M that are reachable from q on input a • If there is no state in Q 1 corresponding to P, add one. • Define δ 1 (q, a) = state in Q 1 corresponding to P – Define A 1 as any state in Q 1 that corresponds to a subset containing any of the final states of M 3
Step 1: NDFA -> FA Step 1: NDFA -> FA q 0 q 3 0 • Now we must show that M 1 accepts the 1 0 same language as M 0 1 q 0 q 2 q 0 q 1 q 3 0 0 – It can be shown (by structural induction) that 0 for all x ∈ Σ * 1 q 0 q 0 q 1 1 1 1 (q 1 , x) = δ * (q 0 , x) • δ * 1 0 q 0 q 2 q 3 q 0 q 1 q 2 1 0 1 q 0 q 1 q 2 q 3 Step 1: NDFA -> FA What have we shown • Show that M and M 1 recognize the same • In Step 1 we’ve shown: language – Given a NDFA – x is accepted by M 1 iff δ *1 (q 1 , x) ∈ A 1 • There exists an FA that accepts the same language – x is accepted by M 1 iff δ * (q 0 , x) ∈ A 1 • Non-determinism can be removed from an NDFA by using a subset construction algorithm. – By def of A 1 , • x is accepted by M 1 iff δ * (q 0 , x) ∩ A ≠ ∅ – Questions? – Thus • x is accepted by M 1 iff x is accepted by M Step 2: NDFA- Λ -> NDFA What have we shown • Given NDFA- Λ find NDFA – Let M = (Q, Σ , q 0 , A, δ ) be a NDFA- Λ then • There exists a NDFA, M 1 = (Q 1 , Σ , q 1 , A 1 , δ 1 ) FA • Such that L(M) = L(M 1 ) NDFA If L ∈ NDFA then L ∈ FA 4
Step 2: NDFA- Λ -> NDFA Step 2: NDFA- Λ -> NDFA • Basic idea • Basic idea – Recall that a NDFA- Λ is still non-deterministic – Accepting states – Replace Λ transitions with non- Λ transitions • If q 0 is not an accepting state of M but it is possible 0 Λ 0 0 to get to an accepting state by just using Λ transitions, then q 0 must be added to the set of accepting states of M 1 – Let δ 1 (q,a) be the set of states reachable from q, reading symbol a, including those reachable via Λ transitions • Which is just δ * (q,a) Step 2: NDFA- Λ -> NDFA Step 2: NDFA- Λ -> NDFA • Formal definition • Algorithm for constructing M 1 – Set of states is the same as M – M = (Q, Σ , q 0 , A, δ ) be a NDFA- Λ – Start state is the same as M – We define NDFA, M 1 = (Q 1 , Σ , q 1 , A 1 , δ 1 ) – Accepting states is the same as M • Q 1 = Q – For each state, q, in M • q 1 = q 0 • compute the Λ closure • δ 1 (q,a) = δ * (q,a) • For each state in the Λ closure,p, and for each symbol a, add all • A 1 = A ∪ {q o } if Λ ({q o } ) ∩ A ≠ ∅ in M elements of the Λ closure of δ (p,a) to the set δ 1 (q, a) – If you can get to to an accepting state in M from q o by • = A otherwise only using Λ transitions, add q 0 to A 1 Step 2: NDFA- Λ -> NDFA Step 2: NDFA- Λ -> NDFA Λ closure State • Example q 0 {q 0 , p, t } p {p} r {r} s {s, w, q 0 , p, t } t {t} u {u} v {v, w, q 0 , p, t } w {w, q 0 , p, t} 5
Step 2: NDFA- Λ -> NDFA Step 2: NDFA- Λ -> NDFA 0 0 0 1 0 • Now we must show that M 1 accepts the r p s 1 same language as M 0 0 1 0 0 0 1 – Can be shown (using structural induction) that 0 w q 0 0 for all x ∈ Σ * 0 0 0 1 (q, x) = δ * (q, x) 0 • δ * 1 t 0 v u 0 0 0 0 0 0 1 1 1 0 Step 2: NDFA- Λ -> NDFA Step 2: NDFA- Λ -> NDFA • Show that M and M 1 recognize the same • Show that M and M 1 recognize the same language – If |x| = 0, I.e. x = Λ language • If Λ accepted by M then Λ (q o ) contains an accepting state, in – x is accepted by M 1 iff δ *1 (q 0 , x) ∩ A ≠ ∅ which case we’ve added q o to the set of accepting states of M 1 – x is accepted by M 1 iff δ * (q 0 , x) ∩ A ≠ ∅ • Thus Λ is accepted by M 1 • If Λ rejected by M, then q o is not an accepting state. Since the – Thus, set of accepting states of M 1 is the same as M (except for the • x is accepted by M 1 iff x is accepted by M special case above), then q - will not be in the set of accepting states for M 1 . • We showed this true for |x| > 0 • This Λ is rejected by M 1 Where we are Where we are • In Step 2 we’ve shown: – Given an NDFA- Λ • There exists an NDFA that accepts the same NDFA language NDFA- Λ • Λ transitions can be removed from an NDFA- Λ by replacing Λ transitions with non- Λ transitions in an already non-deterministic NDFA. If L ∈ NDFA- Λ then L ∈ NDFA 6
Where we are Where we are – We’ve shown that: • If L is accepted by an NDFA- Λ it is also accepted by an NDFA • If L is accepted by an NDFA it is also accepted by an FA NDFA FA • So if L is accepted by an NDFA- Λ , it is accepted by an FA. NDFA- Λ – We still need to show: • If L is accepted by an FA, it is also accepted by an NDFA- Λ – Questions? Step 3: FA-> NDFA- Λ Step 3: FA-> NDFA- Λ • Given FA find NDFA- Λ • Basic idea – Let M = (Q, Σ , q 0 , A, δ ) be a FA then – Since FAs are more restrictive than NDFA- Λ s, any FA is essentially an NDFA- Λ that doesn’t • There exists a NDFA - Λ , M 1 = (Q 1 , Σ , q 1 , A 1 , δ 1 ) take advantage of: • Such that L(M) = L(M 1 ) • Non-determinism • Λ -transitions – Must consider details of transition functions Step 3: FA-> NDFA- Λ Step 3: FA-> NDFA- Λ • Formal definition • Now we must show that M 1 accepts the same language as M – M = (Q, Σ , q 0 , A, δ ) be a FA – We define NDFA- Λ , M 1 = (Q 1 , Σ , q 1 , A 1 , δ 1 ) – Can show (using structural induction) that for all x ∈ Σ * • Q 1 = Q 1 (q, x) = { δ * (q, x) } • δ * • q 1 = q 0 • A 1 = A • δ 1 (q, Λ ) = ∅ for all q ∈ Q • δ 1 (q, a) = { δ (q, a)} for all q ∈ Q, a ∈ Σ 7
Recommend
More recommend