61
THEORY OF COMPUTATION G. Appasami, M.Sc., M.C.A., M.Phil., M.Tech., (Ph.D.) Assistant Professor Department of Computer Science and Engineering Dr. Pauls Engineering Collage Pauls Nagar, Villupuram Tamilnadu, India SARUMATHI PUBLICATIONS Villupuram, Tamilnadu, India

Cs6503 theory of computation book notes

  • Upload
    appasami

  • View
    1.463

  • Download
    18

Embed Size (px)

Citation preview

Page 1: Cs6503 theory of computation book notes

THEORY

OF

COMPUTATION

G Appasami MSc MCA MPhil MTech (PhD)

Assistant Professor

Department of Computer Science and Engineering

Dr Paulrsquos Engineering Collage

Pauls Nagar Villupuram

Tamilnadu India

SARUMATHI PUBLICATIONS

Villupuram Tamilnadu India

First Edition July 2016

Published By

SARUMATHI PUBLICATIONS

copy All rights reserved No part of this publication can be reproduced or stored in any form or

by means of photocopy recording or otherwise without the prior written permission of the

author

Price Rs 101-

Copies can be had from

SARUMATHI PUBLICATIONS

Villupuram Tamilnadu India

Sarumathipublicationsgmailcom

Printed at

Meenam Offset

Pondicherry ndash 605001 India

Acknowledgement

I am very much grateful to the management of paulrsquos educational trust Respected

principal Dr Y R M Rao ME PhD cherished Dean Dr E Mariappane ME

PhD and helpful Head of the department Mr M G Lavakumar ME (PhD)

I thank my colleagues and friends for their cooperation and their support in my

career venture

I thank my parents and family members for their valuable support in completion of

the book successfully

I express my special thanks to SARUMATHI PUBLICATIONS for their continued

cooperation in shaping the work

Suggestions and comments to improve the text are very much solicitated

Mr G Appasami

CS6503 THEORY OF COMPUTATION L T P C 3 0 0 3

OBJECTIVES

The student should be made to Understand various Computing models like Finite State Machine Pushdown Automata

and Turing Machine

Be aware of Decidability and Un-decidability of various problems

Learn types of grammars

UNIT I FINITE AUTOMATA 9

Introduction- Basic Mathematical Notation and techniques- Finite State systems ndash Basic Definitions ndash Finite Automaton ndash DFA amp NDFA ndash Finite Automaton with euro- moves ndash Regular Languages- Regular Expression ndash Equivalence of NFA and DFA ndash Equivalence of NDFA‟s with and without euro-moves ndash Equivalence of finite Automaton and regular expressions ndashMinimization of DFA- - Pumping Lemma for Regular sets ndash Problems based on Pumping Lemma UNIT II GRAMMARS 9

Grammar Introductionndash Types of Grammar - Context Free Grammars and Languagesndash Derivations and Languages ndash Ambiguity- Relationship between derivation and derivation trees ndash Simplification of CFG ndash Elimination of Useless symbols - Unit productions - Null productions ndash Greiback Normal form ndash Chomsky normal form ndash Problems related to CNF and GNF UNIT III PUSHDOWN AUTOMATA 9

Pushdown Automata- Definitions ndash Moves ndash Instantaneous descriptions ndash Deterministic pushdown automata ndash Equivalence of Pushdown automata and CFL - pumping lemma for CFL ndash problems based on pumping Lemma

UNIT IV TURING MACHINES 9

Definitions of Turing machines ndash Models ndash Computable languages and functions ndashTechniques for Turing machine construction ndash Multi head and Multi tape Turing Machines - The Halting problem ndash Partial Solvability ndash Problems about Turing machine- Chomskian hierarchy of languages UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS 9

Unsolvable Problems and Computable Functions ndash Primitive recursive functions ndash Recursive and recursively enumerable languages ndash Universal Turing machine MEASURING AND CLASSIFYING COMPLEXITY Tractable and Intractable problems- Tractable and possibly intractable problems - P and NP completeness - Polynomial time reductions

TOTAL 45 PERIODS

TEXT BOOKS 1 Hopcroft JE Motwani R and Ullman JD ldquoIntroduction to Automata Theory Languages and

Computationsrdquo Second Edition Pearson Education 2008 (UNIT 123)

2 John C Martin ldquoIntroduction to Languages and the Theory of Computationrdquo Third Edition Tata McGraw Hill Publishing Company New Delhi 2007 (UNIT 45)

REFERENCES 1 Mishra K L P and Chandrasekaran N ldquoTheory of Computer Science - Automata Languages and

Computationrdquo Third Edition Prentice Hall of India 2004

2 Harry R Lewis and Christos H Papadimitriou ldquoElements of the Theory of Computationrdquo Second Edition Prentice Hall of India Pearson Education New Delhi 2003

3 Peter Linz ldquoAn Introduction to Formal Language and Automatardquo Third Edition Narosa Publishers New Delhi 2002

4 Kamala Krithivasan and Rama R ldquoIntroduction to Formal Languages Automata Theory and Computationrdquo Pearson Education 2009

TABLE OF CONTENTS

S No Contents Page no

UNIT I FINITE AUTOMATA

1 Introduction - Basic Mathematical Notation and techniques

2 Finite State systems - Basic Definitions Finite Automaton

3 DFA amp NDFA

4 Finite Automaton with ε- moves

5 Regular Languages - Regular Expression

6 Equivalence of NFA and DFA

Equivalence of NDFArsquos with and without ε - moves

7 Equivalence of finite Automaton and regular expressions

8 Minimization of DFA

9 Pumping Lemma for Regular sets

10 Problems based on Pumping Lemma

UNIT II GRAMMARS

1 Grammar Introduction - Types of Grammar

2 Context Free Grammars and Languages

3 Derivations and Languages Ambiguity

4 Relationship between derivation and derivation trees

5 Simplification of CFG

6 Elimination of Useless symbols

Unit productions - Null productions

7 Greiback Normal form

8 Chomsky normal form

9 Problems related to CNF and GNF

UNIT III PUSHDOWN AUTOMATA

1 Pushdown Automata

2 Definitions

3 Moves

4 Instantaneous descriptions

5 Deterministic pushdown automata

6 Equivalence of PDA and CFL

7 Pumping lemma for CFL

8 Problems based on pumping Lemma

UNIT V TURING MACHINES

1 Definitions of Turing machines

2 Models

3 Computable languages and functions

4 Techniques for Turing machine Construction

5 Multi head and Multi tape Turing Machines

6 The Halting problem

7 Partial Solvability

8 Problems about Turing machine

9 Chomskian hierarchy of languages

UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE

FUNCTIONS

1 Unsolvable Problems and Computable Functions

2 Primitive recursive functions

3 Recursive and recursively enumerable languages

4 Universal Turing machine

5 Measuring and classifying complexity

6 Tractable and Intractable problems

7 Tractable and possibly intractable problems

8 P and NP completeness

9 Polynomial time reductions

2 Marks Questions and Answers 74

Question Bank 100

Model Question paper 105

References 107

Theory of Computation 1

THEORY OF COMPUTATION

UNIT I - AUTOMATA

The theory of computation is the branch that deals with whether and how efficiently problems can be solved on a model of computation using an algorithm The field is divided into three major branches automata theory computability theory and computational complexity theory 11 Introduction to formal proof Formal Proofs are the proofs in which we try to prove the statement lsquoBrsquo is true because statement lsquoArsquo is true In other words the Statement ldquoIf A then Brdquo means that B is deduced from A In this statement A is called hypothesis and B is called conclusion statement The formal proofs can be done by deductive proof and inductive proof

111 Deductive Proof It consists of a sequence of statements given with logical reasoning in order to prove the first (or initial) statement The first statement is called hypothesis

112 Inductive Proof It is a recursive kind of proof which consists of sequence of parameterized statements that cure statement itself with lower values of its parameters 113 Additional forms of Proofs

I Proofs about sets II Proofs by contradiction III Proofs by counter example

Proofs about sets Set is a collection of elements or items Let us consider two sets A and B Define the expression R as union of A and B (ie AUB) and S as union of B and A (ie BUA) where U is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B Prove that R=S(ie x is in R if and only if it is in S) Proof To prove R=S we have to prove AUB=BUA (i)x is in AUB then it is in BUA

Sl No Statement Justification

1 x is in AUB Given

2 x is in Aor x is in B By definition of union amp (1)

3 x is in B or x is in A By definition of union amp (2)

4 x is in BUA By definition of union amp (3)

(i) x is in BUA then it is in AUB

Sl No Statement Justification

1 x is in BUA Given

Theory of Computation 2

2 x is in B or x is in A By definition of union amp (1)

3 x is in Aor x is in B By definition of union amp (2)

4 x is in AUB By definition of union amp (3)

So AUB=BUA Thus R=S is true Hence proved Proofs by contradiction

In proof by contradiction to prove the statement of the form ldquoif A true then B truerdquo We start with statement A is not true by assumption and try to get the conclusion statement B When it impossible to reach B then we contradict our self and accept that A is true Example Prove PUQ = QUP Proof Initially assume PUQ = QUP is not true ie PUQ ne QUP Now consider x is in PUQ x is in P or x is in Q (By Definition of Union) x is in Q or x is in P (By Definition of Union) x is in QUP (By Definition of Union) This contradicts our assumption PUQ ne QUP Hence the assumption which we made initially is false Therefore PUQ = QUP is proved Proofs by counter example In order to prove certain statements we need to check all the possible conditions in which that statement remains true There are some situations in which the statement cannot be true Example 1 There is no pair of integers a and b such that amod b = b mod a Proof There are two possibilities They are either agtb or altb If a=2 and b=3 then 2 mod 3 ne 3 mod 2 If a=3 and b=2 then 3 mod 2 ne 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2 so the given statement is true only if a=b so we have to change the statement slightly Thus amod b = b mod a true only when a=b We proved by counter example this type of proof is called proof by counter example Such proof are true only at specific conditions Example 2 All primes are odd numbers 2 3 5 7 1 13 17 23 are prime numbers and all are odd numbers except 2 The integer 2 is prime but not odd so the statement is not a theorem Example 1 Prove that every integer n ge 0 the number 42n + 1 + 3n + 2 is multiple of 13 by induction

Proof Let n= 0 P(0) = 42(0) + 1 + 3(0) + 2= 41 + 32= 4 + 9 = 13 = 13t where t=1

Let n = 1 P(1) = 42(1) + 1 + 3(1) + 2= 43 + 33 = 64 + 27 = 91 = 13t where t= 7

Let n = k P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13t true for some integer t

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 2: Cs6503 theory of computation book notes

First Edition July 2016

Published By

SARUMATHI PUBLICATIONS

copy All rights reserved No part of this publication can be reproduced or stored in any form or

by means of photocopy recording or otherwise without the prior written permission of the

author

Price Rs 101-

Copies can be had from

SARUMATHI PUBLICATIONS

Villupuram Tamilnadu India

Sarumathipublicationsgmailcom

Printed at

Meenam Offset

Pondicherry ndash 605001 India

Acknowledgement

I am very much grateful to the management of paulrsquos educational trust Respected

principal Dr Y R M Rao ME PhD cherished Dean Dr E Mariappane ME

PhD and helpful Head of the department Mr M G Lavakumar ME (PhD)

I thank my colleagues and friends for their cooperation and their support in my

career venture

I thank my parents and family members for their valuable support in completion of

the book successfully

I express my special thanks to SARUMATHI PUBLICATIONS for their continued

cooperation in shaping the work

Suggestions and comments to improve the text are very much solicitated

Mr G Appasami

CS6503 THEORY OF COMPUTATION L T P C 3 0 0 3

OBJECTIVES

The student should be made to Understand various Computing models like Finite State Machine Pushdown Automata

and Turing Machine

Be aware of Decidability and Un-decidability of various problems

Learn types of grammars

UNIT I FINITE AUTOMATA 9

Introduction- Basic Mathematical Notation and techniques- Finite State systems ndash Basic Definitions ndash Finite Automaton ndash DFA amp NDFA ndash Finite Automaton with euro- moves ndash Regular Languages- Regular Expression ndash Equivalence of NFA and DFA ndash Equivalence of NDFA‟s with and without euro-moves ndash Equivalence of finite Automaton and regular expressions ndashMinimization of DFA- - Pumping Lemma for Regular sets ndash Problems based on Pumping Lemma UNIT II GRAMMARS 9

Grammar Introductionndash Types of Grammar - Context Free Grammars and Languagesndash Derivations and Languages ndash Ambiguity- Relationship between derivation and derivation trees ndash Simplification of CFG ndash Elimination of Useless symbols - Unit productions - Null productions ndash Greiback Normal form ndash Chomsky normal form ndash Problems related to CNF and GNF UNIT III PUSHDOWN AUTOMATA 9

Pushdown Automata- Definitions ndash Moves ndash Instantaneous descriptions ndash Deterministic pushdown automata ndash Equivalence of Pushdown automata and CFL - pumping lemma for CFL ndash problems based on pumping Lemma

UNIT IV TURING MACHINES 9

Definitions of Turing machines ndash Models ndash Computable languages and functions ndashTechniques for Turing machine construction ndash Multi head and Multi tape Turing Machines - The Halting problem ndash Partial Solvability ndash Problems about Turing machine- Chomskian hierarchy of languages UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS 9

Unsolvable Problems and Computable Functions ndash Primitive recursive functions ndash Recursive and recursively enumerable languages ndash Universal Turing machine MEASURING AND CLASSIFYING COMPLEXITY Tractable and Intractable problems- Tractable and possibly intractable problems - P and NP completeness - Polynomial time reductions

