Closure under the Regular Operations

Similar documents
Closure under the Regular Operations

Theory of Computation (I) Yijia Chen Fudan University

Lecture 3: Nondeterministic Finite Automata

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

Nondeterministic Finite Automata

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

CS 455/555: Finite automata

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

Finite Automata and Regular languages

Intro to Theory of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Homework 1 Due September 20 M1 M2

CS 154. Finite Automata, Nondeterminism, Regular Expressions

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

Chapter Five: Nondeterministic Finite Automata

Computer Sciences Department

Theory of Computation (II) Yijia Chen Fudan University

Nondeterminism. September 7, Nondeterminism

Constructions on Finite Automata

Non-deterministic Finite Automata (NFAs)

CS 154, Lecture 3: DFA NFA, Regular Expressions

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

Exam 1 CSU 390 Theory of Computation Fall 2007

Finite Automata Part Two

1 Alphabets and Languages

Theory of Languages and Automata

September 7, Formal Definition of a Nondeterministic Finite Automaton

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

CPS 220 Theory of Computation REGULAR LANGUAGES

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

Constructions on Finite Automata

CS 121, Section 2. Week of September 16, 2013

CS 154 Formal Languages and Computability Assignment #2 Solutions

CpSc 421 Homework 1 Solutions

Sri vidya college of engineering and technology

Examples of Regular Expressions. Finite Automata vs. Regular Expressions. Example of Using flex. Application

CISC 4090 Theory of Computation

Lecture 7 Properties of regular languages

Automata: a short introduction

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

Inf2A: Converting from NFAs to DFAs and Closure Properties

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

UNIT-III REGULAR LANGUAGES

Equivalence of DFAs and NFAs

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

Theory of Computation

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

Fooling Sets and. Lecture 5

Nondeterministic Finite Automata. Nondeterminism Subset Construction

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

CS243, Logic and Computation Nondeterministic finite automata

Formal Languages. We ll use the English language as a running example.

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Formal Languages. We ll use the English language as a running example.

Theory of Computation Lecture 1. Dr. Nahla Belal

CSE 105 THEORY OF COMPUTATION

Computational Models - Lecture 1 1

More Properties of Regular Languages

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

CS21 Decidability and Tractability

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Deterministic Finite Automata (DFAs)

Deterministic Finite Automata (DFAs)

CSE 105 THEORY OF COMPUTATION

CSE 355 Homework One Sample Solutions

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Finite Automata. Seungjin Choi

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

3515ICT: Theory of Computation. Regular languages

Finite Automata and Languages

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

CSE 105 THEORY OF COMPUTATION

Nondeterministic Finite Automata

10. The GNFA method is used to show that

TDDD65 Introduction to the Theory of Computation

CSE 105 Homework 3 Due: Monday October 23, Instructions. should be on each page of the submission.

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

Finite Automata Part Two

Non-Deterministic Finite Automata

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

Regular expressions and Kleene s theorem

Finite State Transducers

How do regular expressions work? CMSC 330: Organization of Programming Languages

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

Closure Properties of Regular Languages

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Regular expressions and Kleene s theorem

2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a

Theory of Computation

Deterministic Finite Automaton (DFA)

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

CSE 105 THEORY OF COMPUTATION

Regular Languages. Problem Characterize those Languages recognized by Finite Automata.

Lecture 4 Nondeterministic Finite Accepters

CS 133 : Automata Theory and Computability

Transcription:

September 7, 2013

Application of NFA Now we use the NFA to show that collection of regular languages is closed under regular operations union, concatenation, and star Earlier we have shown this closure for union using a Cartesian product of DFA For uniformity reason we reconstruct that proof using NFA

Theorem 1.45 The class of regular languages is closed under the union operation

Theorem 1.45 The class of regular languages is closed under the union operation Proof idea:

Theorem 1.45 The class of regular languages is closed under the union operation Proof idea: Let regular languages A 1 and A 2 be recognized by NFA N 1 and N 2, respectively

Theorem 1.45 The class of regular languages is closed under the union operation Proof idea: Let regular languages A 1 and A 2 be recognized by NFA N 1 and N 2, respectively To show that A 1 A 2 is regular we will construct an NFA N that recognizes A 1 A 2

Theorem 1.45 The class of regular languages is closed under the union operation Proof idea: Let regular languages A 1 and A 2 be recognized by NFA N 1 and N 2, respectively To show that A 1 A 2 is regular we will construct an NFA N that recognizes A 1 A 2 N must accept its input if either N 1 or N 2 accepts its input. Hence, N must have a new state that will allow it to guess nondeterministically which of N 1 or N 2 accepts it

