CISC 4090 Theory of Computation

Similar documents
CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

CISC 4090 Theory of Computation

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

CHAPTER 1 Regular Languages. Contents

Theory of Computation Regular Languages

Regular expressions, Finite Automata, transition graphs are all the same!!

Let's start with an example:

Lecture 08: Feb. 08, 2019

Chapter 2 Finite Automata

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Some Theory of Computation Exercises Week 1

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Convert the NFA into DFA

Designing finite automata II

NFAs continued, Closure Properties of Regular Languages

Finite-State Automata: Recap

1 Nondeterministic Finite Automata

Fundamentals of Computer Science

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Formal Language and Automata Theory (CS21004)

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

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

Worked out examples Finite Automata

Deterministic Finite Automata

Finite Automata-cont d

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

Java II Finite Automata I

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Nondeterminism and Nodeterministic Automata

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Non-deterministic Finite Automata

Minimal DFA. minimal DFA for L starting from any other

Languages & Automata

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Formal Languages and Automata

CMSC 330: Organization of Programming Languages

Homework 3 Solutions

Chapter 1, Part 1. Regular Languages. CSC527, Chapter 1, Part 1 c 2012 Mitsunori Ogihara 1

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

NFAs continued, Closure Properties of Regular Languages

Thoery of Automata CS402

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

3 Regular expressions

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

In-depth introduction to main models, concepts of theory of computation:

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Formal languages, automata, and theory of computation

Harvard University Computer Science 121 Midterm October 23, 2012

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

CS375: Logic and Theory of Computing

1 From NFA to regular expression

Lexical Analysis Part III

GNFA GNFA GNFA GNFA GNFA

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Non-deterministic Finite Automata

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

Non-Deterministic Finite Automata

State Minimization for DFAs

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

First Midterm Examination

Closure Properties of Regular Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) - Spring L. Blum

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

ɛ-closure, Kleene s Theorem,

Today s Topics Automata and Languages

Automata and Languages

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)

1.4 Nonregular Languages

CS375: Logic and Theory of Computing

Non Deterministic Automata. Formal Languages and Automata - Yonsei CS 1

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Closure Properties of Regular Languages

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

Lexical Analysis Finite Automate

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research

11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?

FABER Formal Languages, Automata and Models of Computation

CSC 311 Theory of Computation

Name Ima Sample ASU ID

Transcription:

9/6/28 Stereotypicl computer CISC 49 Theory of Computtion Finite stte mchines & Regulr lnguges Professor Dniel Leeds dleeds@fordhm.edu JMH 332 Centrl processing unit (CPU) performs ll the instructions Memory stores dt nd instructions for CPU Input collects informtion from the world Output provides informtion to the world Input Output CPU 2 Super-simple computers Smll numer of potentil inputs Smll numer of potentil outputs/ctions Thermostt Elevtor Vending mchine Automtic door Automtic door Desired ehvior Person pproches entrywy, door opens Person goes through entrywy, door stys open Person is no longer ner entrywy, door closes Noody ner entrywy, door stys closed Two sttes: Open, Closed Two inputs: Front-sensor, Bck-sensor 3 Finite stte mchine 4

9/6/28 Grph nd tle representtions Neither Front, Bck, Both Front, Bck, Both More finite stte mchine pplictions Text prsing Closed Neither Open Front Bck Neither Both Closed Open Open Closed Open Open Open Open Closed Open 5 Trffic light Pc-Mn Electronic locks 6 Coding comintion lock q q 3, A finite utomton M with 3 sttes Strt stte q; ccept stte q2 (doule circle) Exmple ccepted string: Wht re ll strings tht this model will ccept? String ending with or string end with followed y even numer of s 8 Forml definition of Finite Stte Automton Finite stte utomton is 5-tuple Q, Σ, δ, q, F Q is finite set clled sttes Σ is finite set clled the lphet δ: Q Σ Q is the trnsition function q Q is the strt stte F Q is the set of ccept sttes 9 2

9/6/28 Descrie M using forml definition q q 3 M = Q, Σ, δ, q, F, Q = q,, q 3 δ = Σ =, Strt stte: q F = q q 3 q q 3 Lnguge of M If A is set of ll strings ccepted y M, A is lnguge of M L(M)=A A mchine my ccept mny strings, ut only one lnguge M ccepts string M recognizes lnguge Descrie L(M)=A A={w w ends with or w end with one followed y even numer of s} 3 Descrie M2 using forml definition Descrie M2 using forml definition q q M2 = Q,,, δ, q, M2 = Q,,, δ, q, Q = Strt stte: δ = Q = {q, } Strt stte: q δ = q q q2 q2 q q2 4 5 3