TOTAL 45 PERIODS

TEXT BOOKS 1 Hopcroft JE Motwani R and Ullman JD ldquoIntroduction to Automata Theory Languages and

Computationsrdquo Second Edition Pearson Education 2008 (UNIT 123)

2 John C Martin ldquoIntroduction to Languages and the Theory of Computationrdquo Third Edition Tata McGraw Hill Publishing Company New Delhi 2007 (UNIT 45)

REFERENCES 1 Mishra K L P and Chandrasekaran N ldquoTheory of Computer Science - Automata Languages and

Computationrdquo Third Edition Prentice Hall of India 2004

2 Harry R Lewis and Christos H Papadimitriou ldquoElements of the Theory of Computationrdquo Second Edition Prentice Hall of India Pearson Education New Delhi 2003

3 Peter Linz ldquoAn Introduction to Formal Language and Automatardquo Third Edition Narosa Publishers New Delhi 2002

4 Kamala Krithivasan and Rama R ldquoIntroduction to Formal Languages Automata Theory and Computationrdquo Pearson Education 2009

TABLE OF CONTENTS

S No Contents Page no

UNIT I FINITE AUTOMATA

1 Introduction - Basic Mathematical Notation and techniques

2 Finite State systems - Basic Definitions Finite Automaton

3 DFA amp NDFA

4 Finite Automaton with ε- moves

5 Regular Languages - Regular Expression

6 Equivalence of NFA and DFA

Equivalence of NDFArsquos with and without ε - moves

7 Equivalence of finite Automaton and regular expressions

8 Minimization of DFA

9 Pumping Lemma for Regular sets

10 Problems based on Pumping Lemma

UNIT II GRAMMARS

1 Grammar Introduction - Types of Grammar

2 Context Free Grammars and Languages

3 Derivations and Languages Ambiguity

4 Relationship between derivation and derivation trees

5 Simplification of CFG

6 Elimination of Useless symbols

Unit productions - Null productions

7 Greiback Normal form

8 Chomsky normal form

9 Problems related to CNF and GNF

UNIT III PUSHDOWN AUTOMATA

1 Pushdown Automata

2 Definitions

3 Moves

4 Instantaneous descriptions

5 Deterministic pushdown automata

6 Equivalence of PDA and CFL

7 Pumping lemma for CFL

8 Problems based on pumping Lemma

UNIT V TURING MACHINES

1 Definitions of Turing machines

2 Models

3 Computable languages and functions

4 Techniques for Turing machine Construction

5 Multi head and Multi tape Turing Machines

6 The Halting problem

7 Partial Solvability

8 Problems about Turing machine

9 Chomskian hierarchy of languages

UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE

FUNCTIONS

1 Unsolvable Problems and Computable Functions

2 Primitive recursive functions

3 Recursive and recursively enumerable languages

4 Universal Turing machine

5 Measuring and classifying complexity

6 Tractable and Intractable problems

7 Tractable and possibly intractable problems

8 P and NP completeness

9 Polynomial time reductions

2 Marks Questions and Answers 74

Question Bank 100

Model Question paper 105

References 107

Theory of Computation 1

THEORY OF COMPUTATION

UNIT I - AUTOMATA

The theory of computation is the branch that deals with whether and how efficiently problems can be solved on a model of computation using an algorithm The field is divided into three major branches automata theory computability theory and computational complexity theory 11 Introduction to formal proof Formal Proofs are the proofs in which we try to prove the statement lsquoBrsquo is true because statement lsquoArsquo is true In other words the Statement ldquoIf A then Brdquo means that B is deduced from A In this statement A is called hypothesis and B is called conclusion statement The formal proofs can be done by deductive proof and inductive proof

111 Deductive Proof It consists of a sequence of statements given with logical reasoning in order to prove the first (or initial) statement The first statement is called hypothesis

112 Inductive Proof It is a recursive kind of proof which consists of sequence of parameterized statements that cure statement itself with lower values of its parameters 113 Additional forms of Proofs

I Proofs about sets II Proofs by contradiction III Proofs by counter example

Proofs about sets Set is a collection of elements or items Let us consider two sets A and B Define the expression R as union of A and B (ie AUB) and S as union of B and A (ie BUA) where U is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B Prove that R=S(ie x is in R if and only if it is in S) Proof To prove R=S we have to prove AUB=BUA (i)x is in AUB then it is in BUA

Sl No Statement Justification

1 x is in AUB Given

2 x is in Aor x is in B By definition of union amp (1)

3 x is in B or x is in A By definition of union amp (2)

4 x is in BUA By definition of union amp (3)

(i) x is in BUA then it is in AUB

Sl No Statement Justification

1 x is in BUA Given

Theory of Computation 2

2 x is in B or x is in A By definition of union amp (1)

3 x is in Aor x is in B By definition of union amp (2)

4 x is in AUB By definition of union amp (3)

So AUB=BUA Thus R=S is true Hence proved Proofs by contradiction

In proof by contradiction to prove the statement of the form ldquoif A true then B truerdquo We start with statement A is not true by assumption and try to get the conclusion statement B When it impossible to reach B then we contradict our self and accept that A is true Example Prove PUQ = QUP Proof Initially assume PUQ = QUP is not true ie PUQ ne QUP Now consider x is in PUQ x is in P or x is in Q (By Definition of Union) x is in Q or x is in P (By Definition of Union) x is in QUP (By Definition of Union) This contradicts our assumption PUQ ne QUP Hence the assumption which we made initially is false Therefore PUQ = QUP is proved Proofs by counter example In order to prove certain statements we need to check all the possible conditions in which that statement remains true There are some situations in which the statement cannot be true Example 1 There is no pair of integers a and b such that amod b = b mod a Proof There are two possibilities They are either agtb or altb If a=2 and b=3 then 2 mod 3 ne 3 mod 2 If a=3 and b=2 then 3 mod 2 ne 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2 so the given statement is true only if a=b so we have to change the statement slightly Thus amod b = b mod a true only when a=b We proved by counter example this type of proof is called proof by counter example Such proof are true only at specific conditions Example 2 All primes are odd numbers 2 3 5 7 1 13 17 23 are prime numbers and all are odd numbers except 2 The integer 2 is prime but not odd so the statement is not a theorem Example 1 Prove that every integer n ge 0 the number 42n + 1 + 3n + 2 is multiple of 13 by induction

Proof Let n= 0 P(0) = 42(0) + 1 + 3(0) + 2= 41 + 32= 4 + 9 = 13 = 13t where t=1

Let n = 1 P(1) = 42(1) + 1 + 3(1) + 2= 43 + 33 = 64 + 27 = 91 = 13t where t= 7

Let n = k P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13t true for some integer t

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 3: Cs6503 theory of computation book notes

Acknowledgement

I am very much grateful to the management of paulrsquos educational trust Respected

principal Dr Y R M Rao ME PhD cherished Dean Dr E Mariappane ME

PhD and helpful Head of the department Mr M G Lavakumar ME (PhD)

I thank my colleagues and friends for their cooperation and their support in my

career venture

I thank my parents and family members for their valuable support in completion of

the book successfully

I express my special thanks to SARUMATHI PUBLICATIONS for their continued

cooperation in shaping the work

Suggestions and comments to improve the text are very much solicitated

Mr G Appasami

CS6503 THEORY OF COMPUTATION L T P C 3 0 0 3

OBJECTIVES

The student should be made to Understand various Computing models like Finite State Machine Pushdown Automata

and Turing Machine

Be aware of Decidability and Un-decidability of various problems

Learn types of grammars

UNIT I FINITE AUTOMATA 9

Introduction- Basic Mathematical Notation and techniques- Finite State systems ndash Basic Definitions ndash Finite Automaton ndash DFA amp NDFA ndash Finite Automaton with euro- moves ndash Regular Languages- Regular Expression ndash Equivalence of NFA and DFA ndash Equivalence of NDFA‟s with and without euro-moves ndash Equivalence of finite Automaton and regular expressions ndashMinimization of DFA- - Pumping Lemma for Regular sets ndash Problems based on Pumping Lemma UNIT II GRAMMARS 9

Grammar Introductionndash Types of Grammar - Context Free Grammars and Languagesndash Derivations and Languages ndash Ambiguity- Relationship between derivation and derivation trees ndash Simplification of CFG ndash Elimination of Useless symbols - Unit productions - Null productions ndash Greiback Normal form ndash Chomsky normal form ndash Problems related to CNF and GNF UNIT III PUSHDOWN AUTOMATA 9

Pushdown Automata- Definitions ndash Moves ndash Instantaneous descriptions ndash Deterministic pushdown automata ndash Equivalence of Pushdown automata and CFL - pumping lemma for CFL ndash problems based on pumping Lemma

UNIT IV TURING MACHINES 9

Definitions of Turing machines ndash Models ndash Computable languages and functions ndashTechniques for Turing machine construction ndash Multi head and Multi tape Turing Machines - The Halting problem ndash Partial Solvability ndash Problems about Turing machine- Chomskian hierarchy of languages UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS 9

Unsolvable Problems and Computable Functions ndash Primitive recursive functions ndash Recursive and recursively enumerable languages ndash Universal Turing machine MEASURING AND CLASSIFYING COMPLEXITY Tractable and Intractable problems- Tractable and possibly intractable problems - P and NP completeness - Polynomial time reductions

TOTAL 45 PERIODS

TEXT BOOKS 1 Hopcroft JE Motwani R and Ullman JD ldquoIntroduction to Automata Theory Languages and

Computationsrdquo Second Edition Pearson Education 2008 (UNIT 123)

2 John C Martin ldquoIntroduction to Languages and the Theory of Computationrdquo Third Edition Tata McGraw Hill Publishing Company New Delhi 2007 (UNIT 45)

REFERENCES 1 Mishra K L P and Chandrasekaran N ldquoTheory of Computer Science - Automata Languages and

Computationrdquo Third Edition Prentice Hall of India 2004

2 Harry R Lewis and Christos H Papadimitriou ldquoElements of the Theory of Computationrdquo Second Edition Prentice Hall of India Pearson Education New Delhi 2003

3 Peter Linz ldquoAn Introduction to Formal Language and Automatardquo Third Edition Narosa Publishers New Delhi 2002

4 Kamala Krithivasan and Rama R ldquoIntroduction to Formal Languages Automata Theory and Computationrdquo Pearson Education 2009

TABLE OF CONTENTS

S No Contents Page no

UNIT I FINITE AUTOMATA

1 Introduction - Basic Mathematical Notation and techniques

2 Finite State systems - Basic Definitions Finite Automaton

3 DFA amp NDFA

4 Finite Automaton with ε- moves

5 Regular Languages - Regular Expression

6 Equivalence of NFA and DFA

Equivalence of NDFArsquos with and without ε - moves

7 Equivalence of finite Automaton and regular expressions

8 Minimization of DFA

9 Pumping Lemma for Regular sets

10 Problems based on Pumping Lemma

UNIT II GRAMMARS

1 Grammar Introduction - Types of Grammar

2 Context Free Grammars and Languages

3 Derivations and Languages Ambiguity

4 Relationship between derivation and derivation trees

5 Simplification of CFG

6 Elimination of Useless symbols

Unit productions - Null productions

7 Greiback Normal form

8 Chomsky normal form

9 Problems related to CNF and GNF

UNIT III PUSHDOWN AUTOMATA

1 Pushdown Automata

2 Definitions

3 Moves

4 Instantaneous descriptions

5 Deterministic pushdown automata

6 Equivalence of PDA and CFL

7 Pumping lemma for CFL

8 Problems based on pumping Lemma

UNIT V TURING MACHINES

1 Definitions of Turing machines

2 Models

3 Computable languages and functions

4 Techniques for Turing machine Construction

5 Multi head and Multi tape Turing Machines

6 The Halting problem

7 Partial Solvability

8 Problems about Turing machine

9 Chomskian hierarchy of languages

UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE

FUNCTIONS

1 Unsolvable Problems and Computable Functions

2 Primitive recursive functions

3 Recursive and recursively enumerable languages

4 Universal Turing machine

5 Measuring and classifying complexity

6 Tractable and Intractable problems

7 Tractable and possibly intractable problems

8 P and NP completeness

9 Polynomial time reductions

2 Marks Questions and Answers 74

Question Bank 100

Model Question paper 105

References 107

Theory of Computation 1

THEORY OF COMPUTATION

UNIT I - AUTOMATA

The theory of computation is the branch that deals with whether and how efficiently problems can be solved on a model of computation using an algorithm The field is divided into three major branches automata theory computability theory and computational complexity theory 11 Introduction to formal proof Formal Proofs are the proofs in which we try to prove the statement lsquoBrsquo is true because statement lsquoArsquo is true In other words the Statement ldquoIf A then Brdquo means that B is deduced from A In this statement A is called hypothesis and B is called conclusion statement The formal proofs can be done by deductive proof and inductive proof

111 Deductive Proof It consists of a sequence of statements given with logical reasoning in order to prove the first (or initial) statement The first statement is called hypothesis

112 Inductive Proof It is a recursive kind of proof which consists of sequence of parameterized statements that cure statement itself with lower values of its parameters 113 Additional forms of Proofs

I Proofs about sets II Proofs by contradiction III Proofs by counter example

Proofs about sets Set is a collection of elements or items Let us consider two sets A and B Define the expression R as union of A and B (ie AUB) and S as union of B and A (ie BUA) where U is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B Prove that R=S(ie x is in R if and only if it is in S) Proof To prove R=S we have to prove AUB=BUA (i)x is in AUB then it is in BUA

Sl No Statement Justification

1 x is in AUB Given

