TDDD65 Introduction to the Theory of Computation

Similar documents
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 154, Lecture 3: DFA NFA, Regular Expressions

Theory of Computation (II) Yijia Chen Fudan University

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

CSE 105 THEORY OF COMPUTATION

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

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

Computer Sciences Department

Outline. CS21 Decidability and Tractability. Regular expressions and FA. Regular expressions and FA. Regular expressions and FA

CSE 105 THEORY OF COMPUTATION

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

Formal Languages, Automata and Models of Computation

CS5371 Theory of Computation. Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)

Finite Automata and Regular languages

Lecture 4: More on Regexps, Non-Regular Languages

CSE 105 THEORY OF COMPUTATION

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

Incorrect reasoning about RL. Equivalence of NFA, DFA. Epsilon Closure. Proving equivalence. One direction is easy:

More Properties of Regular Languages

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

UNIT-III REGULAR LANGUAGES

1.3 Regular Expressions

Intro to Theory of Computation

Computational Theory

Proving languages to be nonregular

Theory of Computation (I) Yijia Chen Fudan University

Chapter 2 The Pumping Lemma

What we have done so far

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Closure under the Regular Operations

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

Applied Computer Science II Chapter 1 : Regular Languages

acs-04: Regular Languages Regular Languages Andreas Karwath & Malte Helmert Informatik Theorie II (A) WS2009/10

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

Theory of Languages and Automata

CSci 311, Models of Computation Chapter 4 Properties of Regular Languages

Exam 1 CSU 390 Theory of Computation Fall 2007

Computational Models - Lecture 3

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

The Pumping Lemma and Closure Properties

Name: Student ID: Instructions:

CS21 Decidability and Tractability

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

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Automata: a short introduction

Properties of Regular Languages. BBM Automata Theory and Formal Languages 1

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

Properties of Regular Languages (2015/10/15)

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

COMP4141 Theory of Computation

10. The GNFA method is used to show that

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

CS 455/555: Finite automata

Context-Free Languages (Pre Lecture)

CSCE 551 Final Exam, Spring 2004 Answer Key

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

Sample Midterm. Understanding the questions is part of the exam; you are not allowed to ask questions during the exam.

CSE 105 Theory of Computation Professor Jeanne Ferrante

3515ICT: Theory of Computation. Regular languages

Introduction to Languages and Computation

Uses of finite automata

Computational Models: Class 3

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

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

CS21 Decidability and Tractability

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Before we show how languages can be proven not regular, first, how would we show a language is regular?

V Honors Theory of Computation

CSE 105 THEORY OF COMPUTATION

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

Please give details of your calculation. A direct answer without explanation is not counted.

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

Automata and Computability. Solutions to Exercises

Lecture 3: Nondeterministic Finite Automata

Finite Automata and Regular Languages

CS 133 : Automata Theory and Computability

Johns Hopkins Math Tournament Proof Round: Automata

Lecture 17: Language Recognition

Automata and Computability. Solutions to Exercises

Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions

Regular languages, regular expressions, & finite automata (intro) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/


CS375 Midterm Exam Solution Set (Fall 2017)

Computational Models Lecture 2 1

Computational Models Lecture 2 1

Regular Expressions. Definitions Equivalence to Finite Automata

Regular Expressions (Pre Lecture)

Computational Models - Lecture 3 1

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

Nondeterministic Finite Automata

2017/08/31 Chapter 1.2 & 1.3 in Sipser Ø Announcement:

Theory of Computation

Non-deterministic Finite Automata (NFAs)

Chapter Five: Nondeterministic Finite Automata

CS 322 D: Formal languages and automata theory

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 9 : Myhill-Nerode Theorem and applications

Nondeterminism and Epsilon Transitions

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

Transcription:

TDDD65 Introduction to the Theory of Computation Lecture 2 Gustav Nordh, IDA gustav.nordh@liu.se 2012-08-31

