Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS 15-251 Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.

Slides:



Advertisements
Similar presentations
Deterministic Finite Automata (DFA)
Advertisements

1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
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.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
Finite Automata and Non Determinism
CS5371 Theory of Computation
CS 310 – Fall 2006 Pacific University CS310 Finite Automata Sections:1.1 page 44 September 8, 2006.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Languages and Finite Automata or how to talk to machines...
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 1 Regular Languages Contents Finite Automata (FA or DFA) definitions, examples,
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
Topics Automata Theory Grammars and Languages Complexities
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Great Theoretical Ideas in Computer Science.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Theory of Languages and Automata
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Language Recognition Rosen, Chapter 12.4.
Great Theoretical Ideas in Computer Science.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CS 203: Introduction to Formal Languages and Automata
Deterministic Finite Automata COMPSCI 102 Lecture 2.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
Machines That Can’t Count CS Lecture 15 b b a b a a a b a b.
Modeling Computation: Finite State Machines without Output
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 
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
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.
Nondeterministic Finite Automata (NFAs). Reminder: Deterministic Finite Automata (DFA) q For every state q in Q and every character  in , one and only.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
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.
Lecture #5 Advanced Computation Theory Finite Automata.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
Languages.
CSE 105 theory of computation
Hierarchy of languages
CS 154, Lecture 3: DFANFA, Regular Expressions.
COSC 3340: Introduction to Theory of Computation
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Great Theoretical Ideas in Computer Science
One Minute To Learn Programming: Finite Automata
Chapter 1 Regular Language
Finite-State Machines with No Output
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon University

A machine so simple that you can understand it in less than one minute Wishful thinking… Deterministic Finite Automata

0 0, The machine accepts a string if the process ends in a double circle

0 0, The machine accepts a string if the process ends in a double circle states start state (q 0 ) accept states (F) transitions

Anatomy of a Deterministic Finite Automaton The alphabet of a finite automaton is the set where the symbols come from, for example {0,1} The language of a finite automaton is the set of strings that it accepts The singular of automata is automaton.

L(M) = All strings of 0s and 1s The Language L(M) of Machine M 0,1 q0q0 The language of a finite automaton is the set of strings that it accepts

0 0 1 L(M) = { w | w has an even number of 1s} q0q0 0 q1q1 1 1 The Language L(M) of Machine M

An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x a string, |x| isthe length of x The unique string of length 0 will be denoted by ε and will be called the empty or null string Notation A language over Σ is a set of strings over Σ

Q is the finite set of states Σ is the alphabet  : Q  Σ → Q is the transition function q 0  Q is the start state F  Q is the set of accept states A finite automaton is M = (Q, Σ, , q 0, F) L(M) = the language of machine M = set of all strings machine M accepts

Q = {q 0, q 1, q 2, q 3 } Σ = {0,1}  : Q  Σ → Q transition function q 0  Q is start state F = {q 1, q 2 }  Q accept states M = (Q, Σ, , q 0, F) where  01 q0q0 q0q0 q1q1 q1q1 q2q2 q2q2 q2q2 q3q3 q2q2 q3q3 q0q0 q2q2 q2q2 0 0, q0q0 q1q1 q3q3 M

The finite-state automata are deterministic, if for each pair Q  Σ of state and input value there is a unique next state given by the transition function. There is another type machine in which there may be several possible next states. Such machines called nondeterministic.

Build an automaton that accepts all and only those strings that contain 001 {0} 0 1 {00} 0 1 {001} 1 0 0,1 EXAMPLE

Build an automaton that accepts all binary numbers that are divisible by 3, i.e, L = 0, 11, 110, 1001, 1100, 1111, 10010, 10101…

A language is regular if it is recognized by a deterministic finite automaton L = { w | w contains 001} is regular L = { w | w has an even number of 1s} is regular A language over Σ is a set of strings over Σ

Determine the language recognized by 0 1 0,1 L(M)={1 n | n = 0, 1, 2, …}

Determine the language recognized by L(M)={1, 01} 0 0,

Determine the language recognized by L(M)={0 n, 0 n 10x | n=0,1,2…, and x is any string} 1 0,

DFA Membership problem Determine whether some word belongs to the language. Theorem: The DFA Membership Problem is solvable in linear time. Let M = (Q, Σ, , q 0, F) and w = w 1...w m. Algorithm for DFA M: p := q 0 ; for i := 1 to m do p :=  (p,w i ); if p  F then return Yes else return No.

Equivalence of two DFAs Given a few equivalent machines, we are naturally interested in the smallest one with the least number of states. Definition: Two DFAs M 1 and M 2 over the same alphabet are equivalent if they accept the same language: L(M 1 ) = L(M 2 ).

Union Theorem Given two languages, L 1 and L 2, define the union of L 1 and L 2 as L 1  L 2 = { w | w  L 1 or w  L 2 } Theorem: The union of two regular languages is also a regular language.

Theorem: The union of two regular languages is also a regular language Proof (Sketch): Let M 1 = (Q 1, Σ,  1, q 0, F 1 ) be finite automaton for L 1 and M 2 = (Q 2, Σ,  2, q 0, F 2 ) be finite automaton for L 2 We want to construct a finite automaton M = (Q, Σ, , q 0, F) that recognizes L = L 1  L 2 1 2

Idea: Run both M 1 and M 2 at the same time! Q = pairs of states, one from M 1 and one from M 2 = { (q 1, q 2 ) | q 1  Q 1 and q 2  Q 2 } = Q 1  Q 2

