1 / 57

CS 208: Computing Theory

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

irisa
Download Presentation

CS 208: Computing Theory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 0,1 1 0, ε 0,1 1 q4 q1 q2 q3

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

  10. 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?

  11. NFA: Informal definition • Transition may be labeled with ε, the empty string 0,1 1 0, ε 0,1 1 q4 q1 q2 q3

  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 0,1 1 0, ε 0,1 1 q4 q1 q2 q3

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

  14. NFA: Informal definition 0,1 1 0, ε 0,1 • What happens on string 11? 1 q4 q1 q2 q3 1 q1 1 q1

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

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

  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? q000 q100 q010 q110 q001 q101 q011 q111

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

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

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

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

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

  26. NFA • How about a NFA? • Because of nondeterminisim, we get a simpler automaton 0,1 1 0, 1 0,1 q4 q1 q2 q3

  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 0,1 1 0, 1 0,1 q4 q1 q2 q3

  28. NFA BONUS • What happens now? 0,1 1 0, 1, ε 0,1, ε q4 q1 q2 q3

  29. BONUS NFA • How many states would an equivalent DFA have? 0,1 1 0, 1, ε 0,1, ε q4 q1 q2 q3

  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 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} Ø ØØ Ø

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

  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 M1 M2

  36. Regular languages closed under union M1 ε M q0 ε M2

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

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

  39. 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 ≠ ε

  40. 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)

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

  42. Regular languages closed under concatenation M1 M2

  43. Regular languages closed under concatenation M1 M ε ε M2

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

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

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

  47. 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)

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

  49. Regular languages closed under star M1

  50. Regular languages closed under star M1 ε ε M ε

More Related