570 likes | 772 Views
CS 208: Computing Theory. Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics. Automata Theory. Non-Deterministic Finite Sate Machines. What about concatenation?. Theorem : The class of regular languages is closed under the concatenation operation
E N D
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics
Automata Theory Non-Deterministic Finite Sate Machines
What about concatenation? • Theorem: The class of regular languages is closed under the concatenation operation • If A1 and A2 are regular languages, so is A1 o A2
Proof Idea • Simulate M1 for a while, then switch to M2 • BUT: when to switch? • … leads us into nondeterminism
Nondeterminism • What is nondeterminisim? • Several choices may exists for the next choice at any point • It cannot be deduced the next state until it triggers another transition.
Nondeterminism • What is nondeterminisim? • A generalization of determinisim • Every deterministic finite automaton is also a nondeterministic one • but not the other way around!
NFA: Informal definition 0,1 1 0, ε 0,1 1 q4 q1 q2 q3
NFA: Informal definition • A NFA may have more than one transition labeled with a symbol 0,1 1 0, ε 0,1 1 q4 q1 q2 q3
NFA: Informal definition • A NFA may have no transitions labeled with a symbol 0,1 1 0, ε 0,1 1 q4 q1 q2 q3 1?
NFA: Informal definition • Transition may be labeled with ε, the empty string 0,1 1 0, ε 0,1 1 q4 q1 q2 q3
NFA: Informal definition • What happens when more than one transition is possible? • The machine “splits” into multiple copies • Each copy follows one possibility • Together, copies follow all possibilities • If the input doesn’t appear, that branch “dies” • Automaton accepts if any branch accepts 0,1 1 0, ε 0,1 1 q4 q1 q2 q3
NFA: Informal definition • What does an ε transition do? • The machine “splits” into multiple copies without reading any input 0,1 1 0, ε 0,1 1 q4 q1 q2 q3
NFA: Informal definition 0,1 1 0, ε 0,1 • What happens on string 11? 1 q4 q1 q2 q3 1 q1 1 q1
NFA: Informal definition 0,1 1 0, ε 0,1 • What happens on string 11? 1 q4 q1 q2 q3 1 q1 1 The second 1 does not take us anywhere q1 1 q2
NFA: Informal definition 0,1 1 0, ε 0,1 • What happens on string 11? 1 q4 q1 q2 q3 1 q1 1 ε 1 q4 q1 1 q2 q3
Why non-determinisim? • Theorem: Deterministic and non-deterministic finite automata accept exactly the same set of languages. • Corollary: A language is regular if and only if some NFA accepts it • Question: So why do we need them?
Why do we need NFA? • NFA may be smaller than its DFA counterpart • NFA are a good introduction to nondeterminism
Why do we need NFA? • Challenge: Can we design a finite automaton that accepts all strings with a 1 in the third-to-the-last position? • Positive examples: 01010111 111 0101 • Negative examples: 01010011 011 0001
Idea for DFA • We need to remember the last 3 digits so far • Why not have states representing the different configurations of the last three digits? q000 q100 q010 q110 q001 q101 q011 q111
Idea for DFA • We need to remember the last 3 digits so far • Which states are an accept state? q000 q100 q010 q110 q001 q101 q011 q111
Idea for DFA • We need to remember the last 3 digits so far • Transition function 0 q000 q100 q010 q110 1 q001 q101 q011 q111
Idea for DFA • We need to remember the last 3 digits so far • Transition function 0 q000 q100 q010 q110 0 1 q001 q101 q011 q111 1
Idea for DFA • We need to remember the last 3 digits so far • Transition function 0 0 0 0 q000 q100 q010 q110 0 1 1 1 0 1 0 q001 q101 q011 q111 1 1 1
Idea for DFA • It is quite a complex DFA! 0 0 0 0 q000 q100 q010 q110 0 1 1 1 0 1 0 q001 q101 q011 q111 1 1 1
NFA • How about a NFA? • Because of nondeterminisim, we get a simpler automaton 0,1 1 0, 1 0,1 q4 q1 q2 q3
NFA • How about a NFA? • Because of nondeterminisim, we get a simpler automaton • the automaton stays at q1 untill it “guesses” that it is three places from end, and checks it is a 1 0,1 1 0, 1 0,1 q4 q1 q2 q3
NFA BONUS • What happens now? 0,1 1 0, 1, ε 0,1, ε q4 q1 q2 q3
BONUS NFA • How many states would an equivalent DFA have? 0,1 1 0, 1, ε 0,1, ε q4 q1 q2 q3
Formal Definition • A non-deterministic finite automaton is a 5-tuple (Q,∑,ξ,q0,F), where • Q is a finite set of states • ∑ is a finite set of symbols called the alphabet • ξ : Q x ∑U {ε} P(Q) is the transition function • q0 Є Q is the start state • F ⊆ Q is the set of accept states or final states
Formal Definition • A non-deterministic finite automaton is a 5-tuple (Q,∑,ξ,q0,F), where • Q is a finite set of states • ∑ is a finite set of symbols called the alphabet • ξ : Q x ∑U {ε} P(Q) is the transition function • q0 Є Q is the start state • F ⊆ Q is the set of accept states or final states
Example 0 1,ε 1 1,0 q1 q2 q3 • M is a NFA = (Q,∑,ξ,q1,F), where • Q is a finite set of states {q1,q2,q3} • ∑ is {0,1} • ξ : Q x ∑U {ε} P(Q) is the transition function • q1 Є Q is the start state • F ⊆ Q is {q2} ξ 0 1 ε q1 q2 q3 {q1} {q2} {q2} {q3} {q2,q3} Ø ØØ Ø
Formal model of computation • Let M= (Q,∑,ξ,q0,F) be a Nondeterministic Finite Automaton (NFA) • Let w=w1w2…wn be a string over ∑U {ε} • M accepts w if a sequence of states r0,…,rnexist such that: • r0=q0 • ξ(ri,wi+1)=ri+1, i<n • rnЄ F
Closure under regular operations • Let us now go back to the theorems which state that • Regular languages are closed under • Union • Concatenation • Star
Regular languages closed under union M1 ε M q0 ε M2
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • Q = q0 U Q1 U Q2
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • … • ∑ is the same
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • … • … • ξ, the transition function is defined as follows ξ(q,a) = ξ1(q,a) q Є Q1 ξ2(q,a) q Є Q2 {q1, q2} q=q0 and a = ε Ø q=qo and a ≠ ε
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • … • … • … • q0 is the start state (q=q0)
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • … • … • … • … • F = F1 U F2
Regular languages closed under concatenation M1 M ε ε M2
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • Q = Q1 U Q2
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • … • ∑ is the same
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • … • … • ξ, the transition function is defined as follows ξ(q,a) = ξ1(q,a) q Є Q1and q ∉F1 ξ1(q,a) q Є F1and a≠ ε ξ1(q,a) U {q2} q Є F1 and a = ε ξ2(q,a) q Є Q2
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • … • … • … • q1 is the start state (q=q1)
Proof: formal details • Let M1 = (Q1,∑,ξ1,q1,F1) accept A1 • Let M2 = (Q2,∑,ξ2,q2,F2) accept A2 • Define M = (Q,∑,ξ,q,F) as follows • … • … • … • … • F = F2
Regular languages closed under star M1 ε ε M ε