CS375: Logic and Theory of Computing

Similar documents
CS375: Logic and Theory of Computing

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

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

Theory of Computation Regular Languages

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

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

Deterministic Finite-State Automata

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Finite-State Automata: Recap

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

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

Finite Automata-cont d

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

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

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

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

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

Deterministic Finite Automata

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

Non-Deterministic Finite Automata

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

Non-deterministic Finite Automata

Non-deterministic Finite Automata

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

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

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

Nondeterminism and Nodeterministic Automata

Chapter 2 Finite Automata

Java II Finite Automata I

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

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

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

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

Lecture 08: Feb. 08, 2019

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Recursively Enumerable and Recursive. Languages

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

CS 275 Automata and Formal Language Theory

First Midterm Examination

Minimal DFA. minimal DFA for L starting from any other

Lexical Analysis Part III

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

1.4 Nonregular Languages

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

Let's start with an example:

Fundamentals of Computer Science

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

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

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

i 1 i 2 i 3... i p o 1 o 2 AUTOMATON q 1, q 2,,q n ... o q Model of a automaton Characteristics of automaton:

CHAPTER 1 Regular Languages. Contents

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.

Worked out examples Finite Automata

More on automata. Michael George. March 24 April 7, 2014

Lexical Analysis Finite Automate

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

NFAs continued, Closure Properties of Regular Languages

Introduction to ω-autamata

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

ɛ-closure, Kleene s Theorem,

CISC 4090 Theory of Computation

Convert the NFA into DFA

Some Theory of Computation Exercises Week 1

Harvard University Computer Science 121 Midterm October 23, 2012

Formal Languages and Automata

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

1.3 Regular Expressions

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

Automata and Languages

Closure Properties of Regular Languages

State Minimization for DFAs

Lecture 6 Regular Grammars

Finite Automata Part Three

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

CMSC 330: Organization of Programming Languages

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Designing finite automata II

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

1 From NFA to regular expression

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

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

3 Regular expressions

Formal Language and Automata Theory (CS21004)

Agenda. Agenda. Regular Expressions. Examples of Regular Expressions. Regular Expressions (crash course) Computational Linguistics 1

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

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

CS 330 Formal Methods and Models

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

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

Myhill-Nerode Theorem

Thoery of Automata CS402

Turing Machines Part One

CSCI FOUNDATIONS OF COMPUTER SCIENCE

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

Normal Forms for Context-free Grammars

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

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Relating logic to formal languages

Transcription:

CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1

Tble of Contents: Week 1: Preliminries (set lgebr, reltions, functions) (red Chpters 1-4) Weeks 3-6: Regulr Lnguges, Finite Automt (Chpter 11) Weeks 7-9: Context-Free Lnguges, Pushdown Automt (Chpters 12) Weeks 10-12: Turing Mchines (Chpter 13) 2

Tble of Contents (conti): Weeks 13-14: Propositionl Logic (Chpter 6), Predicte Logic (Chpter 7), Computtionl Logic (Chpter 9), Algebric Structures (Chpter 10) 3

lgorithm Cn mchine recognize regulr lnguge? Yes Deterministic Finite Automton (DFA) A finite digrph over n lphbet A (vertices re clled sttes). Ech stte emits one lbeled edge for ech letter of A. One stte is defined s the strt stte nd severl sttes my be finl sttes. indicted by double circles 4

Exmple. Either one is cceptble A={, b} 5

The execution of DFA for input string w A* begins t the strt stte nd follows pth whose edges conctente to w. The DFA ccepts w if the pth ends in finl stte. Otherwise the DFA rejects w. The lnguge of DFA is the set of ccepted strings. Input string: bb n empty string will enter the strt stte but the empty set will not. 6

The execution of DFA for input string w A* begins t the strt stte nd follows pth whose edges conctente to w. The DFA ccepts w if the pth ends in finl stte. Otherwise the DFA rejects w. The lnguge of DFA is the set of ccepted strings. Input string: bb n empty string will enter the strt stte but the empty set will not. 7

6. Regulr Ln guges & Finite Automt Exmple. The exmple DFA ccepts the strings The lnguge of the DFA is n m { b, bb n ϵ N, m ϵ N } 8

