Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.

Similar presentations


Presentation on theme: "CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics."— Presentation transcript:

1 CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics

2 Automata Theory Non-Deterministic Finite Sate Machines

3 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

4 Proof Idea Simulate M1 for a while, then switch to M2 BUT: when to switch? … leads us into nondeterminism

5 Nondeterminisim

6 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.

7 Nondeterminism What is nondeterminisim? A generalization of determinisim Every deterministic finite automaton is also a nondeterministic one but not the other way around!

8 NFA: Informal definition q1q2q3 0,11 0, ε q4 1 0,1

9 NFA: Informal definition A NFA may have more than one transition labeled with a symbol q1q2q3 0,11 0, ε q4 1 0,1

10 NFA: Informal definition A NFA may have no transitions labeled with a symbol q1q2q3 0,11 0, ε q4 1 0,1 1?

11 NFA: Informal definition Transition may be labeled with ε, the empty string q1q2q3 0,11 0, ε q4 1 0,1

12 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 q1q2q3 0,11 0, ε q4 1 0,1

13 NFA: Informal definition What does an ε transition do? The machine “splits” into multiple copies without reading any input q1q2q3 0,11 0, ε q4 1 0,1

14 NFA: Informal definition What happens on string 11? q1q2q3 0,11 0, ε q4 1 0,1 q1 1 1

15 NFA: Informal definition What happens on string 11? q1q2q3 0,11 0, ε q4 1 0,1 q1q2 1 q1 1 1 The second 1 does not take us anywhere

16 NFA: Informal definition What happens on string 11? q1q2q3 0,11 0, ε q4 1 0,1 q1q2q3 1 ε q4 1 q1 1 1

17 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?

18 Why do we need NFA? NFA may be smaller than its DFA counterpart NFA are a good introduction to nondeterminism

19 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

20 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? q 000 q 001 q 100 q 101 q 010 q 011 q 110 q 111

21 Idea for DFA We need to remember the last 3 digits so far Which states are an accept state? q 000 q 001 q 100 q 101 q 010 q 011 q 110 q 111

22 Idea for DFA We need to remember the last 3 digits so far Transition function q 000 q 001 q 100 q 101 q 010 q 011 q 110 q 111 0 1

23 Idea for DFA We need to remember the last 3 digits so far Transition function q 000 q 001 q 100 q 101 q 010 q 011 q 110 q 111 0 1 0 1

24 Idea for DFA We need to remember the last 3 digits so far Transition function q 000 q 001 q 100 q 101 q 010 q 011 q 110 q 111 0 1 0 1 0 1 0 1 0 1 0 1 0 1

25 Idea for DFA It is quite a complex DFA! q 000 q 001 q 100 q 101 q 010 q 011 q 110 q 111 0 1 0 1 0 1 0 1 0 1 0 1 0 1

26 NFA How about a NFA? Because of nondeterminisim, we get a simpler automaton q1q2q3 0,11 q4 0,1

27 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 q1q2q3 0,11 q4 0,1

28 NFA What happens now? q1q2q3 0,11 0, 1, ε q4 0,1, ε

29 NFA How many states would an equivalent DFA have? q1q2q3 0,11 0, 1, ε q4 0,1, ε

30 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

31 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

32 Example 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} q1 q2 q3 01,ε11,0 01ε01ε q1 q2 q3 {q1} {q2} {q2} {q3} {q2,q3} Ø Ø Ø Ø ξ

33 Formal model of computation Let M= (Q,∑,ξ,q 0,F) be a Nondeterministic Finite Automaton (NFA) Let w=w 1 w 2 …w n be a string over ∑U { ε } M accepts w if a sequence of states r 0,…,r n exist such that:  r 0 =q 0  ξ(r i,w i+1 )=r i+1, i<n  r n Є F

34 Closure under regular operations Let us now go back to the theorems which state that Regular languages are closed under Union Concatenation Star

35 Regular languages closed under union

36 q0 ε ε

37 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  Q = q0 U Q 1 U Q 2

38 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  …  ∑ is the same

39 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  …  …  ξ, the transition function is defined as follows ξ(q,a) = ξ 1 (q,a) q Є Q 1 ξ 2 (q,a) q Є Q 2 {q1, q2} q=q0 and a = ε Ø q=qo and a ≠ ε

40 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  …  …  …  q0 is the start state (q=q0)

41 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  …  …  …  …  F = F1 U F2

42 Regular languages closed under concatenation

43 ε ε

44 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  Q = Q 1 U Q 2

45 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  …  ∑ is the same

46 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  …  …  ξ, the transition function is defined as follows ξ(q,a) = ξ 1 (q,a) q Є Q 1 and q ∉ F1 ξ 1 (q,a) q Є F1 and a ≠ ε ξ 1 (q,a) U {q2} q Є F1 and a = ε ξ 2 (q,a) q Є Q 2

47 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  …  …  …  q1 is the start state (q=q1)

48 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  …  …  …  …  F = F2

49 Regular languages closed under star

50 ε ε ε

51 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Define M = (Q,∑,ξ,q,F) as follows  Q = {q 0 } U Q 1

52 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Let M2 = (Q 2,∑,ξ 2,q 2,F 2 ) accept A2 Define M = (Q,∑,ξ,q,F) as follows  …  ∑ is the same

53 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Define M = (Q,∑,ξ,q,F) as follows  …  …  ξ, the transition function is defined as follows ξ(q,a) = ξ 1 (q,a) q Є Q 1 and q ∉ F1 ξ 1 (q,a) q Є F1 and a ≠ ε ξ 1 (q,a) U {q1} q Є F1 and a = ε {q1} q =q 0 and a = ε Øq=q0 and a ≠ ε

54 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Define M = (Q,∑,ξ,q,F) as follows  …  …  …  q0 is the start state (q=q0)

55 Proof: formal details Let M1 = (Q 1,∑,ξ 1,q 1,F 1 ) accept A1 Define M = (Q,∑,ξ,q,F) as follows  …  …  …  …  F = {q0} U F1

56 Summary Regular languages are closed under Union Concatenation Star Non-deterministic finite automata Are equivalent to deterministic finite automata But are much easier to use in some proofs

57 Conclusions Nondetreministic Finite Automaton Regular Languages closed under union concatenation start Next: Regular expressions


Download ppt "CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics."

Similar presentations


Ads by Google