Thoery of Automata CS402

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

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

Lecture 08: Feb. 08, 2019

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

Formal Languages and Automata

Finite Automata-cont d

Deterministic Finite Automata

Closure Properties of Regular Languages

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Designing finite automata II

Let's start with an example:

Minimal DFA. minimal DFA for L starting from any other

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

First Midterm Examination

CHAPTER 1 Regular Languages. Contents

1 Nondeterministic Finite Automata

Convert the NFA into DFA

Worked out examples Finite Automata

Context-Free Grammars and Languages

Homework 3 Solutions

First Midterm Examination

Lexical Analysis Finite Automate

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

Harvard University Computer Science 121 Midterm October 23, 2012

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

CMSC 330: Organization of Programming Languages

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

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

Formal languages, automata, and theory of computation

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

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.

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

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

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

CISC 4090 Theory of Computation

FABER Formal Languages, Automata and Models of Computation

Theory of Computation Regular Languages

Some Theory of Computation Exercises Week 1

NFAs continued, Closure Properties of Regular Languages

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

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

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

1 From NFA to regular expression

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

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

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.

Parse trees, ambiguity, and Chomsky normal form

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

Chapter 2 Finite Automata

1.4 Nonregular Languages

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

Name Ima Sample ASU ID

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

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

CS375: Logic and Theory of Computing

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

Lecture 09: Myhill-Nerode Theorem

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

Coalgebra, Lecture 15: Equations for Deterministic Automata

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

3 Regular expressions

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

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

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

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.

CS 275 Automata and Formal Language Theory

Tutorial Automata and formal Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CS 330 Formal Methods and Models

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

Fundamentals of Computer Science

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

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

Languages & Automata

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

NFAs continued, Closure Properties of Regular Languages

Nondeterminism and Nodeterministic Automata

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

Non-deterministic Finite Automata

CS375: Logic and Theory of Computing

ɛ-closure, Kleene s Theorem,

Finite-State Automata: Recap

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

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

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

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

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

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

1.3 Regular Expressions

Formal Languages and Automata Theory. D. Goswami and K. V. Krishna

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

Formal Language and Automata Theory (CS21004)

CS 275 Automata and Formal Language Theory

Chapter 7. Kleene s Theorem. 7.1 Kleene s Theorem. The following theorem is the most important and fundamental result in the theory of FA s:

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

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

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

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

Transcription:

Thoery of Automt C402

Theory of Automt Tle of contents: Lecture N0. 1... 4 ummry... 4 Wht does utomt men?... 4 Introduction to lnguges... 4 Alphets... 4 trings... 4 Defining Lnguges... 5 Lecture N0. 2... 9 ummry... 9 Kleene tr Closure... 9 Recursive definition of lnguges... 9 Lecture N0. 3... 11 ummry... 11 Regulr Expression... 11 Recursive definition of Regulr Expression(RE)... 11 Method 3 (Regulr Expressions)... 11 Lecture N0. 4... 12 Equivlent Regulr Expressions... 12 Method 4 (Finite Automton)... 13 Lecture N0. 5... 15 Lecture N0. 6... 17 Equivlent FAs... 17 Lecture N0. 7... 20 FA corresponding to finite lnguges... 20 Method 5 (Trnsition Grph)... 22 Lecture N0. 8... 23 Exmples of TGs: ccepting ll strings, ccepting none, strting with, not ending in, contining, contining or... 23 Lecture N0. 9... 25 Generlized Trnsition Grphs... 27 Lecture N0. 10... 28 Nondeterminism... 29 Kleene s Theorem... 29 Lecture N0. 11... 30 Proof(Kleene s Theorem Prt II)... 30 Lecture N0. 12... 34 Kleene s Theorem Prt III... 35 Lecture N0. 13... 38 Lecture N0. 14... 41 Lecture N0. 15... 44 Nondeterministic Finite Automton (NFA)... 44 Converting n FA to n equivlent NFA... 45 Lecture N0. 16... 47 NFA with Null tring... 47 Lecture N0. 17... 50 NFA nd Kleene s Theorem... 50 Lecture N0. 18... 53 NFA corresponding to Conctention of FAs... 53 NFA corresponding to the Closure of n FA... 55 Lecture N0. 19... 57 Memory required to recognize lnguge... 57 Distinguishle strings nd Indistinguishle strings... 58 Lecture N0. 20... 60 Finite Automton with output... 60 Moore mchine... 60 Lecture N0. 21... 62 Mely mchine... 62 Lecture N0. 22... 65 2 Copyright Virtul University of Pkistn

Theory of Automt Equivlent mchines... 65 Lecture N0. 23... 68 Lecture N0. 24... 70 Regulr lnguges... 70 Complement of lnguge... 71 Lecture N0. 25... 73 Nonregulr lnguges... 76 Lecture N0. 26... 77 Pumping Lemm... 77 Lecture N0. 27... 80 Pumping Lemm version II... 80 Lecture N0. 28... 82 Pseudo theorem... 83 Lecture N0. 29... 84 Decidility... 84 Determining whether the two lnguges re equivlent or not?... 85 Lecture N0. 30... 88 Lecture N0. 31... 92 Context Free Grmmr (CFG)... 92 CFG terminologies... 92 Lecture N0. 32... 95 Trees... 96 Lecture N0. 33... 98 Polish Nottion (o-o-o)... 99 Lecture N0. 34... 101 Totl lnguge tree... 101 Regulr Grmmr... 102 Lecture N0. 35... 104 Null Production... 104 Lecture N0. 36... 107 Chomsky Norml Form (CNF)... 107 Lecture N0. 37... 110 A new formt for FAs... 110 Lecture N0. 38... 114 Nondeterministic PDA... 116 Lecture N0. 39... 119 PDA corresponding to CFG... 119 Lecture N0. 40... 123 Conversion form of PDA... 124 Lecture N0. 41... 126 Lecture N0. 42... 129 Lecture N0. 43... 132 Non-Context-Free lnguge... 132 Pumping lemm for CFLs... 133 Lecture N0. 44... 139 Decidlity... 139 Prsing Techniques... 142 Lecture N0. 45... 147 Turing mchine... 147 Copyright Virtul University of Pkistn 3

Theory of Automt Theory of Automt Lecture N0. 1 Reding Mteril Introduction to Computer Theory Chpter 2 ummry Introduction to the course title, Forml nd In-forml lnguges, Alphets, trings, Null string, Words, Vlid nd In-vlid lphets, length of string, Reverse of string, Defining lnguges, Descriptive definition of lnguges, EQUAL, EVEN-EVEN, INTEGER, EVEN, { n n }, { n n n }, fctoril, FACTORIAL, DOUBLEFACTORIAL, QUARE, DOUBLEQUARE, PRIME, PALINDROME. Wht does utomt men? It is the plurl of utomton, nd it mens something tht works utomticlly Introduction to lnguges There re two types of lnguges Forml Lnguges (yntctic lnguges) Informl Lnguges (emntic lnguges) Alphets Definition A finite non-empty set of symols (clled letters), is clled n lphet. It is denoted y Σ ( Greek letter sigm). Exmple Σ = {,} Σ = {0,1} (importnt s this is the lnguge which the computer understnds.) Σ = {i,j,k} Note Certin version of lnguge ALGOL hs 113 letters. Σ (lphet) includes letters, digits nd vriety of opertors including sequentil opertors such s GOTO nd IF trings Definition Conctention of finite numer of letters from the lphet is clled string. Exmple If Σ = {,} then,,, Note Empty string or null string ometimes string with no symol t ll is used, denoted y (mll Greek letter Lmd) λ or (Cpitl Greek letter Lmd) Λ, is clled n empty string or null string. The cpitl lmd will mostly e used to denote the empty string, in further discussion. Words Definition Words re strings elonging to some lnguge. Exmple If Σ= {x} then lnguge L cn e defined s L={x n : n=1,2,3,..} or L={x,xx,xxx,.} Here x,xx, re the words of L Note All words re strings, ut not ll strings re words. Copyright Virtul University of Pkistn 4

