Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Similar documents
One Minute To Learn Programming: Finite Automata

Regular Sets and Expressions

Homework 3 Solutions

flex Regular Expressions and Lexical Scanning Regular Expressions and flex Examples on Alphabet A = {a,b} (Standard) Regular Expressions on Alphabet A

FORMAL LANGUAGES, AUTOMATA AND THEORY OF COMPUTATION EXERCISES ON REGULAR LANGUAGES

Reasoning to Solve Equations and Inequalities

Binary Representation of Numbers Autar Kaw

Solution to Problem Set 1

Bypassing Space Explosion in Regular Expression Matching for Network Intrusion Detection and Prevention Systems

Unambiguous Recognizable Two-dimensional Languages

and thus, they are similar. If k = 3 then the Jordan form of both matrices is

Regular Languages and Finite Automata

Solving the String Statistics Problem in Time O(n log n)

MATH 150 HOMEWORK 4 SOLUTIONS

Polynomial Functions. Polynomial functions in one variable can be written in expanded form as ( )

Example 27.1 Draw a Venn diagram to show the relationship between counting numbers, whole numbers, integers, and rational numbers.

Words Symbols Diagram. abcde. a + b + c + d + e

LINEAR TRANSFORMATIONS AND THEIR REPRESENTING MATRICES

DATABASDESIGN FÖR INGENJÖRER F

Regular Repair of Specifications

Pointed Regular Expressions

How fast can we sort? Sorting. Decision-tree model. Decision-tree for insertion sort Sort a 1, a 2, a 3. CS Spring 2009

Bayesian Updating with Continuous Priors Class 13, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

A Visual and Interactive Input abb Automata. Theory Course with JFLAP 4.0

Basic Research in Computer Science BRICS RS Brodal et al.: Solving the String Statistics Problem in Time O(n log n)

2 DIODE CLIPPING and CLAMPING CIRCUITS

Appendix D: Completing the Square and the Quadratic Formula. In Appendix A, two special cases of expanding brackets were considered:

PROF. BOYAN KOSTADINOV NEW YORK CITY COLLEGE OF TECHNOLOGY, CUNY

EQUATIONS OF LINES AND PLANES

Unit 6: Exponents and Radicals

Lec 2: Gates and Logic

CS99S Laboratory 2 Preparation Copyright W. J. Dally 2001 October 1, 2001

MODULE 3. 0, y = 0 for all y

Automated Grading of DFA Constructions

Use Geometry Expressions to create a more complex locus of points. Find evidence for equivalence using Geometry Expressions.

Java CUP. Java CUP Specifications. User Code Additions You may define Java code to be included within the generated parser:

Vectors Recap of vectors

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 16 th May Time: 14:00 16:00

Example A rectangular box without lid is to be made from a square cardboard of sides 18 cm by cutting equal squares from each corner and then folding

Modular Generic Verification of LTL Properties for Aspects

Algebra Review. How well do you remember your algebra?

Lecture 5. Inner Product

Learning Outcomes. Computer Systems - Architecture Lecture 4 - Boolean Logic. What is Logic? Boolean Logic 10/28/2010

A.7.1 Trigonometric interpretation of dot product A.7.2 Geometric interpretation of dot product

Small Business Networking

Integration by Substitution

Generating In-Line Monitors For Rabin Automata

Small Business Networking

9.3. The Scalar Product. Introduction. Prerequisites. Learning Outcomes

Small Business Networking

Experiment 6: Friction

Small Business Networking

FAULT TREES AND RELIABILITY BLOCK DIAGRAMS. Harry G. Kwatny. Department of Mechanical Engineering & Mechanics Drexel University

Physics 43 Homework Set 9 Chapter 40 Key

Factoring Polynomials

Brillouin Zones. Physics 3P41 Chris Wiebe

Or more simply put, when adding or subtracting quantities, their uncertainties add.

Protocol Analysis / Analysis of Software Artifacts Kevin Bierhoff

How To Network A Smll Business

0.1 Basic Set Theory and Interval Notation

Graphs on Logarithmic and Semilogarithmic Paper

On the expressive power of temporal logic

