Finite Automata and Regular languages

Similar documents
Theory of Computation (I) Yijia Chen Fudan University

CS 455/555: Finite automata

Theory of Computation (II) Yijia Chen Fudan University

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Closure under the Regular Operations

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Inf2A: Converting from NFAs to DFAs and Closure Properties

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,

Lecture 3: Nondeterministic Finite Automata

3515ICT: Theory of Computation. Regular languages

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Computer Sciences Department

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

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

Intro to Theory of Computation

Theory of Languages and Automata

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

Non-deterministic Finite Automata (NFAs)

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

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

Computational Theory

Sri vidya college of engineering and technology

September 7, Formal Definition of a Nondeterministic Finite Automaton

CS 154, Lecture 3: DFA NFA, Regular Expressions

Nondeterministic Finite Automata

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

CS243, Logic and Computation Nondeterministic finite automata

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

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

UNIT-III REGULAR LANGUAGES

Automata: a short introduction

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSE 105 THEORY OF COMPUTATION

Computational Models - Lecture 3 1

Uses of finite automata

CSE 105 THEORY OF COMPUTATION

CSE 105 Theory of Computation Professor Jeanne Ferrante

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

TDDD65 Introduction to the Theory of Computation

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

CPS 220 Theory of Computation REGULAR LANGUAGES

What we have done so far

The Pumping Lemma and Closure Properties

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

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

Equivalence of DFAs and NFAs

CSE 105 THEORY OF COMPUTATION

CS21 Decidability and Tractability

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

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

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

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

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

DM17. Beregnelighed. Jacob Aae Mikkelsen

Languages, regular languages, finite automata

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

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

Fooling Sets and. Lecture 5

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

The Church-Turing Thesis

Formal Languages, Automata and Models of Computation

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

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

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

Computational Models - Lecture 4

CS 154 Introduction to Automata and Complexity Theory

Properties of Regular Languages (2015/10/15)

arxiv: v2 [cs.fl] 29 Nov 2013

Finite Automata Part Two

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

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

Lecture 1: Finite State Automaton

More Properties of Regular Languages

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

CPSC 421: Tutorial #1

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

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

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

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Lecture 4: More on Regexps, Non-Regular Languages

Computational Models - Lecture 3

Formal Definition of Computation. August 28, 2013

Computational Models - Lecture 3 1

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

Formal Models in NLP

We define the multi-step transition function T : S Σ S as follows. 1. For any s S, T (s,λ) = s. 2. For any s S, x Σ and a Σ,

Büchi Automata and their closure properties. - Ajith S and Ankit Kumar

Chapter 6: NFA Applications

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Lecture 17: Language Recognition

Closure under the Regular Operations

Computational Models - Lecture 5 1

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

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

CSE 105 THEORY OF COMPUTATION

Exam 1 CSU 390 Theory of Computation Fall 2007

CSCE 551 Final Exam, Spring 2004 Answer Key

Finite Automata and Regular Languages

Transcription:

Finite Automata and Regular languages Huan Long Shanghai Jiao Tong University

Acknowledgements Part of the slides comes from a similar course in Fudan University given by Prof. Yijia Chen. http://basics.sjtu.edu.cn/ chen/ http://basics.sjtu.edu.cn/ chen/teaching/toc/ Textbook Introduction to the theory of computation Michael Sipser, MIT Third edition, 2012

Outline Finite automata and regular language Nondeterminism automata Equivalence of DFA and NFA Regular expression Pumping lemma for regular languages Some decision problems related to FA