Theory of Automt Vlid/In-vlid lphets While defining n lphet, n lphet my contin letters consisting of group of symols for exmple Σ 1 = {B, B,, d}. Now consider n lphet Σ 2 = {B, B,, d} nd string BB. This string cn e tokenized in two different wys (B), (), (B) (B), (), (B) Which shows tht the second group cnnot e identified s string, defined over Σ = {, }. As when this string is scnned y the compiler (Lexicl Anlyzer), first symol B is identified s letter elonging to Σ, while for the second letter the lexicl nlyzer would not e le to identify, so while defining n lphet it should e kept in mind tht miguity should not e creted. Remrks While defining n lphet of letters consisting of more thn one symols, no letter should e strted with the letter of the sme lphet i.e. one letter should not e the prefix of nother. However, letter my e ended in letter of sme lphet. Conclusion Σ 1 = {B, B,, d} Σ 2 = {B, B,, d} Σ 1 is vlid lphet while Σ 2 is n in-vlid lphet. Length of trings Definition The length of string s, denoted y s, is the numer of letters in the string. Exmple Σ={,} s= s =5 Exmple Σ= {B, B,, d} s=bbbd Tokenizing=(B), (B), (), (B), (d) s =5 Reverse of tring Definition The reverse of string s denoted y Rev(s) or s r, is otined y writing the letters of s in reverse order. Exmple If s=c is string defined over Σ={,,c} then Rev(s) or s r = c Exmple Σ= {B, B,, d} s=bbbd Rev(s)=dBBB Defining Lnguges The lnguges cn e defined in different wys, such s Descriptive definition, Recursive definition, using Regulr Expressions(RE) nd using Finite Automton(FA) etc. Descriptive definition of lnguge The lnguge is defined, descriing the conditions imposed on its words. Copyright Virtul University of Pkistn 5

Theory of Automt Exmple The lnguge L of strings of odd length, defined over Σ={}, cn e written s L={,,,..} Exmple The lnguge L of strings tht does not strt with, defined over Σ ={,,c}, cn e written s L ={L,, c,,, c, c, c, cc, } Exmple The lnguge L of strings of length 2, defined over Σ ={0,1,2}, cn e written s L={00, 01, 02,10, 11,12,20,21,22} Exmple The lnguge L of strings ending in 0, defined over Σ ={0,1}, cn e written s L={0,00,10,000,010,100,110, } Exmple The lnguge EQUAL, of strings with numer of s equl to numer of s, defined over Σ={,}, cn e written s {Λ,,,,,, } Exmple The lnguge EVEN-EVEN, of strings with even numer of s nd even numer of s, defined over Σ={,}, cn e written s {Λ,,,,,,,,,,, } Exmple The lnguge INTEGER, of strings defined over Σ={-,0,1,2,3,4,5,6,7,8,9}, cn e written s INTEGER = {,-2,-1,0,1,2, } Exmple The lnguge EVEN, of stings defined over Σ={-,0,1,2,3,4,5,6,7,8,9}, cn e written s EVEN = {,-4,-2,0,2,4, } Exmple The lnguge { n n }, of strings defined over Σ={,}, s { n n : n=1,2,3, }, cn e written s {,,,, } Exmple The lnguge { n n n }, of strings defined over Σ={,}, s { n n n : n=1,2,3, }, cn e written s {,,,, } Exmple The lnguge fctoril, of strings defined over Σ={0,1,2,3,4,5,6,7,8,9} i.e. {1,2,6,24,120, } Exmple The lnguge FACTORIAL, of strings defined over Σ={}, s { n! : n=1,2,3, }, cn e written s {,,, }. It is to e noted tht the lnguge FACTORIAL cn e defined over ny single letter lphet. Exmple The lnguge DOUBLEFACTORIAL, of strings defined over Σ={, }, s { n! n! : n=1,2,3, }, cn e written s {,,, } Exmple The lnguge QUARE, of strings defined over Σ={}, s Copyright Virtul University of Pkistn 6

Theory of Automt { n 2 : n=1,2,3, }, cn e written s {,,, } Exmple The lnguge DOUBLEQUARE, of strings defined over Σ={,}, s { n 2 n 2 : n=1,2,3, }, cn e written s {,,, } Exmple The lnguge PRIME, of strings defined over Σ={}, s { p : p is prime}, cn e written s {,,,, } An Importnt lnguge PALINDROME The lnguge consisting of Λ nd the strings s defined over Σ such tht Rev(s)=s. It is to e denoted tht the words of PALINDROME re clled plindromes. Exmple For Σ={,}, PALINDROME={Λ,,,,,,,,,...} Remrk There re s mny plindromes of length 2n s there re of length 2n-1. To prove the ove remrk, the following is to e noted: Note Numer of strings of length m defined over lphet of n letters is n m. Exmples The lnguge of strings of length 2, defined over Σ={,} is L={,,, } i.e. numer of strings = 2 2 The lnguge of strings of length 3, defined over Σ={,} is L={,,,,,,, } i.e. numer of strings = 2 3 To clculte the numer of plindromes of length(2n), consider the following digrm, which shows tht there re s mny plindromes of length 2n s there re the strings of length n i.e. the required numer of plindromes re 2 n. To clculte the numer of plindromes of length (2n-1) with s the middle letter, consider the following digrm, which shows tht there re s mny plindromes of length 2n-1 s there re the strings of length n-1 i.e. the required numer of plindromes re 2 n-1. Copyright Virtul University of Pkistn 7

Theory of Automt imilrly the numer of plindromes of length 2n-1, with s middle letter, will e 2 n-1 s well. Hence the totl numer of plindromes of length 2n-1 will e 2 n-1 + 2 n-1 = 2 (2 n-1 )= 2 n. Copyright Virtul University of Pkistn 8

Theory of Automt Theory of Automt Lecture N0. 2 Reding Mteril Introduction to Computer Theory Chpter 3 ummry Kleene tr Closure, Plus opertion, recursive definition of lnguges, INTEGER, EVEN, fctoril, PALINDROME, { n n }, lnguges of strings (i) ending in, (ii) eginning nd ending in sme letters, (iii) contining or (iv) contining exctly one Kleene tr Closure Given Σ, then the Kleene tr Closure of the lphet Σ, denoted y Σ *, is the collection of ll strings defined over Σ, including Λ. It is to e noted tht Kleene tr Closure cn e defined over ny set of strings. Exmples If Σ = {x} Then Σ * = {Λ, x, xx, xxx, xxxx,.} If Σ = {0,1} Then Σ * = {Λ, 0, 1, 00, 01, 10, 11,.} If Σ = {B, c} Then Σ * = {Λ, B, c, BB, Bc, cb, cc,.} Note Lnguges generted y Kleene tr Closure of set of strings, re infinite lnguges. (By infinite lnguge, it is supposed tht the lnguge contins infinite mny words, ech of finite length). PLU Opertion ( + ) Plus Opertion is sme s Kleene tr Closure except tht it does not generte Λ (null string), utomticlly. Exmple If Σ = {0,1} Then Σ + = {0, 1, 00, 01, 10, 11,.} If Σ = {, c} Then Σ + = {, c,, c, c, cc,.} Remrk It is to e noted tht Kleene tr cn lso e operted on ny string i.e. * cn e considered to e ll possile strings defined over {}, which shows tht * genertes Λ,,,, It my lso e noted tht + cn e considered to e ll possile non empty strings defined over {}, which shows tht + genertes,,,, Recursive definition of lnguges The following three steps re used in recursive definition ome sic words re specified in the lnguge. Rules for constructing more words re defined in the lnguge. No strings except those constructed in ove, re llowed to e in the lnguge. Exmple Defining lnguge of INTEGER tep 1: 1 is in INTEGER. tep 2: If x is in INTEGER then x+1 nd x-1 re lso in INTEGER. tep 3: No strings except those constructed in ove, re llowed to e in INTEGER. Exmple Copyright Virtul University of Pkistn 9

