CS 154. Finite Automata, Nondeterminism, Regular Expressions

Similar documents
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 154, Lecture 3: DFA NFA, Regular Expressions

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

Equivalence of DFAs and NFAs

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

Theory of Computation (I) Yijia Chen Fudan University

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

CSE 105 THEORY OF COMPUTATION

Intro to Theory of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 455/555: Finite automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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,

Non-deterministic Finite Automata (NFAs)

Finite Automata and Regular languages

CS21 Decidability and Tractability

Nondeterministic Finite Automata

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

Lecture 3: Nondeterministic Finite Automata

CSE 105 Theory of Computation Professor Jeanne Ferrante

CS 154 Introduction to Automata and Complexity Theory

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

September 7, Formal Definition of a Nondeterministic Finite Automaton

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

CSE 105 THEORY OF COMPUTATION

Computational Models Lecture 2 1

Closure under the Regular Operations

Computational Models Lecture 2 1

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

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

CSE 105 THEORY OF COMPUTATION

Chapter Five: Nondeterministic Finite Automata

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

CPS 220 Theory of Computation REGULAR LANGUAGES

CSE 105 THEORY OF COMPUTATION

Theory of Computation (II) Yijia Chen Fudan University

Nondeterministic finite automata

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

Deterministic Finite Automata (DFAs)

CS243, Logic and Computation 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

Inf2A: Converting from NFAs to DFAs and Closure Properties

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

Nondeterminism. September 7, Nondeterminism

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

Nondeterministic Finite Automata

Theory of Languages and Automata

CS21 Decidability and Tractability

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

CSE 105 THEORY OF COMPUTATION

Fooling Sets and. Lecture 5

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

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

3515ICT: Theory of Computation. Regular languages

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

Deterministic Finite Automata (DFAs)

Computational Models - Lecture 1 1

Deterministic Finite Automata (DFAs)

CSE 105 THEORY OF COMPUTATION

Finite Automata. BİL405 - Automata Theory and Formal Languages 1

Sri vidya college of engineering and technology

Finite Automata Part Two

CSC173 Workshop: 13 Sept. Notes

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

CSC236 Week 11. Larry Zhang

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

CSE 105 THEORY OF COMPUTATION

Finite Automata and Regular Languages

Introduction to Languages and Computation

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

CSE 105 THEORY OF COMPUTATION

Theory of computation: initial remarks (Chapter 11)

CHAPTER 1 Regular Languages. Contents

Nondeterminism and Epsilon Transitions

Lecture 4: More on Regexps, Non-Regular Languages

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Lecture 4 Nondeterministic Finite Accepters

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

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

Theory of Computation Lecture 1. Dr. Nahla Belal

Automata and Languages

Finite Automata Part Two

Computational Theory

CSE 105 THEORY OF COMPUTATION

Critical CS Questions

Non-Deterministic Finite Automata

CSE 105 THEORY OF COMPUTATION

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

Chap. 1.2 NonDeterministic Finite Automata (NFA)

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

Computer Sciences Department

CSE 105 THEORY OF COMPUTATION

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

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

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Chapter 5. Finite Automata

Regular Expressions. Definitions Equivalence to Finite Automata

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

Computational Models #1

TDDD65 Introduction to the Theory of Computation

Transcription:

CS 54 Finite Automata, Nondeterminism, Regular Expressions

Read string left to right The DFA accepts a string if the process ends in a double circle

A DFA is a 5-tuple M = (Q, Σ, δ, q, F) Q is the set of states (finite) Σ is the alphabet (finite) δ : Q Σ Q is the transition function q Q is the start state F Q is the set of accept/final states L(M) = set of all strings that M accepts = the language recognized by M

A DFA is a 5-tuple M = (Q, Σ, δ, q, F) L(M) = set of all strings that M accepts = the language recognized by M Definition: A language L is regular if it is recognized by a DFA; that is, there is a DFA M where L = L(M).

Union Theorem for Regular Languages The union of two regular languages is also a regular language Intersection Theorem for Regular Languages The intersection of two regular languages is also a regular language

Complement Theorem for Regular Languages The complement of a regular language is also a regular language

The Reverse of a Language Reverse of L: L R = { w w k w k w L, w i Σ} If L is recognized by the usual kind of DFA, Then L R is recognized by a DFA that reads its strings from right to left! Question: If L is regular, then is L R also regular? Can every Right-to-Left DFA be replaced by a normal Left-to-Right DFA?

,, L(M) = { w w begins with } Suppose our machine reads strings from right to left Then L(M) = {w w ends with a }. Is this regular?

Reversing DFAs Assume L is a regular language. Let M be a DFA that recognizes L We ll build a machine M R that accepts L R If M accepts w, then w describes a directed path in M from start to an accept First Attempt: Try to define M R as M with the arrows reversed, turn start state into a final state, turn final states into starts

Problem: M R IS NOT ALWAYS A DFA! It could have many start states Some states may have more than one outgoing edge, or none at all!

,

Non-deterministic Finite Automata (NFA), What happens with? We will say this new machine accepts a string x if there is some path reading in x that reaches some accept state from some start state

Non-deterministic Finite Automata (NFA), Then, this machine recognizes: {w w contains } We will say this new machine accepts a string x if there is some path reading in x that reaches some accept state from some start state

Another Example of an NFA,,, ε At each state, we can have any number of out arrows for a letter σ Σ, including ε Set of strings accepted by this NFA = {w w contains a }

Multiple Start States We allow multiple start states for NFAs, and Sipser allows only one Can easily convert NFA with many start states into one with a single start state: ε ε ε