9/6/28 Wht is the lnguge of M2? L(M2)={w } Wht is the lnguge of M2? L(M2)={w w ends with t lest one } 6 7 CFG prctice G -> AB A -> xxa y B -> wbw z Wht is the lnguge of M4? (pge 38, Ex..) q s r G 2 -> D D -> nd o L(M4)={w w ends nd egins with sme letter (either or )} r 2 8 2 4

9/6/28 Perform modulo rithmetic Let Σ={RESET,,, 2} Construct M5 to ccept string only if the sum of ech input symol is multiple of 3, nd RESET sets the sum ck to (.3, pge 39),RES 2 More modulo rithmetic Generlize M5 to ccept if sum of symols is multiple of i insted of 3 q, q, q2, q3,, q i,,,2, RESET, δ, q, F q q 2,RES 2 q 3, RES 22 23 More modulo rithmetic Generlize M5 to ccept if sum of symols is multiple of i insted of 3 q, q, q2, q3,, q i,,,2, RESET, δ, q, F δ qj, RESET = q δ qj, = qj δ qj, = qk for k = j+ mod i δ qj, 2 = qk for k = j+2 mod i 24 Definition of M ccepting string Let M = Q, Σ, δ, q, F e finite utomton nd let w = w w 2 w n Then M ccepts w if sequence of sttes r, r,, r n in Q exists with 3 conditions r =q δ r i, w i+ = r i+ for i =,,, n r n F 25 5

9/6/28 Regulr lnguges Definition: lnguge is clled regulr lnguge if some finite utomton recognizes it equivlently All of the strings in regulr lnguge re ccepted y some finite utomton Designing finite utomt (FAs) Determine wht you need to rememer How mny sttes needed for your tsk? Set strt nd finish sttes Assign trnsitions Check your solution Should ccept w L Should reject w L Be creful out ε! 26 27 FA design prctice! FA to ccept lnguge where numer of s is odd (pge 43) FA to ccept string with sustring, FA to ccept string with s sustring (pge 44) q q q 3 q 4 FA to ccept string with sustring (next pge!) 29 3 6

9/6/28 Regulr opertions Let A nd B e lnguges. We define 3 regulr opertions: Union: A B = x x A or x B Conctention: A B = xy x A nd y B Str: A = x x 2 x k k nd ech x i A Repet string or more times Exmples of regulr opertions Let A = good, d nd B = oy, girl Wht is: A B = good, d, oy, girl A B = goodoy, goodgirl, doy, dgirl A = ε, good, d, goodgood, goodd, dgood, dd, 32 34 Express CFG s RegEx? Closure G 2 -> D D -> nd o n * o A collection of ojects is closed under n opertion if pplying tht opertion to memers of the collection returns n oject in the collection G -> AB A -> xxa y B -> wbw z None ville Regulr lnguges re closed under,, 36 37 7

9/6/28 Closure of Union Theorem.25: The clss of regulr lnguges is closed under the union opertion Proof y construction Let s consider two lnguges L: strt with, end with L2: strt with, end with Construct mchines for ech lnguges Construct mchines M3 to recognize L U L2 38 39 Exmple union A = {w w strts with ends with } M q q B = {w w strts with ends with } M2 r r r 2 q rej, r rej, 4 Exmple union Simulte M nd M2 sttes (q,r ) (q,r rej) (,r rej ) (q rej,r ) (q rej,r 2 ) 4 8

