Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMS 3261, Lecture 2 Strings, Languages, Automata September 6, 2001.

Similar presentations


Presentation on theme: "COMS 3261, Lecture 2 Strings, Languages, Automata September 6, 2001."— 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? 1) Vending machines have been around long before computers or Java! 2) Don’t really need int ’s. Each int introduces 2 32 possibilities multiplicatively!!! 3) Don’t need to know how to add integers to model venting machine ( total += coin ) 4) if/else, Java grammar, all really artifices that just complicate the essence

7 Vending Machine Example

8 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 1. Only needed two coin types “D” and “Q” – symbols/letters in alphabet 2. Only needed 7 possible current total amounts – states/nodes/vertices 3. Much cleaner and aesthetically pleasing than Java lingo Now generalize and abstractify…

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

16 Alphabets, Strings, Languages A1:   D, Q  A2: Good: QDD, DQD, DDQ, QQQQDD, etc. Bad: Q, D, DD, etc. Ugly: DDD …now you’re screwed! A3:  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  ?

18 Alphabets, Strings, Languages A: 

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 reversal of a string u is denoted by u R. EG: (banana) R = ananab DEF: If  is an alphabet,   denotes the set of all strings over  A language over  is a subset of  , i.e. a set of strings each consisting of sequences of letters in 

22 Alphabets, Strings, Languages EG:   D, Q    , D, Q, DD, DQ, QD, QQ, DDD, DDQ, DQD, DQQ, QDD, QDQ, QQD, QQQ, DDDD, DDDQ, …  Define L =  u   | 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 0 1 0 1 1 1 0 0 1 More computer-like example: 0 1 sourceless arrow denotes start double circle denotes accept input put on tape read left to right

24 Finite Deterministic Automata 0 1 0 1 1 1 0 0 1 0 1

25 0 1 0 1 1 1 0 0 1 0 1

26 0 1 0 1 1 1 0 0 1 0 1

27 0 1 0 1 1 1 0 0 1 0 1

28 0 1 0 1 1 1 0 0 1 0 1

29 0 1 0 1 1 1 0 0 1 0 1 REJECT!

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

31 Finite Deterministic Automata 0 1 0 1 0 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-10 number is divisible by 3. What should your alphabet be? How can you tell when a number is divisible by 3?

33 Finite Deterministic Automata Solution: (except for  0 mod 3 1 mod 3 2 mod 3 0,3,6,9 1,4,7 2,5,8

34 Formal Definition of FA DEF: A (deterministic ) finite automaton (FA) consists of a set of states Q, an alphabet , labeled transitions between states , a start state q 0  Q, and a set of accept states F. This is all encapsulated by the “5-tuple” M = (Q, , , q 0, 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. Vending Machine Example

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

38 Definition of FA, example Q = { 0 mod 3, 1 mod 3, 2 mod 3 } ( rename: {q 0, q 1, q 2 } )  = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } q 0 = 0 mod 3 F = { 0 mod 3 }  -- further explanation required

39 The labeling function   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 ,  defines a unique target state in Q. In other words,  is a function from the Cartesian product Q x  to Q :

40 The labeling function 

41 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 q 0 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  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


Download ppt "COMS 3261, Lecture 2 Strings, Languages, Automata September 6, 2001."

Similar presentations


Ads by Google