Theory of Automt Defining lnguge of EVEN tep 1: 2 is in EVEN. tep 2: If x is in EVEN then x+2 nd x-2 re lso in EVEN. tep 3: No strings except those constructed in ove, re llowed to e in EVEN. Exmple Defining the lnguge fctoril tep 1: As 0!=1, so 1 is in fctoril. tep 2: n!=n*(n-1)! is in fctoril. tep 3: No strings except those constructed in ove, re llowed to e in fctoril. Defining the lnguge PALINDROME, defined over Σ = {,} tep 1: nd re in PALINDROME tep 2: if x is plindrome, then s(x)rev(s) nd xx will lso e plindrome, where s elongs to Σ * tep 3: No strings except those constructed in ove, re llowed to e in plindrome Defining the lnguge { n n }, n=1,2,3,, of strings defined over Σ={,} tep 1: is in { n n } tep 2: if x is in { n n }, then x is in { n n } tep 3: No strings except those constructed in ove, re llowed to e in { n n } Defining the lnguge L, of strings ending in, defined over Σ={,} tep 1: is in L tep 2: if x is in L then s(x) is lso in L, where s elongs to Σ * tep 3: No strings except those constructed in ove, re llowed to e in L Defining the lnguge L, of strings eginning nd ending in sme letters, defined over Σ={, } tep 1: nd re in L tep 2: ()s() nd ()s() re lso in L, where s elongs to Σ * tep 3: No strings except those constructed in ove, re llowed to e in L Defining the lnguge L, of strings contining or, defined over Σ={, } tep 1: nd re in L tep 2: s()s nd s()s re lso in L, where s elongs to Σ * tep 3: No strings except those constructed in ove, re llowed to e in L Defining the lnguge L, of strings contining exctly one, defined over Σ={, } tep 1: is in L tep 2: s()s is lso in L, where s elongs to * tep 3: No strings except those constructed in ove, re llowed to e in L Copyright Virtul University of Pkistn 10

Theory of Automt Theory of Automt Lecture N0. 3 Reding Mteril Introduction to Computer Theory Chpter 4 ummry RE, Recursive definition of RE, defining lnguges y RE, { x}*, { x}+, {+}*, Lnguge of strings hving exctly one, Lnguge of strings of even length, Lnguge of strings of odd length, RE defines unique lnguge (s Remrk), Lnguge of strings hving t lest one, Lnguge of strings hving t lest one nd one, Lnguge of strings strting with nd ending in, Lnguge of strings strting with nd ending in different letters. Regulr Expression As discussed erlier tht * genertes Λ,,,, nd + genertes,,,,, so the lnguge L 1 = {Λ,,,, } nd L 2 = {,,,, } cn simply e expressed y * nd +, respectively. * nd + re clled the regulr expressions (RE) for L 1 nd L 2 respectively. Note +, * nd * generte L 2. Recursive definition of Regulr Expression(RE) tep 1: Every letter of Σ including Λ is regulr expression. tep 2: If r 1 nd r 2 re regulr expressions then (r 1 ) r 1 r 2 r 1 + r 2 nd r 1 * re lso regulr expressions. tep 3: Nothing else is regulr expression. Method 3 (Regulr Expressions) Consider the lnguge L={Λ, x, xx, xxx, } of strings, defined over Σ = {x}. We cn write this lnguge s the Kleene str closure of lphet Σ or L=Σ * ={x} *. This lnguge cn lso e expressed y the regulr expression x *. imilrly the lnguge L={x, xx, xxx, }, defined over Σ = {x}, cn e expressed y the regulr expression x +. Now consider nother lnguge L, consisting of ll possile strings, defined over Σ = {, }. This lnguge cn lso e expressed y the regulr expression ( + )*. Now consider nother lnguge L, of strings hving exctly one, defined over Σ = {, }, then it s regulr expression my e **. Now consider nother lnguge L, of even length, defined over Σ = {, }, then it s regulr expression my e ((+)(+))*. Now consider nother lnguge L, of odd length, defined over Σ = {, }, then it s regulr expression my e (+)((+)(+))* or ((+)(+))*(+). Remrk It my e noted tht lnguge my e expressed y more thn one regulr expression, while given regulr expression there exist unique lnguge generted y tht regulr expression. Exmple Consider the lnguge, defined over Σ = {, } of words hving t lest one, my e expressed y regulr expression (+)*(+)*. Consider the lnguge, defined over Σ = {, } of words hving t lest one nd one, my e expressed y regulr expression (+)*(+)*(+)*+ (+)*(+)*(+)*. Consider the lnguge, defined over Σ ={, }, of words strting with doule nd ending in doule then its regulr expression my e (+)* Consider the lnguge, defined over Σ ={, } of words strting with nd ending in OR strting with nd ending in, then its regulr expression my e (+)*+(+)* Copyright Virtul University of Pkistn 11

Theory of Automt Theory of Automt Lecture N0. 4 Reding Mteril Introduction to Computer Theory Chpter 4, 5 ummry Regulr expression of EVEN-EVEN lnguge, Difference etween * + * nd (+)*, Equivlent regulr expressions; sum, product nd closure of regulr expressions; regulr lnguges, finite lnguges re regulr, introduction to finite utomton, definition of FA, trnsition tle, trnsition digrm An importnt exmple The Lnguge EVEN-EVEN Lnguge of strings, defined over Σ={, } hving even numer of s nd even numer of s. i.e. EVEN-EVEN = {Λ,,,,,,,,,,, }, its regulr expression cn e written s (++(+)(+)*(+))* Note It is importnt to e cler out the difference of the following regulr expressions r 1 = *+* r 2 = (+)* Here r 1 does not generte ny string of conctention of nd, while r 2 genertes such strings. Equivlent Regulr Expressions Definition Two regulr expressions re sid to e equivlent if they generte the sme lnguge. Exmple Consider the following regulr expressions r 1 = ( + )* ( + ) r 2 = ( + )* + ( + )* then oth regulr expressions define the lnguge of strings ending in or. Note If r 1 = ( + ) nd r 2 = ( + ) then r 1 +r 2 = ( + ) + ( + ) r 1 r 2 = ( + ) ( + ) = ( + + + ) (r 1 )* = ( + )* Regulr Lnguges Definition The lnguge generted y ny regulr expression is clled regulr lnguge. It is to e noted tht if r 1, r 2 re regulr expressions, corresponding to the lnguges L 1 nd L 2 then the lnguges generted y r 1 + r 2, r 1 r 2 ( or r 2 r 1 ) nd r 1 *( or r 2 *) re lso regulr lnguges. Note It is to e noted tht if L 1 nd L 2 re expressed y r 1 nd r 2, respectively then the lnguge expressed y r 1 + r 2, is the lnguge L 1 + L 2 or L 1 «L 2 r 1 r 2,, is the lnguge L 1 L 2, of strings otined y prefixing every string of L 1 with every string of L 2 r 1 *, is the lnguge L 1 *, of strings otined y conctenting the strings of L, including the null string. Exmple If r 1 = (+) nd r 2 = (+) then the lnguge of strings generted y r 1 +r 2, is lso regulr lnguge, expressed y (+) + (+) If r 1 = (+) nd r 2 = (+) then the lnguge of strings generted y r 1 r 2, is lso regulr lnguge, expressed y (+)(+) If r = (+) then the lnguge of strings generted y r*, is lso regulr lnguge, expressed y (+)* Copyright Virtul University of Pkistn 12