1 Fractions from an advanced point of view

. At first sight a! b seems an unwieldy formula but use of the following mnemonic will possibly help. a 1 a 2 a 3 a 1 a 2

Linear Equations in Two Variables

Math 135 Circles and Completing the Square Examples

String Searching. String Search. Spam Filtering. String Search

Solutions for Selected Exercises from Introduction to Compiler Design

! What can a computer do? ! What can a computer do with limited resources? ! Don't talk about specific machines or problems.

On decidability of LTL model checking for process rewrite systems

1. Introduction Texts and their processing

Lecture 3 Gaussian Probability Distribution

Novel Methods of Generating Self-Invertible Matrix for Hill Cipher Algorithm

(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.

The remaining two sides of the right triangle are called the legs of the right triangle.

Mathematics. Vectors. hsn.uk.net. Higher. Contents. Vectors 128 HSN23100

Automata theory. An algorithmic approach. Lecture Notes. Javier Esparza

Babylonian Method of Computing the Square Root: Justifications Based on Fuzzy Techniques and on Computational Complexity

Concept Formation Using Graph Grammars

Ratio and Proportion

6.2 Volumes of Revolution: The Disk Method

1.2 The Integers and Rational Numbers

Treatment Spring Late Summer Fall Mean = 1.33 Mean = 4.88 Mean = 3.

Section 5-4 Trigonometric Functions

19. The Fermat-Euler Prime Number Theorem

Angles 2.1. Exercise Find the size of the lettered angles. Give reasons for your answers. a) b) c) Example

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Chapter. Contents: A Constructing decimal numbers

Geometry 7-1 Geometric Mean and the Pythagorean Theorem

Section 5.2, Commands for Configuring ISDN Protocols. Section 5.3, Configuring ISDN Signaling. Section 5.4, Configuring ISDN LAPD and Call Control

Helicopter Theme and Variations

Lectures 8 and 9 1 Rectangular waveguides

FUNCTIONS AND EQUATIONS. xεs. The simplest way to represent a set is by listing its members. We use the notation

Math 314, Homework Assignment Prove that two nonvertical lines are perpendicular if and only if the product of their slopes is 1.

, and the number of electrons is -19. e e C. The negatively charged electrons move in the direction opposite to the conventional current flow.

Learning Workflow Petri Nets

WHAT HAPPENS WHEN YOU MIX COMPLEX NUMBERS WITH PRIME NUMBERS?

Rotating DC Motors Part II

When Simulation Meets Antichains (on Checking Language Inclusion of NFAs)

5 a LAN 6 a gateway 7 a modem

Transcription:

Anupm Gupt Dnny Sletor Gret Theoreticl Ides In Computer Science CS 5-25 Fll 2 Lecture 2 Oct 28, 2 Crnegie Mellon University Deterministic Finite Automt Finite Automt A mchine so simple tht you cn understnd it in less thn one minute Wishful thinking, strt stte (q ) ccept sttes (F), trnsitions The mchine ccepts string if the process ends in doule circle The mchine ccepts string if the process ends in doule circle sttes Antomy of Deterministic Finite Automton The singulr of utomt is utomton. The Lnguge L(M) of Mchine M, The lphet of finite utomton is the set where the symols come from, for exmple {,} The lnguge of finite utomton is the set of strings tht it ccepts q L(M) = All strings of s nd s The lnguge of finite utomton is the set of strings tht it ccepts

The Lnguge L(M) of Mchine M q q L(M) = { w w hs n even numer of s} Nottion An lphet Σ is finite set (e.g., Σ = {,}) A string over Σ is finite-length sequence of elements of Σ For x string, x is the length of x The unique string of length will e denoted y ε nd will e clled the empty or null string A lnguge over Σ is set of strings over Σ A finite utomton is M = (Q, Σ, δ, q, F) Q is the finite set of sttes Σ is the lphet δ : Q Σ Q is the trnsition function q Q is the strt stte F Q is the set of ccept sttes L(M) = the lnguge of mchine M = set of ll strings mchine M ccepts M = (Q, Σ, δ, q, F) where q q M q 3 Q = {q, q, q 2, q 3 } Σ = {,} q Q is strt stte F = {q, q 2 } Q ccept sttes δ : Q Σ Q trnsition function, q 2 δ q q q q q 2 q 2 q 2 q 3 q 2 q 3 q q 2 EXAMPLE The finite-stte utomt re deterministic, if for ech pir Q Σ of stte nd input vlue there is unique next stte given y the trnsition function. There is nother type mchine in which there my e severl possile next sttes. Such mchines clled nondeterministic. Build n utomton tht ccepts ll nd only those strings tht contin {} {}, {} 2