Theorem: The union of two regular languages is also a regular language 0 0 q0q0 0 q1q p0p0 1 p1p1 0 0

Automaton for Union 0 p 0 q p 0 q 1 p 1 q 0 p 1 q 1 0 0

The Regular Operations Union: A  B = { w | w  A or w  B } Intersection: A  B = { w | w  A and w  B } Negation:  A = { w | w  A } Reverse: A R = { w 1 …w k | w k …w 1  A } Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w 1 …w k | k ≥ 0 and each w i  A }

Reverse Reverse: A R = { w 1 …w k | w k …w 1  A } How to construct a DFA for the reversal of a language? The direction in which we read a string should be irrelevant. If we flip transitions around we might not get a DFA.

The Kleene closure: A* From the definition of the concatenation, we definite A n, n =0, 1, 2, … recursively A 0 = { ε } A n+1 = A n A Star: A* = { w 1 …w k | k ≥ 0 and each w i  A } A* is a set consisting of concatenations of arbitrary many strings from A.

The Kleene closure: A* What is A* of A={0,1}? All binary strings What is A* of A={11}? All binary strings of an even number of 1s

Regular Languages Are Closed Under The Regular Operations We have seen part of the proof for Union. The proof for intersection is very similar. The proof for negation is easy.

Theorem: Any finite language is regular Claim 1: Let w be a string over an alphabet. Then {w} is a regular language. Proof: By induction on the number of characters. If {a} and {b} are regular then {ab} is regular Claim 2: A language consisting of n strings is regular Proof: By induction on the number of strings. If {a} then L  {a} is regular

Input: Text T of length t, string S of length n Pattern Matching Problem: Does string S appear inside text T? a 1, a 2, a 3, a 4, a 5, …, a t Naïve method: Cost:Roughly nt comparisons

Automata Solution Build a machine M that accepts any string with S as a consecutive substring Feed the text to M Cost: As luck would have it, the Knuth, Morris, Pratt algorithm builds M quickly t comparisons + time to build M

Grep Coke Machines Thermostats (fridge) Elevators Train Track Switches Lexical Analyzers for Parsers Real-life Uses of DFAs

Are all languages regular?

i.e., a bunch of a’s followed by an equal number of b’s Consider the language L = { a n b n | n > 0 } No finite automaton accepts this language Can you prove this?

a n b n is not regular. No machine has enough states to keep track of the number of a’s it might encounter

That is a fairly weak argument Consider the following example…

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

M accepts only the strings with an equal number of ab’s and ba’s! b b a b a a a b a b

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

Let me show you a professional strength proof that a n b n is not regular…

How to prove a language is not regular… Assume it is regular, hence is accepted by a DFA M with n states. Show that there are two strings s 1 and s 2 which both reach some state in M (usually by pigeonhole principle) Then show there is some string t such that string s 1 t is in the language, but s 2 t is not. However, M accepts either both or neither.

Pigeonhole principle: If we put n objects into m pigeonholes and if n > m, then at least one pigeonhole must have more than one item in it.

Theorem: L= {a n b n | n > 0 } is not regular Proof (by contradiction): Assume that L is regular, M=(Q, {a,b}, ,q 0,F) Consider  (q 0, a i ) for i = 1,2,3, … There are infinitely many i’s but a finite number of states.  (q 0, a n )=q and  (q 0, a m ) =q, and n  m Since M accepts a n b n  (q, b n )=q f  (q 0, a m b n )=  (  (q 0, a m ),b n )=  (q, b n )= q f It follows that M accepts a m b n, and n  m

The finite-state automata are deterministic, if for each pair of state and input value there is a unique next state given by the transition function. There is another type machine in which there may be several possible next states. Such machines called nondeterministic.

A NFA is defined using the same notations M = (Q, Σ, , q 0, F) as DFA except the transition function  assigns a set of states to each pair Q  Σ of state and input. Nondeterministic finite automaton (NFA) Note, every DFA is automatically also a NFA.

Nondeterministic finite automaton a a q k a Allows transitions from q k on the same symbol to many states

NFA for {0 k | k is a multiple of 2 or 3} ε ε

What does it mean that for a NFA to recognize a string x = x 1 x 2 …x k ? ,1 1 1 s 1 s 2 s 3 s 4 s 0 Since each input symbol x j (for j>1) takes the previous state to a set of states, we shall use a union of these states.

What does it mean that for a NFA to recognize a string? Here we are going formally define this. For a state q and string w,  * (q, w) is the set of states that the NFA can reach when it reads the string w starting at the state q. Thus for NFA= (Q, Σ, , q 0, F), the function  * : Q x Σ* -> 2 Q is defined by  * (q, y x k ) =  p   *(q,y)  (p,x k )

Find the language recognized by this NFA ,1 1 1 s 1 s 2 s 3 s 4 s 0 L = {0 n, 0 n 01, 0 n 11 | n = 0, 1, 2…}

Find the language recognized by this NFA s 0 L = 1 * (01, 1, 10) (00)* 0

Nondeterministic finite automaton Theorem. If the language L is recognized by a NFA M 0, then L is also recognized by a DFA M 1. In other words, if we ask if there is a NFA that is not equivalent to any DFA. The answer is No.

NFA vs. DFA Advantages. Easier to construct and manipulate. Sometimes exponentially smaller. Sometimes algorithms much easier. Drawbacks Acceptance testing slower. Sometimes algorithms more complicated.

Study Bee DFA NFA