Theory of Automt All finite lnguges re regulr Exmple Consider the lnguge L, defined over Σ = {,}, of strings of length 2, strting with, then L = {, }, my e expressed y the regulr expression +. Hence L, y definition, is regulr lnguge. Note It my e noted tht if lnguge contins even thousnd words, its RE my e expressed, plcing + etween ll the words. Here the specil structure of RE is not importnt. Consider the lnguge L = {,,,,,,, }, tht my e expressed y RE +++++++, which is equivlent to (+)(+)(+). Introduction to Finite Automton Consider the following gme ord tht contins 64 oxes There re some pieces of pper. ome re of white colour while others re of lck colour. The numer of pieces of pper re 64 or less. The possile rrngements under which these pieces of pper cn e plced in the oxes, re finite. To strt the gme, one of the rrngements is supposed to e initil rrngement. There is pir of dice tht cn generte the numers 2,3,4, 12. For ech numer generted, unique rrngement is ssocited mong the possile rrngements. It shows tht the totl numer of trnsition rules of rrngement re finite. One nd more rrngements cn e supposed to e the winning rrngement. It cn e oserved tht the winning of the gme depends on the sequence in which the numers re generted. This structure of gme cn e considered to e finite utomton. Method 4 (Finite Automton) Definition A Finite utomton (FA), is collection of the followings Finite numer of sttes, hving one initil nd some (mye none) finl sttes. Finite set of input letters (Σ) from which input strings re formed. Finite set of trnsitions i.e. for ech stte nd for ech input letter there is trnsition showing how to move from one stte to nother. Exmple Σ = {,} ttes: x, y, z where x is n initil stte nd z is finl stte. Trnsitions: At stte x reding, go to stte z At stte x reding, go to stte y At stte y reding, go to stte y At stte z reding, go to stte z These trnsitions cn e expressed y the following tle clled trnsition tle Copyright Virtul University of Pkistn 13

Theory of Automt Old ttes x - y z + Reding z y z New ttes Reding y y z Note It my e noted tht the informtion of n FA, given in the previous tle, cn lso e depicted y the following digrm, clled the trnsition digrm, of the given FA, x Z+ Remrk The ove trnsition digrm is n FA ccepting the lnguge of strings, defined over Σ = {, }, strting with. It my e noted tht this lnguge my e expressed y the regulr expression ( + )* y, Copyright Virtul University of Pkistn 14

Theory of Automt Theory of Automt Lecture N0. 5 Reding Mteril Introduction to Computer Theory Chpter 5 ummry Different nottions of trnsition digrms, lnguges of strings of even length, Odd length, strting with, ending in, eginning with, not eginning with, eginning nd ending in sme letters Note It my e noted tht to indicte the initil stte, n rrow hed cn lso e plced efore tht stte nd tht the finl stte with doule circle, s shown elow. It is lso to e noted tht while expressing n FA y its trnsition digrm, the lels of sttes re not necessry., Exmple Σ = {,} ttes: x, y, where x is oth initil nd finl stte. Trnsitions: At stte x reding or go to stte y. At stte y reding or go to stte x., These trnsitions cn e expressed y the following trnsition tle Old ttes Reding New ttes Reding x ± y y y x x It my e noted tht the ove trnsition tle my e depicted y the following trnsition digrm. x ±,, y The ove trnsition digrm is n FA ccepting the lnguge of strings, defined over Σ={, } of even length. It my e noted tht this lnguge my e expressed y the regulr expression ((+ ) ( + )) * Exmple: Consider the lnguge L of strings, defined over Σ={, }, strting with. The lnguge L my e expressed y RE ( + ) *, my e ccepted y the following FA, +, 1 Exmple Consider the lnguge L of strings, defined over Σ={, }, ending in. The lnguge L my e expressed y RE (+) *. Copyright Virtul University of Pkistn 15

Theory of Automt This lnguge my e ccepted y the FA shown side + There my e nother FA corresponding to the given lnguge, s shown side + Note It my e noted tht corresponding to given lnguge there my e more thn one FA ccepting tht lnguge, ut for given FA there is unique lnguge ccepted y tht FA. It is lso to e noted tht given the lnguges L 1 nd L 2,where L 1 = The lnguge of strings, defined over Σ ={, }, eginning with. L 2 = The lnguge of strings, defined over Σ ={, }, not eginning with The Λ does not elong to L 1 while it does elong to L 2. This fct my e depicted y the corresponding trnsition digrms of L 1 nd L 2. FA 1 Corresponding to L 1, +, The lnguge L 1 my e expressed y the regulr expression ( + ) * FA 2 Corresponding to L 2, ± +, The lnguge L 2 my e expressed y the regulr expression ( + ) * + Λ Exmple Consider the Lnguge L of trings of length two or more, defined over Σ = {, }, eginning with nd ending in sme letters. The lnguge L my e expressed y the following regulr expression ( + ) * + ( + ) * It is to e noted tht if the condition on the length of string is not imposed in the ove lnguge then the strings nd will then elong to the lnguge. This lnguge L my e ccepted y the FA s shown side + + Copyright Virtul University of Pkistn 16

Theory of Automt Theory of Automt Lecture N0. 6 Reding Mteril Introduction to Computer Theory Chpter 5 ummry Lnguge of strings eginning with nd ending in different letters, Accepting ll strings, ccepting nonempty strings, ccepting no string, contining doule s, hving doule 0 s or doule 1 s, contining triple s or triple s, EVEN-EVEN Exmple Consider the Lnguge L of trings, defined over Σ = {, }, eginning with nd ending in different letters. The lnguge L my e expressed y the following regulr expression ( + ) * + ( + ) * This lnguge my e ccepted y the following FA The lnguge L my lso e ccepted y the following FA, 1 3 5+ Exmple Consider the Lnguge L, defined over Σ = {, } of ll strings including Λ. The lnguge L my e ccepted y the following FA, The lnguge L my e expressed y the regulr expression ( + ) * ± Exmple Consider the Lnguge L, defined over Σ = {, } of ll non empty strings. The lnguge L my e ccepted y the following FA,, - + The ove lnguge my e expressed y the regulr expression ( + ) + 1±, 2 2+ 4+ Exmple Consider the following FA, defined over Σ = {, }, -, + It is to e noted tht the ove FA does not ccept ny string, even it does not ccept the null string; s there is no pth strting from initil stte nd ending in finl stte. Equivlent FAs It is to e noted tht two FAs re sid to e equivlent, if they ccept the sme lnguge, s shown in the following FAs. FA 1,, + Copyright Virtul University of Pkistn 17

