Theory of Computation (I) Yijia Chen Fudan University

Similar documents
Finite Automata and Regular languages

Theory of Computation (II) Yijia Chen Fudan University

COM364 Automata Theory Lecture Note 2 - Nondeterminism

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Theory of Languages and Automata

Nondeterministic Finite Automata

Closure under the Regular Operations

Intro to Theory of Computation

September 7, Formal Definition of a Nondeterministic Finite Automaton

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

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

Lecture 3: Nondeterministic Finite Automata

Inf2A: Converting from NFAs to DFAs and Closure Properties

CS 455/555: Finite automata

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

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

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

Equivalence of DFAs and NFAs

Chapter Five: Nondeterministic Finite Automata

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

CS21 Decidability and Tractability

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

CPS 220 Theory of Computation REGULAR LANGUAGES

Nondeterministic Finite Automata

Computer Sciences Department

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

CSE 105 Theory of Computation Professor Jeanne Ferrante

Lecture 1: Finite State Automaton

Chap. 1.2 NonDeterministic Finite Automata (NFA)

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Lecture 4 Nondeterministic Finite Accepters

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

CS 154, Lecture 3: DFA NFA, Regular Expressions

Automata: a short introduction

INF Introduction and Regular Languages. Daniel Lupp. 18th January University of Oslo. Department of Informatics. Universitetet i Oslo

Non-deterministic Finite Automata (NFAs)

Computational Models Lecture 2 1

Computational Models Lecture 2 1

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Automata and Languages

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

Finite Automata Part Two

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

Non-Deterministic Finite Automata

CISC 4090 Theory of Computation

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

CS243, Logic and Computation Nondeterministic finite automata

Theory of Computation (IV) Yijia Chen Fudan University

Nondeterministic finite automata

Introduction to Languages and Computation

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

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

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

Fooling Sets and. Lecture 5

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

Computational Models - Lecture 1 1

Closure under the Regular Operations

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

Harvard CS 121 and CSCI E-207 Lecture 4: NFAs vs. DFAs, Closure Properties

UNIT-III REGULAR LANGUAGES

CS 154 Formal Languages and Computability Assignment #2 Solutions

C2.1 Regular Grammars

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

Classes and conversions

Theory of Computation Lecture 1. Dr. Nahla Belal

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

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

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,

C2.1 Regular Grammars

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Nondeterminism and Epsilon Transitions

CSC236 Week 10. Larry Zhang

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

2017/08/29 Chapter 1.2 in Sipser Ø Announcement:

Context-Free Languages

Sri vidya college of engineering and technology

TDDD65 Introduction to the Theory of Computation

CS 133 : Automata Theory and Computability

Finite Automata and Regular Languages (part III)

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

CSE 105 THEORY OF COMPUTATION

CSCI 2670 Introduction to Theory of Computing

Applied Computer Science II Chapter 1 : Regular Languages

Critical CS Questions

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Theory of Computation

CS 208: Automata Theory and Logic

CS 154 Introduction to Automata and Complexity Theory

Lecture 17: Language Recognition

Computational Theory

Formal Models in NLP

Finite Automata. Seungjin Choi

Nondeterminism. September 7, Nondeterminism

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

Theory of Computation (IX) Yijia Chen Fudan University

CSE 105 THEORY OF COMPUTATION

Transcription:

Theory of Computation (I) Yijia Chen Fudan University

Instructor Yijia Chen Homepage: http://basics.sjtu.edu.cn/~chen Email: yijiachen@fudan.edu.cn

Textbook Introduction to the Theory of Computation Michael Sipser, MIT Third Edition, 2012.

Part One. Automata and Languages

Regular Languages

Finite automata Definition A (deterministic) finite automaton (DFA) is a 5-tuple ( Q, Σ, δ, q 0, F ), where 1. Q is a finite set called the states, 2. Σ is a finite set called the alphabet, 3. δ : Q Σ Q is the transition function, 4. q 0 Q is the start state, and 5. F Q is the set of accept states.

Formal definition of computation Let M = ( Q, Σ, δ, q 0, F ) be a finite automaton and let w = w 1w 2 w n be a string with w i Σ for all i [n]. Then M accepts w if a sequence of states r 0, r 1,..., r n in Q exists with: 1. r 0 = q 0, 2. δ(r i, w i+1 ) = r i+1 for i = 0,..., n 1, and 3. r n F. We say that M recognizes A if A = { w M accepts w }.

Regular languages Definition A language is called regular if some finite automaton recognizes it.

The regular operators Definition Let A and B be languages. We define the regular operations union, concatenation, and star as follows: Union: A B = { x x A or x B }. Concatenation: A B = { xy x A and y B }. Star: A = { x 1x 2... x k k 0 and each xi A }.

Closure under union Theorem The class of regular languages is closed under the union operation. In other words, if A 1 and A 2 are regular languages, so is A 1 A 2.

Proof (1) For i [2] let M i = ( Q i, Σ i, δ i, q i, F i ) recognize Ai. We can assume without loss of generality Σ 1 = Σ 2: Let a Σ 2 Σ 1. We add δ 1(r, a) = r trap, where r trap is a new state with δ 1(r trap, w) = r trap for every w.