2 x is in Aor x is in B By definition of union amp (1)

3 x is in B or x is in A By definition of union amp (2)

4 x is in BUA By definition of union amp (3)

(i) x is in BUA then it is in AUB

Sl No Statement Justification

1 x is in BUA Given

Theory of Computation 2

2 x is in B or x is in A By definition of union amp (1)

3 x is in Aor x is in B By definition of union amp (2)

4 x is in AUB By definition of union amp (3)

So AUB=BUA Thus R=S is true Hence proved Proofs by contradiction

In proof by contradiction to prove the statement of the form ldquoif A true then B truerdquo We start with statement A is not true by assumption and try to get the conclusion statement B When it impossible to reach B then we contradict our self and accept that A is true Example Prove PUQ = QUP Proof Initially assume PUQ = QUP is not true ie PUQ ne QUP Now consider x is in PUQ x is in P or x is in Q (By Definition of Union) x is in Q or x is in P (By Definition of Union) x is in QUP (By Definition of Union) This contradicts our assumption PUQ ne QUP Hence the assumption which we made initially is false Therefore PUQ = QUP is proved Proofs by counter example In order to prove certain statements we need to check all the possible conditions in which that statement remains true There are some situations in which the statement cannot be true Example 1 There is no pair of integers a and b such that amod b = b mod a Proof There are two possibilities They are either agtb or altb If a=2 and b=3 then 2 mod 3 ne 3 mod 2 If a=3 and b=2 then 3 mod 2 ne 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2 so the given statement is true only if a=b so we have to change the statement slightly Thus amod b = b mod a true only when a=b We proved by counter example this type of proof is called proof by counter example Such proof are true only at specific conditions Example 2 All primes are odd numbers 2 3 5 7 1 13 17 23 are prime numbers and all are odd numbers except 2 The integer 2 is prime but not odd so the statement is not a theorem Example 1 Prove that every integer n ge 0 the number 42n + 1 + 3n + 2 is multiple of 13 by induction

Proof Let n= 0 P(0) = 42(0) + 1 + 3(0) + 2= 41 + 32= 4 + 9 = 13 = 13t where t=1

Let n = 1 P(1) = 42(1) + 1 + 3(1) + 2= 43 + 33 = 64 + 27 = 91 = 13t where t= 7

Let n = k P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13t true for some integer t

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 4: Cs6503 theory of computation book notes

CS6503 THEORY OF COMPUTATION L T P C 3 0 0 3

OBJECTIVES

The student should be made to Understand various Computing models like Finite State Machine Pushdown Automata

and Turing Machine

Be aware of Decidability and Un-decidability of various problems

Learn types of grammars

UNIT I FINITE AUTOMATA 9

Introduction- Basic Mathematical Notation and techniques- Finite State systems ndash Basic Definitions ndash Finite Automaton ndash DFA amp NDFA ndash Finite Automaton with euro- moves ndash Regular Languages- Regular Expression ndash Equivalence of NFA and DFA ndash Equivalence of NDFA‟s with and without euro-moves ndash Equivalence of finite Automaton and regular expressions ndashMinimization of DFA- - Pumping Lemma for Regular sets ndash Problems based on Pumping Lemma UNIT II GRAMMARS 9

Grammar Introductionndash Types of Grammar - Context Free Grammars and Languagesndash Derivations and Languages ndash Ambiguity- Relationship between derivation and derivation trees ndash Simplification of CFG ndash Elimination of Useless symbols - Unit productions - Null productions ndash Greiback Normal form ndash Chomsky normal form ndash Problems related to CNF and GNF UNIT III PUSHDOWN AUTOMATA 9

Pushdown Automata- Definitions ndash Moves ndash Instantaneous descriptions ndash Deterministic pushdown automata ndash Equivalence of Pushdown automata and CFL - pumping lemma for CFL ndash problems based on pumping Lemma

UNIT IV TURING MACHINES 9

Definitions of Turing machines ndash Models ndash Computable languages and functions ndashTechniques for Turing machine construction ndash Multi head and Multi tape Turing Machines - The Halting problem ndash Partial Solvability ndash Problems about Turing machine- Chomskian hierarchy of languages UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS 9

Unsolvable Problems and Computable Functions ndash Primitive recursive functions ndash Recursive and recursively enumerable languages ndash Universal Turing machine MEASURING AND CLASSIFYING COMPLEXITY Tractable and Intractable problems- Tractable and possibly intractable problems - P and NP completeness - Polynomial time reductions

TOTAL 45 PERIODS

TEXT BOOKS 1 Hopcroft JE Motwani R and Ullman JD ldquoIntroduction to Automata Theory Languages and

Computationsrdquo Second Edition Pearson Education 2008 (UNIT 123)

2 John C Martin ldquoIntroduction to Languages and the Theory of Computationrdquo Third Edition Tata McGraw Hill Publishing Company New Delhi 2007 (UNIT 45)

REFERENCES 1 Mishra K L P and Chandrasekaran N ldquoTheory of Computer Science - Automata Languages and

Computationrdquo Third Edition Prentice Hall of India 2004

2 Harry R Lewis and Christos H Papadimitriou ldquoElements of the Theory of Computationrdquo Second Edition Prentice Hall of India Pearson Education New Delhi 2003

3 Peter Linz ldquoAn Introduction to Formal Language and Automatardquo Third Edition Narosa Publishers New Delhi 2002

4 Kamala Krithivasan and Rama R ldquoIntroduction to Formal Languages Automata Theory and Computationrdquo Pearson Education 2009

TABLE OF CONTENTS

S No Contents Page no

UNIT I FINITE AUTOMATA

1 Introduction - Basic Mathematical Notation and techniques

2 Finite State systems - Basic Definitions Finite Automaton

3 DFA amp NDFA

4 Finite Automaton with ε- moves

5 Regular Languages - Regular Expression

6 Equivalence of NFA and DFA

Equivalence of NDFArsquos with and without ε - moves

7 Equivalence of finite Automaton and regular expressions

8 Minimization of DFA

9 Pumping Lemma for Regular sets

10 Problems based on Pumping Lemma

UNIT II GRAMMARS

1 Grammar Introduction - Types of Grammar

2 Context Free Grammars and Languages

3 Derivations and Languages Ambiguity

4 Relationship between derivation and derivation trees

5 Simplification of CFG

6 Elimination of Useless symbols

Unit productions - Null productions

7 Greiback Normal form

8 Chomsky normal form

9 Problems related to CNF and GNF

UNIT III PUSHDOWN AUTOMATA

1 Pushdown Automata

2 Definitions

3 Moves

4 Instantaneous descriptions

5 Deterministic pushdown automata

6 Equivalence of PDA and CFL

7 Pumping lemma for CFL

8 Problems based on pumping Lemma

UNIT V TURING MACHINES

1 Definitions of Turing machines

2 Models

3 Computable languages and functions

4 Techniques for Turing machine Construction

5 Multi head and Multi tape Turing Machines

6 The Halting problem

7 Partial Solvability

8 Problems about Turing machine

9 Chomskian hierarchy of languages

UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE

FUNCTIONS

1 Unsolvable Problems and Computable Functions

2 Primitive recursive functions

3 Recursive and recursively enumerable languages

4 Universal Turing machine

5 Measuring and classifying complexity

6 Tractable and Intractable problems

7 Tractable and possibly intractable problems

8 P and NP completeness

9 Polynomial time reductions

2 Marks Questions and Answers 74

Question Bank 100

Model Question paper 105

References 107

Theory of Computation 1

THEORY OF COMPUTATION

UNIT I - AUTOMATA

The theory of computation is the branch that deals with whether and how efficiently problems can be solved on a model of computation using an algorithm The field is divided into three major branches automata theory computability theory and computational complexity theory 11 Introduction to formal proof Formal Proofs are the proofs in which we try to prove the statement lsquoBrsquo is true because statement lsquoArsquo is true In other words the Statement ldquoIf A then Brdquo means that B is deduced from A In this statement A is called hypothesis and B is called conclusion statement The formal proofs can be done by deductive proof and inductive proof

111 Deductive Proof It consists of a sequence of statements given with logical reasoning in order to prove the first (or initial) statement The first statement is called hypothesis

112 Inductive Proof It is a recursive kind of proof which consists of sequence of parameterized statements that cure statement itself with lower values of its parameters 113 Additional forms of Proofs

I Proofs about sets II Proofs by contradiction III Proofs by counter example

Proofs about sets Set is a collection of elements or items Let us consider two sets A and B Define the expression R as union of A and B (ie AUB) and S as union of B and A (ie BUA) where U is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B Prove that R=S(ie x is in R if and only if it is in S) Proof To prove R=S we have to prove AUB=BUA (i)x is in AUB then it is in BUA

Sl No Statement Justification

1 x is in AUB Given

2 x is in Aor x is in B By definition of union amp (1)

3 x is in B or x is in A By definition of union amp (2)

4 x is in BUA By definition of union amp (3)

(i) x is in BUA then it is in AUB

Sl No Statement Justification

1 x is in BUA Given

Theory of Computation 2

2 x is in B or x is in A By definition of union amp (1)

3 x is in Aor x is in B By definition of union amp (2)

4 x is in AUB By definition of union amp (3)

So AUB=BUA Thus R=S is true Hence proved Proofs by contradiction

In proof by contradiction to prove the statement of the form ldquoif A true then B truerdquo We start with statement A is not true by assumption and try to get the conclusion statement B When it impossible to reach B then we contradict our self and accept that A is true Example Prove PUQ = QUP Proof Initially assume PUQ = QUP is not true ie PUQ ne QUP Now consider x is in PUQ x is in P or x is in Q (By Definition of Union) x is in Q or x is in P (By Definition of Union) x is in QUP (By Definition of Union) This contradicts our assumption PUQ ne QUP Hence the assumption which we made initially is false Therefore PUQ = QUP is proved Proofs by counter example In order to prove certain statements we need to check all the possible conditions in which that statement remains true There are some situations in which the statement cannot be true Example 1 There is no pair of integers a and b such that amod b = b mod a Proof There are two possibilities They are either agtb or altb If a=2 and b=3 then 2 mod 3 ne 3 mod 2 If a=3 and b=2 then 3 mod 2 ne 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2 so the given statement is true only if a=b so we have to change the statement slightly Thus amod b = b mod a true only when a=b We proved by counter example this type of proof is called proof by counter example Such proof are true only at specific conditions Example 2 All primes are odd numbers 2 3 5 7 1 13 17 23 are prime numbers and all are odd numbers except 2 The integer 2 is prime but not odd so the statement is not a theorem Example 1 Prove that every integer n ge 0 the number 42n + 1 + 3n + 2 is multiple of 13 by induction

Proof Let n= 0 P(0) = 42(0) + 1 + 3(0) + 2= 41 + 32= 4 + 9 = 13 = 13t where t=1

Let n = 1 P(1) = 42(1) + 1 + 3(1) + 2= 43 + 33 = 64 + 27 = 91 = 13t where t= 7

Let n = k P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13t true for some integer t

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 5: Cs6503 theory of computation book notes

TABLE OF CONTENTS

S No Contents Page no

UNIT I FINITE AUTOMATA

1 Introduction - Basic Mathematical Notation and techniques

2 Finite State systems - Basic Definitions Finite Automaton

3 DFA amp NDFA

4 Finite Automaton with ε- moves

5 Regular Languages - Regular Expression

6 Equivalence of NFA and DFA

Equivalence of NDFArsquos with and without ε - moves

7 Equivalence of finite Automaton and regular expressions

8 Minimization of DFA

9 Pumping Lemma for Regular sets

10 Problems based on Pumping Lemma

UNIT II GRAMMARS

1 Grammar Introduction - Types of Grammar

2 Context Free Grammars and Languages

3 Derivations and Languages Ambiguity

4 Relationship between derivation and derivation trees

5 Simplification of CFG

6 Elimination of Useless symbols

Unit productions - Null productions

7 Greiback Normal form

8 Chomsky normal form

9 Problems related to CNF and GNF

UNIT III PUSHDOWN AUTOMATA

1 Pushdown Automata

2 Definitions

3 Moves

4 Instantaneous descriptions

5 Deterministic pushdown automata

6 Equivalence of PDA and CFL

7 Pumping lemma for CFL

8 Problems based on pumping Lemma

UNIT V TURING MACHINES

1 Definitions of Turing machines

2 Models

3 Computable languages and functions

4 Techniques for Turing machine Construction

5 Multi head and Multi tape Turing Machines

6 The Halting problem

7 Partial Solvability

8 Problems about Turing machine

9 Chomskian hierarchy of languages

UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE

FUNCTIONS

1 Unsolvable Problems and Computable Functions

2 Primitive recursive functions

3 Recursive and recursively enumerable languages

4 Universal Turing machine

5 Measuring and classifying complexity

6 Tractable and Intractable problems

7 Tractable and possibly intractable problems

8 P and NP completeness

9 Polynomial time reductions

2 Marks Questions and Answers 74

Question Bank 100

Model Question paper 105

References 107

Theory of Computation 1

THEORY OF COMPUTATION

UNIT I - AUTOMATA

The theory of computation is the branch that deals with whether and how efficiently problems can be solved on a model of computation using an algorithm The field is divided into three major branches automata theory computability theory and computational complexity theory 11 Introduction to formal proof Formal Proofs are the proofs in which we try to prove the statement lsquoBrsquo is true because statement lsquoArsquo is true In other words the Statement ldquoIf A then Brdquo means that B is deduced from A In this statement A is called hypothesis and B is called conclusion statement The formal proofs can be done by deductive proof and inductive proof