Theorem 1.45 The class of regular languages is closed under the union operation Proof idea: Let regular languages A 1 and A 2 be recognized by NFA N 1 and N 2, respectively To show that A 1 A 2 is regular we will construct an NFA N that recognizes A 1 A 2 N must accept its input if either N 1 or N 2 accepts its input. Hence, N must have a new state that will allow it to guess nondeterministically which of N 1 or N 2 accepts it Guessing is implemented by ɛ transitions from the new state to the start states of N 1 and N 2, as seen in Figure 1

An NFA recognizing A 1 A 2 N N 1 ɛ ɛ N 2 Figure 1 : Construction of N to recognize A 1 A 2

Proof Let N 1 = (Q 1, Σ, δ 1, q 1 0, F 1), and N 2 = (Q 2, Σ, δ 2, q 2 0, F 2) Construct N = (Q, Σ, δ, q 0, F ) to recognize A 1 A 2 using the following procedure:

Construction procedure

Construction procedure 1. Q = {q 0 } Q 1 Q 2 : That is, the states of N are all states on N 1 and N 2 with the addition of a new state q 0

Construction procedure 1. Q = {q 0 } Q 1 Q 2 : That is, the states of N are all states on N 1 and N 2 with the addition of a new state q 0 2. The start state of N is q 0

Construction procedure 1. Q = {q 0 } Q 1 Q 2 : That is, the states of N are all states on N 1 and N 2 with the addition of a new state q 0 2. The start state of N is q 0 3. The accept states of N are F = F 1 F 2 : That is, the accept states of N are all the accept states of N 1 and N 2

Construction procedure 1. Q = {q 0 } Q 1 Q 2 : That is, the states of N are all states on N 1 and N 2 with the addition of a new state q 0 2. The start state of N is q 0 3. The accept states of N are F = F 1 F 2 : That is, the accept states of N are all the accept states of N 1 and N 2 4. Define δ so that for any q Q and any a Σ ɛ:

Construction procedure 1. Q = {q 0 } Q 1 Q 2 : That is, the states of N are all states on N 1 and N 2 with the addition of a new state q 0 2. The start state of N is q 0 3. The accept states of N are F = F 1 F 2 : That is, the accept states of N are all the accept states of N 1 and N 2 4. Define δ so that for any q Q and any a Σ ɛ: δ 1 (q, a), if q Q 1 δ 2 (q, a), if q Q 2 δ(q, a) = {q0 1, q2 0 }, if q = q 0 and a = ɛ, if q = q 0 and a ɛ.

Application Consider the alphabet Σ = {0, 1} and the languages: A = {w w begins with 1 and ends with 0} B = {w w contains at least three 1} C = {w w = x0101y, x, y Σ } D = {w w does not contain the substring 110} Use the construction given in the proof of theorem 1.45 to give the state diagrams recognizing the languages A B and C D.

Theorem 1.47 The class of regular languages is closed under concatenation operation

Theorem 1.47 The class of regular languages is closed under concatenation operation Proof idea: Assume two regular languages, A 1 and A 2 recognized by NFAs N 1 and N 2, respectively. Construct N as suggested in Figure 2

Construction of NFA N N 1 N 2 N ɛ ɛ ɛ Figure 2 : Construction of N to recognize A 1 A 2

Construction procedure Combine N 1 and N 2 into a new automaton N that starts in the start state of N 1 Add ɛ transitions from the accept states of N 1 to the start state of N 2 Set accept states of N to be the accept states on N 2

Proof Let N 1 = (Q 1, Σ, δ 1, q 1 0, F 1) recognize A 1 and N 2 = (Q 2, Σ, δ 2, q 2 0, F 2) recognize A 2. Construct N = (Q, Σ, δ, q 1 0, F 2) by the following procedure:

Construction procedure

Construction procedure 1. Q = Q 1 Q 2. The states of N are all states of N 1 and N 2

Construction procedure 1. Q = Q 1 Q 2. The states of N are all states of N 1 and N 2 2. The start state is the state q 1 0 of N 1

Construction procedure 1. Q = Q 1 Q 2. The states of N are all states of N 1 and N 2 2. The start state is the state q 1 0 of N 1 3. The accept states is the set F 2 of the accept states of N 2

Construction procedure 1. Q = Q 1 Q 2. The states of N are all states of N 1 and N 2 2. The start state is the state q0 1 of N 1 3. The accept states is the set F 2 of the accept states of N 2 4. Define δ so that for any q Q and any a Σ ɛ:

Construction procedure 1. Q = Q 1 Q 2. The states of N are all states of N 1 and N 2 2. The start state is the state q0 1 of N 1 3. The accept states is the set F 2 of the accept states of N 2 4. Define δ so that for any q Q and any a Σ ɛ: δ 1 (q, a), if q Q 1 and q F 1 δ 1 (q, a), if q F 1 and a ɛ δ(q, a) = δ 1 (q, a) {q0 2}, if q F 1 and a = ɛ δ 2 (q, a), if q Q 2.