Theory of Automt, FA 2 1-, 2 FA 3 Note 1-, 2 3+ FA 1 hs lredy een discussed, while in FA 2, there is no finl stte nd in FA 3, there is finl stte ut FA 3 is disconnected s the sttes 2 nd 3 re disconnected. It my lso e noted tht the lnguge of strings ccepted y FA 1, FA 2 nd FA 3 is denoted y the empty set i.e. { } OR Ø Exmple Consider the Lnguge L of strings, defined over Σ = {, }, contining doule. The lnguge L my e expressed y the regulr expression (+) * () (+) *. This lnguge my e ccepted y the following FA., 1-2 3+ Exmple Consider the lnguge L of strings, defined over Σ={0, 1}, hving doule 0 s or doule 1 s, The lnguge L my e expressed y the regulr expression (0+1) * (00 + 11) (0+1) * This lnguge my e ccepted y the following FA x,, 0 0 0,1-0 1 + 1 1 y Copyright Virtul University of Pkistn 18

Theory of Automt Exmple Consider the lnguge L of strings, defined over Σ={, }, hving triple s or triple s. The lnguge L my e expressed y RE (+) * ( + ) (+) * 2 4 This lnguge my e ccepted y the FA s shown side, 1 6+ 1± 3 5 3 2 4 Exmple Consider the EVEN-EVEN lnguge, defined over Σ = {, }. As discussed erlier tht EVEN-EVEN lnguge cn e expressed y the regulr expression (++(+)(+) * (+)) * EVEN-EVEN lnguge my e ccepted y the FA s shown side Copyright Virtul University of Pkistn 19

Theory of Automt Theory of Automt Lecture N0. 7 Reding Mteril Introduction to Computer Theory Chpter 5, 6 ummry FA corresponding to finite lnguges(using oth methods), Trnsition grphs. FA corresponding to finite lnguges Exmple Consider the lnguge L = {Λ,,, }, defined over Σ ={, }, expressed y Λ + + + OR Λ + (Λ + + ). The lnguge L my e ccepted y the FA s shown side, y, 1± 3 2+ 5+ 4+ It is to e noted tht the sttes x nd y re clled Ded ttes, Wste Bskets or Dvey John Lockers, s the moment one enters these sttes there is no wy to leve it., Note It is to e noted tht to uild n FA ccepting the lnguge hving less numer of strings, the tree structure my lso help in this regrd, which cn e oserved in the following trnsition digrm for the 4 Lnguge L, discussed in the ove exmple x, 1± 3 5+ 6,,, 8, 2+ 7+,, x Exmple Consider the lnguge L = {,,, }, defined over Σ ={, }, expressed y + + + OR (Λ + ) + ( + ) The ove lnguge my e ccepted y the FA s shown side 1 2 3+ 4 6 7 8 9+ 10, 11+, y, Copyright Virtul University of Pkistn, 5+ 20

Theory of Automt Exmple Consider the lnguge L = {w elongs to {,} * : length(w) 2 nd w neither ends in nor }. The lnguge L my e expressed y the regulr expression (+) * (+) This lnguge my e ccepted y the following FA Copyright Virtul University of Pkistn 21

Theory of Automt 1 2 3 4+ 5+ Note It is to e noted tht uilding n FA corresponding to the lnguge L, discussed in the ove exmple, seems to e quite difficult, ut the sme cn e done using tree structure long with the technique discussed in the ook Introduction to Lnguges nd Theory of Computtion, y J. C. Mrtin so tht the strings ending in,, nd should end in the sttes leled s,, nd, respectively; s shown in the following FA Λ Exmple Consider the lnguge FA corresponding to r 1 +r 2 cn e determined s L = {w elongs to {,} * : w does not end in }. The lnguge L my e expressed y the regulr expression Λ + + + (+) * (++). This lnguge my e ccepted y the following FA Λ Method 5 (Trnsition Grph) Definition: A Trnsition grph (TG), is collection of the followings Finite numer of sttes, t lest one of which is strt stte nd some (mye none) finl sttes. Finite set of input letters (Σ) from which input strings re formed. Finite set of trnsitions tht show how to go from one stte to nother sed on reding specified sustrings of input letters, possily even the null string (Λ). Copyright Virtul University of Pkistn 22

Theory of Automt Theory of Automt Lecture N0. 8 Reding Mteril Introduction to Computer Theory Chpter 6 ummry Exmples of TGs: ccepting ll strings, ccepting none, strting with, not ending in, contining, contining or Note It is to e noted tht in TG there my exist more thn one pths for certin string, while there my not exist ny pth for certin string s well. If there exists t lest one pth for certin string, strting from initil stte nd ending in finl stte, the string is supposed to e ccepted y the TG, otherwise the string is supposed to e rejected. Oviously collection of ccepted strings is the lnguge ccepted y the TG. Exmple Consider the Lnguge L, defined over Σ = {, } of ll strings including Λ. The lnguge L my e ccepted y the following TG,, L + The lnguge L my lso e ccepted y the following TG, TG 1 ±, TG 2, ± + Exmple Consider the following TGs TG 1 TG 2 TG 3 -, - 1, - 1, It my e oserved tht in the first TG, no trnsition hs een shown. Hence this TG does not ccept ny string, defined over ny lphet. In TG 2 there re trnsitions for nd t initil stte ut there is no trnsition t stte 1. This TG still does not ccept ny string. In TG 3 there re trnsitions t oth initil stte nd stte 1, ut it does not ccept ny string. Thus none of TG 1, TG 2 nd TG 3 ccepts ny string, i.e. these TGs ccept empty lnguge. It my e noted tht TG 1 nd TG 2 re TGs ut not FA, while TG 3 is oth TG nd FA s well. It my e noted tht every FA is TG s well, ut the converse my not e true, i.e. every TG my not e n FA. Exmple Consider the lnguge L of strings, defined over Σ={, }, strting with. The lnguge L my e expressed y RE ( + ) *, my e ccepted y the following TG, æ + Copyright Virtul University of Pkistn 23

Theory of Automt Exmple Consider the lnguge L of strings, defined over Σ={, }, not ending in. The lnguge L my e expressed y RE Λ + ( + ) *, my e ccepted y the following TG, + Exmple Consider the Lnguge L of strings, defined over Σ = {, }, contining doule. The lnguge L my e expressed y the following regulr expression (+) * () (+) *. This lnguge my e ccepted y the following TG,, Exmple Consider the lnguge L of strings, defined over Σ={, }, hving doule or doule. The lnguge L cn e expressed y RE (+) * ( + ) (+) *. The ove lnguge my lso e expressed y the following TGs. Λ 1-2+ x +,, + y OR OR, -,, +,, 1-2+,, 3-4+ Note In the ove TG if the sttes re not leled then it my not e considered to e single TG Copyright Virtul University of Pkistn 24

Theory of Automt Theory of Automt Lecture N0. 9 Reding Mteril Introduction to Computer Theory Chpter 6 ummry TGs ccepting the lnguges: contining or, eginning nd ending in different letters, eginning nd ending in sme letters, EVEN-EVEN, s occur in even clumps nd ends in three or more s, exmple showing different pths trced y one string, Definition of GTG Exmple Consider the lnguge L of strings, defined over Σ = {, }, hving triple or triple. The lnguge L my e expressed y RE (+) * ( + ) (+) * This lnguge my e ccepted y the following TG 2 4,, 1 6+ 3 5 OR OR Exmple Consider the lnguge L of strings, defined over Σ = {, }, eginning nd ending in different letters. The lnguge L my e expressed y RE ( + ) * + ( + ) * The lnguge L my e ccepted y the following TG Copyright Virtul University of Pkistn 25