Finite Automata Definition A deterministic finite automata (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, 5. F Q is the set of accept states.

Computation by DFA Let M = (Q, Σ, δ, q 0, F ) be a DFA and let w = w 1 w 2 w n be a string with w i Σ for all i [n]. Then M accepts w if there exists a sequence of states r 0, r 1,..., r n in Q such that: 1. r 0 = q 0, 2. δ(r i, w i+1 ) = r i+1 for i = 0,..., n 1, 3. r n F. For a set A, we say that M recognizes A if A = {l M accepts l}

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

The regular operators Definition Let A and B be languages. We define the following three regular operations: Union: A B = {x x A x B} Concatenation: A B = {xy x A y B} Kleene star: A = {x 1 x 2... x k k 0 x i A}

Nondeterminism Definition A nondeterministic finite automata (NFA) 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 Σ ɛ P(Q) is the transition function, where Σ ɛ = Σ {ɛ}, 4. q 0 Q is the start state, 5. F Q is the set of accept states.

Computation by NFA Let N = (Q, Σ, δ, q 0, F ) be a NFA and let w = y 1 y 2 y m be a string with y i Σ ɛ for all i [m]. Then N accepts w if there exists a sequence of states r 0, r 1,..., r n in Q such that: 1. r 0 = q 0, 2. r i+1 δ(r i, y i+1 ) for i = 0,..., m 1, 3. r n F.

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

Proof (1) NFA: N = (Q, Σ, δ, q 0, F ) Main idea: view a NFA as occupying a set of states at any moment. Step 1: For any state q Q, compute its silently reachable class E(q): initially set E(q) = {q}; repeat E (q) = E(q) x E(q), if y δ(x, ɛ) y E(q), E(q) = E(q) {y} until E(q) = E (q) return E(q).

Proof (2) Step 2: build the equivalent DFA NFA: N = (Q, Σ, δ, q 0, F ) DFA: M = (Q, Σ, δ, q 0, F ) 1. Q = P(Q); 2. Let R Q and a Σ, define δ (R, a) = {E(q) q Q ( r R)(q σ(r, a))} ; 3. q 0 = {q 0}; 4. F = {R Q R F }.

Corollary A language is regular if and only if some NFA recognizes it.

Recall: regular operators Definition Let A and B be languages. We define the following three regular operations: Union: A B = {x x A x B} Concatenation: A B = {xy x A y B} Kleene star: A = {x 1 x 2... x k k 0 x i A}

Closure under the regular operators Theorem The class of regular languages is closed under the,, operations. Proof. Let N 1 = (Q 1, Σ 1, δ 1, q 1, F 1 ) recognize A 1, N 2 = (Q 2, Σ 2, δ 2, q 2, F 2 ) recognize A 2 ; We will build NFAs which recognize A 1 A 2, A 1 A 2, A 1 respectively.

I. Closure under union : A 1 A 2 is regular N 1 = (Q 1, Σ 1, δ 1, q 1, F 1 ) recognize A 1, N 2 = (Q 2, Σ 2, δ 2, q 2, F 2 ) recognize A 2 ; Define the NFA as: 1. Q = {q 0 } Q 1 Q 2 ; 2. q 0 is the new start state; 3. F = F 1 F 2 ; 4. For any q Q and any a Σ ɛ {q 1, q 2 } q = q 0 a = ɛ q = q δ(q, a) = 0 a ɛ δ 1 (q, a) q Q 1 δ 2 (q, a) q Q 2

II. Closure under concatenation : A 1 A 2 is regular N 1 = (Q 1, Σ 1, δ 1, q 1, F 1 ) recognize A 1, N 2 = (Q 2, Σ 2, δ 2, q 2, F 2 ) recognize A 2 ; Define the NFA as: 1. Q = Q 1 Q 2 ; 2. the start state is q 1 ; 3. the set of accept states is F 2 ; 4. For any q Q and any a Σ ɛ δ 1 (q, a) q Q 1 F 1 δ δ(q, a) = 1 (q, a) q F 1 a ɛ δ 1 (q, a) {q 2 } q F 1 a = ɛ δ 2 (q, a) q Q 2

III. Closure under Kleene star : A 1 is regular N 1 = (Q 1, Σ, δ 1, q 1, F 1 ) recognize A 1 ; Define the NFA as: 1. Q = {q 0 } Q 1 ; 2. the new start state is q 0 ; 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 a ɛ δ(q, a) = δ 1 (q, a) {q 1 } q F 1 a = ɛ {q 1 } q = q 0 a = ɛ q = q 0 a ɛ

Regular expression Given alphabet Σ, 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 expression. Sometimes, we use R 1 R 2 instead of (R 1 R 2 ) if no confusion arises.

Other closure property Given N = (Q, Σ, δ, q, F ) the set of language recognized by N is A, then Complement: A = Σ A Intersection: A B = {x x A x B} Lemma The class of regular languages is closed under complementation and intersection. Proof. w.l.o.g, N is a DFA, then N = (Q, Σ, δ, q, Q F ) will recognize A. A B = A B.

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. Proof. Only if: build the NFAs; (relatively easy) If: Automata = regular expressions. Sketch: (Dynamic programming) R(i, j, k) = R(i, j, k 1) R(i, k, k 1)R(k, k, k 1) R(k, j, k 1) L(M) = {R(1, j, n) q j F }.

Languages need counting L 1 = {l {0, 1} l has an equal number of 0s and 1s}. L 2 = {l {0, 1} l has an equal number of occurrences of 01 and 10 as substrings}. L 2 is regular; L 1 is or is not regular? It is not regular!

The pumping lemma for regular languages Lemma If A is a regular language, then there is a number p (i.e., the pumping length where if s is any string in A of length at least p, then s my be divided into three pieces, s = xyz, satisfying the following conditions: 1. y > 0, 2. xy p, 3. for each i 0, we have xy i z A. Any string xyz in A can be pumped along y.

Proof Pigeonhole principle Let M = (Q, Σ, δ, q 1, F ) be a DFA recognizing A and p = Q. Let s = s 1 s 2 s n be a string in A with n p. Let r 1,, r n+1 be the sequence of states that M enters while processing s, i.e., r i+1 = δ(r i, s i ) for i [n]. Among the first p + 1 states in the sequence, two must be the same, say r j and r k with j < k p + 1. Define x = s 1 s j 1, y = s j s k 1, z = s k s n.

Example (1) The language L = {0 n 1 n n 0} is not regular. Proof. If it is regular, choose p be the pumping length and consider s = 0 p 1 p.by the Pumping lemma, s = xyz with xy i z L for all i 0. As xy p and y > 0, y = 0 i for some i > 0. But then xz = a n i b n L. Contradicting the lemma.

Example (2) The language L = {w w has an equal number of 0s and 1s} is not regular. Proof. If it is regular, then L 0 1 would also be regular. However, this latter language is precisely the language in Example (1), which is not regular.

Problems from formal language theory Decision Problems Acceptance: does a given string belong to a given language? Emptiness: is a given language empty? Equality: are given two languages equal?

Language Problems concerning FA Theorem The following three problems: Acceptance: Given a DFA (NFA) A and a string w, does A accept w? Emptiness: Given a DFA (NFA) A is the language L(A) empty? Equality: Given two DFA (NFA) A and B is L(A) equal to L(B)? The corresponding decision problems are all decidable. Proof.