Outline - Lecture 2 Closure properties of regular languages Regular expressions Equivalence of regular expressions and finite automata Pumping lemma for regular languages

Closure properties of regular languages The natural numbers N = {0, 1, 2, 3,...} are closed under multiplication in the sense that for any natural numbers x and y, x y is again a natural number The natural numbers are not closed under subtraction (3 5 = 2 which is not a natural number) Definition We say that a class of languagesc is closed under an operation op if applying op to any languages from C results in a language in C

Closure properties of regular languages Understanding under which operations a class of languagesc is closed is important!

Closure properties of regular languages Theorem The class of regular languages is closed under union (if L 1 and L 2 are regular languages, then so is L 1 L 2 ) Proof.

Closure properties of regular languages Theorem The class of regular languages is closed under concatenation (if L 1 and L 2 are regular languages, then so is L 1 L 2 ) Proof.

Closure properties of regular languages Theorem The class of regular languages is closed under star (if L 1 is a regular language, then so is L 1 ) Proof.

Regular expressions

Regular expressions

Regular expressions

Definition of regular expressions Definition L(R) denotes the language described by the regular expression R. R is a regular expression if R is 1 a for a Σ, L(a) = {a} 2, L() = {} 3, L( ) = 4 R 1 + R 2 where R 1 and R 2 are regular expressions, L(R 1 + R 2 ) = L(R 1 ) L(R 2 ) 5 R 1 R 2 where R 1 and R 2 are regular expressions, L(R 1 R 2 ) = L(R 1 )L(R 2 ) 6 R 1 where R 1 is a regular expression, L(R 1 ) = L(R 1) has higher precedence than concatenation and +, concatenation has higher precedence than +

Examples of regular expressions Example (0+1) 0 binary strings ending with 0 (0+1) 00(0+1) binary strings with at least two consecutive 0 s (0+1+2+3+4+5+6+7+8+9) 1234(0+ 1+2+ 3+4+5+6+7+8+9)

Equivalence with finite automata Theorem A language is regular if and only if some regular expression describes it

Equivalence with finite automata If a language is described by a regular expression then it is recognized by a NFA

Equivalence with finite automata If a language is described by a regular expression then it is recognized by a NFA Proof. R = a for a Σ, L(R) = {a} R =, L(R) = {} a R =, L(R) =

Equivalence with finite automata If a language is described by a regular expression then it is recognized by a NFA Proof. R = R 1 + R 2, L(R) = L(R 1 ) L(R 2 )

Equivalence with finite automata If a language is described by a regular expression then it is recognized by a NFA Proof. R = R 1 R 2, L(R) = L(R 1 )L(R 2 )

Equivalence with finite automata If a language is described by a regular expression then it is recognized by a NFA Proof. R = R 1, L(R) = L(R 1)

Equivalence with finite automata: Example Example (0+1) to NFA 0 0 1 1 0+1 0 1 (0+1) 0 1

Equivalence with finite automata RegExp Closure Properties NFA Subset Construction DFA