Theory of Automt Exmple Consider the Lnguge L of strings of length two or more, defined over Σ = {, }, eginning with nd ending in sme letters. The lnguge L my e expressed y the following regulr expression ( + ) * + ( + ) * This lnguge my e ccepted y the following TG Exmple Consider the EVEN-EVEN lnguge, defined over Σ = {, }. As discussed erlier tht EVEN-EVEN lnguge cn e expressed y regulr expression (++(+)(+) * (+)) * The lnguge EVEN-EVEN my e ccepted y the following TG Exmple Consider the lnguge L, defined over Σ={, }, in which s occur only in even clumps nd tht ends in three or more s. The lnguge L cn e expressed y its regulr expression () * ( * +(() * ) * ) OR () * ( * +( () + ) * ). The lnguge L my e ccepted y the following TG Exmple Consider the following TG Copyright Virtul University of Pkistn 26

Theory of Automt Consider the string. It my e oserved tht the ove string trces the following three pths, (using the sttes) ()() () () () () () () () (-)(4)(4)(+)(+)(3)(2)(2)(1)(+) ()() (()()) () () () () () (-)(4)(+)(+)(+)(3)(2)(2)(1)(+) ()(() ()) () () () () () () (-) (4)(4)(4)(+) (3)(2)(2)(1)(+) Which shows tht ll these pths re successful, (i.e. the pth strting from n initil stte nd ending in finl stte). Hence the string is ccepted y the given TG. Generlized Trnsition Grphs A generlized trnsition grph (GTG) is collection of three things Finite numer of sttes, t lest one of which is strt stte nd some (mye none) finl sttes. Finite set of input letters (Σ) from which input strings re formed. Directed edges connecting some pir of sttes leled with regulr expression. It my e noted tht in GTG, the lels of trnsition edges re corresponding regulr expressions Copyright Virtul University of Pkistn 27

Theory of Automt Theory of Automt Lecture N0. 10 Reding Mteril Introduction to Computer Theory Chpter 6, 7 ummry Exmples of GTG ccepting the lnguges of strings: contining or, eginning with nd ending in sme letters, eginning with nd ending in different letters, contining or, Nondeterminism, Kleene s theorem (prt I, prt II, prt III), proof of Kleene s theorem prt I Exmple Consider the lnguge L of strings, defined over Σ = {,}, contining doule or doule. The lnguge L cn e expressed y the following regulr expression (+) * ( + ) (+) * The lnguge L my e ccepted y the following GTG. Exmple Consider the Lnguge L of strings, defined over Σ = {, }, eginning with nd ending in sme letters. The lnguge L my e expressed y the following regulr expression (+)+ ( + ) * + ( + ) *. This lnguge my e ccepted y the following GTG Exmple Exmple Consider the lnguge L of strings of, defined over Σ = {, }, eginning nd ending in different letters. The lnguge L my e expressed y RE ( + ) * + ( + ) * The lnguge L my e ccepted y the following GTG The lnguge L my e ccepted y the following GTG s well Exmple Consider the lnguge L of strings, defined over Σ = {, }, hving triple or triple. The lnguge L my e expressed y RE (+) * ( + ) (+) * This lnguge my e ccepted y the following GTG Copyright Virtul University of Pkistn 28

Theory of Automt Nondeterminism TGs nd GTGs provide certin relxtions i.e. there my exist more thn one pth for certin string or there my not e ny pth for certin string, this property cretes nondeterminism nd it cn lso help in differentiting TGs or GTGs from FAs. Hence n FA is lso clled Deterministic Finite Automton (DFA). Kleene s Theorem If lnguge cn e expressed y FA or TG or RE then it cn lso e expressed y other two s well. It my e noted tht the theorem is proved, proving the following three prts Kleene s Theorem Prt I If lnguge cn e ccepted y n FA then it cn e ccepted y TG s well. Kleene s Theorem Prt II If lnguge cn e ccepted y TG then it cn e expressed y n RE s well. Kleene s Theorem Prt III If lnguge cn e expressed y RE then it cn e ccepted y n FA s well. Proof(Kleene s Theorem Prt I) ince every FA cn e considered to e TG s well, therefore there is nothing to prove. Copyright Virtul University of Pkistn 29

Theory of Automt Theory of Automt Lecture N0. 11 Reding Mteril Introduction to Computer Theory Chpter 7 ummry proof of Kleene s theorem prt II (method with different steps), prticulr exmples of TGs to determine corresponding REs. Proof(Kleene s Theorem Prt II) To prove prt II of the theorem, n lgorithm consisting of different steps, is explined showing how RE cn e otined corresponding to the given TG. For this purpose the notion of TG is chnged to tht of GTG i.e. the lels of trnsitions re corresponding REs. Bsiclly this lgorithm converts the given TG to GTG with one initil stte long with single loop, or one initil stte connected with one finl stte y single trnsition edge. The lel of the loop or the trnsition edge will e the required RE. tep 1 If TG hs more thn one strt sttes, then introduce new strt stte connecting the new stte to the old strt sttes y the trnsitions leled y Λ nd mke the old strt sttes the non-strt sttes. This step cn e shown y the following exmple Exmple The ove TG cn e converted to tep 2: If TG hs more thn one finl sttes, then introduce new finl stte, connecting the old finl sttes to the new finl stte y the trnsitions leled y Λ. This step cn e shown y the previous exmple of TG, where the step 1 hs lredy een processed Exmple Copyright Virtul University of Pkistn 30

Theory of Automt The ove TG cn e converted to tep 3: If stte hs two (more thn one) incoming trnsition edges leled y the corresponding REs, from the sme stte (including the possiility of loops t stte), then replce ll these trnsition edges with single trnsition edge leled y the sum of corresponding REs. This step cn e shown y prt of TG in the following exmple Exmple The ove TG cn e reduced to Note The step 3 cn e generlized to ny finite numer of trnsitions s shown elow The ove TG cn e reduced to tep 4 (ypss nd stte elimintion) If three sttes in TG, re connected in sequence then eliminte the middle stte nd connect the first stte with the third y single trnsition (include the possiility of circuit s well) leled y the RE which is the conctention of corresponding two REs in the existing sequence. This step cn e shown y prt of TG in the following exmple Exmple r 3 To eliminte stte 5 the ove cn e reduced to Consider the following exmple contining circuit Copyright Virtul University of Pkistn 31

Theory of Automt Exmple Consider the prt of TG, contining circuit t stte, s shown elow To eliminte stte 3 the ove TG cn e reduced to Exmple Consider prt of the following TG To eliminte stte 3 the ove TG cn e reduced to To eliminte stte 4 the ove TG cn e reduced to Note It is to e noted tht to determine the RE corresponding to certin TG, four steps hve een discussed. This process cn e explined y the following prticulr exmples of TGs Exmple Consider the following TG To hve single finl stte, the ove TG cn e reduced to the following Copyright Virtul University of Pkistn 32

Theory of Automt To eliminte sttes 2 nd 3, the ove TG cn e reduced to the following To eliminte stte 1 the ove TG cn e reduced to the following Hence the required RE is (+)(+) * (+) Copyright Virtul University of Pkistn 33