Exmple. The exmple DFA ccepts the strings The regulr expression of the lnguge of the DFA is ( + b)b* Why? +b (+b)b (+b)b 2 (+b)b n 9

Theorem (Kleene) The clss of regulr lnguges is exctly the sme s the clss of lnguges ccepted by DFAs. Proof. Need three lemms or by induction. ccepts ccepts { } ccepts { } 10

Theorem (Kleene) The clss of regulr lnguges is exctly the sme s the clss of lnguges ccepted by DFAs. Proof. (conti.) together with the bsis step would prove the theorem. 11

Exmple. Find DFA for ech lnguge over the lphbet {,b}. Solution: n (). (b) {Λ}. (c) { (b) n N}, which hs regulr expression (b)*. This DFA does not ccept nything, even n empty string. Why? 12

Exmple. Find DFA for the lnguge of + *b., b, b 13

Exmple. Find DFA for the lnguge of + *b. Solution: Question: Would this DFA work? is ccepted by this DFA, but 14

A DFA tht recognizes bc* + c A DFA tht recognizes bc* + bc* + c c c b b b strt strt c c c c 15

A DFA tht recognizes bc* + c A DFA tht recognizes bc* + bc* + c c,b c,b strt b c,b c, b, c strt b c b c, b, c, b, c, b, c 16

Would the following DFA recognize *bc* + c? c strt b b c c 17

A DFA tht recognizes bc* + bc* + 2 bc* + c c strt b b b c c c 18

A DFA tht recognizes *bc* + c c bc* + bc* + 2 bc* + n bc* b b b n 3 strt c c c How to mke this FA rel DFA? 19

A DFA tht recognizes *bc* + c c,b strt,b,c b b b c c c rel DFA now,b,c,b,c 20

Tble Representtion of DFA DFA over A cn be represented by trnsition function T : Sttes A Sttes, where T(i, ) is the stte reched from stte i long the edge lbeled, nd we mrk the strt nd finl sttes. Exmple: 21

Note: T cn be extended to T : Sttes A* Sttes by T(i, Λ) = i, T(i, w) = T(T(i, ), w) A, w A* Question: T(0, bb) =? T(0, bb) = T(1, b) = T(1, ) = T(2, Λ) = 2. 22 or

Exmple. Find DFA to recognize ( + b)*bb( + b)*. A solution: {bb},b {( b) bb} ny combintion of * nd (b)*,b 23

Exmple (conti). Find DFA to recognize ( + b)*bb( + b)*. A solution: {( b) bb ( b) } b b ny combintion of * nd (b)*,b 24

Nondeterministic Finite Automt (NFA) An NFA over n lphbet A is similr to DFA except tht Λ-edges re llowed, there is no requirement to emit edges from stte, nd multiple edges with the sme letter cn be emitted from stte. Exmple. The following NFA recognizes the lnguge of + *b + *b.? *b: b, b? *b: b, b? 25

Tble representtion of NFA An NFA over A cn be represented by function T : Sttes A {Λ} power(sttes), where T(i, ) is the set of sttes reched from stte i long the edge lbeled, nd we mrk the strt nd finl sttes. Exmple: 0 26

the proof is similr to Kleene s theorem Theorem (Rbin nd Scott): The clss of regulr lnguges is exctly the sme s the clss of lnguges ccepted by NFAs. Questions. Find n NFA for ech of the lnguges over {, b}. {, b, ( b) } 27 =?,b

Exmple. Find n NFA to recognize ( + b)*bb( + b)*. A solution: {bb} {( b) bb} ny combintion of * nd (b)* {( b) bb( b) } ny combintion of * nd (b)* 28

Exmple (conti). Find n NFA to recognize ( + b)*bb( + b)*. A solution: But not {( b) bb ( b) * } 29

(DFA or NFA) Algorithm: Trnsform Regulr Expression (RE) into Finite Automton (1) Plcing the RE on the edge between strt nd finl stte: (2) Apply the following rules to obtin finite utomton fter ersing ny -edges. 30

Exmple. Use the lgorithm to construct finite utomton for (b)* + b. Solution: 31