Equivalence with finite automata RegExp Closure Properties GNFA Construction NFA Subset Construction DFA

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Idea: Use a generalized NFA (GNFA) where the transition arrows can be labeled by regular expressions (aa) a ab q 1 q 2 ab+ba

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Idea: Use a generalized NFA (GNFA) where the transition arrows can be labeled by regular expressions Given a DFA Add a new start state with an transition to the old start state Add a new accept state with transitions from all old accept states Replace transitions of the form a, b, c by a+b + c

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Add a new start state with an transition to the old start state Add a new accept state with transitions from all old accept states Replace transitions of the form a, b, c by a+b + c 0 1 1 q 1 q 2 0

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Add a new start state with an transition to the old start state Add a new accept state with transitions from all old accept states Replace transitions of the form a, b, c by a+b + c 0 1 q s 1 q 1 q 2 q F 0

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Add a new start state with an transition to the old start state Add a new accept state with transitions from all old accept states Replace transitions of the form a, b, c by a+b + c Eliminate a state different from the start and accept state (reducing the number of states by 1)

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate a state different from the start and accept state (reducing the number of states by 1) R 2 R 1 R 3 q 1 q e q 2 R 4

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate a state different from the start and accept state (reducing the number of states by 1) R 2 R 1 R 3 q 1 q e q 2 R 4 q 1 R 1 R 2 R 3 + R 4 q 2

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate a state different from the start and accept state (reducing the number of states by 1) 0 1 q s 1 q 1 q 2 q F 0

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate q 2 0 1 q s 1 q 1 q 2 q F 0

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate q 2 0 1 q s 1 q 1 q 2 q F 0 Using the rule R 1 R 2 R 3 + R 4 the new transition from q 1 to q F is labeled 11 +

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate q 2 0 1 q s 1 q 1 q 2 q F 0 Using the rule R 1 R 2 R 3 + R 4 the new transition from q 1 to q F is labeled 11 + Using the rule R 1 R 2 R 3 + R 4 the new transition from q 1 to q 1 is labeled 11 0+0

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate q 2 0 1 q s 1 q 1 q 2 q F 0 11 0+0 q s q 1 11 + q F

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate q 1 11 0+0 q s q 1 11 + q F

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate q 1 11 0+0 q s q 1 11 + q F Using the rule R 1 R 2 R 3 + R 4 the new transition from q s to q F is labeled (11 0+0) (11 + )+

Equivalence with finite automata If a language is recognized by a DFA then it is described by a regular expression Eliminate q 1 11 0+0 q s q 1 11 + q F q s (11 0+0) (11 + )+ q F

Equivalence with finite automata RegExp Closure Properties GNFA Construction NFA Subset Construction DFA

Nonregular languages

Nonregular languages Example L = {a n b n n 0} is not a regular language Why?

Nonregular languages Example L = {a n b n n 0} is not a regular language Why? Imagine a DFA that recognize L When reading a string the DFA needs to keep track of the number of a s seen so far so that it can check that the same number of b s follow The number of a s is unbounded so the DFA needs to remember an unbounded number This is not possible since the memory of the DFA is bounded (finite number of states)

