outline
play

Outline Nondeterminism Regular expressions Elementary - PowerPoint PPT Presentation

Outline Nondeterminism Regular expressions Elementary reductions Computation, Computers, and Programs Nondetermistic Finite Automata 1 http://www.cs.caltech.edu/~cs20/a October 8, 2002 Determistic Finite Automata A finite


  1. Outline • Nondeterminism • Regular expressions • Elementary reductions Computation, Computers, and Programs Nondetermistic Finite Automata 1 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  2. Determistic Finite Automata • A finite automaton is a 5-tuple (Q, Σ , δ, q 0 , F) – Q is a finite set of states – Σ is an alphabet – δ : Q × Σ → Q is a transition function – q 0 ∈ Q is the initial state – F ⊆ Q is a set of final or accepting states Computation, Computers, and Programs Nondetermistic Finite Automata 2 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  3. Transition diagrams Q = { q 0 , q 1 , q 2 , q 3 } { 0 , 1 } = Σ 1 δ = State Symbol Goto q0 q1 1 q 0 0 q 2 q 0 1 q 1 0 0 0 0 q 1 0 q 3 1 q 1 1 q 0 q2 q3 q 2 0 q 0 1 q 2 1 q 3 q 3 0 q 1 q 3 1 q 2 q 0 = q 0 F = { q 0 } Computation, Computers, and Programs Nondetermistic Finite Automata 3 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  4. A finite automaton Read-only tape 1. In state q a. read a symbol c b. move the tape head right 0 1 1 0 0 1 0 1 b. goto state delta(q, c) 2. Accept iff the FA is in a final Tape head state after reading the last symbol Finite Control Computation, Computers, and Programs Nondetermistic Finite Automata 4 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  5. Definition of regular expressions • Let Σ be an alphabet. The regular expressions are defined inductively as follows: – ∅ is a regular expression denoting {} , – ǫ is a regular expression denoting { ǫ } , – for each a ∈ Σ , a is a regular expression de- noting { a } , – Assume r and s are regular expressions de- noting sets R and S , then ∗ rs denotes RS , ∗ r + s denoted R ∪ S , ∗ r ∗ denotes R ∗ Computation, Computers, and Programs Nondetermistic Finite Automata 5 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  6. Examples of regular expressions • abc denotes { abc } , • a ∗ b denotes { b, ab, aab, aaab, . . . } , • (a + b) ∗ aa(a + b) ∗ : all strings containing at least two consecutive a 's. • ( 0 ∗ ( 101 ∗ 01 ) ∗ ) ∗ : all binary numbers that are a multiple of 3. Computation, Computers, and Programs Nondetermistic Finite Automata 6 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  7. Nondeterminism • For determistic finite automata, the transition function delta is a function – delta : state * symbol -> state – For each state, and each symbol, there is a unique next state • What if we relax this? • In a nondeterministic finite automaton, delta is a transition relation Computation, Computers, and Programs Nondetermistic Finite Automata 7 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  8. Definition of an NFA • A nondeterministic finite automaton is a 5-tuple (Q, Σ , δ, s, F) – Q is a finite set of states – Σ is an alphabet – δ : Q × Σ → 2 Q is a transition relation – s ∈ Q is the initial state – F ⊆ Q is a set of final or accepting states Computation, Computers, and Programs Nondetermistic Finite Automata 8 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  9. The delta relation • Note, the following definitions are equivalent: – δ : Q × Σ → 2 Q is a transition relation – δ ⊆ Q × Σ × Q is a transition relation • The transition diagram is often drawn without empty edges: – if δ(q, c) = {} , then the machine rejects and we do not draw the edge Computation, Computers, and Programs Nondetermistic Finite Automata 9 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  10. Example NFA 0,1 0 0,1 q1 q2 0 0,1 q0 1 1 q3 q4 Computation, Computers, and Programs Nondetermistic Finite Automata 10 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  11. Executions (for DFAs) • An execution of a deterministic automaton M = (Q, Σ , δ, q 0 , F) is a sequence (q 0 , c 0 )(q 1 , c 1 ) . . . (q n − 1 , c n − 1 )q n ∈ (Q × Σ ) ∗ such that: – q 0 is the start state – δ(q i , c i ) = q i + 1 • The execution string s is c 0 c 1 . . . c n − 1 • If there exists an execution for string s with q n ∈ F the automaton accepts and s ∈ L(M) ; otherwise it rejects Computation, Computers, and Programs Nondetermistic Finite Automata 11 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  12. Executions (for NFAs) • An execution of a nondeterministic automaton M = (Q, Σ , δ, q 0 , F) is a sequence (q 0 , c 0 )(q 1 , c 1 ) . . . (q n − 1 , c n − 1 )q n ∈ (Q × Σ ) ∗ such that: – q 0 is the start state – q i + 1 ∈ δ(q i , c i ) • The execution string s is c 0 c 1 . . . c n − 1 • If there exists an execution for string s with q n ∈ F the automaton accepts and s ∈ L(M) ; otherwise it rejects Computation, Computers, and Programs Nondetermistic Finite Automata 12 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  13. A nondeterministic finite automaton Read-only tape 1. In state q a. read a symbol c b. move the tape head right 0 1 1 0 0 1 0 1 b. goto some state in delta(q, c) 2. Accept iff the NFA is in a final Tape head state after reading the last symbol Finite Control Computation, Computers, and Programs Nondetermistic Finite Automata 13 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  14. Execution models 1. Classical: For each state q and input sym- bol c , the automaton makes a nontermistic choice among all the possible options δ(q, c) ; it accepts if it made all the right choices 2. Another choice: – At any point, the automaton is in a super- position of states Q 1 – For each symbol c , it enters states Q 2 where q 2 ∈ Q 2 iff ∃ q 1 ∈ Q 1 .q 2 ∈ δ(q 1 , c) Computation, Computers, and Programs Nondetermistic Finite Automata 14 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  15. Extending the transition relation • Defining � δ : – � δ(q, ǫ) = { q } – � δ(q, wa) = { p | ∃ r ∈ � δ(q, w).p ∈ δ(r, a) } • A machine M = (Q, Σ , δ, q 0 , F) accepts string s iff � δ(q 0 , s) ∩ F ≠ {} Computation, Computers, and Programs Nondetermistic Finite Automata 15 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  16. Expressive power of NFAs vs. DFAs • Every DFA is an NFA • NFAs allow more transitions • Is the language more expressive? – Is there a language L=L(M) for some NFA M, where L<>L(M’) for some DFA M’? Computation, Computers, and Programs Nondetermistic Finite Automata 16 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  17. NFA/DFA Equivalence • To prove equivalence of DFAs and NFAs we must do two things: – I: For each DFA, produce an NFA that accepts the same language – II: For each NFA, produce a DFA that accepts the same language • This is called a reduction— reduce one construction to another equivalent one – We’ll do part II; part I is immediate Computation, Computers, and Programs Nondetermistic Finite Automata 17 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  18. NFA->DFA construction • Consider an arbitrary NFA M = (Q, Σ , δ, s, F) ; con- struct an equivalent DFA M ′ = (Q ′ , Σ , δ ′ , s ′ , F ′ ) – Let Q ′ = 2 Q – Let s ′ = { s } � n – Let δ ′ ( { q 1 , . . . , q n } , c) = i = 1 δ(q i , c) – Let F ′ = { t ∈ 2 Q | t ∩ F ≠ {}} Computation, Computers, and Programs Nondetermistic Finite Automata 18 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  19. NFA->DFA construction: verification Theorem δ(s, x) = δ ′ ( { s } , x) Corollary δ(s, x) ∩ F ≠ {} ⇔ δ ′ ( { s } , x) ∩ F ′ ≠ {} Computation, Computers, and Programs Nondetermistic Finite Automata 19 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  20. NFA->DFA construction: base case Theorem δ(s, x) = δ ′ ( { s } , x) Base case δ(s, ǫ) = { s } = δ ′ ( { s } , ǫ) Computation, Computers, and Programs Nondetermistic Finite Automata 20 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  21. NFA->DFA construction: induction step • Assume δ(s, x) = δ ′ ( { s } , x) for some x • Prove δ(s, xa) = δ ′ ( { s } , xa) for any a δ(s, xa) by definition of � = δ δ(δ(s, x), a) by definition of � = δ � p ∈ δ(s,x) δ(p, a) = by induction � p ∈ δ ′ (s,x) δ(p, a) by definition of δ ′ = � p ∈ δ ′ (s,x) δ ′ ( { p } , a) by definition of δ ′ = � p ∈ δ ′ ( { s } ,x) δ ′ ( { p } , a) by definition of δ ′ = δ ′ (δ ′ ( { s } , x), a) by definition of δ ′ = δ ′ ( { s } , xa) Computation, Computers, and Programs Nondetermistic Finite Automata 21 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  22. NFA with epsilon transitions • Suppose we add a new twist – Allow transitions that require no input – Label them epsilon (no input) – The automaton may choose to take an epsilon transition without any input • Executions include (q_i, epsilon) (q_i+1, _) steps • A machine accepts if there exists an execution that accepts Computation, Computers, and Programs Nondetermistic Finite Automata 22 http://www.cs.caltech.edu/~cs20/a October 8, 2002

  23. Example e-NFA 0 1 2 ε ε q0 q1 q2 Computation, Computers, and Programs Nondetermistic Finite Automata 23 http://www.cs.caltech.edu/~cs20/a October 8, 2002

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