CS375: Logic and Theory of Computing

Similar documents
CS375: Logic and Theory of Computing

CHAPTER 1 Regular Languages. Contents

Finite Automata-cont d

First Midterm Examination

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

Worked out examples Finite Automata

First Midterm Examination

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

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

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

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

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.

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

Harvard University Computer Science 121 Midterm October 23, 2012

Finite-State Automata: Recap

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

Lecture 08: Feb. 08, 2019

Lexical Analysis Finite Automate

Languages & Automata

Lecture 6 Regular Grammars

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. Transition Graphs. Department of Computer Science

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

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

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

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

Fundamentals of Computer Science

Let's start with an example:

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

1 Nondeterministic Finite Automata

Theory of Computation Regular Languages

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

Non-deterministic Finite Automata

Formal languages, automata, and theory of computation

Today s Topics Automata and Languages

Automata and Languages

Deterministic Finite Automata

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

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

CS 330 Formal Methods and Models

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

Homework 3 Solutions

Context-Free Grammars and Languages

Some Theory of Computation Exercises Week 1

Non-deterministic Finite Automata

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

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

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

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

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

CMSC 330: Organization of Programming Languages

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

Automata and Languages

Java II Finite Automata I

Minimal DFA. minimal DFA for L starting from any other

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

SWEN 224 Formal Foundations of Programming WITH ANSWERS

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

CS 330 Formal Methods and Models

CSC 311 Theory of Computation

Convert the NFA into DFA

1.4 Nonregular Languages

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

Thoery of Automata CS402

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

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

Tutorial Automata and formal Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

CS 275 Automata and Formal Language Theory

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

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

CISC 4090 Theory of Computation

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

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

Nondeterminism and Nodeterministic Automata

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

Formal Language and Automata Theory (CS21004)

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

Closure Properties of Regular Languages

1 From NFA to regular expression

Formal Languages and Automata

Chapter 2 Finite Automata

input tape head moves current state

Name Ima Sample ASU ID

Coalgebra, Lecture 15: Equations for Deterministic Automata

Designing finite automata II

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

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

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

Deterministic Finite-State Automata

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

Regular languages refresher

Recursively Enumerable and Recursive. Languages

Myhill-Nerode Theorem

ɛ-closure, Kleene s Theorem,

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15

Lexical Analysis Part III

Transcription:

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

