1 / 46

COMS 3261, Lecture 2

COMS 3261, Lecture 2. Strings, Languages, Automata September 6, 2001. Agenda. Today Strings Languages Deterministic Finite Automata For next time: Read up to 1.2 Check out ABCEZ in lecture 2-4 directory. Due 9/13: HW 1. Vending Machine Example.

yamin
Download Presentation

COMS 3261, Lecture 2

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. COMS 3261, Lecture 2 Strings, Languages, Automata September 6, 2001

  2. Agenda • Today • Strings • Languages • Deterministic Finite Automata • For next time: • Read up to 1.2 • Check out ABCEZ in lecture 2-4 directory. • Due 9/13: • HW 1

  3. Vending Machine Example • Vending machine dispenses soda for $0.45 • Accepts only dimes and quarters • Eats your money if you don’t have correct change Model this by Java-method pseudocode:

  4. Vending Machine Example Soda vend(){ int total = 0, coin; while (total != 45){ receive(coin); if ((coin==10 && total==40) ||(coin==25 && total>=25)) reject(coin); else total += coin; } return new Soda(); }

  5. Vending Machine Example Why was this over-kill?

  6. Vending Machine Example Why was this over-kill? • Vending machines have been around long before computers or Java! • Don’t really need int’s. Each int introduces 232 possibilities multiplicatively!!! • Don’t need to know how to add integers to model venting machine (total += coin) • if/else, Java grammar, all really artifices that just complicate the essence

  7. Vending Machine Example Draw Me!

  8. Vending Machine Example Input: DQQD About to put in a dime

  9. Vending Machine Example Input: DQQD About to put in a quarter

  10. Vending Machine Example Input: DQQD About to put in a quarter

  11. Vending Machine Example Input: DQQD About to put in a dime

  12. Vending Machine Example Input: DQQD DONE! MONEY ACCEPTED.

  13. Vending Machine Example What made this example simpler than the Java pseudocode?

  14. Vending Machine Example • Only needed two coin types “D” and “Q” – symbols/letters in alphabet • Only needed 7 possible current total amounts – states/nodes/vertices • Much cleaner and aesthetically pleasing than Java lingo Now generalize and abstractify…

  15. Alphabets, Strings, Languages DEF: AnalphabetSis a set of symbols (characters, letters). A string(or word) over Sis a sequence of symbols. The empty string is the string containing no symbols at all, and is denoted by e. Q1: What is Sin our vending machine example? Q2: What are some good/bad strings in our example? Q3: What does e signify in our example?

  16. Alphabets, Strings, Languages A1: S = { D, Q } A2: Good: QDD, DQD, DDQ, QQQQDD, etc. Bad: Q, D, DD, etc. Ugly: DDD …now you’re screwed! A3: e signifies trying to get something for nothing (putting no money in at all).

  17. Alphabets, Strings, Languages DEF: The length of a string is the number of symbols that it contains (repetitions allowed). Absolute values are used to denote length. EG: Lengths of the above good (QDD, DQD, DDQ, QQQQDD) are: 3, 3, 3, 6 Q: What’s the length of e ?

  18. Alphabets, Strings, Languages A: |e| = 0

  19. Alphabets, Strings, Languages DEF: The concatenation of two strings is the string resulting from putting them together from left to right. Given strings u and v, denote the concatenation by u v, or just uv. EG: ire  land = ireland, QQ  DD = QQDD, DDD  u is still bad, no-matter what u is! Q1: Why the last claim? Q2: What’s the Java equivalent of concatenation? Q3: Find a formula for |u v |.

  20. Alphabets, Strings, Languages A1: You are still screwed no matter what combination of coins you put in. A2: The + operator on strings. A3: |u v | = |u |+|v |

  21. Alphabets, Strings, Languages DEF: The reversalof a string u is denoted by u R. EG: (banana)R = ananab DEF: If S is an alphabet, S* denotes the set of all strings over S. A languageover S is a subset of S*, i.e. a set of strings each consisting of sequences of letters in S.

  22. Alphabets, Strings, Languages EG: S = { D, Q } S* = {e, D, Q, DD, DQ, QD, QQ, DDD, DDQ, DQD, DQQ, QDD, QDQ, QQD, QQQ, DDDD, DDDQ, … } Define L = { uS* | u successfully vends } Classroom exercise: What are all the strings in L of length 1? Of length 2? 3? 4? 5?

  23. Finite Deterministic Automata More computer-like example: double circle denotes accept sourceless arrow denotes start 0 0 0 1 1 1 input put on tape read left to right

  24. Finite Deterministic Automata 0 0 0 1 1 1

  25. Finite Deterministic Automata 0 0 0 1 1 1

  26. Finite Deterministic Automata 0 0 0 1 1 1

  27. Finite Deterministic Automata 0 0 0 1 1 1

  28. Finite Deterministic Automata 0 0 0 1 1 1

  29. Finite Deterministic Automata 0 0 0 1 1 1 REJECT!

  30. Finite Deterministic Automata 0 0 0 1 1 1 Q: What kinds of bitstrings are accepted?

  31. Finite Deterministic Automata 0 0 0 1 1 1 A: Bitstrings that represent binary even numbers.

  32. Finite Deterministic Automata Exercise: Design with a friend a machine that tells us when a base-10number is divisible by 3. What should your alphabet be? How can you tell when a number is divisible by 3?

  33. Finite Deterministic Automata 0,3,6,9 Solution: (except for e ) 1 mod 3 1,4,7 0 mod 3 2,5,8 1,4,7 2,5,8 2,5,8 0,3,6,9 2 mod 3 1,4,7 0,3,6,9

  34. Formal Definition of FA DEF: A (deterministic ) finite automaton (FA) consists of a set of statesQ, an alphabetS, labeled transitions between states d, a start stateq0 Q, and a set of accept statesF. This is all encapsulated by the “5-tuple” M = (Q, S, d, q0, F )

  35. Formal Definition of FA Notice that the input string, as well as the tape containing the input string, are implicit in the definition of an FA. I.e., definition only deals with static view. Further explaining needed for understanding how FA’s interact with their input.

  36. Why Deterministic? Deterministic means that there is enough information to always determine which state the Automaton goes into next, when reading a particular symbol. Our Vending Machine Example was actually not deterministic because after $.45 have been deposited, the effects of an additional coin deposit are undefined.

  37. 0,3,6,9 0 mod 3 1,4,7 1 mod 3 2,5,8 0,3,6,9 2,5,8 2,5,8 1,4,7 1,4,7 2 mod 3 Exercise: Find the formal description of this automaton. 0,3,6,9

  38. Definition of FA, example Q = { 0 mod 3, 1 mod 3, 2 mod 3 } ( rename: {q0, q1, q2} ) S = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } q0 =0 mod 3 F = { 0 mod 3 } d -- further explanation required

  39. The labeling function d d tells us which state to go to, if machine reads a given symbol. I.e., given a source state in Q and a letter in S, d defines a unique target state in Q. In other words, d is a function from the Cartesian product Q x S to Q :

  40. The labeling function d

  41. The labeling function d Usually don’t have such neat and Simple formulas.

  42. Formal Definition of an FA:Dynamic How does an FA operate on strings? Implicitly, there is some notion of an auxiliary tape containing the string. The FA reads the tape from left to right with each new character causing the FA to go into another state. When the string is completely read, the string is accepted depending on whether the FA’s final state was an accept state.

  43. Formal Definition of an FA:Dynamic DEF: A string u is accepted by an automaton iff (IF and only iF )the path starting at q0 which is labeled by u ends in an accept state. Note: To really define what it means for string to label a path, you need to break u up into its sequence of characters and apply d repeatedly, keeping track of states. See Sipser for further details.

  44. Language Accepted by an FA DEF: The language accepted by an FA M is the set of all strings which are accepted by M and is denoted by L (M ). Intuitively, think of all the possible ways of getting from the start state to any accept state. Then think of all the possible ways of labeling those paths (if there are multiple labels on some edges).

  45. Regular Languages We will eventually see that not all languages can be described as the accepted language of some FA. Languages which do belong to some FA, exhibit a high degree of regularity and fit the pattern defined by the FA. In fact, DEF: A language L is called a regular language if some FA M exists such that L = L (M ).

  46. Blackboard exercises

More Related