languages
play

Languages Recall. Non deterministic finite automata What is a - PDF document

Languages Recall. Non deterministic finite automata What is a language? with transitions What is a class of languages? Finite Automata First there was the DFA Consists of Deterministic Finite Automata A set of


  1. Languages • Recall. Non deterministic finite automata – What is a language? with ε transitions – What is a class of languages? Finite Automata First there was the DFA • Consists of • Deterministic Finite Automata – A set of states (Q) – For every state and every alphabet symbol there – A start state ( q o ) is exactly one move that the machine can make. – A set of accepting states ( F ) – δ : Q x Σ → Q – Read symbols ( Σ ) – δ is a total function: completely defined. I.e. it – Transition function ( δ ) is defined for all q ∈ Q and a ∈ Σ • Let’s recap Non-Deterministic Finite Automata Then, the NFA (NFA) • Non-determinism • Transition function – δ is a function from Q x Σ to 2 Q – When machine is in a given state and reads a symbol, the machine will have a choice of – δ (q, a) = subset of Q (possibly empty) where to move to next. – There may be states where, after reading a given symbol, the machine has nowhere to go. – Applying the transition function will give, not 1 state, but 0 or more states. 1

  2. Nondeterministic Finite Automata with ε transitions ( ε -NFA) • And now… • For both DFAs and NFAs, you must read a symbol in order for the machine to make a move. • Introducing… • In Nondeterministic Finite Automata with ε transitions ( ε -NFA ) • The newest in the FA family… – Can make move without reading a symbol off • The Non deterministic finite automata with ε the read tape transitions ( ε -NFA ) – Such a move is called a ε transition Nondeterministic Finite Automata with ε Nondeterministic Finite Automata with ε transitions ( ε -NFA) transitions ( ε -NFA) • Example: • How does such a machine accept? – Machine to accept decimal numbers – A string will be accepted if there is at least one 0,1,..9 0,1,..9 sequence of state transitions on an input ε 0,1,..9 (including ε transitions) that leaves the machine ε + - . q 0 q 1 q 2 q 3 q 5 in an accepting state. 0,1,..9 . q 4 Nondeterministic Finite Automata with ε Nondeterministic Finite Automata with ε transitions ( ε -NFA) transitions ( ε -NFA) • A Non-Deterministic Finite Automata with ε • Example: transitions is a 5-tuple ( Q , Σ , q o , δ , F ) where – -3.45 is accepted – Q is a finite set (of states) – .5678 – Σ is a finite alphabet of symbols – 37 is rejected 0,1,..9 – q o ∈ Q is the start state 0,1,..9 – F ⊆ Q is the set of accepting states ε 0,1,..9 ε + - . – δ is a function from Q x ( Σ ∪ { ε }) to 2 Q (transition q 0 q 1 q 2 q 3 q 5 function) 0,1,..9 . q 4 2

  3. Nondeterministic Finite Automata with ε Nondeterministic Finite Automata with ε transitions ( ε -NFA) transitions ( ε -NFA) • Transition function • Transition function on a string – δ is a function from Q x ( Σ ∪ { ε }) to 2 Q is a function from Q x Σ * to 2 Q – δ ^ – δ (q, a) = subset of Q (possibly empty) – (q, x) = subset of Q (possibly empty) δ ^ – In our example – Set of all states that the machine can be in, • δ (q 1 , 0) = {q 1 , q 4 } upon following all possible paths on input x. • δ (q 1 , .) = {q 1 } – We’ll need to consider all paths that include the • δ (q 1 , +) = ∅ use of ε transitions • δ (q 0 , ε ) = {q 1 } ε -Closure ε -Closure • ε closure • ε closure: Recursive definition – Let M = ( Q , Σ , q o , δ , F ) be a ε -NFA – Before defining the transition function on a string ( (q,x)), it is useful to first define what ^ δ – Let S be a subset of Q is known as the ε closure. – The ε closure, denotes ECLOSE (S) is defined: – Given a set of states S, the ε closure will give • For each state p ∈ S, p ∈ ECLOSE (S) the set of states reachable from each state in S • For any q ∈ ECLOSE (S), every element of δ (q, ε ) ∈ using only ε transitions. ECLOSE (S) • No other elements of Q are in ECLOSE (S) ε -Closure ε -Closure • ε -Closure : Algorithm • Example – Since we know that ECLOSE (S) is finite, we can convert the recursive definition to an algorithm. – To find ECLOSE (S) where S is a subset of Q – Let T = S – While (T does not change) do • Add all elements of δ (q, ε ) where q ∈ T – ECLOSE (S) = T 3

  4. Nondeterministic Finite Automata with ε ε -Closure transitions ( ε -NFA) • ε closure: Example • Now lets define δ ^ For any q ∈ Q, (q, ε ) = ECLOSE ({q}) – Find ECLOSE({s}) in our example 1. δ ^ For any y ∈ Σ * , a ∈ Σ , q ∈ Q – T = {s} initial step 2. – T = {s, w} add δ (s, ε ) ⎛ ⎞ ⎜ ⎟ δ ˆ = δ ∈ U – T = {s, w, q 0 } add δ (w, ε ) ( q , ya ) ECLOSE ( p , a ) ⎜ ⎟ ⎝ ⎠ – T = {s, w, q 0 , p,t} add δ (q 0 , ε ) δ ˆ p ( q , y ) δ (w, ε ) = δ (w, ε ) = ∅ – Set of all states obtained by applying δ to all states in δ * (q,y) and input a and taking the ε closure of the result – We are done, • ECLOSE({s}) = T = {s, w, q 0 , p,t} Nondeterministic Finite Automata with ε Nondeterministic Finite Automata with ε transitions ( ε -NFA) transitions ( ε -NFA) • Are the following strings accepted by the ε - • Accepting a string NFA below: – A string x is accepted if running the machine on input x, considering all paths, including the use – aba – ababa of ε transitions, puts the machine into one of – aaabbb the accepting states – Formally: • x ∈ Σ * is accepted by M if (q 0 , x) ∩ F ≠ ∅ • δ ^ Nondeterministic Finite Automata with ε Nondeterministic Finite Automata with ε transitions ( ε -NFA) transitions ( ε -NFA) • Language accepted by M • I bet that you’re asking… – Can JFLAP handle ε -NFAs ? – The language accepted by M • L(M) = { x ∈ Σ * | x is accepted by M } – Well, let’s check and see! • If L is a language over Σ , L is accepted by M iff L = L(M). – For all x ∈ L, x is accepted by M. – For all x ∉ L, x is rejected by M. 4

  5. Nondeterministic Finite Automata with ε DFA / NFA / ε -NFA Equivalence transitions ( ε -NFA) • Surprisingly enough • Why they’re a good idea – ε transitions to our NDFA does NOT give it any – Given a regular expression, it is far easier to create an ε -NFA for the language described by additional language accepting power. – DFAs and NFAs and ε -NFA are all equivalent the expression than it is to create a plain old DFA. • Every language that can be accepted by a ε -NFA can also be accepted by an DFA which can also be – It will also be essential when showing the Fas accepted by a NFA. accept the class of Regular Languages. – Questions? – Let’s show this ε -NFA -> DFA ε -NFA -> DFA • Given ε -NFA find DFA • Basic idea – Let E = (Q E , Σ , δ E , q 0 , F E ) be a ε -NFA then – Very similar to the subset construction algorithm • There exists a DFA, D = (Q D , Σ , δ D , q D , F D ) • Recall that for a ε -NFA , δ : Q x Σ → 2 Q • Such that L(E) = L(D) • Use the states of D to represent subsets of Q. ε -NFA -> DFA ε -NFA -> DFA • Computing δ D • Formal definition – δ D (S, a) for S ∈ Q D , a ∈ Σ – E = (Q E , Σ , δ E , q 0 , F E ) be a ε -NFA • Let S = { p 1 , p 2 , …, p n } – We define DFA, D = (Q D , Σ , δ D , q D , F D ) • Compute the set of all states reachable from states in • Q D = 2 QE S on input a using transitions from E. • q D = ECLOSE (q 0 ) n = U δ { , , L , } ( , ) r r r p a 1 2 m E i • F D = sets containing at least one state from F E = 1 i • δ D (S, a) will be the union of the ε closures of the elements of {r 1 , …, r m } m δ = U ( S , a ) ECLOSE ( r ) D j = j 1 5

  6. ε -NFA -> DFA ε -NFA -> DFA ε closure State 0,1,..9 0,1,..9 q 0 {q 0 , q 1 } ε 0,1,..9 ε + - . q 0 q 1 q 2 q 3 q 5 q 1 {q 1 } q 2 {q 2 } 0,1,..9 . q 3 {q 3 , q 5 } q 4 q 4 {q 4 } q 5 {q 5 } ε -NFA -> DFA ε -NFA -> DFA 0,1,…,9 • Now we must show that D accepts the same . q 1 q 4 q 2 q 3 q 5 language as E 0,1,…,9 – Can be shown (using induction) that for all x ∈ 0,1,…,9 Σ * + - q 0 q 1 q 1 0,1,…,9 • δ D ^ (q, x) = ^ δ E (q, x) . . q 2 q 3 q 5 • See Theorem 2.22 0,1,…,9 0,1,…,9 ε -NFA -> DFA DFA -> ε -NFA • Show that D and E recognize the same • The other direction is fairly straighforward. language – For any DFA, there is an equivalent NFA (q 0 , x) ∩ F E ≠ ∅ – An NFA is nothing more than a ε -NFA with no ε – x is accepted by E iff ^ δ E – x is accepted by D iff (q D , x) ∩ F E ≠ ∅ transitions. Thus ^ δ D – Thus, • δ (q, ε ) for all states q = ∅ • x is accepted by D iff x is accepted by E • Questions? 6

  7. What have we shown Questions? • For every DFA, there is an NFA that • Let’s take a break. accepts the same language and visa versa • For every DFA, there is a ε -NFA that accepts the same language, and visa versa • Thus, for every NFA there is a ε -NFA that accepts the same language, and visa versa • DFAs, NFAs, and ε -NFA s are equivalent! 7

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