comp20121 the implementation and power of computer
play

COMP20121 The Implementation and Power of Computer Languages Power - PowerPoint PPT Presentation

COMP20121 The Implementation and Power of Computer Languages Power Part http://www.cs.man.ac.uk/ petera/2121/index.html . Peter Aczel room: CS2.52, tel: 56155 petera@cs.man.ac.uk email: School of Computer Science, University of


  1. COMP20121 The Implementation and Power of Computer Languages ‘Power’ Part http://www.cs.man.ac.uk/ ∼ petera/2121/index.html . Peter Aczel room: CS2.52, tel: 56155 petera@cs.man.ac.uk email: School of Computer Science, University of Manchester COMP20121 - Section 0 – p.1/307

  2. COMP20121, ‘power’ part: section 1 lecture 1: Regular languages LECTURE TWO Finite automata for regular languages COMP20121 - Section 1 – p.36/307

  3. Match, or no match? It can be hard to work out whether a given word matches a pattern. COMP20121 - Section 1 – p.37/307

  4. Match, or no match? It can be hard to work out whether a given word matches a pattern. Consider the pattern: ab ∗ ( a | b ) b ∗ ( a | b ) ∗ , COMP20121 - Section 1 – p.37/307

  5. Match, or no match? It can be hard to work out whether a given word matches a pattern. Consider the pattern: ab ∗ ( a | b ) b ∗ ( a | b ) ∗ , and the word: abbababababbbababab. Does it match, or doesn’t it? COMP20121 - Section 1 – p.37/307

  6. Match, or no match? It can be hard to work out whether a given word matches a pattern. Consider the pattern: ab ∗ ( a | b ) b ∗ ( a | b ) ∗ , and the word: abbababababbbababab. Does it match, or doesn’t it? We want to match letters in the target word with letters in the pattern. COMP20121 - Section 1 – p.37/307 Answering ‘yes’ or ‘no’ is subject to a

  7. Automata Instead of dealing with syntax, human beings often do better with pictures. e.g. when working with the pattern (((0 ∗ ) | 1)2 | (0 | (1 ∗ ))2) : you might draw COMP20121 - Section 1 – p.38/307

  8. Automata Instead of dealing with syntax, human beings often do better with pictures. e.g. when working with the pattern (((0 ∗ ) | 1)2 | (0 | (1 ∗ ))2) : you might draw 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.38/307

  9. Accepting a word We can follow any word through the automaton. Consider 0002 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.39/307

  10. Accepting a word We can follow any word through the automaton. Consider 0002 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.39/307

  11. Accepting a word We can follow any word through the automaton. Consider 0002 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.39/307

  12. Accepting a word We can follow any word through the automaton. Consider 0002 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.39/307

  13. Accepting a word We can follow any word through the automaton. Consider 0002 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.39/307

  14. Accepting a word We can follow any word through the automaton. Consider 0002 . 0 2 0 2 1 2 1 The double circle is an accepting state. COMP20121 - Section 1 – p.39/307

  15. Rejecting a word-I We can follow any word through the automaton. Consider 0001 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.40/307

  16. Rejecting a word-I We can follow any word through the automaton. Consider 0001 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.40/307

  17. Rejecting a word-I We can follow any word through the automaton. Consider 0001 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.40/307

  18. Rejecting a word-I We can follow any word through the automaton. Consider 0001 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.40/307

  19. Rejecting a word-I We can follow any word through the automaton. Consider 0001 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.40/307

  20. Rejecting a word-I We can follow any word through the automaton. Consider 0001 . 0 2 0 2 1 2 1 Reject this word because we are stuck. COMP20121 - Section 1 – p.40/307

  21. Rejecting a word-II We can follow any word through the automaton. Consider 000 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.41/307

  22. Rejecting a word-II We can follow any word through the automaton. Consider 000 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.41/307

  23. Rejecting a word-II We can follow any word through the automaton. Consider 000 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.41/307

  24. Rejecting a word-II We can follow any word through the automaton. Consider 000 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.41/307

  25. Rejecting a word-II We can follow any word through the automaton. Consider 000 . 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.41/307

  26. Rejecting a word-II We can follow any word through the automaton. Consider 000 . 0 2 0 2 1 2 1 Reject: we end in a non-accepting state. COMP20121 - Section 1 – p.41/307

  27. DFA—Definition Definition 7 Let Σ be a finite alphabet. A (deterministic) finite automaton, (DFA), over Σ consists of ( Q, q • , F, δ ) where: • Q is a finite set of states; COMP20121 - Section 1 – p.42/307

  28. DFA—Definition Definition 7 Let Σ be a finite alphabet. A (deterministic) finite automaton, (DFA), over Σ consists of ( Q, q • , F, δ ) where: • Q is a finite set of states; • q • ∈ Q is the start state; COMP20121 - Section 1 – p.42/307

  29. DFA—Definition Definition 7 Let Σ be a finite alphabet. A (deterministic) finite automaton, (DFA), over Σ consists of ( Q, q • , F, δ ) where: • Q is a finite set of states; • q • ∈ Q is the start state; • F ⊆ Q is the set of accepting states; and COMP20121 - Section 1 – p.42/307

  30. DFA—Definition (continued) • δ is a transition function which for every state q ∈ Q and every symbol x ∈ Σ returns the next state δ ( q, x ) ∈ Q . • So δ is a function from Q × Σ to Q . • When δ ( q, x ) = q ′ we often write x → q ′ . q COMP20121 - Section 1 – p.43/307

  31. NFA—Definition Definition 8 A non-deterministic finite automaton, (NFA), consists of ( Q, q • , F, δ ) where: • Q is a a finite set of states; COMP20121 - Section 1 – p.44/307

  32. NFA—Definition Definition 8 A non-deterministic finite automaton, (NFA), consists of ( Q, q • , F, δ ) where: • Q is a a finite set of states; • q • ∈ Q is the start state; COMP20121 - Section 1 – p.44/307

  33. NFA—Definition Definition 8 A non-deterministic finite automaton, (NFA), consists of ( Q, q • , F, δ ) where: • Q is a a finite set of states; • q • ∈ Q is the start state; • F ⊆ Q is the set of accepting states; and COMP20121 - Section 1 – p.44/307

  34. NFA—Definition (continued) • δ is a transition relation which relates a pair consisting of a state and a letter with a state. COMP20121 - Section 1 – p.45/307

  35. NFA—Definition (continued) • δ is a transition relation which relates a pair consisting of a state and a letter with a state. When ( q, x ) is δ -related to q ′ we often write → q ′ . x q COMP20121 - Section 1 – p.45/307

  36. Variation of DFA: Dump states Strictly speaking, our pictures do not quite fit the definition. 0 2 0 2 1 2 1 COMP20121 - Section 1 – p.46/307

  37. Variation of DFA: Dump states Strictly speaking, our pictures do not quite fit the definition. 0 2 0 2 1 2 1 There is no arrow labelled 1 from the red state. So reject 001 ! COMP20121 - Section 1 – p.46/307

  38. Variation of DFA: Dump states We do not always draw all the states. We can leave out ‘dump states’; i.e. states from which no accepting state can be reached. If we add a dump state to this DFA, it would look like this: 3 0 , 1 , 2 , 3 0 1 , 3 2 0 0 , 1 , 2 , 3 2 1 2 0 , 3 1 COMP20121 - Section 1 – p.46/307

  39. Variation of DFA: Dump states We obtain this new picture by adding in one new state, . . . 0 2 0 2 1 2 0 , 3 1 COMP20121 - Section 1 – p.46/307

  40. Variation of DFA: Dump states We obtain this new picture by adding in one new state, and arrows to this new state whenever there is an arrow missing in the original picture. 3 0 1 , 3 2 0 0 , 1 , 2 , 3 2 1 2 0 , 3 1 COMP20121 - Section 1 – p.46/307

  41. Variation of DFA: Dump states Further we add an arrow from the new state to itself labelled with all the letters of the underlying alphabet Σ = { 0 , 1 , 2 , 3 } . 3 0 , 1 , 2 , 3 0 1 , 3 2 0 0 , 1 , 2 , 3 2 1 2 0 , 3 1 COMP20121 - Section 1 – p.46/307

  42. Variation of DFA: Dump states If we draw all states, then we can follow a word through the automaton along a unique path without getting stuck. The word is accepted if and only if the state reached when the word ends is an accepting state. COMP20121 - Section 1 – p.46/307

  43. Variation of DFA: Dump states If we leave out some dump states, then we can follow a word through the automaton along a unique path, but we might get stuck. The word is accepted if and only if we do not get stuck and the state reached when the word ends is an accepting state. COMP20121 - Section 1 – p.46/307

  44. Accepting a word Definition 9 A word α = x 1 · · · x n is accepted by a DFA if δ ( q • , x 1 ) = q 1 , δ ( q 1 , x 2 ) = q 2 , . . . δ ( q n − 1 , x n ) = q n ∈ F COMP20121 - Section 1 – p.47/307

  45. Accepting a word This means that we have a sequence of states q • , q 1 , . . . , q n such that x 1 x 2 x n ✲ · · · → q 1 → q 2 → q n ∈ F q • COMP20121 - Section 1 – p.47/307

  46. Acceptance for NFAs When we consider an NFA, there may be more than one way of following a word through the automaton. Consider the word 002 . 0 2 0 , 1 2 1 2 1 COMP20121 - Section 1 – p.48/307

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