111 Deductive Proof It consists of a sequence of statements given with logical reasoning in order to prove the first (or initial) statement The first statement is called hypothesis

112 Inductive Proof It is a recursive kind of proof which consists of sequence of parameterized statements that cure statement itself with lower values of its parameters 113 Additional forms of Proofs

I Proofs about sets II Proofs by contradiction III Proofs by counter example

Proofs about sets Set is a collection of elements or items Let us consider two sets A and B Define the expression R as union of A and B (ie AUB) and S as union of B and A (ie BUA) where U is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B Prove that R=S(ie x is in R if and only if it is in S) Proof To prove R=S we have to prove AUB=BUA (i)x is in AUB then it is in BUA

Sl No Statement Justification

1 x is in AUB Given

2 x is in Aor x is in B By definition of union amp (1)

3 x is in B or x is in A By definition of union amp (2)

4 x is in BUA By definition of union amp (3)

(i) x is in BUA then it is in AUB

Sl No Statement Justification

1 x is in BUA Given

Theory of Computation 2

2 x is in B or x is in A By definition of union amp (1)

3 x is in Aor x is in B By definition of union amp (2)

4 x is in AUB By definition of union amp (3)

So AUB=BUA Thus R=S is true Hence proved Proofs by contradiction

In proof by contradiction to prove the statement of the form ldquoif A true then B truerdquo We start with statement A is not true by assumption and try to get the conclusion statement B When it impossible to reach B then we contradict our self and accept that A is true Example Prove PUQ = QUP Proof Initially assume PUQ = QUP is not true ie PUQ ne QUP Now consider x is in PUQ x is in P or x is in Q (By Definition of Union) x is in Q or x is in P (By Definition of Union) x is in QUP (By Definition of Union) This contradicts our assumption PUQ ne QUP Hence the assumption which we made initially is false Therefore PUQ = QUP is proved Proofs by counter example In order to prove certain statements we need to check all the possible conditions in which that statement remains true There are some situations in which the statement cannot be true Example 1 There is no pair of integers a and b such that amod b = b mod a Proof There are two possibilities They are either agtb or altb If a=2 and b=3 then 2 mod 3 ne 3 mod 2 If a=3 and b=2 then 3 mod 2 ne 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2 so the given statement is true only if a=b so we have to change the statement slightly Thus amod b = b mod a true only when a=b We proved by counter example this type of proof is called proof by counter example Such proof are true only at specific conditions Example 2 All primes are odd numbers 2 3 5 7 1 13 17 23 are prime numbers and all are odd numbers except 2 The integer 2 is prime but not odd so the statement is not a theorem Example 1 Prove that every integer n ge 0 the number 42n + 1 + 3n + 2 is multiple of 13 by induction

Proof Let n= 0 P(0) = 42(0) + 1 + 3(0) + 2= 41 + 32= 4 + 9 = 13 = 13t where t=1

Let n = 1 P(1) = 42(1) + 1 + 3(1) + 2= 43 + 33 = 64 + 27 = 91 = 13t where t= 7

Let n = k P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13t true for some integer t

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 6: Cs6503 theory of computation book notes

8 Chomsky normal form

9 Problems related to CNF and GNF

UNIT III PUSHDOWN AUTOMATA

1 Pushdown Automata

2 Definitions

3 Moves

4 Instantaneous descriptions

5 Deterministic pushdown automata

6 Equivalence of PDA and CFL

7 Pumping lemma for CFL

8 Problems based on pumping Lemma

UNIT V TURING MACHINES

1 Definitions of Turing machines

2 Models

3 Computable languages and functions

4 Techniques for Turing machine Construction

5 Multi head and Multi tape Turing Machines

6 The Halting problem

7 Partial Solvability

8 Problems about Turing machine

9 Chomskian hierarchy of languages

UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE

FUNCTIONS

1 Unsolvable Problems and Computable Functions

2 Primitive recursive functions

3 Recursive and recursively enumerable languages

4 Universal Turing machine

5 Measuring and classifying complexity

6 Tractable and Intractable problems

7 Tractable and possibly intractable problems

8 P and NP completeness

9 Polynomial time reductions

2 Marks Questions and Answers 74

Question Bank 100

Model Question paper 105

References 107

Theory of Computation 1

THEORY OF COMPUTATION

UNIT I - AUTOMATA

The theory of computation is the branch that deals with whether and how efficiently problems can be solved on a model of computation using an algorithm The field is divided into three major branches automata theory computability theory and computational complexity theory 11 Introduction to formal proof Formal Proofs are the proofs in which we try to prove the statement lsquoBrsquo is true because statement lsquoArsquo is true In other words the Statement ldquoIf A then Brdquo means that B is deduced from A In this statement A is called hypothesis and B is called conclusion statement The formal proofs can be done by deductive proof and inductive proof

111 Deductive Proof It consists of a sequence of statements given with logical reasoning in order to prove the first (or initial) statement The first statement is called hypothesis

112 Inductive Proof It is a recursive kind of proof which consists of sequence of parameterized statements that cure statement itself with lower values of its parameters 113 Additional forms of Proofs

I Proofs about sets II Proofs by contradiction III Proofs by counter example

Proofs about sets Set is a collection of elements or items Let us consider two sets A and B Define the expression R as union of A and B (ie AUB) and S as union of B and A (ie BUA) where U is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B Prove that R=S(ie x is in R if and only if it is in S) Proof To prove R=S we have to prove AUB=BUA (i)x is in AUB then it is in BUA

Sl No Statement Justification

1 x is in AUB Given

2 x is in Aor x is in B By definition of union amp (1)

3 x is in B or x is in A By definition of union amp (2)

4 x is in BUA By definition of union amp (3)

(i) x is in BUA then it is in AUB

Sl No Statement Justification

1 x is in BUA Given

Theory of Computation 2

2 x is in B or x is in A By definition of union amp (1)

3 x is in Aor x is in B By definition of union amp (2)

4 x is in AUB By definition of union amp (3)

So AUB=BUA Thus R=S is true Hence proved Proofs by contradiction

In proof by contradiction to prove the statement of the form ldquoif A true then B truerdquo We start with statement A is not true by assumption and try to get the conclusion statement B When it impossible to reach B then we contradict our self and accept that A is true Example Prove PUQ = QUP Proof Initially assume PUQ = QUP is not true ie PUQ ne QUP Now consider x is in PUQ x is in P or x is in Q (By Definition of Union) x is in Q or x is in P (By Definition of Union) x is in QUP (By Definition of Union) This contradicts our assumption PUQ ne QUP Hence the assumption which we made initially is false Therefore PUQ = QUP is proved Proofs by counter example In order to prove certain statements we need to check all the possible conditions in which that statement remains true There are some situations in which the statement cannot be true Example 1 There is no pair of integers a and b such that amod b = b mod a Proof There are two possibilities They are either agtb or altb If a=2 and b=3 then 2 mod 3 ne 3 mod 2 If a=3 and b=2 then 3 mod 2 ne 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2 so the given statement is true only if a=b so we have to change the statement slightly Thus amod b = b mod a true only when a=b We proved by counter example this type of proof is called proof by counter example Such proof are true only at specific conditions Example 2 All primes are odd numbers 2 3 5 7 1 13 17 23 are prime numbers and all are odd numbers except 2 The integer 2 is prime but not odd so the statement is not a theorem Example 1 Prove that every integer n ge 0 the number 42n + 1 + 3n + 2 is multiple of 13 by induction

Proof Let n= 0 P(0) = 42(0) + 1 + 3(0) + 2= 41 + 32= 4 + 9 = 13 = 13t where t=1

Let n = 1 P(1) = 42(1) + 1 + 3(1) + 2= 43 + 33 = 64 + 27 = 91 = 13t where t= 7

Let n = k P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13t true for some integer t

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 7: Cs6503 theory of computation book notes

2 Primitive recursive functions

3 Recursive and recursively enumerable languages

4 Universal Turing machine

5 Measuring and classifying complexity

6 Tractable and Intractable problems

7 Tractable and possibly intractable problems

8 P and NP completeness

9 Polynomial time reductions

2 Marks Questions and Answers 74

Question Bank 100

Model Question paper 105

References 107

Theory of Computation 1

THEORY OF COMPUTATION

UNIT I - AUTOMATA

The theory of computation is the branch that deals with whether and how efficiently problems can be solved on a model of computation using an algorithm The field is divided into three major branches automata theory computability theory and computational complexity theory 11 Introduction to formal proof Formal Proofs are the proofs in which we try to prove the statement lsquoBrsquo is true because statement lsquoArsquo is true In other words the Statement ldquoIf A then Brdquo means that B is deduced from A In this statement A is called hypothesis and B is called conclusion statement The formal proofs can be done by deductive proof and inductive proof

111 Deductive Proof It consists of a sequence of statements given with logical reasoning in order to prove the first (or initial) statement The first statement is called hypothesis

112 Inductive Proof It is a recursive kind of proof which consists of sequence of parameterized statements that cure statement itself with lower values of its parameters 113 Additional forms of Proofs

I Proofs about sets II Proofs by contradiction III Proofs by counter example

Proofs about sets Set is a collection of elements or items Let us consider two sets A and B Define the expression R as union of A and B (ie AUB) and S as union of B and A (ie BUA) where U is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B Prove that R=S(ie x is in R if and only if it is in S) Proof To prove R=S we have to prove AUB=BUA (i)x is in AUB then it is in BUA

Sl No Statement Justification

1 x is in AUB Given

2 x is in Aor x is in B By definition of union amp (1)

3 x is in B or x is in A By definition of union amp (2)

4 x is in BUA By definition of union amp (3)

(i) x is in BUA then it is in AUB

Sl No Statement Justification

1 x is in BUA Given

Theory of Computation 2

2 x is in B or x is in A By definition of union amp (1)

3 x is in Aor x is in B By definition of union amp (2)

4 x is in AUB By definition of union amp (3)

So AUB=BUA Thus R=S is true Hence proved Proofs by contradiction

In proof by contradiction to prove the statement of the form ldquoif A true then B truerdquo We start with statement A is not true by assumption and try to get the conclusion statement B When it impossible to reach B then we contradict our self and accept that A is true Example Prove PUQ = QUP Proof Initially assume PUQ = QUP is not true ie PUQ ne QUP Now consider x is in PUQ x is in P or x is in Q (By Definition of Union) x is in Q or x is in P (By Definition of Union) x is in QUP (By Definition of Union) This contradicts our assumption PUQ ne QUP Hence the assumption which we made initially is false Therefore PUQ = QUP is proved Proofs by counter example In order to prove certain statements we need to check all the possible conditions in which that statement remains true There are some situations in which the statement cannot be true Example 1 There is no pair of integers a and b such that amod b = b mod a Proof There are two possibilities They are either agtb or altb If a=2 and b=3 then 2 mod 3 ne 3 mod 2 If a=3 and b=2 then 3 mod 2 ne 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2 so the given statement is true only if a=b so we have to change the statement slightly Thus amod b = b mod a true only when a=b We proved by counter example this type of proof is called proof by counter example Such proof are true only at specific conditions Example 2 All primes are odd numbers 2 3 5 7 1 13 17 23 are prime numbers and all are odd numbers except 2 The integer 2 is prime but not odd so the statement is not a theorem Example 1 Prove that every integer n ge 0 the number 42n + 1 + 3n + 2 is multiple of 13 by induction

Proof Let n= 0 P(0) = 42(0) + 1 + 3(0) + 2= 41 + 32= 4 + 9 = 13 = 13t where t=1

Let n = 1 P(1) = 42(1) + 1 + 3(1) + 2= 43 + 33 = 64 + 27 = 91 = 13t where t= 7

Let n = k P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13t true for some integer t

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 8: Cs6503 theory of computation book notes

Theory of Computation 1

THEORY OF COMPUTATION

UNIT I - AUTOMATA

The theory of computation is the branch that deals with whether and how efficiently problems can be solved on a model of computation using an algorithm The field is divided into three major branches automata theory computability theory and computational complexity theory 11 Introduction to formal proof Formal Proofs are the proofs in which we try to prove the statement lsquoBrsquo is true because statement lsquoArsquo is true In other words the Statement ldquoIf A then Brdquo means that B is deduced from A In this statement A is called hypothesis and B is called conclusion statement The formal proofs can be done by deductive proof and inductive proof

111 Deductive Proof It consists of a sequence of statements given with logical reasoning in order to prove the first (or initial) statement The first statement is called hypothesis

112 Inductive Proof It is a recursive kind of proof which consists of sequence of parameterized statements that cure statement itself with lower values of its parameters 113 Additional forms of Proofs

I Proofs about sets II Proofs by contradiction III Proofs by counter example

Proofs about sets Set is a collection of elements or items Let us consider two sets A and B Define the expression R as union of A and B (ie AUB) and S as union of B and A (ie BUA) where U is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B Prove that R=S(ie x is in R if and only if it is in S) Proof To prove R=S we have to prove AUB=BUA (i)x is in AUB then it is in BUA

Sl No Statement Justification

1 x is in AUB Given

2 x is in Aor x is in B By definition of union amp (1)

3 x is in B or x is in A By definition of union amp (2)

4 x is in BUA By definition of union amp (3)

(i) x is in BUA then it is in AUB

Sl No Statement Justification

1 x is in BUA Given

Theory of Computation 2

2 x is in B or x is in A By definition of union amp (1)

3 x is in Aor x is in B By definition of union amp (2)

4 x is in AUB By definition of union amp (3)

So AUB=BUA Thus R=S is true Hence proved Proofs by contradiction