Application Consider the alphabet Σ = {0, 1} and the languages: A = {w w 5} B = {w every odd position of w is 1} C = {w w contains at least three 1} D = {ɛ} Use the construction given in the proof of theorem 1.47 to give the state diagrams recognizing the languages A B and C D where is concatenation operator.

Theorem 1.49 The class of regular languages is closed under star operation

Theorem 1.49 The class of regular languages is closed under star operation Proof idea: we have a regular language A 1, recognized by the NFA N 1 and want to prove that A 1 is also a regular language. The procedure to prove this theorem is by construction of the NFA N that recognizes A 1 as shown in Figure 3

Procedure for the construction of N N N 1 ɛ ɛ ɛ Figure 3 : Construction of N to recognize A 1

More on the proof idea

More on the proof idea N is like N 1 with a new start state and an ɛ transition from the new start state to q 1

More on the proof idea N is like N 1 with a new start state and an ɛ transition from the new start state to q 1 Since ɛ A 1 the new start state is an accepts state

More on the proof idea N is like N 1 with a new start state and an ɛ transition from the new start state to q 1 Since ɛ A 1 the new start state is an accepts state We add ɛ transitions from the previous accept states of N 1 to the start state of N 1 allowing the machine to read and recognize strings of the form w 1... w k where w 1,..., w k A 1

Proof Let N 1 = (Q 1, Σ, δ 1, q 1 0, F 1) recognize A 1. Construct N = (Q, Σ, δ, q 0, F ) by the procedure:

Construction procedure

Construction procedure 1. Q = {q 0 } Q 1 ; that is, states of N are the states of N 1 plus a new state q 0

Construction procedure 1. Q = {q 0 } Q 1 ; that is, states of N are the states of N 1 plus a new state q 0 2. Start state if N is q 0

Construction procedure 1. Q = {q 0 } Q 1 ; that is, states of N are the states of N 1 plus a new state q 0 2. Start state if N is q 0 3. F = {q 0 } F 1 ; that is, the accept states of N are the accept states of N 1 plus the new start state

Construction procedure 1. Q = {q 0 } Q 1 ; that is, states of N are the states of N 1 plus a new state q 0 2. Start state if N is q 0 3. F = {q 0 } F 1 ; that is, the accept states of N are the accept states of N 1 plus the new start state 4. Define δ so that for any q Q and a Σ ɛ:

Construction procedure 1. Q = {q 0 } Q 1 ; that is, states of N are the states of N 1 plus a new state q 0 2. Start state if N is q 0 3. F = {q 0 } F 1 ; that is, the accept states of N are the accept states of N 1 plus the new start state 4. Define δ so that for any q Q and a Σ ɛ: δ 1 (q, a), if q Q 1 and q F 1 δ 1 (q, a), if q F 1 and a ɛ δ(q, a) = δ 1 (q, a) {q0 1}, if q F 1 and a = ɛ {q 0 1}, if q = q 0 and a = ɛ, if q = q 0 and a ɛ.

Application Consider the alphabet Σ = {0, 1} and the languages: A = {w w contains at least three 1s} B = {w w contains at least two 0s and at most one 1} C = {ɛ} Use the construction given in the proof of theorem 1.49 to give the state diagrams recognizing the languages A, B and C.

Closure under complementation We show here that class of regular languages is closed under complementation. For that we will first show that if M is a DFA that recognizes a language B, swapping the accept and non-accept states in M yields a new DFA that recognizes the complement of B.

Proof Let M be the DFA M with accept and non-accept states swapped. We will show that M recognizes the complement of B 1. Suppose M accept x, i.e., if we run M on x we end in an accept state of M 2. Because M and M have swapped accept/non-accept states, if we run M on x we would end in a non-accept state. Hence, x B 3. Similarly, if x is not accepted by M, it would be accepted by M Consequently, M accepts those strings that are not accepted by M and therefore M recognizes the complement of B.

Conclusion B has been an arbitrary regular language. Therefore, our construction shows how to build an automaton to recognize its complement Hence, the complement of any regular language is also regular Consequently the class of regular languages is closed under complementation

Interesting property If M is an NFA that recognizes language C, swapping its accept and non-accept states doesn t necessarily yield a new NFA that recognizes the complement of C.

Proof We prove the interesting property by constructing a counter-example. Consider the construction in Figure 4, where both NFA-s, M and M, accept aa. a a,b 1 b 2 a a,b 1 b 2 Figure 4 : NFAs M and M

Question Is the class of languages recognized by NFAs closed under complementation?

Closure under complementation The class of languages recognized by NFA is still closed under complementation This follows from the fact that the class of languages recognized by NFAs is precisely the class of languages recognized by DFA The counter-example in Figure 4 shows the difference between the process of computations performed by DFAs and NFAs