One Minute To Learn Programming: Finite Automata

Slides:



Advertisements
Similar presentations
CS 3240: Languages and Computation
Advertisements

Formal Languages Languages: English, Spanish,... PASCAL, C,... Problem: How do we define a language? i.e. what sentences belong to a language? e.g.Large.
Deterministic Finite Automata (DFA)
Finite Automata CPSC 388 Ellen Walker Hiram College.
Finite Automata Course: Theory of Computation Date: Nov 16 th, 2011 Lin Liu lliu AT cs.kent.edu.
January 5, 2015CS21 Lecture 11 CS21 Decidability and Tractability Lecture 1 January 5, 2015.
CS21 Decidability and Tractability
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Fall Nonregular languages? We now know: –Regular languages may be specified either by regular.
CS5371 Theory of Computation
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
1 Finite Automata. 2 Finite Automaton Input “Accept” or “Reject” String Finite Automaton Output.
1 Languages and Finite Automata or how to talk to machines...
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Great Theoretical Ideas in Computer Science.
Cantor’s Legacy: Infinity And Diagonalization Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 25Apr 13, 2004Carnegie.
CMPS 3223 Theory of Computation
Lecture 23: Finite State Machines with no Outputs Acceptors & Recognizers.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Does not Compute 4: Finite Automata In which we temporarily admit defeat with cellular automata (we will face them again, in the epic final “Does Not Compute”
Great Theoretical Ideas in Computer Science.
Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein.
CS 203: Introduction to Formal Languages and Automata
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Deterministic Finite Automata COMPSCI 102 Lecture 2.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Machines That Can’t Count CS Lecture 15 b b a b a a a b a b.
Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 10Sept Carnegie Mellon University b b a b a a a b a b One.
Lecture Notes 
Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2006 Lecture 22 November 9, 2006Carnegie Mellon University b b a b a a a b a b.
Great Theoretical Ideas in Computer Science for Some.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2005 Lecture 9Feb Carnegie Mellon University b b a b a a a b a b One Minute.
1 Advanced Theory of Computation Finite Automata with output Pumping Lemma Theorem.
Fall 2004COMP 3351 Finite Automata. Fall 2004COMP 3352 Finite Automaton Input String Output String Finite Automaton.
Lecture Three: Finite Automata Finite Automata, Lecture 3, slide 1 Amjad Ali.
Languages.
Non-regular languages
Non Deterministic Automata
CSE 105 theory of computation
CSE 105 theory of computation
Chapter 2 Finite Automata
Pushdown Automata.
Pushdown Automata.
Hierarchy of languages
Non-Deterministic Finite Automata
CS 154, Lecture 3: DFANFA, Regular Expressions.
Intro to Data Structures
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/
NFAs and Transition Graphs
Finite Automata Reading: Chapter 2.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Great Theoretical Ideas in Computer Science
CS21 Decidability and Tractability
CSE 105 theory of computation
Instructor: Aaron Roth
CSC312 Automata Theory Transition Graphs Lecture # 9
Recap lecture 18 NFA corresponding to union of FAs,example, NFA corresponding to concatenation of FAs,examples, NFA corresponding to closure of an FA,examples.
NFAs and Transition Graphs
LECTURE # 07.
Non Deterministic Automata
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

One Minute To Learn Programming: Finite Automata Great Theoretical Ideas In Computer Science John Lafferty CS 15-251 Fall 2006 Lecture 22 November 9, 2006 Carnegie Mellon University One Minute To Learn Programming: Finite Automata b a

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Today we’ll talk about a programming language so simple that you can learn it in less than a minute. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Meet “ABA” The Automaton! Input String Result aba Accept aabb Reject aabba  Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 The Simplest Interesting Machine: Finite State Machine OR Finite Automaton Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Finite Automaton Finite set of states A start state A set of accepting states A finite alphabet a b # x 1 State transition instructions Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 How Machine M operates. M “reads” one letter at a time from the input string (going from left to right) M starts in state q0. If M is in state qi reads the letter a then If (qi. a) is undefined then CRASH. Otherwise M moves to state (qi,a) Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Let M=(Q,,F,) be a finite automaton. M accepts the string x if when M reads x it ends in an accepting state. M rejects the string x if when M reads x it ends in a non-accepting state. M crashes on x if M crashes while reading x. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

The set (or language) accepted by M is: Notice that this is  Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Back to “ABA” The Automaton Input String Result aba Accept aabb Reject aabba  Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What is the language accepted by this machine? a,b L = {a,b}* = all finite strings of a’s and b’s Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What is the language accepted by this machine? a,b a,b Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What is the language accepted by this machine? a,b a,b L = all even length strings of a’s and b’s Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What machine accepts this language? L = all strings in {a,b}* that contain at least one a a a,b b Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What machine accepts this language? L = strings with an odd number of b’s and any number of a’s b a Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What is the language accepted by this machine? L = any string ending with a b Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What is the language accepted by this machine? a,b a Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What is the language accepted by this machine? a,b a L = any string with at least two a’s Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What machine accepts this language? L = any string with an a and a b Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What machine accepts this language? L = any string with an a and a b b a,b a Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

What machine accepts this language? L = strings with an even number of ab pairs a b Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

L = all strings containing ababb as a consecutive substring Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

L = all strings containing ababb as a consecutive substring  Invariant: I am state s exactly when s is the longest suffix of the input (so far) that forms a prefix of ababb. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 The “grep” Problem Input: text T of length t string S of length n Problem: Does the string S appear inside the text T ? Naïve method: Cost: O(nt) comparisons Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Automata Solution Build a machine M that accepts any string with S as a consecutive substring. Feed the text to M. Cost: t comparisons + time to build M. As luck would have it, the Knuth, Morris, Pratt algorithm builds M quickly. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Real-life uses of finite state machines grep coke machines thermostats (fridge) elevators train track switches lexical analyzers for parsers Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Any L   is defined to be a language. L is just a set of strings. It is called a language for historical reasons. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Let L   be a language. L is called a regular language if there is some finite automaton that accepts L. In this lecture we have seen many regular languages.  even length strings strings containing ababb Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Theorem: Any finite langage is regular. Proof: Make a machine with a “path” for each string in the language, sharing prefixes Example: L = {a, bcd, ac, bb} b d a c Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Are all languages regular? Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

i.e., a bunch of a’s followed by an equal number of b’s Consider the language i.e., a bunch of a’s followed by an equal number of b’s No finite automaton accepts this language. Can you prove this? Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 anbn is not regular. No machine has enough states to keep track of the number of a’s it might encounter. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 That is a fairly weak argument. Consider the following example… Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 L = strings where the # of occurrences of the pattern ab is equal to the number of occurrences of the pattern ba Can’t be regular. No machine has enough states to keep track of the number of occurrences of ab. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Remember “ABA”? b a ABA accepts only the strings with an equal number of ab’s and ba’s! Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Let me show you a professional strength proof that anbn is not regular…. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Pigeonhole principle: Given n boxes and m > n objects, at least one box must contain more than one object. Letterbox principle: If the average number of letters per box is a, then some box will have at least a letters. (Similarly, some box has at most a.) Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Theorem: anbn is not regular. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Theorem: anbn is not regular. Proof: Assume that it is. Then  M with k states that accepts it. For each 0  i  k, let Si be the state M is in after reading ai. i,j  k s.t. Si = Sj, but i  j M will do the same thing on aibi and ajbi . But a valid M must reject ajbi and accept aibi.  Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Finite automata can’t count. MORAL: Finite automata can’t count. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Advertisement You can learn much more about these creatures in the FLAC course. Formal Languages, Automata, and Computation There is a unique smallest automaton for any regular language It can be found by a fast algorithm. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Cellular Automata Line up a bunch of identical finite automata in a straight line. Transitions are based on the states of the machine’s two neighbors or an indicator that a neighbor is missing. (There is no other input.) All cells move to their next states at the same time: synchronous transition Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

The Firing Squad Problem Five “soldiers” all start in the sleep state. You change the one on the left to the wake state. All five must get to the fire state at the same time (for the first time). sleep wake fire sleep wake fire Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Shorthand Means use this transition when your left neighbor is in any state at all and your right neighbor is in state a,b, or d. Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 {sleep,fire,end},Q sleep {w},Q {w4},Q {w3},Q {w2},Q wake wake2 wake3 wake4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 sleep Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 {sleep,fire,end},Q sleep {w},Q {w4},Q {w3},Q {w2},Q wake wake2 wake3 wake4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wake sleep Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 {sleep,fire,end},Q sleep {w},Q {w4},Q {w3},Q {w2},Q wake wake2 wake3 wake4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wake sleep wake2 Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 {sleep,fire,end},Q sleep {w},Q {w4},Q {w3},Q {w2},Q wake wake2 wake3 wake4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wake sleep wake2 wake3 Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 {sleep,fire,end},Q sleep {w},Q {w4},Q {w3},Q {w2},Q wake wake2 wake3 wake4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wake sleep wake2 wake3 wake4 Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 {sleep,fire,end},Q sleep {w},Q {w4},Q {w3},Q {w2},Q wake wake2 wake3 wake4 Q,Q Q,Q Q,Q Q,Q fire! 1 2 3 4 5 wake sleep wake2 wake3 wake4 fire Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Question Can you build the soldier’s finite automaton brain before you know how many soldiers will be in the line? No. Finite automata can’t count! Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789

Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789 Don’t jump to conclusions! It is possible to design a single cellular automaton that works for any number of soldiers! Steven Rudich: www.cs.cmu.edu/~rudich rudich0123456789