In proof by contradiction to prove the statement of the form ldquoif A true then B truerdquo We start with statement A is not true by assumption and try to get the conclusion statement B When it impossible to reach B then we contradict our self and accept that A is true Example Prove PUQ = QUP Proof Initially assume PUQ = QUP is not true ie PUQ ne QUP Now consider x is in PUQ x is in P or x is in Q (By Definition of Union) x is in Q or x is in P (By Definition of Union) x is in QUP (By Definition of Union) This contradicts our assumption PUQ ne QUP Hence the assumption which we made initially is false Therefore PUQ = QUP is proved Proofs by counter example In order to prove certain statements we need to check all the possible conditions in which that statement remains true There are some situations in which the statement cannot be true Example 1 There is no pair of integers a and b such that amod b = b mod a Proof There are two possibilities They are either agtb or altb If a=2 and b=3 then 2 mod 3 ne 3 mod 2 If a=3 and b=2 then 3 mod 2 ne 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2 so the given statement is true only if a=b so we have to change the statement slightly Thus amod b = b mod a true only when a=b We proved by counter example this type of proof is called proof by counter example Such proof are true only at specific conditions Example 2 All primes are odd numbers 2 3 5 7 1 13 17 23 are prime numbers and all are odd numbers except 2 The integer 2 is prime but not odd so the statement is not a theorem Example 1 Prove that every integer n ge 0 the number 42n + 1 + 3n + 2 is multiple of 13 by induction

Proof Let n= 0 P(0) = 42(0) + 1 + 3(0) + 2= 41 + 32= 4 + 9 = 13 = 13t where t=1

Let n = 1 P(1) = 42(1) + 1 + 3(1) + 2= 43 + 33 = 64 + 27 = 91 = 13t where t= 7

Let n = k P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13t true for some integer t

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 9: Cs6503 theory of computation book notes

Theory of Computation 2

2 x is in B or x is in A By definition of union amp (1)

3 x is in Aor x is in B By definition of union amp (2)

4 x is in AUB By definition of union amp (3)

So AUB=BUA Thus R=S is true Hence proved Proofs by contradiction

In proof by contradiction to prove the statement of the form ldquoif A true then B truerdquo We start with statement A is not true by assumption and try to get the conclusion statement B When it impossible to reach B then we contradict our self and accept that A is true Example Prove PUQ = QUP Proof Initially assume PUQ = QUP is not true ie PUQ ne QUP Now consider x is in PUQ x is in P or x is in Q (By Definition of Union) x is in Q or x is in P (By Definition of Union) x is in QUP (By Definition of Union) This contradicts our assumption PUQ ne QUP Hence the assumption which we made initially is false Therefore PUQ = QUP is proved Proofs by counter example In order to prove certain statements we need to check all the possible conditions in which that statement remains true There are some situations in which the statement cannot be true Example 1 There is no pair of integers a and b such that amod b = b mod a Proof There are two possibilities They are either agtb or altb If a=2 and b=3 then 2 mod 3 ne 3 mod 2 If a=3 and b=2 then 3 mod 2 ne 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2 so the given statement is true only if a=b so we have to change the statement slightly Thus amod b = b mod a true only when a=b We proved by counter example this type of proof is called proof by counter example Such proof are true only at specific conditions Example 2 All primes are odd numbers 2 3 5 7 1 13 17 23 are prime numbers and all are odd numbers except 2 The integer 2 is prime but not odd so the statement is not a theorem Example 1 Prove that every integer n ge 0 the number 42n + 1 + 3n + 2 is multiple of 13 by induction

Proof Let n= 0 P(0) = 42(0) + 1 + 3(0) + 2= 41 + 32= 4 + 9 = 13 = 13t where t=1

Let n = 1 P(1) = 42(1) + 1 + 3(1) + 2= 43 + 33 = 64 + 27 = 91 = 13t where t= 7

Let n = k P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13t true for some integer t

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 10: Cs6503 theory of computation book notes

Theory of Computation 3

Let n = k + 1 P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2

= 42(k + 1) + 1 + 3(k + 1) + 2

= 42k + 2 + 1 + 3k + 1 + 2

= 42k + 1 + 2 + 3k + 2 + 1

= 42k + 142 + 3k + 231

= 4242k + 1 + 33k + 2

= 4242k + 1 + 423k+2 - 423k+2 + 33k + 2 Add amp Sub 423k+2

= 42(42k + 1 + 3k+2 ) + 3k+2 (-42+ 3)

= 42(13t)- 3k+2 (-42+ 3) 42k + 1 + 3k + 2 = 13t

= 16 (13t)- 3k+2 (-13)

= 13[16 t + 3k+2 ]

= Multiple of 13

P(k + 1) is multiple of 13 Hence proved

Example 2

Prove 1 + 2 + 3 + hellip + n = n (n+1)2 using induction method Proof Let n = 1 then LHS = 1 and RHS = 1 (1 + 1) 2 = 1 LHS = RHS Let n = 2 then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) 2 = 3 LHS = RHS Let n = k 1 + 2 + 3 + hellip + k = k (k+1)2 Consider n = k +1 then LHS = 1 + 2 + 3 + hellip + k + (k+1) = (k+1) (k+2) 2 RHS = k (k+1)2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) 2 = (k+1) (k+2) 2 LHS = RHS Hence Proved

Example 3 Show that 2ngt n3 for n ge 10 by mathematical induction

Proof

Let n= 10 210gt 103 1024 gt 1000 The condition is true

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 11: Cs6503 theory of computation book notes

Theory of Computation 4

Let n= 11 211gt 113 2048 gt 1331 The condition is true

Let n = 12 212gt 123 4096 gt 1728 The condition is true

Let n = k 2kgt k3 Assume the condition is true for k

Let n = k +1 2k+1 = 2k2 1

= 2k2 1

gt k32 1

2k+1 gt k32 1

Let k =12 in above inequality LHS = 212+1

= 213 = 8192

RHS = 1232 = 3456

LHS RHS Hence Proved

Example 4 Show that n gt= 2n - 1 by mathematical induction

Proof

Let n = 1 LHS = 1 = 1 RHS = 21 - 1 = 20 = 1

LHS gt= RHS

Let n = 2 LHS = 2 = 21 = 2 RHS = 22 - 1 = 21 = 2

LHS gt= RHS

Let n = 3 LHS = 3 = 3 21 = 6 RHS = 23 - 1 = 24 = 4

LHS gt= RHS

Let n = k k gt= 2k ndash 1

Let n = k + 1 (k + 1)= (k + 1) k

gt=(k + 1) 2k ndash 1

(k + 1)gt=(k + 1) 2k ndash 1

Let k=2 LHS = (2+1) = 3 =6

RHS = (2+1)2 2- 1 =32 = 6

LHS RHS Hence Proved

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 12: Cs6503 theory of computation book notes

Theory of Computation 5

Example 4

Prove by mathematical induction Ʃn2 = + + for all n ge 1

Proof

12 + 22 + + n2 = + +

Let n = 1 LHS = 12= 1 RHS = + +

= 119909 119909

= 1 LHS = RHS

Let n = 2 LHS = 12 + 22= 1 + 4 = 5 RHS = + +

= 119909 119909

= 5 LHS = RHS

Let n = k 12 + 22 + + k2= + +

assumed to be true

Let n = k+1 LHS = 12 + 22 + + k2+ (k + 1)2

= + +

+ (k + 1)2

= + +

+ (k + 1) (k +1)

= + +

+ + +

= + + + + +

= + [ + + + ]

= + ( 2+ + + )

= + ( 2+ + )

= + + +

RHS = + + + [ + ]+

= + + + +

= + + +

LHS = RHS Hence Proved

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 13: Cs6503 theory of computation book notes

Theory of Computation 6

Alphabets Strings and language

Alphabet

An alphabet is a finite non empty set of symbols The symbol Σ is used to denote the

alphabet

1) Σ = 0 1 2) Σ = a b c hellip z 3) Σ = Set of ASII character

String

A string is a finite sequence of symbols chosen from some alphabet

1) Σ =01 11001 [ Empty string is denoted by ] 2) Σ = a b c aabbcbbbaa

The total number of symbols in the string is called length of the string

Example

1) |0001|=4

2) |100|=3

Empty string ( )

Empty string is the string with zero occurrence of symbol This empty string is denote

by

Power of an alphabet

If Σ is an alphabet then the set of all string of certain length forms an alphabet

Σk to be the set of string of length k for each symbol in Σ

Example

sum = 0 1 sum = sum = 0 1 sum = 00 01 10 11 sum = 000 001 010 011 100 101 110 111

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 14: Cs6503 theory of computation book notes

Theory of Computation 7

sum + = sum 119880 sum 119880 sum hellip sum + = sum ⋃ infin= sum lowast = sum 119880 sum 119880 sum 119880 hellip sum lowast = sum ⋃ infin=

Set of all strings over an alphabet is denoted by sum lowast

Set of all strings over an alphabet except null string is denoted by sum +

Concatination of strings

Let X and Y be the two strings over Σ = a b c Then XY denotes the concatenation

of X and Y

X = aabb

Y = cccc

XY = aabbcccc

YX = ccccaabb

Language [Language is a collection of all strings]

A set of strings of all which are chosen from sum lowast is called a language where sum is a

particular alphabet set

Finite state system (or) finite automata

A finite automata has a several parts It has set of states and rules for moving from

one state to another state depending on the input symbols

It has the input alphabet start state and a set of accept state

Definition of finite automata

A finite automata is a collection of 5-tuples A = (Q sum q0 F)

Where A Name of the finite automata

Q Finite set of states [non-empty]

sum The set of input symbols [input set]

The transition function [Move from one state to another ] Qx ΣQ

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 15: Cs6503 theory of computation book notes

Theory of Computation 8

q0

q1 q

2 q

3

1 1 Start 1

q0

q1 q

3

0 1 Start

0 1

0

q0 Initial or start state q

0isinQ

F Set of all final states

Types of finite automata (FA)

Deterministic finite automata (DFA)

Non deterministic finite automat (NFA)

Transition diagram

Transition diagram for a DFA A = (Q sum q0 F) is a graph define as follows

o For each state q in Q there is a node

o For each state q in Q and each input symbol a in sum then the transition

diagram has an arc from node q to node p

Transition table

A transition table is a conventional table represent of a function like in finite automata That takes two argument and return a value The rows of the table correspond to

the state and column corresponds to the input symbols

Deterministic finite automata

Finite automata are called Deterministic automata if there is only one path for its

specified input from current state to next state

Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ = 1

Solution

Example 2 Design FA which accepts only those strings which start with 0 and end with 1

over the input set Σ = 0 1

Solution

a b c a a b c a Input tape

Finite control

Tape head

reader

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 16: Cs6503 theory of computation book notes

Theory of Computation 9

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q2 1 1

Start

1

1

Input

0

q0 q

1

q

1 q

1

q

2 q

3

1

q2

q2

q

1

States

q3 q

2

q3

q0

q2 0

0

Start

1

1 q1

q3

0

0

1 1 0

q0

q1

q2

0

1

Start

0

0

1 1

Example 3 Design FA amp State Table which accepts odd number of 1rsquos and any number of

0rsquos

State Transition Diagram State Transition Table

FA A = (Q sum q0 F)

= (q0 q1 q2 0 1 (q0 0)= q1 (q0 1)= q2 (q1 0)= q1 (q1 1)= q2 (q2 0)=

q2 (q2 1)= q1 q0 q2)

Check 0110 amp 1110

q00110 0q

1110 01q

210 011q

10 0110q

1 Reached non final state not accepted

q01110 1q

2110 11q

110 111q

20 1110q

2Reached final state string accepted

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = 1

Check 111 amp 1111

q0111 1q

111 11q

21 111q

3 Reached final state String accepted

q01111 1q

1111 11q

211 111q

31 1111q

1 Reached non final state not accepted

Example5 Design FA amp State Table which accepts the binary number which is divisible by 3

State Transition Diagram State Transition Table

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 17: Cs6503 theory of computation book notes

Theory of Computation 10

Input a

s0 s

1

s

1 s

2

s3

s1

b

s0

s3

States

s2 s

3

b

s0

s2 s

3 a a s

1

a

b

a

Input

0

q0 q

1

q

1 q

1

q

2 q

2

1

q2

q2

q

1

States

q0

q2

q1

0

Start

0

1

0 1

1

q0

q0

q0

b a

b

b

rt Start

Start

Check 9 amp 8 (ie 1001 amp1000 )

q01001 1q

2001 10q

301 100q

2 1 1001q

1 Reached final state String accepted

q01000 1q

2000 10q

300 100q

20 1000q

3 non final state not accepted

Example 6 Design FA to accept L where L= Strings in which lsquoarsquo always appears tripled

over the input set Σ = a b

Example 7 Design FA which checks the given binary number is even

State Transition Diagram

State Transition Table

Check 6 amp 7 (ie 0110 amp 0111)

q00110 0q

1110 01q

210 011q

20 0110q

1 Reached final state string accepted

q00111 0q

1111 01q

211 011q

21 0111q

2 Reached non final state not accepted

Non deterministic automata

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 18: Cs6503 theory of computation book notes

Theory of Computation 11

q1 q

3 q

4

0 01 Start q

2 1

q6

0

0

0

q5

1

q2

1

Start

1

0

0

0

0

q1

0

0

1

q3

Finite automata is also called as non deterministic automata when many paths are

specified in code from the current state to next state

NFA can be defined as the collection of five tuple

A =Q sum qo F

Example 1 construct NFA where L=0101 + 0100 n ge 0 over the string sum=01

Example 2 construct the transmission diagram for NFA where

M=( q1 q2 q3 01 q1 q3 )

Where is given by