Build n utomton tht ccepts ll inry numers tht re divisile y 3, i.e, L =,,,,,,, A lnguge over Σ is set of strings over Σ A lnguge is regulr if it is recognized y deterministic finite utomton L = { w w contins } is regulr L = { w w hs n even numer of s} is regulr Determine the lnguge recognized y Determine the lnguge recognized y,,, L(M)={ n n =,, 2, } L(M)={, } Determine the lnguge recognized y DFA Memership prolem Determine whether some word elongs to the lnguge.,, L(M)={ n, n x n=,,2, nd x is ny string} Theorem: The DFA Memership Prolem is solvle in liner time. Let M = (Q, Σ, δ, q, F) nd w = w...w m. Algorithm for DFA M: p := q ; for i := to m do p := δ(p,w i ); if p F then return Yes else return No. 3

Equivlence of two DFAs Definition: Two DFAs M nd M 2 over the sme lphet re equivlent if they ccept the sme lnguge: L(M ) = L(M 2 ). Given few equivlent mchines, we re nturlly interested in the smllest one with the lest numer of sttes. Union Theorem Given two lnguges, L nd L 2, define the union of L nd L 2 s L L 2 = { w w L or w L 2 } Theorem: The union of two regulr lnguges is lso regulr lnguge. Theorem: The union of two regulr lnguges is lso regulr lnguge Proof (Sketch): Let M = (Q, Σ, δ, q, F ) e finite utomton for L 2 nd M 2 = (Q 2, Σ, δ 2, q, F 2 ) e finite utomton for L 2 We wnt to construct finite utomton M = (Q, Σ, δ, q, F) tht recognizes L = L L 2 Ide: Run oth M nd M 2 t the sme time Q = pirs of sttes, one from M nd one from M 2 = { (q, q 2 ) q Q nd q 2 Q 2 } = Q Q 2 q = (q,q 2 ) δ ((q,q 2 ),σ) = (δ (q,σ), δ 2 (q 2,σ)) F = (F Q 2 ) (Q F 2 ) Esy to see tht this simultes oth mchines nd ccepts the union. QED Theorem: The union of two regulr lnguges is lso regulr lnguge Automton for Union q q p q p q p p p q p q 4

The Regulr Opertions Union: A B = { w w A or w B } Reverse Reverse: A R = { σ σ k σ k σ A } Intersection: A B = { w w A nd w B } Negtion: A = { w w A } Reverse: A R = { σ σ k σ k σ A } Conctention: A B = { vw v A nd w B } Str: A* = { w w k k nd ech w i A } How to construct DFA for the reversl of lnguge? The direction in which we red string should e irrelevnt. If we flip trnsitions round we might not get DFA. The Kleene closure: A* Str: A* = { w w k k nd ech w i A } From the definition of the conctention, we define A n, n =,, 2, recursively A = {ε} A n+ = A n A A* is set consisting of conctentions of ny numer of strings from A. A * = A k k< The Kleene closure: A* Wht is A* of A={,}? Wht is A* of A={}? All inry strings All inry strings of n even numer of s Regulr Lnguges Are Closed Under The Regulr Opertions We hve seen the proof for Union. You will prove some of these on your homework. Theorem: Any finite lnguge is regulr Clim : Let w e string over n lphet. Then {w} is regulr lnguge. Proof: Construct the utomton tht ccepts {w}. Clim 2: A lnguge consisting of n strings is regulr Proof: By induction on the numer of strings. If {} then L {} is regulr 5