Theory of Automt Theory of Automt Lecture N0. 12 Reding Mteril Introduction to Computer Theory Chpter 7 ummry Exmples of writing REs to the corresponding TGs, RE corresponding to TG ccepting EVEN-EVEN lnguge, Kleene s theorem prt III (method 1:union of FAs), exmples of FAs corresponding to simple REs, exmple of Kleene s theorem prt III (method 1) continued Exmple Consider the following TG To hve single initil nd single finl stte the ove TG cn e reduced to the following To otin single trnsition edge etween 1 nd 3; 2 nd 4, the ove cn e reduced to the following To eliminte sttes 1,2,3 nd 4, the ove TG cn e reduced to the following TG OR Copyright Virtul University of Pkistn 34

Theory of Automt To connect the initil stte with the finl stte y single trnsition edge, the ove TG cn e reduced to the following Hence the required RE is (+) * +(+) * Exmple Consider the following TG, ccepting EVEN-EVEN lnguge 1± It is to e noted tht since the initil stte of this TG is finl s well nd there is no other finl stte, so to otin TG with single initil nd single finl stte, n dditionl initil nd finl stte re introduced s shown in the following TG To eliminte stte 2, the ove TG my e reduced to the following To hve single loop t stte 1, the ove TG my e reduced to the following To eliminte stte 1, the ove TG my e reduced to the following Hence the required RE is (++(+)(+) * (+)) * Kleene s Theorem Prt III ttement: If the lnguge cn e expressed y RE then there exists n FA ccepting the lnguge. Copyright Virtul University of Pkistn 35

Theory of Automt As the regulr expression is otined pplying ddition, conctention nd closure on the letters of n lphet nd the Null string, so while uilding the RE, sometimes, the corresponding FA my e uilt esily, s shown in the following exmples Exmple Consider the lnguge, defined over Σ = {,}, consisting of only, then this lnguge my e ccepted y the following FA which shows tht this FA helps in uilding n FA ccepting only one letter Exmple Consider the lnguge, defined over Σ = {,}, consisting of only Ÿ, then this lnguge my e ccepted y the following FA As, if r 1 nd r 2 re regulr expressions then their sum, conctention nd closure re lso regulr expressions, so n FA cn e uilt for ny regulr expression if the methods cn e developed for uilding the FAs corresponding to the sum, conctention nd closure of the regulr expressions long with their FAs. These three methods re explined in the following discussion Method1 (Union of two FAs): Using the FAs corresponding to r 1 nd r 2 n FA cn e uilt, corresponding to r 1 + r 2. This method cn e developed considering the following exmples Exmple Let r 1 = (+) * defines L 1 nd the FA 1 e nd r 2 = (+ ) * (+ ) * defines L 2 nd FA 2 e Let FA 3 e n FA corresponding to r 1 + r 2, then the initil stte of FA 3 must correspond to the initil stte of FA 1 or the initil stte of FA 2. ince the lnguge corresponding to r 1 + r 2 is the union of corresponding lnguges L 1 nd L 2, consists of the strings elonging to L 1 or L 2 or oth, therefore finl stte of FA 3 must correspond to finl stte of FA 1 or FA 2 or oth. ince, in generl, FA 3 will e different from oth FA 1 nd FA 2, so the lels of the sttes of FA 3 my e supposed to e z 1,z 2, z 3,, where z 1 is supposed to e the initil stte. ince z 1 corresponds to the sttes x 1 or y 1, so there will e two trnsitions seprtely for ech letter red t z 1. It will give two possiilities of sttes either z 1 or different from z 1. This process my e expressed in the following trnsition tle for ll possile sttes of FA 3. Copyright Virtul University of Pkistn 36

Theory of Automt Old ttes z 1 (x 1,y 1 ) z 2 (x 1,y 2 ) New ttes fter reding (x 1,y 2 ) z 2 (x 2,y 1 ) z 3 (x 1,y 3 ) z 4 (x 2,y 1 ) z 3 z 3 + (x 2,y 1 ) z 4 + (x 1,y 3 ) z 5 + (x 2,y 3 ) (x 1,y 2 ) z 2 (x 1,y 3 ) z 4 (x 1,y 3 ) z 4 (x 2,y 1 ) z 3 (x 2,y 3 ) z 5 (x 2,y 3 ) z 5 RE corresponding to the ove FA my e r 1 +r 2 = (+) * + (+ ) * (+ ) *. Note: Further exmples re discussed in the next lecture. Copyright Virtul University of Pkistn 37

Theory of Automt Theory of Automt Lecture N0. 13 Reding Mteril Introduction to Computer Theory Chpter 7 ummry Exmples of Kleene s theorem prt III (method 1) continued, Kleene s theorem prt III (method 2: Conctention of FAs), Exmple of Kleene s theorem prt III (method 2 : Conctention of FAs) Note It my e noted tht the exmple discussed t the end of previous lecture, FA 1 contins two sttes while FA 2 contins three sttes. Hence the totl numer of possile comintions of sttes of FA 1 nd FA 2, in sequence, will e six. For ech comintion the trnsitions for oth nd cn e determined, ut using the method in the exmple, numer of sttes of FA 3 ws reduced to five. Exmple Let r 1 = (+) * nd the corresponding FA 1 e lso r 2 = (+)((+)(+)) * or ((+)(+)) * (+) nd FA 2 e, x 1 - x 2 + y 1 - y 2 +, FA corresponding to r 1 +r 2 cn e determined s x 1 - x 2 +, y 1 - y 2 + Old ttes z 1 - (x 1,y 1 ) z 2 + (x 2,y 2 ), New ttes fter reding (x 2,y 2 ) z 2 (x 1,y 2 ) z 3 (x 2,y 1 ) z 4 (x 1,y 1 ) z 1 z 3 + (x 1,y 2 ) (x 2,y 1 ) z 4 (x 1,y 1 ) z 1 z 4 + (x 2,y 1 ) z 1 - (x 2,y 2 ) z 2 z 2 + (x 1,y 2 ) z 3 z 3 + Exmple Let r 1 = ((+)(+)) * nd the corresponding FA 1 e, z 4 + x 1 ± x, 2 Copyright Virtul University of Pkistn 38

Theory of Automt lso r 2 = (+)((+)(+)) * or ((+)(+)) * (+) nd FA 2 e, y 1 - y 2 + FA corresponding to r 1 +r 2 cn e determined s Old ttes, New ttes fter reding z 1 ± (x 1,y 1 ) z 2 + (x 2,y 2 ) Hence the required FA will e s follows (x 2,y 2 ) z 2 (x 1,y 1 ) z 1, (x 2,y 2 ) z 2 (x 1,y 1 ) z 1 z 1 ± z, 2 + Method2 (Conctention of two FAs): Using the FAs corresponding to r 1 nd r 2, n FA cn e uilt, corresponding to r 1 r 2. This method cn e developed considering the following exmples Exmple Let r 1 = (+) * defines L 1 nd FA 1 e x 1 - x 2 + nd r 2 = (+ ) * (+ ) * defines L 2 nd FA 2 e, y 1 - y 2 y 3 + Let FA 3 e n FA corresponding to r 1 r 2, then the initil stte of FA 3 must correspond to the initil stte of FA 1 nd the finl stte of FA 3 must correspond to the finl stte of FA 2.ince the lnguge corresponding to r 1 r 2 is the conctention of corresponding lnguges L 1 nd L 2, consists of the strings otined, conctenting the strings of L 1 to those of L 2, therefore the moment finl stte of first FA is entered, the possiility of the initil stte of second FA will e included s well. ince, in generl, FA 3 will e different from oth FA 1 nd FA 2, so the lels of the sttes of FA 3 my e supposed to e z 1,z 2, z 3,, where z 1 stnds for the initil stte. ince z 1 corresponds to the sttes x 1, so there will e two trnsitions seprtely for ech letter red t z 1. It will give two possiilities of sttes which correspond to either z 1 or different from z 1. This process my e expressed in the following trnsition tle for ll possile sttes of FA 3 x 1 - x 2 +, y 1 - y 2 y 3 + Copyright Virtul University of Pkistn 39