rsquo(q1 0) = q2 q3 rsquo(q1 1)= q1

rsquo(q2 0) = q1 q2 rsquo(q2 1)= ɸ

rsquo(q3 0) = q2 rsquo(q3 1)= q1 q2

sol

Stateip 0 1

q1 q

2 ɸ

q2 ɸ q

3

q3 q

4 q

5 ɸ

q4 ɸ q

4

q5 q

6 ɸ

q6 ɸ ɸ

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 19: Cs6503 theory of computation book notes

Theory of Computation 12

NFA with Epsilon transition

The transition in NFA is given in order to move from one state to another without

having any symbol from input

state 0 1

q1 q2 q3 q1

q2 q1 q2 ɸ

q3 q2 q1 q2

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 20: Cs6503 theory of computation book notes

Theory of Computation 13

q0

q

q2 Start q

1

q

b c

a

q0

q2

Start q

1

b

a

Definition

The language L is accepted by NFA with denoted by M =Q sum qo F can be

defined as follow

Q x ( sum u ) 2Q

L(M) = ww euro sum lowast

Epsilon closure (p)

It is set of all state which are reachable from state p or epsilon transition such that

1) closure (p) =p Where p euro Q

2) If there exist -closure (p) =q and ( q ) = r then closure (p) =q r

Example 1 Find the closure for the following NFA with

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

Conversion from NFA with to NFA without

1) Find all the transition for each state from Q that will be called as closure qi

Where qi is the element of Q 2) rsquo transition can be obtained from transition ie an closure of

3) Step 2 is repeated for each input symbol and for each state of given NFA

4) Using the resultant state the transition table for equivalent NFA without can be

built

rsquo(q a) = closure( ( ^ (q ) a))

Example 1 Convert the given NFA with transition to NFA without transition

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 21: Cs6503 theory of computation book notes

Theory of Computation 14

Step 1 closure

closure (q0 )= q0

closure (q1 )= q1 q2

closure (q2 )= q2

Step 2

rsquo(q0 a) = q1 rsquo(q0 b) = ɸ rsquo (q0 ) = ɸ

rsquo(q1 a) = ɸ rsquo(q1 b) = ɸ rsquo (q1 ) = q2

rsquo(q2 a) = ɸ rsquo(q2 b) = q2 rsquo (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a))

= closure(q1)

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 ) b))

= closure( (q0 b))

= closure ɸ

= ɸ

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 )a))

= closure( (q1 q2 a))

= closure( (q1 a) U (q2 a))

= closure (ɸ U ɸ)

= closure (ɸ)

= ɸ

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 22: Cs6503 theory of computation book notes

Theory of Computation 15

q2

Start b

b

a q

2 q

2

a

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 q2 b))

= closure( (q1 b) U (q2 b))

= closure (ɸ U q2)

= closure ( q2 )

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( ( q2 a))

= closure ɸ

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

= closure( ( q2 b))

= closure (q2 )

= q2

Transition table

Step 4

Transition diagram NFA without

state a b

q0 q1 q2 ɸ

q1 ɸ q2

q2 ɸ q2

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 23: Cs6503 theory of computation book notes

Theory of Computation 16

q0

q2

Start q

1

b c

a

Example 2 Construct NFA with which access a language consisting of a string of any

number of lsquoarsquo followed by any number of lsquobrsquo and followed by any number lsquo c lsquo Convert

the NFA with to NFA without

sol

Step 1 closure

closure (q0 )= q0 q1 q2

closure (q1 )= q1 q2

closure (q2 )= q2

step 2

(q0 a) = q0 (q0 b) = ɸ (q0 c) = ɸ (q0 ) = q1

(q1 a) = ɸ (q1 b) = q1 (q1 c) = ɸ (q1 ) = q2

(q2 a) = ɸ (q2 b) = ɸ (q2 c) = q2 (q2 ) = ɸ

Step 3

rsquo(q0 a) = closure( ( ^ (q0 ) a))

= closure( ( closure (q0 ) a))

= closure( (q0 a) 119880 (q1 a) 119880 (q2 a))

= closure ( q0 Uɸ U ɸ)

= closure ( q0 )

= q0 q1 q2

rsquo(q0 b) = closure( ( ^ (q0 ) b))

= closure( ( closure (q0 )b))

= closure( (q0 b) 119880 (q1 b) 119880 (q2 b))

= closure (ɸ 119880q1 119880ɸ)

= q1 q2

rsquo(q0 c) = closure( ( ^ (q0 ) c))

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 24: Cs6503 theory of computation book notes

Theory of Computation 17

= closure( ( closure (q0 ) c))

= closure( (q0 c) 119880 (q1 c) 119880 (q2 c))

= closure (ɸ Uɸ Uq2)

= q2

rsquo(q1 a) = closure( ( ^ (q1 ) a))

= closure( ( closure (q1 ) a))

= closure( (q1 a) 119880 (q2 a))

= closure (ɸ 119880 ɸ )

= closure (ɸ)

= ɸ

rsquo(q1 b) = closure( ( ^ (q1 )b))

= closure( ( closure (q1 )b))

= closure( (q1 b) 119880 (q2 b))

= closure (q1)

= q1 q2

rsquo(q1 c) = closure( ( ^ (q1 ) c))

= closure( ( closure (q1 ) c))

= closure( (q1 c) 119880 (q2 c))

= closure (ɸ119880q2)

= q2

rsquo(q2 a) = closure( ( ^ (q2 ) a))

= closure( ( closure (q2 ) a))

= closure( (q2 a))

= closure (ɸ)

= ɸ

rsquo(q2 b) = closure( ( ^ (q2 ) b))

= closure( ( closure (q2 ) b))

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 25: Cs6503 theory of computation book notes

Theory of Computation 18

q0

q2

Start q

1

a b

a

a b

b c

b

= closure( (q2 b))

= closure (ɸ)

= ɸ

rsquo(q2c) = closure( ( ^ (q2 ) c))

= closure( ( closure (q2 ) c))

= closure( (q2 c))

= closure (q2)

= q2

Step 4

Transition table

state a b c

q0 q0 q1 q2 q1 q2 q2

q1 ɸ q1 q2 q2

q2 ɸ ɸ q2

Transition diagram

Conversion NFA to DFA

Let M=Q sum qo F is the NFA which accepts the language L(M) then there

should be equivalent DFA denoted by Mrsquo= Qrsquo sumrsquo rsquo qorsquo Frsquo such that L(M)=L(Mrsquo)

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 26: Cs6503 theory of computation book notes

Theory of Computation 19

Conversion Steps

STEP 1 The start state of NFA M will be the start state of DFA Mrsquo Hence add qo of NFA to

Qrsquo then find the transition for this start state

STEP 2 For each state q1 q2 q3helliphellipqi in Qrsquo The transition for each input symbol sum can be obtained as follows

(i) rsquo( [q1q2q3helliphellipqi] a) = (q1a ) U (q2 a)helliphellip U (qi a) = [q1 q2 q3 qk]

(ii) Add the [q1 q2 q3 qk] in DFA if it is not already in Q

(iii) Then find the transition for every input symbol from sum for states [q1 q2

q3 qk] if we get some state [q1q2hellipqn] which is not Qrsquo of DFA then add

this to Qrsquo

(iv) If there is no new state generating then stop the process after finding all

the transition

(v) For the state [q1 q2 q3 qk] euro Qrsquo of DFA if any 1 state qi is a final

state of NFA then [q1q2hellipqn] becomes a final state Thus the set of all final

states euro Frsquo of DFA

Example 1 Construct the equivalent DFA for the given NFA

M = (q0 q1 01 qo q1) where is given by

(q00) = q0 q1

(q01) = q1

(q10) = φ

(q10) = q0 q1

Sol

Transition Table (NFA)

StIp 0 1

q0 q0 q1

q1

q1 φ q0 q1

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 27: Cs6503 theory of computation book notes

Theory of Computation 20

Transition Diagram

rsquo( q0 q1 0) = (q0 0) U (q1 0)

= q0 q1 U φ

= q0 q1

rsquo( q0 q1 1) = (q01) U (q1 1)

= q1 U q0 q1

= q0 q1

Transition Table

StIp 0 1

qo q0 q1 q1

q1 φ q0 q1

q0 q1 q0 q1 q0 q1

Transition Diagram (DFA)

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 28: Cs6503 theory of computation book notes

Theory of Computation 21

ssq

q

Example 2 Construct an DFA equivalent to the given NFA

StIp 0 1

rarrp p q p

q r r

r s φ

s s s

Sol

Transition Diagram

Transition Table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

rsquo( p q 0) = ( p0) U ( q0)

= p q U r

= p q r

rsquo(p q 1) = ( p1) U ( q1)

= p U r

= p r

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 29: Cs6503 theory of computation book notes

Theory of Computation 22

q

q

New State table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

rsquo(p q r 0) = ( p0) U ( q0) U ( r0)

= p q U r U s

= p q r s

rsquo(p q r 1) = ( p1) U ( q1) U ( r1)

= p U r U φ

= p r

rsquo(p r 0) = ( p0) U ( r0)

= p q U s

= p q s

rsquo(p r 1) = ( p1) U ( r1)

= p U φ

= p

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 30: Cs6503 theory of computation book notes

Theory of Computation 23

q

p q p q r p r

p q r p q r s p r

p r p q s p

rsquo(p q r s 0) = ( p0) U ( q0) U ( r0) U ( s0)

= pq U r U s U s

= p q r s

rsquo(p q r s 1) = ( p1) U ( q1) U ( r1) U ( s1)

= p U r U φ U s

= p r s

rsquo( [pqs]0) = ( p0) U ( q0) U ( s0)

= pq U r U s

= p q r s

rsquo( [pqs]1) = ( p1) U ( q1) U ( s1)

= pq U r U s

= p q r s

New transition table

StIp 0 1

rarrP p q p

q r r

r s φ

s s s

p q p q r p r

p q r p q r s p r

p r p q s p

pqrs p q r s p r s

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 31: Cs6503 theory of computation book notes

Theory of Computation 24

q2

pqs p q r s p r s

rsquo(p r s 0) = ( p0) U ( r0) U ( s0)

= pq U s U s

= p q s

rsquo(p r s 1) = ( p1) U ( r1) U ( s1)

= p U s U s

= p s

New transition table

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] φ

s [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

pqrs [pqrs] [prs]

pqs [pqrs] [prs]

prs [pqs] [ps]

rsquo( [ps]0) = ( p0) U ( s0)

= pq U s

= [pqs]

rsquo( [ps]1) = ( p1) U ( s1)

= p U s

= [ps]

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 32: Cs6503 theory of computation book notes

Theory of Computation 25

New transition table

Transition Diagram (DFA)

METHOD FOR CONVERSION NFA WITH TO DFA

Step 1 Consider M=Q sum q0 F is a NFA with we have to convert this NFA with to

equivalent DFA

MD =( QDsum D D qD FD) Obtain closure (q0 ) = p1p2helliphellippn becomes its start

state of DFA

Step2 Obtain transition on p1p2helliphellippn for each input

D ( p1p2helliphellippn a) = closure( (P1 a) U (P2 (a) U helliphellipU(Pn a))

=⋃ closure Pi a= where a ϵ sum

Step3 State obtained [ P1P2helliphellipPn ] ϵ QD states containing final state Pi is a final state

DFA

StIp 0 1

rarr[P] [pq] [ p]

[q] [r] [ r]

[r] [s] -

[s] [s] [s]

[pq] [pqr] [pr]

[pqr] [pqrs] [pr]

[pr] [pqs] [p]

[pqrs] [pqrs] [prs]

[pqs] [pqrs] [prs]

[prs] [pqs] [ps]

[ps] [pqs] [ps]

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 33: Cs6503 theory of computation book notes

Theory of Computation 26

EXAMPLE 1 Convert the following NFA with to equivalent DFA

b a

a

b

closure(q0 )= q0 q1 q2

closure(q1)= q1 q2

closure(q2)=q2

(q0 a) = ɸ (q0 b) = q0 (q1 ) = q1

(q1 a) = q1 (q1 b) = ɸ (q2 ) = q2

(q2 a) = q1 (q2 b) = q0 (q2 ) = ɸ

rsquo(q0 a) = closure( ( ^ (q0 )a))

rsquo(q0 a) = closure( ( closure q0 )a))

= closure( (q0 q1 q2 a) )

= closure( (q0 a)U (q1 a)U (q2 a) )

= closure(ɸ U q1 U q1 )

= closure q1

= q1 q2

rsquo(q0 b) = closure( ( ^ (q0 )b))

rsquo(q0 b) = closure( ( closure q0 )b))

= closure( (q0 q1 q2 b) )

= closure( (q0 b)U (q1 b)U (q2 b) )

q0 q1

q2

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 34: Cs6503 theory of computation book notes

Theory of Computation 27

= closure(q0 U ɸ U q0 )

= closure q0

= q0 q1 q2

rsquo(q1 a) = closure( ( ^ (q1 )a))

rsquo(q1 a) = closure( ( closure q1 )a))

= closure( ( q1 q2 a) )

= closure( (q1 a)U (q2 a) )

= closure( q1 U ɸ )

= closure q1

= q1 q2

rsquo(q1 b) = closure( ( ^ (q1 )b))

rsquo(q1 b) = closure( ( closure q1 )b))

= closure( ( q1 q2 b) )

= closure( (q1 b)U (q2 b) )

= closure(ɸ U q0 )

= closure q0 = q0 q1 q2

rsquo(q2 a) = closure( ( ^ (q2 )a))

rsquo(q2 a) = closure( ( closure q2 )a))

= closure( ( q2 a) )