Nonregular languages, pumping Given a sufficiently long string s in a regular language L Then the DFA that recognizes L will be in the same state q t several times s = s 1 s j 1 s j s k 1 s k s n L }{{}}{{}}{{} q t q t q accept

Nonregular languages, pumping Given a sufficiently long string s in a regular language L Then the DFA that recognizes L will be in the same state q t several times So for any i 0 s = s 1 s j 1 s j s k 1 s k s n L }{{}}{{}}{{} q t q t q accept s = s 1 s j 1 (s j s k 1 ) i s k s n L }{{}}{{}}{{} q t q t q accept

The Pumping for Regular Languages If L is a regular language, then there exists a positive integer p (the pumping length) such that every string s L, s p, can be partitioned into three pieces, s = xyz, such that the following conditions hold: y > 0, xy p, and for each i 0, xy i z L

Proof of the Pumping If L is a regular language, then there exists a positive integer p (the pumping length) such that every string s L, s p, can be partitioned into three pieces, s = xyz, such that the following conditions hold: y > 0, xy p, and for each i 0, xy i z L Proof. If L is regular, let M be a DFA recognizing L. Let p be the number of states of M and let s = s 1 s 2 s n L with n p. Let r 1 r n+1 be the sequence of states that M enters while reading s. Among the first p+1 states in this sequence, two must be the same. Let r j = r k (j < k) be such two. Let x = s 1 s j 1, y = s j s k 1, and z = s k s n.

Proof of the Pumping If L is a regular language, then there exists a positive integer p (the pumping length) such that every string s L, s p, can be partitioned into three pieces, s = xyz, such that the following conditions hold: y > 0, xy p, and for each i 0, xy i z L Proof. If L is regular, let M be a DFA recognizing L. Let p be the number of states of M and let s = s 1 s 2 s n L with n p. Let r 1 r n+1 be the sequence of states that M enters while reading s. Among the first p+1 states in this sequence, two must be the same. Let r j = r k (j < k) be such two. Let x = s 1 s j 1, y = s j s k 1, and z = s k s n. y = s j s k 1 x = s 1 s j 1 z = sk s n r 1 r j = r k r n+1

Proof of the Pumping If L is a regular language, then there exists a positive integer p (the pumping length) such that every string s L, s p, can be partitioned into three pieces, s = xyz, such that the following conditions hold: y > 0, xy p, and for each i 0, xy i z L Proof. If L is regular, let M be a DFA recognizing L. Let p be the number of states of M and let s = s 1 s 2 s n L with n p. Let r 1 r n+1 be the sequence of states that M enters while reading s. Among the first p+1 states in this sequence, two must be the same. Let r j = r k (j < k) be such two. Let x = s 1 s j 1, y = s j s k 1, and z = s k s n. y i, i 0 x = s 1 s j 1 z = sk s n r 1 r j = r k r n+1

Proof of the Pumping If L is a regular language, then there exists a positive integer p (the pumping length) such that every string s L, s p, can be partitioned into three pieces, s = xyz, such that the following conditions hold: y > 0, xy p, and for each i 0, xy i z L Proof. If L is regular, let M be a DFA recognizing L. Let p be the number of states of M and let s = s 1 s 2 s n L with n p. Let r 1 r n+1 be the sequence of states that M enters while reading s. Among the first p+1 states in this sequence, two must be the same. Let r j = r k (j < k) be such two. Let x = s 1 s j 1, y = s j s k 1, and z = s k s n. We have xy i z L for each i 0.

Proof of the Pumping If L is a regular language, then there exists a positive integer p (the pumping length) such that every string s L, s p, can be partitioned into three pieces, s = xyz, such that the following conditions hold: y > 0, xy p, and for each i 0, xy i z L Proof. If L is regular, let M be a DFA recognizing L. Let p be the number of states of M and let s = s 1 s 2 s n L with n p. Let r 1 r n+1 be the sequence of states that M enters while reading s. Among the first p+1 states in this sequence, two must be the same. Let r j = r k (j < k) be such two. Let x = s 1 s j 1, y = s j s k 1, and z = s k s n. We have y > 0 (since j k). We have xy = s 1 s k 1 p since r k occurs among the first p + 1 places in the sequence of states (so k p+1).

Strategy for showing that a language L is not regular 1 Assume that L is regular (with the aim of reaching a contradiction). 2 Choose a string s L, such that s p where p is the pumping length given by the Pumping. The Pumping then says that s can be partitioned into three pieces s = xyz where y > 0 and xy p, such that xy i z L for all i 0. 3 Show that for ALL POSSIBLE partitions of s = xyz satisfying y > 0 and xy p there exists an i such that xy i z / L. If we succeed to show this, then we have a contradiction with the Pumping and our assumption that L is regular is wrong.

The standard example Example L = {a n b n n 0} is not regular. Proof. 1 Assume that L is regular 2 Choose s = a p b p where p is the pumping length given by the Pumping. s L and s p, so the Pumping says that s can be partitioned into three pieces s = xyz where y > 0 and xy p, such that xy i z L for all i 0. 3 s = a p b p = xyz where y > 0 and xy p. For all such partitions of s, y is a string of a s of length at least 1. Choose i = 2, xy 2 z contains more a s than b s, thus, xy 2 z / L. This contradicts the Pumping, hence, our assumption that L is regular is wrong.

Regular languages: Summary Regular languages are the languages recognized by DFAs For every NFA there is an equivalent DFA The subset construction A language can be described by a regular expression if and only if it can be recognized by a DFA GNFA construction, closure properties There are simple non-regular languages Pumping lemma