Theory of Automt Old ttes New ttes fter reding z 1 - x 1 z 2 (x 2,y 1 ) z 3 (x 1,y 2 ) z 4 + (x 1,y 3 ) z 5 + (x 2,y 1,y 3 ) z 6 + (x 1,y 2,y 3 ) Hence the required FA will e s follows x 1 z 1 (x 1,y 2 ) z 3 (x 1,y 3 ) z 4 (x 1,y 3 ) z 4 (x 1,y 2,y 3 ) z 6 (x 1,y 3 ) z 4 z 2 z 3 (x 2,y 1 ) z 2 (x 2,y 1 ) z 2 (x 2,y 1 ) z 2 (x 2,y 1,y 3 ) z 5 (x 2,y 1,y 3 ) z 5 (x 2,y 1,y 3 ) z 5 z 1 - z 4 + z 6 + z 5 + Note: Another exmple is discussed in the next lecture. Copyright Virtul University of Pkistn 40

Theory of Automt Theory of Automt Lecture N0. 14 Reding Mteril Introduction to Computer Theory Chpter 7 ummry Exmples of Kleene s theorem prt III (method 1) continued,kleene s theorem prt III (method 2: Conctention of FAs), Exmples of Kleene s theorem prt III(method 2:conctention FAs) continued, Kleene s theorem prt III (method 3:closure of n FA), exmples of Kleene s theorem prt III(method 3:Closure of n FA) continued Exmple Let r 1 = ((+)(+)) * nd the corresponding FA 1 e, lso r 2 = (+)((+)(+)) * or ((+)(+)) * (+) nd FA 2 e FA corresponding to r 1 r 2 cn e determined s x 1 ± x 2,, y 1 - y 2 +, Old ttes New ttes fter reding z 1 - (x 1,y 1 ) z 2 + (x 2,y 2 ) Hence the required FA will e s follows (x 2,y 2 ) z 2 (x 1,y 1 ) z 1 (x 2,y 2 ) z 2 (x 1,y 1 ) z 1 Method3: (Closure of n FA), Building n FA corresponding to r *, using the FA corresponding to r. It is to e noted tht if the given FA lredy ccepts the lnguge expressed y the closure of certin RE, then the given FA is the required FA. However the method, in other cses, cn e developed considering the following exmples Closure of n FA, is sme s conctention of n FA with itself, except tht the initil stte of the required FA is finl stte s well. Here the initil stte of given FA, corresponds to the initil stte of required FA nd non finl stte of the required FA s well., y 1 - y 2 + Exmple Let r = (+) * nd the corresponding FA e x 1 - x 2 + Copyright Virtul University of Pkistn 41

Theory of Automt then the FA corresponding to r * my e determined s under x 1 - x 2 + x 1 - x 2 + New ttes fter reding Old ttes Finl z 1 ± x 1 Non-finl z 2 x 1 z 3 + (x 2,x 1 ) x 1 z 2 x 1 z 2 x 1 z 2 (x 2,x 1 ) z 3 (x 2,x 1 ) z 3 (x 2,x 1 ) z 3 The corresponding trnsition digrm my e s under z 1 ± z 3 + z 2 Exmple Let r = (+) * (+) * nd the corresponding FA e, y 1 - y 2 y 3 + then the FA corresponding to r * my e determined s under New ttes fter reding Old ttes Finl z 1 ± y 1 Non-Finl z 2 y 1 z 3 y 2 z 4 + (y 3,y 1 ) z 5 + (y 3,y 1,y 2 ) y 2 z 3 y 2 z 3 (y 3,y 1 ) z 4 (y 3,y 1,y 2 ) z 5 (y 3,y 1,y 2 ) z 5 y 1 z 2 y 1 z 2 y 1 z 2 (y 3,y 1 ) z 4 (y 3,y 1 ) z 4 The corresponding trnsition digrm my e z 1 ± z 3 z 4 + z 5 + z 2 Copyright Virtul University of Pkistn 42

Theory of Automt Exmple Consider the following FA, ccepting the lnguge of strings with s second letter, y 1 - y 2, y 3 + y 4, then the FA corresponding to r * my e determined s under Old ttes New ttes fter reding z 1 ± y 1 z 2 y 2 z 3 y 4 z 4 + (y 3,y 1 ) z 5 + (y 3,y 1,y 2 ) z 6 (y 1,y 1,y 2,y 4 ) The corresponding trnsition digrm my e y 2 z 2 y 4 z 3 y 4 z 3 (y 3,y 1,y 2 ) z 5 (y 3,y 1,y 2,y 4 ) z 6 (y 1,y 1,y 2,y 4 ) z 6 y 2 z 2 (y 3,y 1 ) z 4 y 4 z 3 (y 3,y 1,y 2 ) z 5 (y 3,y 1,y 2 ) z 5 (y 1,y 1,y 2,y 4 ) z 6, z 1 ± z 2, z 3 z 4 +, z 5 + z 6 +, Copyright Virtul University of Pkistn 43

Theory of Automt Theory of Automt Lecture N0. 15 Reding Mteril Introduction to Computer Theory Chpter 7 ummry Exmples of Kleene s theorem prt III (method 3), NFA, exmples, voiding loop using NFA, exmple, converting FA to NFA, exmples, pplying n NFA on n exmple of mze Note It is to e noted tht s oserved in the exmples discussed in previous lecture, if t the initil stte of the given FA, there is either loop or n incoming trnsition edge, the initil stte corresponds to the finl stte nd nonfinl stte s well, of the required FA, otherwise the initil stte of given FA will only correspond to single stte of the required FA (i.e. the initil stte which is finl s well). Nondeterministic Finite Automton (NFA) Definition An NFA is TG with unique strt stte nd property of hving single letter s lel of trnsitions. An NFA is collection of three things Finite mny sttes with one initil nd some finl sttes Finite set of input letters, sy, = {,, c} Finite set of trnsitions, showing where to move if letter is input t certin stte (Ÿ is not vlid trnsition), there my e more thn one trnsition for certin letters nd there my not e ny trnsition for certin letters. Oservtions It my e oserved, from the definition of NFA, tht the string is supposed to e ccepted, if there exists t lest one successful pth, otherwise rejected. It is to e noted tht n NFA cn e considered to e n intermedite structure etween FA nd TG. The exmples of NFAs cn e found in the following Exmple It is to e noted tht the ove NFA ccepts the lnguge consisting of nd.,, Exmple 1-2 3+ It is to e noted tht the ove NFA ccepts the lnguge of strings, defined over Σ = {, }, contining. Note It is to e noted tht NFA helps to eliminte loop t certin stte of n FA. This process is done converting the loop into circuit. But during this process the FA remins no longer FA nd is converted to corresponding NFA, which is shown in the following exmple. Exmple Consider prt of the following FA with n lphet Σ = {,,c,d} 1-2+ 3 4 4 6 5 c 5+ 7 c d 8 9 10 Copyright Virtul University of Pkistn 44