= closure q1

= q1 q2

rsquo(q2 b) = closure( ( ^ (q2 )b))

rsquo(q2 b) = closure( ( closure q2 )b))

= closure( ( q2 b) )

= closure q0

= q0 q1 q2

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 35: Cs6503 theory of computation book notes

Theory of Computation 28

q0

q2

11

Start

ab

ab

q1

ab

ab ab

ab

b b

b

Transition of NFA

input state

a b

q0

q1 q2

q0 q1 q2

q1

q1 q2

q0 q1 q2

q2

q1 q2

q0 q1 q2

Transition diagram

lsquo([q1 q2 ]a)= (q1 a) U (q2a)

= q1 q2U q1 q2

=[ q1 q2 ]

lsquo([q1 q2 ]b)= (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2

=[q0 q1 q2 ]

lsquo([q0 q1 q2 ]a)= (q0 a) U (q1 a) U (q2a)

= q1 q2U q1 q2 U q1 q2

=[ q1 q2 ]

lsquo([q0 q1 q2 ]b)= (q0 b) U (q1 b) U (q2b)

= q0 q1 q2U q0 q1 q2 U q0 q1 q2

=[ q0 q1 q2 ]

Transition table for DFA

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 36: Cs6503 theory of computation book notes

Theory of Computation 29

[q1q2q3]

input state

a b

q0

[ q1 q2 ]

[ q0 q1 q2 ]

q1

[ q1 q2 ]

[ q0 q1 q2 ]

q2

[ q1 q2 ]

[ q0 q1 q2 ]

q1 q2

[ q1 q2 ]

[ q0 q1 q2 ]

[ q0 q1 q2 ]

[ q1 q2 ]

[ q0 q1 q2 ]

a a b

a b b

b

a

a b

[q1q2]

q0

q0 q1 q2

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 37: Cs6503 theory of computation book notes

Theory of Computation 30

MINIMIZE METHOD

TABLE FILLING METHOD

(A0)=B (A1)=F (B0)=G (B1)=C (C0)=A (C1)=C (D0)=C (D1)=G (E0)=H (E1)=F (F0)=C (F1)=G (G0)=G (G1)=E (H0)=G (H1)=C

TABLE 1 C is final state It is distinguishable from other states B

C

X

X

D

X

E

X

F

X

G

X

H

X

A B C D E F G

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 38: Cs6503 theory of computation book notes

Theory of Computation 31

TABLE 2

B

X

C

X

X

D

X

X

E

X

F

X

X

G

X

X

H

X

X

TABLE 3

B

X

C

X

X

D

X

X

X

E

X

X

F

X

X

X

G

X

X

H

X

X

A B C D E F G

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 39: Cs6503 theory of computation book notes

Theory of Computation 32

TABLE 4

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

H

X

X

X

A B C D E F G

TABLE 5

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

H

X

X

X

X

A B C D E F G

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 40: Cs6503 theory of computation book notes

Theory of Computation 33

TABLE 6

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

G

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

TABLE 7

B

X

C

X

X

D

X

X

X

E

X

X

X

F

X

X

X

X

G

X

X

X

X

X

X

H

X

X

X

X

X

X

A B C D E F G

Minimized DFA StateInput 0 1

-gtA B D

B G C

C A C

D C G

E G A

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 41: Cs6503 theory of computation book notes

Theory of Computation 34

MINIMIZE METHOD [alter method]

120633(A0)=B (A1)=F

(B0)=G (B1)=C

(C0)=A (C1)=C

(D0)=C (D1)=G

(E0)=H (E1)=F

(F0)= C (F1)=G

(G0)=G (G1)=E

(H0)=G (H1)=c

Table 1

Stinput 0 1

A B F

B G C

C A C

D C G

E HB F

F C G

G G E

H G C

B=H

Eliminate H

Replace H by B

Table 2

Stinput 0 1

A B F

B G C

C A C

D C G

E B F

F C G

G G EA

A=E

Eliminate E

Replace E by A

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 42: Cs6503 theory of computation book notes

Theory of Computation 35

A

B

G

D

c

Table 3

Stinput 0 1

A B FD

B G C

C A C

D C G

F C G

G G A

D=F

Eliminate F

Replace F with D

Table 4

Stinput 0 1

A B D

B G C

C A C

D C G

G G A

This is the minimized DFA

0

0

1 1 0 1 1

0

1

0

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 43: Cs6503 theory of computation book notes

Theory of Computation 36

THEOREM Let L be a set accepted by Nondeterministic finite automata (NFA) then there exist a Deterministic finite automata (DFA) that accepts L Proof

Let M = (Q Σ qo F) be an NFA for language L then Define DFA Mʹ such that Mʹ = (Qʹ Σʹ ʹ qoʹ Fʹ) (i) The states of Mʹ are all the subsets of M then the Qʹ=2Q

(ii) The input symbols are common for both NFA and DFA ie Σʹ = Σ (iii) If q0 is the initial state in the NFA then q0ʹ = [q0] = initial state in DFA

(iv) Fʹ be the set of all final states which contain final states of M ie Fʹ sube 2Q cup F (v) The element in Qʹ will be denoted by [q1 q2 q3 hellip qi] is a single state in Qʹ and the elements in Q denoted byq1 q2 q3 hellip qi are multiple states in Q Define ʹ such that ʹ([q1 q2 q3 hellip qi] a) = [p1 p2 p3 hellip pj] iff ʹ(q1 q2 q3 hellip qi a) = p1 p2 p3 hellip pj

This mean that in NFA at the current states q1 q2 q3 hellip qi if we give input a then it goes to the next states p1 p2 p3 hellip pj

While constructing DFA the current state is assumed to be [q1 q2 q3 hellip qi] with input a the next state is assumed to be [p1 p2 p3 hellip pj]

On applying function on each of states q1 q2 q3 hellip qi the new states may be any of the states from p1 p2 p3 hellip pj

The theorem can be proved by mathematical induction on length of the input string x ʹ(q0ʹ x) = [q1 q2 q3 hellip qi] if and only if (q0 x) = q1 q2 q3 hellip qi

Basis If the length of input string is 0 ie |x|=0 that means x is then q0ʹ = [q0] Induction If we assume that the hypothesis is true for the input string of length (or less than ) then if xa is the string of length +

Now the function ʹ can be written as ʹ(q0ʹ xa) = ʹ( ʹ(q0 x) a) By the induction hypothesis

ʹ(q0ʹ x) = [p1 p2 p3 hellip pj] if and only if (q0 x) = p1 p2 p3 hellip pj By definition of ʹ ʹ([p1 p2 hellip pj] a) = [r1 r2 rk] if and only if (p1 p2 hellip pj a) = r1 r2 rk Thus ʹ(q0ʹ xa) = [r1 r2 rk] if and only if (q0 xa) = r1 r2 rk is shown by induction

Therefore L(M)=L(Mʹ) ie If a language is accepted by NFA then the same language is also accepted by DFA

Hence the theorem∎ THEOREM If L is accepted by NFA with transition then their exist L which is accepted by NFA without transition (Show that the language L accepted by NFA with move must be accepted by NFA without move) Proof Let M = (Q Σ q0 F) be an NFA with transition Construct Mʹ = (Q Σ ʹ q0 Fʹ) where Fʹ= F cupq0 if closure contains state off F otherwise Mʹ is a NFA without moves The ʹ function can be denoted by the ʹʹ with same input For example ʹ(q a) = ʹʹ(q a) for some q in Q and a from Σ We will apply the method of induction with input string x Basis The x will not be because ʹ(q0 )=q0 and ʹʹ(q0 ) = -closure(q0) Assume that the length of string x to be 1 ie |x|=1 then x is a symbol say ʹaʹ ʹ(q0 a) = ʹʹ(q0 a) Induction Assume that the length of string x to be more than 1 ie |x| gt1

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 44: Cs6503 theory of computation book notes

Theory of Computation 37

Let w = xa ʹ(q0 wa) = ʹ( ʹ(q0 w) a) By Induction hypothesis ʹ(q0 w) = ʹʹ(q0 w) = P Now we will show that ʹ(p a) = (q0wa) But ʹ(p a) = cupq in P ʹ(q a) = cupq in P ʹʹ(q a) AS P = ʹʹ(q0 w) We have cupq in P ʹʹ(q a)= ʹʹ(q0wa)

Thus by define of ʹʹ ʹ(q0 wa) = ʹʹ(q0wa) L(M)=Lʹ(M)

ie If a language is accepted by NFA with transition then the same language is also accepted by NFA without transition

Hence the theorem∎

REGULAR EXPRESSION

DEFENITION The language accepted by finite automata are easily described by simple expression called regular expression REGULAR SET Regular sets are the sets which are accepted by finite automata EXACT DEFENITION Let sum be an alphabet which is used to denote the input set The regular expression over sum can be defined as follows

1) Фis the regular expression which denotes the empty set 2) ξ is the regular expression and denote the set ξ (null string) 3) For each a in sum a is a regular expression and denote the seta 4) If lsquoRrsquo and lsquoSrsquo are regular expression denoting the languages L1 and L2

respectively then r+s is equivalent to L1υL2 ieunion rs is equivalent to L1L2 ieconcatenation r equivalent to L1 ieklean closure EXAMPLE 1 write the regular expression for the language accepting all combination of arsquos over the set sum=a Solution Regular set= ξaaaaaahelliphellip Regular expression(RE)=a EXAMPLE 2 design the RE for the language accepting all combination all combination of arsquos except the null q string over sum=a Solution Regular set= aaaaaahelliphelliphellip Regular expression(RE)=a+ EXAMPLE 3 design the RE for the language containing any no of arsquos and brsquos Solution Regular set= ξabaaabbbbaaaahelliphelliphelliphellip

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 45: Cs6503 theory of computation book notes

Theory of Computation 38