A non-deterministic finite automaton (NFA) is a 5-tuple N = (Q, Σ, δ, Q, F) where Q is the set of states Σ is the alphabet δ : Q Σ ε 2 Q is the transition function Q Q is the set of start states F Q is the set of accept states 2 Q is the set of all possible subsets of Q Σ ε = Σ {ε}

Def. Let w Σ*. Let N be an NFA. N accepts w if there s a sequence of states r, r,..., r k Q and w can be written as w... w k with w i Σ {ε} such that. r Q 2. r i+ δ(r i, w i+ ) for all i =,..., k-, and 3. r k F L(N) = the language recognized by N = set of all strings machine N accepts A language L is recognized by an NFA N if L = L(N).

q 2 q 4 ε q 3 N = (Q, Σ, δ, Q, F) Q = {q, q 2, q 3, q 4 } Σ = {,} Q = {q, q 2 } q F = {q 4 } L(N) = {,,} δ(q 2,) = {q 4 } δ(q 3,) = δ(q,) = {q 3 }

Deterministic Computation Non-Deterministic Computation reject accept or reject accept Are these equally powerful???

NFAs are generally simpler than DFAs A DFA recognizing the language {},, An NFA recognizing the language {}

Every NFA can be perfectly simulated by some DFA! Theorem: For every NFA N, there is a DFA M such that L(M) = L(N) Corollary: A language L is regular if and only if L is recognized by an NFA Corollary: L is regular iff L R is regular

From NFAs to DFAs Input: NFA N = (Q, Σ, δ, Q, F) Output: DFA M = (Q, Σ, δ, q, F ) accept reject To learn if an NFA accepts, we could do the computation in parallel, maintaining the set of all possible states that can be reached Idea: Set Q = 2 Q

* From NFAs to DFAs: Subset Construction Input: NFA N = (Q, Σ, δ, Q, F) Output: DFA M = (Q, Σ, δ, q, F ) Q = 2 Q δ : Q Σ Q δ (R,σ) = ε( δ(r,σ) ) r R q = ε(q ) F = { R Q f R for some f F } For S Q, the ε-closure of S is ε(s) = {q Q reachable from some s S by taking or more ε transitions} *

Example of the ε-closure,,,ε,ε q q q 2 ε({q }) = {q, q, q 2 } ε({q }) = {q, q 2 } ε({q 2 }) = {q 2 }

Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) a N b Construct: Equivalent DFA M M = (2 {,2,3}, {a,b}, δ, {,3}, ) a a b {,3} {3} a b b b a,b ε a, b 2 3 ε({}) = {,3} {2} a {2,3} {}, {,2}? a b {,2,3} a

Reverse Theorem for Regular Languages The reverse of a regular language is also a regular language If a language can be recognized by a DFA that reads strings from right to left, then there is an normal DFA that accepts the same language Proof? Given a DFA for a language L, reverse its arrows and flip its start and accept states, getting an NFA. Convert that NFA back to a DFA.

Using NFAs in place of DFAs can make proofs about regular languages much easier! Remember this on homework/exams!

Union Theorem using NFAs?

Regular Languages are closed under concatenation Concatenation: A B = { vw v A and w B } Given DFAs M and M 2, connect the accept states of M to the start states of M 2, ε, ε L(N) = L(M ) L(M 2 )

Regular Languages are closed under star A* = { s s k k and each s i A } Let M be a DFA, and let L = L(M) We can construct an NFA N that recognizes L* ε, ε ε

Formally, the construction is: Input: DFA M = (Q, Σ, δ, q, F) Output: NFA N = (Q, Σ, δ, {q }, F ) Q = Q {q } F = F {q } δ (q,a) = {δ(q,a)} {q } {q } if q Q and a ε if q F and a = ε if q = q and a = ε if q = q and a ε else

Regular Languages are closed under star How would we prove that this NFA construction works? Want to show: L(N) = L*. L(N) L* 2. L(N) L*

. L(N) L* Assume w = w w k is in L* where w,,w k L We show N accepts w by induction on k Base Cases: k = k = (w = ε) (w L) Inductive Step: Assume N accepts all strings v = v v k L*, v i L Let u = u u k u k+ L*, u j L Since N accepts u u k (by induction) and M accepts u k+, N also accepts u (by construction)

2. L(N) L* Assume w is accepted by N; we want to show w L* If w = ε, then w L* I.H. N accepts u and takes at most k ε-transitions u L* Let w be accepted by N with k+. Write w as w=uv, where v is the substring read after the last ε-transition v u ε ε accept u L(N), so u L* v L By I.H. w = uv L*

Regular Languages are closed under all of the following operations: Union: A B = { w w A or w B } Intersection: A B = { w w A and w B } Complement: A = { w Σ* w A } Reverse: A R = { w w k w k w A } Concatenation: A B = { vw v A and w B } Star: A* = { w w k k and each w i A }

Homework is coming out today watch for it!

Regular Expressions

Inductive Definition of Regexp Let Σ be an alphabet. We define the regular expressions over Σ inductively: For all σ Σ, σ is a regexp ε is a regexp is a regexp If R and R 2 are both regexps, then (R R 2 ), (R + R 2 ), and (R )* are regexps

Precedence Order: * then then + ( R * R 2 Example: R *R 2 + R 3 = ( ) ) + R 3

Definition: Regexps Represent Languages The regexp σ Σ represents the language {σ} The regexp ε represents {ε} The regexp represents If R and R 2 are regular expressions representing L and L 2 then: (R R 2 ) represents L L 2 (R + R 2 ) represents L L 2 (R )* represents L *

Regexps Represent Languages For every regexp R, define L(R) to be the language that R represents A string w Σ* is acceptedby R (or, w matches R) if w L(R) Example: matches the regexp ()*

end