Tle of Contents: Week 1: Preliminries (set lger, 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

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

Regulr lnguges cn e chrcterized y regulr expressions, y DFAs, y NFAs, s well s y regulr grmmrs. RECALL: wht is grmmr? set of rules used to define the structure of the strings in lnguge, usully represented s 4-tuple G = (N, T, S, P) N : lphet of nonterminls (uppercse letters) T : lphet of terninls (lowercse letters) S : strt symol (nonterminl) P : set of productions 4

Exmple. N = {S}, T = {,, c}, S: strt symol, P : S S S S S S cs then the grmmr cn e represented y the 4-tuple G = ( {S}, {,, c}, S, P ) 5

Bck to regulr grmmrs - A regulr grmmr is grmmr whose productions tke the following form: where w is string of terminls. A wb or A w So we cn hve productions like: A Ʌ A w (w: not empty) A B (A nd B cn e the sme) A wb (w: not empty) 6

Exmple. Construct regulr grmmr for the lnguge of { Ʌ,,,,,,,, n, n, } Would S Ʌ S S work? 7

Exmple. Write regulr grmmr for {, c, cc, ccc, cccc, }. Solution: A regulr expression for the lnguge is c*. A regulr grmmr is S T T ct. True? : S T c 2 : S T ct cct cc c 2 Would S S cs lso work? 8

Trnsforming n NFA to Regulr Grmmr 1. Stte nmes ecome the nonterminls. 2. Edge symols of the NFA ecome the ternimls 3. The strt stte ecomes the strt symol of the grmmr. 4. For ech stte trnsition from I to J leled with x construct production I xj. 5. For ech finl stte F construct production F Λ. 9 if x then simply I J

Exmple. Trnsform the following NFA into regulr grmmr. Non-terminls: S, F, I Strt symol: S Terminls:, Productions : S I F I I F F Ʌ 10

11

Solution (conti): 0 1 2 4 3 5 Hence, (0) {0,1, 2, 3, 5} (1) {1, 2, 3, 5} (2) {2, 3, 5} (3) {3, 5} (4) {4} (5) {5} 12

Solution: Drw n NFA nd then use the lgorithm. 0 1 2 5 3 4 Then, 1. uild the tree on the right 2. identify ll distinct nodes 13

Solution: Drw n NFA nd then use the lgorithm. Then, 1. uild the trnsition tle 2. nd write it in simplified form (0) {0,1,2,3,5} {1,2,3,5} {4} {1,2,3,5} {4} {3,5} {4} 14

Solution: Drw n NFA nd then use the lgorithm. Then, 1. uild the trnsition tle 2. nd write it in simplified form T S F {0,1,2,3,5} {1,2,3,5} {4} F {1,2,3,5} {1,2,3,5} {4} T S F 0 1 2 F 1 1 2 {4} {3,5} F {3,5} {4} 2 3 4 F 3 4 2 4 4 4 15

Solution: Drw n NFA nd then use the lgorithm. Then, drw n DFA 0 1 T 3 2 4, S F 0 1 2 F 1 1 2 2 3 4 F 3 4 2 4 4 4 16 Don t need

Solution: Drw n NFA nd then use the lgorithm. Then, drw n DFA 1 I 0 S 2 J 3 F 4, 17 Don t need

Solution: Drw n NFA nd then use the lgorithm. Then, construct regulr grmmr Resulting grmmr : S I J S I I J J F F J F S I F simplify I I F F F cn this e further simplified? 18 I J F S S F F

Trnsforming Regulr Grmmr to n NFA 1. Replce ny production with multiple terminls y productions with single terminls. 2. The strt stte is the grmmr strt symol. 3. Trnsform I J into trnsition from I to J leled with. 4. Trnsform I J into trnsition from I to J leled with Λ. 5. Trnsform ech I into trnsition from I to new single finl stte F leled with. 6. The finl sttes re F together with ech stte I with production I Λ. S J S I I J 19

5. Trnsform ech I into trnsition from I to new single finl stte F leled with. I mens the production stops once is produced, so must e the lel of n edge to finl stte. 6. ech stte I with production I Λ is finl stte. I Ʌ mens the production stops t I, so I must e finl stte. 20

Exmple. Trnsform the following regulr grmmr into n NFA. S S T Λ T ct d Solution. Trnsform S S S I nd I S, so the grmmr ecomes S I T Λ I S T ct d They cn e written s : into 21

S I S T S Ʌ I S T ct T d strt S Ʌ T I c d F Now the NFA cn e drwn: 22

Exmple. Wht is the regulr expression for the lnguge of the grmmr? Answer: ( ) ( ) c d ( ) ( ) c d ( ) ( c d) 23

Properties of Regulr Lnguges By using certin properties of regulr lnguges we cn prove, BWOC, tht certin lnguges re not regulr. Why? A string of length m is uilt y m edges nd so y m+1 sttes. 24

The following grph depicts the sitution. x, z could e empty Dotted rrows represent the pth of cceptnce for s Letters x, y, nd z represent the conctention of the letters long the edges of the pth. So s = xyz nd y Λ. 25

n n Exmple. The lnguge L = { n N} is not regulr. Proof: Assume, BWOC, tht L is regulr. Since L is infinite, the Pumping Lemm pplies. Choose s = m m. Then s = xyz, where y Ʌ, xy 2m, nd xy k z L for ll k ϵ N. We clim tht y consists completely of s or s only. For if y is of the form y = i j, i > 0, j > 0, then we hve x = m i nd z = m j. So, xy 2 z = m i ( i j )( i j ) m j = m j i m L. But this is contrdction. So we hve either 26 y = i, i > 0, or y = j, j > 0.

n n Exmple. The lnguge L = { n N} is not regulr. Proof (conti.): If y = i for some i > 0 then xy is string of s. Since s = xyz = m m nd xy 2 is lso string of s, we hve xy 2 z = m+i m. By Pumping Lemm, this is supposed to e n element of L, ut this is impossile ecuse nd hve different exponents. Similrly we cn lso prove tht if y = j for some j > 0, we would lso get into contrdiction. Hence, L cn not e regulr. QED 27

Exmple. In the previous proof we exhiited contrdiction when k = 2. Find similr contrdictions for k = 0 nd k = 3. 28

End of Regulr Lnguge nd Finite Automt IV 29