Regular expression(RE)=(a+b) EXAMPLE 4 construct RE for the language accepting all the strings which are ending with 00 sum=01 Solution Regular set= 000001000000010010001100helliphelliphellip Regular expression(RE)=(0+1)00 EXAMPLE 5 write the RE for the language accepting the strings which are starting with 1 and ending with 0 sum=01 Solution Regular set= 101001101000101011001110helliphelliphellip Regular expression(RE)=1(0+1)0 EXAMPLE 6 write RE to denote the language which accepts all the string which begin or end with with either 00 or 11 Solution L1=string begin with 00 or 11 L1=(00+11)(0+1) L2=string end with 00 or 11 L2 =(0+1)(00+11) RE=(00+11)(0+1)+(0+1)(00+11) EXAMPLE 7 construct a RE for the language L which accepts all strings with atlest two lsquobrsquo over sum=ab Solution RE=(a+b)b(a+b)b(a+b) EXAMPLE 8Construct RE for the language which accepts all the string with atleast two b over sum=abc Solution ` RE=(a+b+c)b(a+b+c)b(a+b+c) EXAMPLE 9construct a RE for the language which consist of exactly 2brsquos over the set sum=ab Solution RE=ababa EXAMPLE10construct a RE for the language Lsum=ab in which total no of arsquos are divisible by 3 Solution RE=(bababab) METHOD FOR CONSTRUCTION OF NFA FROM RE EXAMPLE1Construct NFA for the RE b+ba Sol r=b+ba r=r +r

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 46: Cs6503 theory of computation book notes

Theory of Computation 39

r =b r =r r r =b r =a step1 r =b EXAMPLE2 Construct an NFA for the given RE (01+2)1 Sol

R=(01+2)1 R=r r r =01+2 r =1 r =r +r r =01 r =2 step1

r4=2 Step2 R3=01

Step3 R2=1

Step4 01+2

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 47: Cs6503 theory of computation book notes

Theory of Computation 40

Step5(01+2)1

DIRECT OR SUBSET METHOD EXAMPLE 1 design FA for the RE 10+(0+11)01 Step1

Step2

Step3

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 48: Cs6503 theory of computation book notes

Theory of Computation 41

Step4

Step5

Step6

Step7

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 49: Cs6503 theory of computation book notes

Theory of Computation 42

EXAMPLE 2design the DFA for the FE 0+01 Step1

Step2

Step3

EXAMPLE3design DFA for the given RE Step1

Step2

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 50: Cs6503 theory of computation book notes

Theory of Computation 43

Step3

Step4

IDENTITY RULES FOR RE 1ξR=Rξ=R 2ξ =ξ 3(Ф)=ξ 4ФR=RФ=Ф 5Ф+R=R 6R+R=R 7RR =RR=R+

8(R)=R 9ξ+RR=R+

10(P+Q)R=PQ+PR 11(P+Q)=PQ=(P+Q) 12R(ξ+R)=(ξ+R)R=R 13(R+ξ)=R 14ξ+R=R 15(PQ)P=P(QP) 16RR+R=RR AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION Step1 let q1 be the initial state

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 51: Cs6503 theory of computation book notes

Theory of Computation 44

Step2 there areq2q3helliphellipqn no of states the final state may be qj where jlen Step3let αji represents the transition from qj to qi Step4calculate qi Є qi=αjiqij If qi is the start state then qi=αjiqj+ξ Step5similarly compute the final state which ultimately gives the regular expression R R=Q+P then R=QP EXAMPLE1 construct the RE for the given DFA

Solution q1=ξ+q1a 1 q2=q1b+q2d 2 consider q1=ξ+q1a q1=ξa q1= a consider q2=q1b+q2b sub q1= a =gtq2= ab+q2b q2= ab+ b q2= ab+ RE= ab+ EXAMPLE2 construct RE for the DFA given below

Solution q1=ξ+q30+q10 1 q2= q11+q21+ q31 2 q3= q20 3 sub q3 in q2 q2= q11+q21+ q31 q2= q11+q2(1+01) q2= q11(1+01) 4 sub 3 in 4 q1=ξ+ q200+q10 5 sub 4 in 5

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 52: Cs6503 theory of computation book notes

Theory of Computation 45

q1=ξ+ q11(1+01)00+ q10 q1=ξ+ q1(0+1(1+01)00) q1=ξ+(0+1(1+01)00) q1=(0+1(1+01)00) (ξR=Rξ=R) EXAMPLE3 construct the RE for the given DFA

Solution Refer example 1 Since q2 is the final state its enough to find q2 only and q3 is not the final state USING DIRECT METHOD Construct RE for the given DFA

Step1

K=0

r11 ξ r12 0 r21 Ф r22 ξ

Step2 rikj=(rik-1k) (rkk-1k) (rkk-1j)+ rik-1j K=1 (r111) i=1j=1

(r111)= (r101) (r101)(r1o1)+ r101 =(ξ)(ξ)(ξ)+ξ =ξ+ξ = ξ

(r112) i=1j=2

(r112)= (r101) (r101)(r1o2)+ r102 =ξ+0+0 =0

(r211) i=2j=1

(r211)= (r201) (r101)(r1o1)+ r201 =Фξξ+Ф =Ф

(r212) i=2j=2

(r212)= (r201) (r101)(r1o2)+ r202 =Ф(ξ)0+(1+ξ) =Ф+ξ

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 53: Cs6503 theory of computation book notes

Theory of Computation 46

Step3 Compute and find state from state q1 to final state q2 K=2 (r122)= (r102) (r202)(r2o2)+ r102 =0(ξ)ξ+0 =0+0 r12=0

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 54: Cs6503 theory of computation book notes

Theory of Computation 47

Theorem Every language defined by a regular expression is also defined by a finite automaton Proof Suppose L = L(R) for a regular expression R We show that L = L(E) for some -NFA E with

1 Exactly one accepting state 2 No arcs into the initial state 3 No arcs out of the accepting state

BASIS There are three parts to the basis as shown in the following three figures Part (a) to handle the expression The language of the automaton is easily seen to be since the only path from the start state to an accepting state is labeled ie Regular expression =

Part (b) shows the construction for ϕ Clearly there are no paths from start state to accepting state so ϕ is the language of this automaton ie Regular expression = ϕ

Finally part (c) gives the automaton for a regular expression a The language of this automaton evidently consists of the one length string a which is also L(a) ie Regular expression = a

It is easy to check that these automata all satisfy conditions (1) (2) and (3) of the inductive hypothesis INDUCTION We assume that the statement of the theorem is true for the immediate sub-expressions of a given regular expression that is the languages of these sub-expressions are also the languages of -NFAs with a single accepting state The four cases are

1 The expression is R + S for some smaller expressions R and S Then the automaton of Figure serves That is starting at the new start state we can go to the start state of either the automaton for R or the automaton for S We then reach the accepting state of one of these automata following a path labeled by some string in L(R) or L(S) respectively Once we reach the accepting state of the automaton for R or S we can follow one of the -arcs to the accepting state of the new automaton

Thus the language of the automaton in Figure is L(R) U L(S)

R

S

a

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 55: Cs6503 theory of computation book notes

Theory of Computation 48

2 The expression is RS for some smaller expressions R and S The automaton for the concatenation is shown in Figure Note that the start state of the first automaton becomes the start state of the whole and the accepting state of the second automaton becomes the accepting state of the whole The idea is that the only paths from start to accepting state go first through the automaton for R where it must follow a path labeled by a string in L(R) and then through the automaton for S where it follows a path labeled by a string in L(S)

Thus the paths in the automaton of Figure are all and only those labeled by strings in L(R)L(S)

3 The expression is R for some smaller expression R Then we use the automaton of Figure That automaton allows us to go either

(a) Directly from the start state to the accepting state along a path labeled ε That path lets us accept which is in L(R) no matter what expression R is

(b) To the start state of the automaton for R through that automaton one or more times and then to the accepting state This set of paths allows us to accept strings in L(R) L(R)L(R) L(R)L(R)L(R) and so on thus covering all strings in L(R) except perhaps ε which was covered by the direct arc to the accepting state mentioned in the figure

4 The expression is (R) for some smaller expression R The automaton for R also serves as the automaton for (R) since the parentheses do not change the language defined by the expression

It is a simple observation that the constructed automata satisfy the 3 conditions given in the inductive hypothesis - one accepting state with no arcs into the initial state or out of the accepting state ∎

R

R S

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 56: Cs6503 theory of computation book notes

Theory of Computation 49

PUMPING LEMMA To prove languages are not regular Statement Let L be a regular language then there is a constant such that for every string in L and | | We can break into three sub-strings and represented as = such that

1 ne 120598 ie | | 2 | | 3 For all the string is also in L

Proof If L is a regular Language then it is accepted by a DFA 119860 = 119876 120564 120575 119865 with n states ie L = L(A) Consider the input string w of length or more say = 119886 119886 119886 where and each 119886 is an input symbol The mapping function can be defined as 120575 119886 119886 119886 =

For the string of length m this is more than the number of states n By pigeonhole principle at least one state must repeat Thus we can find two different integers and with lt such that = Now we break = as follows

1 = 119886 119886 hellip 119886 2 = 119886 + 119886 + hellip 119886 3 = 119886 + 119886 + hellip 119886

In the DFA 119860 as shown in figure we can move from the start state p0 to pi with the input string takes us from back to (since = ) and takes us from to

Note that may be empty if = Also may be empty if = = However

cannot be empty as lt 120575 119886 119886 119886 119886 + hellip 119886 119886 + hellip 119886 = 120575 120575 119886 hellip 119886 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 120575 119886 + hellip 119886 119886 + hellip 119886

= 120575 119886 + hellip 119886

= If the automaton 119860 receives the input w that is Case 1 If = 0 then = 0 = The automaton 119860 goes from the start state 0 to on

input Since is also A goes from to the accepting state on input Thus 119860 accepts Case 2 If gt 0 then the automaton 119860 goes from 0 to on input Circles from to k

times on input and then goes from to the accepting state on input Thus 119860 accepts Thus for 0 is accepted by a automaton 119860 That is is in 119871 ie We have proved that given string of any length can be accepted by Finite Automata by pumping a substring ie substring repeated as many times as we like and resulting string may be accepted by Finite Automata ∎ ADVANTAGES Pumping lemma is used to check the given language is not regular or not

p0 pi pF Start = 119886 hellip 119886

= 119886 + hellip 119886

= 119886 + hellip 119886

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 57: Cs6503 theory of computation book notes

Theory of Computation 50

EXAMPLE1show that the set L=bi2 is not regular Solution To prove L=bi2 is not regular i=2 L=2 =gt L=b4=bbbb i=3 L=3 =gt L=b9=bbbbbbbbb according to pumping lemma Luiw Є L where ige1 L=uviw L=b(bb)ib if i=2 =gt bbbbbb not belongs to L If i=3 =gt bbbbbbbb not belongs to L

EXAMPLE2 show that the language L=0n1n+1 ngt0 is not regular Solution To prove L=0n1n+1 ngt0 is not regular Let n=1 L=0112= 011 Let n=2 L=0213=00111 Let n=3 L=0314=0001111 Length of the string =n+n+1 =2n+1 Then according to pumping lemma L=011 U=0 v=1 w=1 uviw=01i1 =0111(if i=2)not belongs to L

e length of the string after pumping is not in 2n+1 form

EXAMPLE3 check the given language L=02nnnge1 is not regular or not Solution Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note L=string consisting of even no of 0rsquos L=even length of string with 0 Then according to pumping lemma L= 0000 uviw= o(00)i0 =0000(if n=1) 0(00)i0 Є L

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 58: Cs6503 theory of computation book notes

Theory of Computation 51

Closure properties of regular languages (RL)

If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular These properties are called closure properties of regular languages Such languages represent the class of regular languages which is closed under the certain operations The closure properties express the idea that when one or many languages are regular then certain related languages are also regular The closure properties of regular languages are as given below

1 The union of two regular languages is regular 2 The intersection of two regular languages is regular 3 The complement of a regular language is regular 4 The difference of two regular languages is regular 5 The reversal of a regular language is regular 6 The Kleene closure operation on a regular language is regular 7 The concatenation of regular language is regular 8 A homomorphism of regular languages is regular 9 The inverse homomorphism of regular language is regular

Theorem 1 If L1 and L2 are two languages then L1 cup L2 is regular Proof If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2) Then L1 cup L2 = L (R1 + R2) thus we get L1 cup L2 as regular language (Any language given by some regular expression is regular) Theorem 2 The complement of regular language is regular Proof Consider L1 be regular language which is accepted by a DFA M = (Q Σ q0 F) The complement of regular language L1 is which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states isin F and M is a DFA in which all the non-final states of M become final In other words we can say that strings that are accepted by M are rejected by M similarly the strings rejected by M are accepted by M Thus L1 is accepted by M is regular Theorem 3 If L1 and L2 are two languages then L1 cap L2 is regular Proof Consider that languages L1 is regular That means there exists some DFA M1 that accepts L1 We can write M1 = (Q1 Σ 1 q1 F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2 Σ 2 q2 F2 ) Let L be the language obtained from L1 cap L2 We can the simulate M=(Q Σ q F ) Where Q = Q1 cap Q2 = 1 cap 2 a mapping function derived from both the DFAs

q isin Q which is initial state of machine M F = F1 cap F2 the set of final states which is common for M1 and M2 both It is clear

that there exists some DFA which accepts L1 cap L2 ie L Hence L is a regular language This proves that if L1 and L2 are two regular languages then L1 cap L2 is regular In other words the regular language is closed under intersection Theorem 4 If L1 and L2 are two regular languages then L1 - L2 is regular Proof The L1 - L2 can also be denoted as L1 cup L2 Consider L1 be regular language which is accepted by DFA M = (Q Σ q0 F) The complement of regular language L1 is L2 which is accepted by M = (Q Σ q0 Q-F) That means M is a DFA with final states set F and M is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L2

are two regular languages That also means these languages are accepted by regular expressions If L1 =L(R1) and L2=L(R2) Then L1 cup L2 = L(R1+R2) This ultimately shows

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 59: Cs6503 theory of computation book notes

Theory of Computation 52

that L1 cup L2 is regular In other words L1 - L2 is regular Thus regular languages are closed under difference

Theorem 5 The reversal of a regular languages is regular Proof Reversal of a string means obtaining a string which is written from backward that is W

R is denoted as reversal of string w That means L(wR) = (L(w))R This proof can be done

with basis of induction Basis If w = ɛ or ϕ then w R is also ɛ or ϕ

ie (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R) is also regular Induction

Case 1 If w = w1 + w2 then w = (w1)R +( w2)

R As the regular language is closed under union w is also regular Case 2 If w = w1 w2 then w = (w1)

R ( w2)R

As the regular language is closed under concatenation w is also regular Thus the reversal of a regular languages is regular

Theorem 6 The closure operation on regular language is regular Proof If language L1 is regular then it can be expressed as L1 =L(R1

) Thus for a closure operation a language can be expressed as a language of regular expressions Hence L1 is said to be a regular language Theorem 7 If L1 and L2 are two languages then L1 L2 is regular In other words regular languages are closed under concatenation Proof If L1 and L2 are regular then they can be expressed as L1 =L(R1) and L2 =L(R2) Then L1L2 =L(R1 R2) thus we get a regular language Hence it is proved that regular languages are closed under concatenation

Theorem 8 A homomorphism of regular language is regular Proof The term homomorphism means substitution of string by some other symbols For instance the string aabb can be written as 0011 under homomorphism Clearly here a is replaced by 0 and b is replaced by 1 Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ rarrΓ is homomorphism The definition of homomorphism can be extended as

Let w = a1 a2 hellip an h(w) = h(a1)h(a2)h(an)

If L is a Language that belongs to the set Σ then homomorphic image of L can be defined as h(L) = h(w) wisinL To prove that if L is regular h(L) is also regular consider following example Let Σ = ab and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011

The homomorphism to language is applied by applying homomorphism on each string of language there4 If L = abb = ab+ = ab abb abbb abbbb

Now h(L) = 0011 001111 00111111 0011111111 there4 h(L) = 00 (11)+ As it can be represented by a regular expression it is a regular language Hence it is

proved that if L is regular then h(L) is also regular In other words family of regular languages is closed under homomorphism

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2

Page 60: Cs6503 theory of computation book notes

Theory of Computation 53

Theorem 9 The inverse homomorphism of regular language is regular Proof Let h ΣrarrΓ is homomorphism The Σ is the input set and Γ be the substitution symbols used by homomorphic function Let L be the regular language where L isin Σ then h(L) be homomorphic language The inverse homomorphic language can be represented as h-1(L) such that h-1 Γ rarr Σ

Let h-1(L) = w | w isin L If L is regular then h(L) is also regular because regular language is closed under homomorphism That if there exist a FA M = (Q Σ q F) which accepts L then h(L) must also be accepted by FA M For complement of L ie language L the inverse homomorphic language is h-1(L) Let M = (Q Σ q Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states Clearly the language L can be accepted by M Hence h-1(L) must also be accepted by FA M Let L= (010) is a RL h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba) h-1(h(L))= (010) = L as the inverse homomorphism h-1(a)=0 and h-1(bb)=1

Decision properties of regular languages (RL)

1 Membership property A string is in a language ie w isin L 2 Emptiness property Accepting state separated from start state ie ɸ 3 Equivalence property Two languages are equal ie L1 = L2