1 / 343

CS 461 – Aug. 24

CS 461 – Aug. 24. Course overview Section 1.1 Definition of finite automaton (FA) How to draw FAs. Overview. What is Computational Theory? Not so concerned with specific HW/SW Search for general truths, models, imagination Ex. What is possible vs. impossible? Facets

Download Presentation

CS 461 – Aug. 24

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 461 – Aug. 24 • Course overview • Section 1.1 • Definition of finite automaton (FA) • How to draw FAs

  2. Overview • What is Computational Theory? • Not so concerned with specific HW/SW • Search for general truths, models, imagination Ex. What is possible vs. impossible? • Facets • Automata & Formal Languages (Ch. 1 – 3) There are 3 important models of computation. • Computability (Ch. 3 – 5) “Some problems can’t be solved.” • Complexity (Ch. 7) “Some problems take too long to solve.”

  3. Theory • What is theory? • You have already dealt with abstract ideas in earlier courses • Difference between void, null, zero • Different kinds of zeros (int, float, positive, negative) • Infinity versus NaN • Correctness of an algorithm • Number of iterations in a loop • Does recursion really work?

  4. Computation Models • Purpose of a model is to study what computers and programs can do. • Models range from simple to complete: • Model #1: Finite Automaton • Model #2: Pushdown Automaton • Model #3: Turing Machine • Assume programming essentially boils down to input  outputs. • For simplicity / convenience, • input = any binary string • output = 0/1, T/F, accept/reject

  5. Finite Automaton • Our first model – Chapter 1 • Purpose of FA is to take (binary) input string and either “accept” or “reject” it. • The set of all strings accepted by an FA is called the language of the FA. • “Language” simply means a set of strings, e.g. the set of all binary strings starting with “0”.

  6. Example • Start state • Accept/happy state(s) • If we are in one of these when input is done, we accept string. • Transitions • “finite” refers to # of states. More on limitations later. 0 s1 s2 1 0, 1

  7. Example • The FA could also be expressed in a table. • The table tells us where to go on each possible input bit. 0 s1 s2 1 0, 1

  8. Example • Let’s try sample input like 101. • Can you figure out the language of this machine? • i.e. How do we get to the happy state? 0 s1 s2 1 0, 1

  9. Example #2 0 1 • What is language of this FA? • Note: if we change which state is the accept state, we’d have a different language! s1 s2 s3 0 1 0, 1

  10. CS 44 – Aug. 26 • Finish section 1.1 • Definition of FA • Examples • Regular languages • Union of 2 regular languages (handout)

  11. Formal Definition A finite automaton has 5 things: • A set of states • An alphabet, for input • A start state • A set of accept states • Transition function: δ(state, input) = state • When we create/define an FA, must specify all 5 things. A drawing does a pretty good job.

  12. Example 0 1 s1 s2 s3 0 1 0, 1

  13. Let’s make FA’s • L = bit strings that have exactly two 1’s • L = starts with 01 • L = ends with 01 • L = has an even number of 1’s • L = starts and ends with same symbol *** Very good idea to give meaningful names to your states. Since L is a set… how would we create an FA for the complement of L?

  14. Regular Language • A regular language is a set of strings accepted by some FA. • Examples • Starting with 01; ending with 01, containing 01. • Strings of length 2. • {0, 11} • Any finite set is regular. Infinite sets are more interesting. Yet, # states always finite!

  15. Operations on sets • We can create new regular sets from existing ones, rather than starting from scratch.  • Binary operations • Union • Intersection • Unary operations • Complement • Star: This is the concatenation of 0 or more elements. For example, if A = {0, 11}, then A* is { ε, 0, 11, 00, 1111, 011, 110, …} • “Closure property”: you always get a regular set when you use the above operations.

  16. Union • Book shows construction (see handout) • We want to union two languages A1 and A2: M1 accepts A1 and M2 accepts A2. The combined machine is called M. • M pretends it’s running M1 and M2 at same time! δ((r1,r2),a) = (δ1(r1,a),δ2(r2,a)) • # states increases because it’s the Cartesian product of M1 and M2’s states. • Next section will show easier way to do union. 

  17. Wolf, Goat, Cabbage • A man would like to cross a river with his wolf, goat and head of cabbage. • Can only ferry 1 of 3 items at a time. Plus: • Leaving wolf & goat alone: wolf will eat goat. • Leaving goat & cabbage alone: goat will eat cabbage. • Yes, we can solve this problem using an FA! • Think about possible states and transitions.

  18. CS 44 – Aug. 29 • Regular operations • Union construction • Section 1.2 - Nondeterminism • 2 kinds of FAs • How to trace input • NFA design makes “union” operation easier • Equivalence of NFAs and DFAs

  19. Wolf, Goat, Cabbage • A man would like to cross a river with his wolf, goat and head of cabbage. • Can only ferry 1 of 3 items at a time. Plus: • Leaving wolf & goat alone: wolf will eat goat. • Leaving goat & cabbage alone: goat will eat cabbage. • Yes, we can solve this problem using an FA! • Think about possible states and transitions.

  20. Operations on sets • We can create new regular sets from existing ones, rather than starting from scratch.  • Binary operations • Union • Intersection • Unary operations • Complement • Star: This is the concatenation of 0 or more elements. For example, if A = {0, 11}, then A* is { ε, 0, 11, 00, 1111, 011, 110, …} • “Closure property”: you always get a regular set when you use the above operations.

  21. Union • Book shows construction (see handout) • We want to union two languages A1 and A2: M1 accepts A1 and M2 accepts A2. The combined machine is called M. • M pretends it’s running M1 and M2 at same time! δ((r1,r2),a) = (δ1(r1,a),δ2(r2,a)) • # states increases because it’s the Cartesian product of M1 and M2’s states. • Next section will show easier way to do union. 

  22. Union • Book shows construction (see handout) • We want to union two languages A1 and A2: M1 accepts A1 and M2 accepts A2. The combined machine is called M. • M pretends it’s running M1 and M2 at same time! δ((r1,r2),a) = (δ1(r1,a),δ2(r2,a)) • # states increases because it’s the Cartesian product of M1 and M2’s states. • Next section will show easier way to do union. 

  23. Non-determinism • There are 2 kinds of FA’s • DFA: deterministic FA • NFA: non-deterministic FA • NFA is like DFA except: • A state may have any # of arrows per input symbol • You can have ε-transitions. With this kind of transition, you can go to another state “for free”. • Non-determinism can make machine construction more flexible. At first the theory seems more complex, but NFA’s will come in handy.

  24. Example 1 0, ε 1 s1 s2 s3 s4 0, 1 0, 1

  25. continued 1 0, ε 1 • See the non-determinism? • Remember, any time you reach a state that has ε-transitions coming out, take it! It’s free. • Let’s trace input 010110. s1 s2 s3 s4 0, 1 0, 1

  26. 1 0, ε 1 s1 s2 s3 s4 0, 1 0, 1

  27. Moral • When tracing a word like 010110, we just want to know if there is any way to get to the accept state. • Language is anything containing 11 or 101. • Corresponding DFA would have more states.

  28. CS 461 – Aug. 31 Section 1.2 – Nondeterministic FAs • How to trace input √ • NFA design makes “union” operation easier • Equivalence of NFAs and DFAs

  29. NFA’s using “or” • Can you draw NFA for: { begin with 0 or end with 1 } ? Old start 1 ε New start Old start 2 ε

  30. Amazing fact • NFA = DFA • In other words, the two kinds of machines have the same power. • Proof idea: we can always convert a DFA into an NFA, or vice versa. Which do you think is easier to do?

  31. Formal NFA def’n • The essential difference with DFA is in the transition function: DFA δ: Q x Σ Q NFA δ: Q x Σε P(Q) • Thus, converting DFA  NFA is easy. We already satisfy the definition!

  32. NFA  DFA construction • When creating DFA, states will be all possible subsets of states from NFA. • This takes care of “all possible destinations.” • In practice we won’t need whole subset: only create states as you need them. • “empty set” can be our dead state. • DFA start state = NFA’s start state or anywhere you can begin for free. Happy state will be any subset containing NFA’s happy state. • Transitions: Please write as a table. Drawing would be too cluttered. When finished, can eliminate useless states.

  33. Example #1 • NFA transition table given to the right. • DFA start state is {1, 3}, or more simply 13. • DFA accept state would be anything containing 1. Could be 1, 12, 13, 123, but we may not need all these states.

  34. continued • The resulting DFA could require 2n states, but we should only create states as we need them. Let’s begin: If we’re in state 1 or 3, where do we go if we read an ‘a’ or a ‘b’? δ(13, a) = 1, but we can get to 3 for free. δ(13, b) = 2. We need to create a new state “2”. Continue the construction by considering transitions from state 2.

  35. NFA DFA answer Notice that the DFA is in fact deterministic: it has exactly one destination per transition. Also there is no column for ε.

  36. Example #2 • NFA transition table given to the right. • DFA start state is A. • DFA accept state would be anything containing D.

  37. continued Let’s begin. δ(A, 0) = A δ(A, 1) = AC We need new state AC. δ(AC, 0) = A δ(AC, 1) = ABC Continue from ABC…

  38. NFA DFA answer

  39. final thoughts • NFAs and DFAs have same computational power. • NFAs often have fewer states than corresponding DFA. • Typically, we want to design a DFA, but NFAs are good for combining 2+ DFAs. • After doing NFA  DFA construction, we may see that some states can be combined. • Later in chapter, we’ll see how to simplify FAs.

  40. CS 461 – Sept. 2 • Review NFA  DFA • Combining FAs to create new languages • union, intersection, concatenation, star • We can basically understand how these work by drawing a picture. • Section 1.3 – Regular expressions • A compact way to define a regular set, rather than drawing an FA or writing transition table.

  41. Example #2 • NFA transition table given to the right. • DFA start state is A. • DFA accept state would be anything containing D.

  42. continued Let’s begin. δ(A, 0) = A δ(A, 1) = AC We need new state AC. δ(AC, 0) = A δ(AC, 1) = ABC Continue from ABC…

  43. NFA DFA answer

  44. Moral • NFAs and DFAs have same computational power. • NFAs often have fewer states than corresponding DFA. • Typically, we want to design a DFA, but NFAs are good for combining 2+ DFAs. • After doing NFA  DFA construction, we may see that some states can be combined. • Later in chapter, we’ll see how to simplify FAs.

  45. U and ∩ • Suppose M1 and M2 are DFAs. We want to combine their languages. • Union: We create new start state. √ • Do you understand formalism p. 60 ? • How can we also do intersection? Hint: A ∩ B = (A’ U B’)’

  46. Concatenation • Concat: For each happy state in M1, turn it into a reject state and add ε-trans to M2’s start. • Example L1 = { does not contain 00 } L2 = { has even # of 1’s } Let’s draw NFA for L1L2. • Let’s decipher formal definition of δ on p. 61.

  47. Star • We want to concat the language with itself 0+ times. • Create new start state, and make it happy. • Add ε-transitions from other happy states to the start state. • Example L = { begins with 1 and ends with 0 } Let’s draw NFA for L*. • Formal definition of δon p. 63.

  48. Regular expression • A concise way to describe a language • Text representation, straightforward to input into computer programs. • Use alphabet symbols along with operators + means “or” * means repetition Concatenation • There is no “and” or complement.

  49. Examples • What do you think these regular expressions mean? 0* + 1* 0*1* 00*11* (a shorthand would be 0+1+) (0 + 1)* • What’s the difference between 10*1 and 1(0+1)*1 ? Does this mean “anything with 1 at beginning and end?”

  50. Practice • Words with 2 or more 0’s. What’s wrong with this answer: 1*01*01 ? • Words containing substring 110. • Every even numbered symbol is 0. • What’s wrong with: ((0 + 1)*0)* ? • Words of even length. • The last 2 symbols are the same. • What is the shortest word not in: 1*(01)*0* ? • True or false: (111*) = (11 + 111)*

More Related