Pttern Mtching Input: Text T of length t, string S of length n Prolem: Does string S pper inside text T? Nïve method:, 2, 3, 4, 5,, t Cost: Roughly nt comprisons Automt Solution Build mchine M tht ccepts ny string with S s consecutive sustring Feed the text to M Cost: t comprisons + time to uild M As luck would hve it, the Knuth, Morris, Prtt lgorithm uilds M quickly Rel-life Uses of DFAs Regulr Expressions Are ll lnguges regulr? Coke Mchines Thermostts (fridge) Elevtors Trin Trck Switches Lexicl Anlyzers for Prsers Consider the lnguge L = { n n n > } i.e., unch of s followed y n equl numer of s No finite utomton ccepts this lnguge Cn you prove this? n n is not regulr. No mchine hs enough sttes to keep trck of the numer of s it might encounter 6

Tht is firly wek rgument Consider the following exmple L = strings where the # of occurrences of the pttern is equl to the numer of occurrences of the pttern Cn t e regulr. No mchine hs enough sttes to keep trck of the numer of occurrences of L = strings where the # of occurrences of the pttern is equl to the numer of occurrences of the pttern Cn t e regulr. No mchine hs enough sttes to keep trck of the numer of occurrences of M ccepts only the strings with n equl numer of s nd s! Let me show you professionl strength proof tht n n is not regulr How to prove lnguge is not regulr Assume it is regulr, hence is ccepted y DFA M with n sttes. Show tht there re two strings s nd s 2 which oth rech some stte in M (usully y pigeonhole principle) Then show there is some string t such tht string s t is in the lnguge, ut s 2 t is not. However, M ccepts either oth or neither. 7

Theorem: L= { n n n > } is not regulr Proof (y contrdiction): Assume tht L is regulr, M=(Q,{,},δ,q,F) Consider δ(q, i ) for i =,2,3, There re infinitely mny i s ut finite numer of sttes. δ(q, n )=q nd δ(q, m ) =q, nd n m Since M ccepts n n δ(q, n )=q f The finite-stte utomt re deterministic, if for ech pir of stte nd input vlue there is unique next stte given y the trnsition function. There is nother type mchine in which there my e severl possile next sttes. Such mchines clled nondeterministic. δ(q, m n )=δ( δ(q, m ), n )=δ(q, n )= q f It follows tht M ccepts m n, nd n m Nondeterministic finite utomton (NFA) A NFA is defined using the sme nottions M = (Q, Σ, δ, q, F) s DFA except the trnsition function δ ssigns set of sttes to ech pir Q Σ of stte nd input. A string is ccepted iff there exists some set of choices tht leds to n ccepting stte Note, every DFA is utomticlly lso NFA. Nondeterministic finite utomton q k Allows trnsitions from q k on the sme symol to mny sttes NFA for { k k is multiple of 2 or 3} Wht does it men tht for NFA to recognize string x = x x 2 x k? s s s 3, s 2 s 4 Since ech input symol x j (for j>) tkes the previous stte to set of sttes, we shll use union of these sttes. 8

Wht does it men tht for NFA to recognize string? Here we re going formlly define this. For stte q nd string w, δ * (q, w) is the set of sttes tht the NFA cn rech when it reds the string w strting t the stte q. Thus for NFA= (Q, Σ, δ, q, F), the function δ * : Q x Σ* -> 2 Q is defined y δ * (q, y x k ) = p δ*(q,y) δ(p,x k ) Find the lnguge recognized y this NFA s s s 2 s 3 s 4, L = { n, n, n n =,, 2 } Find the lnguge recognized y this NFA Theorem: The lnguges ccepted y n NFA re regulr. s In other words: For ny NFA there is n equivlent DFA. L = * (,, ) ()* This theorem my prove useful on the homework. You should prove it if you wnt to use it. NFA vs. DFA NFA Richer nottion to represent lnguge. Sometimes exponentilly smller. DFA Implementle in low level hrdwre. Very fst to simulte. Study Bee DFAs Regulr Lnguges Regulr opertors n n is not regulr NFAs NFAs ccept regulr lnguges 9