Algorithm: Trnsform Finite Automton into Regulr Expression Connect new strt stte s to the strt stte of the FA nd connect ech finl stte of the FA to new finl stte ƒ s shown in the figure. s Ʌ Given FA Ʌ f Connect to strt stte of FA Connect from ech finl stte of FA 32

If needed, combine ll multiple edges between the sme two nodes into one edge with lbel the sum of the lbels on the multiple edges. If there is no edge between two sttes, ssume there is n -edge. 33 Φ

Now eliminte ech stte k of the FA by constructing new edge (i, j) for ech pir of edges (i, k) nd (k, j) where i k nd j k. New lbel new(i, j) is defined s follows: new(i, j) = old(i, j) + old(i, k) old(k, k)* old(k, j) Exmple: A A+ BC*D 34

Think of the process of eliminting stte k s two-step procedure: i A B k D j i i A BC*D A + BC*D 35 j j Put Φ here if there ws not direct edge between i nd j originlly

Exmple. Trnsform the following NFA into regulr expression. Solution I (eliminte stte 1 first): 0 Stte 1 is lso considered stte between stte 0 nd stte 0 36 0 b 1 Stte 1 is considered stte between stte 0 nd stte f

Exmple. Trnsform the following NFA into regulr expression. Solution I (eliminte stte 1 first): new(0, f ) new(0,0) b b 0 37 0 b 1

Exmple. Trnsform the following NFA into regulr expression. Solution I (eliminte stte 1 first): new( s, ( b) ( b) 38 f )

Exmple. Trnsform the following NFA into regulr expression. Solution II (eliminte stte 0 first): 0 b 1 Stte 0 is considered stte between stte s nd stte 1 Stte 0 is lso considered stte between stte 1 nd stte 1 39 1

Exmple. Trnsform the following NFA into regulr expression. Solution II (eliminte stte 0 first): new( s,1) new(1, 1) b b 40

Exmple. Trnsform the following NFA into regulr expression. Solution II (eliminte stte 0 first): new( s, ( b ) ( b ) 41 f )

Note. The two regulr expressions obtined in the previous exmple re equl, i.e., *( b* )* = ( + b)*. Proof I. ( + b )* ( R + S )* = R* (S R* )* = [ * ( (b) * )* ] is ssocitive = * [ ( ( b ) * )* ] is ssocitive = * [ ( ( b * ) )* ] (R S )* R = R (S R )* = * [ (( b* ) )* ] is ssocitive 42 = * (b* )*

Note. The two regulr expressions obtined in the previous exmple re equl, i.e., *(b*)* = ( + b)*. Proof II. * ( b* )* = *[(( b* ) )*] is ssocitive = *[( (b*) )* ] R(SR)* = (RS)*R = *[ ( (b)* )* ] is ssocitive = [* ((b) *)* ] is ssocitive = ( + b)* R*(SR*)* = (R + S)* QED. 43

6. Regulr Lnguges & Finite ny combintions Automt of Note. The two regulr expressions obtined in the previous exmple re equl, i.e., *(b*)* = ( + b)*. Intuitive Proof. LHS = * ( b* )* = *(b*)(b*)(b*) (b*) RHS = ( + b)* = *(b)**(b)* *(b)* LHS RHS Why? *(b*)(b*)(b*) ϵ LHS = *(b)*(b)*(b)* = *(b)*(b)*(b)*(b) 0 ϵ RHS Hence, LHS RHS * nd (b)* 44

Note. The two regulr expressions obtined in the previous exmple re equl, i.e., *(b*)* = ( + b)*. Intuitive Proof (conti). LHS = * ( b* )* = *(b*)(b*)(b*) (b*) RHS = ( + b)* = *(b)**(b)* *(b)* RHS LHS Why? *(b) 2 *(b) 2 *(b) 2 ϵ RHS = *(b)(b)*(b)(b)*(b)(b) = *(b)(b*)(b)(b*)(b)(b) = *(b 0 )(b*)(b 0 )(b*)(b 0 )(b 0 ) ϵ LHS Hence, RHS LHS 45

End of Regulr Lnguge nd Finite Automt II 48