Proof (2) We construct M = ( Q, Σ, δ, q 0, F ) to recognize A 1 A 2: 1. Q = Q 1 Q 2 = { (r 1, r } 2) r 1 Q 1 and r 2 Q 2. 2. Σ = Σ 1 = Σ 2. 3. For each (r 1, r 2) Q and a Σ we let δ ( (r 1, r 2), a ) = ( δ 1(r 1, a), δ 2(r 2, a) ). 4. q 0 = (q 1, q 2). 5. F = (F 1 Q 2) (Q 1 F 2) = { (r 1, r } 2) r 1 F 1 or r 2 F 2.

Closure under concatenation Theorem The class of regular languages is closed under the concatenation operation. In other words, if A 1 and A 2 are regular languages, so is A 1 A 2. We prove the above theorem by nondeterministic finite automata.

Nondeterminism Definition A nondeterministic finite automaton (NFA) is a 5-tuple ( Q, Σ, δ, q 0, F ), where 1. Q is a finite set of states, 2. Σ is a finite alphabet, 3. δ : Q Σ ε P(Q) is the transition function, where Σ ε = Σ {ε}, 4. q 0 Q is the start state, and 5. F Q is the set of accept states.

Formal definition of computation Let N = ( Q, Σ, δ, q 0, F ) be an NFA and let w = y 1y 2 y m be a string with y i Σ ε for all i [m]. Then N accepts w if a sequence of states r 0, r 1,..., r m in Q exists with: 1. r 0 = q 0, 2. r i+1 δ(r i, y i+1 ) for i = 0,..., m 1, and 3. r m F.

Equivalence of NFAs and DFAs Theorem Every NFA has an equivalent DFA, i.e., they recognize the same language.

Proof (1) Let N = ( Q, Σ, δ, q 0, F ) be the NFA recognizing some language A. We construct a DFA M = ( Q, Σ, δ, q 0, F ) recognizing the same A. First assume N has no ε arrows. 1. Q = P(Q). 2. Let R Q and a Σ. Then we define 3. q 0 = {q 0}. δ (R, a) = { q Q q δ(r, a) for some r R }. 4. F = { R Q R F }.

Proof (2) Now we allow ε arrows. For every R Q, i.e., R Q, let E(R) = { q Q q can be reached from R by traveling along 0 and more ε arrows }. 1. Q = P(Q). 2. Let R Q and a Σ. Then we define δ (R, a) = { q Q ( ) } q E δ(r, a) for some r R. 3. q 0 = E ( {q ) 0}. 4. F = { R Q } R F.

Corollary A language is regular if and on if some nondeterministic finite automaton recognizes it.

Second proof of the closure under union For i [2] let N i = ( Q i, Σ i, δ i, q i, F i ) recognize Ai. We construct an N = ( Q, Σ, δ, q 0, F ) to recognize A 1 A 2: 1. Q = {q 0} Q 1 Q 2. 2. q 0 is the start state. 3. F = F 1 F 2. 4. For any q Q and any a Σ ε δ 1(q, a) q Q 1 δ 2(q, a) q Q 2 δ(q, a) = {q 1, q 2} q = q 0 and a = ε q = q 0 and a ε.

Closure under concatenation Theorem The class of regular languages is closed under the concatenation operation.

Proof For i [2] let N i = ( Q i, Σ i, δ i, q i, F i ) recognize Ai. We construct an N = ( Q, Σ, δ, q 1, F 2 ) to recognize A1 A 2: 1. Q = Q 1 Q 2. 2. The start state q 1 is the same as the start state of N 1. 3. The accept states F 2 are the same as the accept states of N 2. 4. For any q Q and any a Σ ε δ 1(q, a) q Q 1 F 1 δ 1(q, a) q F 1 and a ε δ(q, a) = δ 1(q, a) {q 2} q F 1 and a = ε δ 2(q, a) q Q 2.

Closure under star Theorem The class of regular languages is closed under the star operation.

Proof Let N 1 = ( Q 1, Σ, δ 1, q 1, F 1 ) recognize Ai. We construct an N = ( Q, Σ, δ, q 0, F ) to recognize A 1 : 1. Q = {q 0} Q 1. 2. The start state q 0 is the new start state. 3. F = {q 0} F 1. 4. For any q Q and any a Σ ε δ 1(q, a) q Q 1 F 1 δ 1(q, a) q F 1 and a ε δ(q, a) = δ 1(q, a) {q 1} q F 1 and a = ε {q 1} q = q 0 and a = ε q = q 0 and a ε.

Regular expression Definition We say that R is a regular expression if R is 1. a for some a Σ, 2. ε, 3., 4. (R 1 R 2), where R 1 and R 2 are regular expressions, 5. (R 1 R 2), where R 1 and R 2 are regular expressions, 6. (R 1 ), where R 1 is a regular expressions. We often write R 1R 2 instead of (R 1 R 2) if no confusion arises.

Language defined by regular expressions regular expression R language L(R) a {a} ε {ε} (R 1 R 2) L(R 1) L(R 2) (R 1 R 2) L(R 1) L(R 2) (R1 ) L(R 1)

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

The languages defined by regular expressions are regular 1. R = a: Let N = ( {q 1, q 2}, Σ, δ, q 1, {q 2} ), where δ(q 1, a) = {q 2} and δ(r, b) = for all r q 1 or b a. 2. R = ε: Let N = ( {q 1}, Σ, δ, q 1, {q 1} ), where δ(r, b) = for all r and b. 3. R = : Let N = ( {q 1}, Σ, δ, q 1, ), where δ(r, b) = for all r and b. 4. R = R 1 R 2: L(R) = L(R 1) L(R 2). 5. R = R 1 R 2: L(R) = L(R 1) L(R 2). 6. R = R 1 : L(R) = L(R 1).