9/6/28 Closure of Union Proof y Construction Let us ssume M recognizes lnguge L Define M s M = Q, Σ, δ, q, F Let us ssume M2 recognizes lnguge L2 Define M2 s M2 = R, Σ, δ 2, r, F 2 Proof y construction: Construct M3 to recognize L3 = L L2 Let M3 e defined s M3 = S, Σ, δ 3, s, F 3 Closure of Union Proof y Construction Let M3 e defined s M3 = S, Σ, δ 3, s, F 3 Use ech stte of M3 to simulte eing in stte of M nd nother stte in M2 simultneously M3 sttes: S = q i, r j q i Q nd r j R Strt stte: s = q, r Accept stte: F 3 = q i, r j q i F or r j F 2 42 Trnsition function: δ 3 q i, r j, x = δ 3 q i, x, δ 3 q j, x 43 Closure of Conctention Theorem.26: The clss of regulr lnguges is closed under the conctention opertion If A nd A2 re regulr lnguges, then so is A A2 Chllenge: How do we know when M ends nd M2 egins? Determinism vs. non-determinism Determinism: Single trnsition llowed given current stte nd given input Non-determinism: multiple trnsitions llowed for current stte nd given input trnsition permitted for null input ε,,,ε q q 3 q 4 44 45 9

9/6/28 NFA in ction When there is choice, follow ll pths like cloning If there is no forwrd rrow, pth termintes nd clone dies (no ccept) NFA will ccept if t lest one pth termintes t ccept Alterntive thought: Mgiclly pick est pth from the set of options 46 The lnguge of M, q List some ccepted strings t third entry, we re in sttes {q,q 3, nd q 4 } Wht is L(M)? {w w contins or },,ε q 3 q 4 48 NFA construction prctice Build n NFA tht ccepts ll strings over {,} with in the third position from the end NFA -> DFA Build n NFA tht ccepts ll strings over {,} with in the third position from the end Cn we construct DFA for this? 49 5

9/6/28 Forml definition of Nondeterministic Finite Automton Similr to DFA: 5-tuple Q, Σ, δ, q, F Q is finite set clled sttes Σ is finite set clled the lphet δ: Q Σε P(Q) is the trnsition function q Q is the strt stte F Q is the set of ccept sttes 52 Descrie M using forml definition, M = Q, Σ, δ, q, F Q = Σ = Strt stte: F = q q δ =,, q 3 q q q 3 ε 53 Consider NFA N q q Convert NFA N to DFA M q q N Lnguge: L(N)={w w egins with, ends with, every in w is preceded y } 54

9/6/28 Equivlence of NFAs nd DFAs NFAs nd DFAs recognize the sme clss of lnguges Two mchines re equivlent if they recognize the sme lnguge Every NFA hs n equivlent DFA Union Closure with NFAs Proofs y construction fewer sttes! Any NFA proof pplies to DFA Given two regulr lnguges A nd A 2 recognized y N nd N2 respectively, construct N to recognize A A 2 59 6 Let s consider two lnguges L: strt with, end with L2: strt with, end with Let s consider two lnguges L: strt with, end with N, q q Construct mchines for ech lnguges Construct mchines N3 to recognize L U L2 L2: strt with, end with N2, r r r 2 62 63 2

9/6/28 N3 recognizes L U L2 ε N, q q Closure under conctention Given two regulr lnguges A nd A 2 recognized y N nd N2 respectively, construct N to recognize A A 2 s ε N2, r r r 2 64 66 Closure under str Str: L Prove if A is regulr, A is lso regulr s N, q q ε 69 7 3

9/6/28 Closure of regulr lnguges under str Let N = Q, Σ, δ, q, F N3 = Q 3, Σ, δ 3, s, F 3 Q 3 = Q s Strt stte: s F = F 3 s recognize L will recognize L * iff δ 3 q, = δ q, q s if q Q if q = s nd = ε if q F nd = ε Regulr expressions A regulr expression is description of set of possile strings using single chrcters nd possily including regulr opertions Exmples: 7 72 Regulr expressions forml definition R is regulr expression if R is, for some in lphet Σ ε R R2, where R nd R2 re regulr expressions R R2, where R nd R2 re regulr expressions R, where R is regulr expression Exmples of Regulr Expressions Σ Σ ε ε This is recursive definition 74 75 4

9/6/28 FA cn recognize ny Regulr Expression Theorem: A lnguge is regulr if nd only if some regulr expression descries it Prove: If lnguge is descried y regulr expression, then it is regulr Prove: If lnguge is regulr, then it is descried y regulr expression Prove if lnguge descried regulr expression, it is regulr (recognized y FSA) Ech regulr expression is either Cse : ϵσ Cse 2: ε Cse 3: Cse 4: R R2 Theorem.45 Cse 5: R R2 Theorem.47 Cse 6: R Proven on slide 5 Cse : Cse 2: Cse 3: q q q q 77 78 Converting from FSA to Regulr Expression, 2 79 5