FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Similar documents
CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

CS 154, Lecture 3: DFA NFA, Regular Expressions

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

Equivalence of DFAs and NFAs

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Theory of Computation (I) Yijia Chen Fudan University

COM364 Automata Theory Lecture Note 2 - Nondeterminism

CSE 105 THEORY OF COMPUTATION

Intro to Theory of Computation

Nondeterministic Finite Automata

CS 455/555: Finite automata

CS 154 Introduction to Automata and Complexity Theory

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

Non-deterministic Finite Automata (NFAs)

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

CSE 105 Theory of Computation Professor Jeanne Ferrante

Finite Automata and Regular languages

Chapter Five: Nondeterministic Finite Automata

Closure under the Regular Operations

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

Lecture 3: 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

CSE 105 THEORY OF COMPUTATION

Nondeterministic finite automata

CPS 220 Theory of Computation REGULAR LANGUAGES

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,

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

Computational Models Lecture 2 1

September 7, Formal Definition of a Nondeterministic Finite Automaton

Computational Models Lecture 2 1

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

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

Theory of Languages and Automata

CS21 Decidability and Tractability

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

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)

Nondeterminism. September 7, Nondeterminism

Theory of Computation Lecture 1. Dr. Nahla Belal

CSE 105 THEORY OF COMPUTATION

Fooling Sets and. Lecture 5

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

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

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

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

Computational Models - Lecture 1 1

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

Lecture 4 Nondeterministic Finite Accepters

Sri vidya college of engineering and technology

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

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

CSC173 Workshop: 13 Sept. Notes

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

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

Nondeterministic Finite Automata

3515ICT: Theory of Computation. Regular languages

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

Finite Automata Part Two

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

CS243, Logic and Computation Nondeterministic finite automata

Inf2A: Converting from NFAs to DFAs and Closure Properties

CS21 Decidability and Tractability

Automata: a short introduction

CSE 105 THEORY OF COMPUTATION

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

CHAPTER 1 Regular Languages. Contents

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

CSE 105 THEORY OF COMPUTATION

Closure under the Regular Operations

Computer Sciences Department

Formal Definition of Computation. August 28, 2013

Chapter 5. Finite Automata

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

CSC236 Week 11. Larry Zhang

Deterministic Finite Automata (DFAs)

Deterministic Finite Automata (DFAs)

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

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Course 4 Finite Automata/Finite State Machines

Computational Models - Lecture 4

Introduction to Languages and Computation

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Computational Models - Lecture 5 1

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

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

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

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

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

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

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

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

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

Finite Automata. Mahesh Viswanathan

Finite Automata Part Two

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

Transcription:

5-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

NON-DETERMINISM and REGULAR OPERATIONS THURSDAY JAN 6

UNION THEOREM The union of two regular languages is also a regular language Regular Languages Are Closed Under Union INTERSECTION THEOREM The intersection of two regular languages is also a regular language

Complement THEOREM The complement of a regular language is also a regular language In other words, if L is regular than so is L, where L= { w Σ* w L } Proof?

,, L(M) = { w w begins with }

,, L(M) = { w w begins with } Suppose our machine reads strings from right to left What language would be recognized then?

,, L(M) = { w w begins with } Suppose our machine reads strings from right to left What language would be recognized then? L(M) = { w w ends with } Is L(M) regular?

L(M) = { w w ends with } Is L(M) regular?

THE REVERSE OF A LANGUAGE Reverse: L R = { w w k w k w L, w i Σ} If L is recognized by a normal DFA, Then L R is recognized by a DFA reading from right to left! Can every Right-to-Left DFA be replaced by a normal DFA??

REVERSE THEOREM The reverse of a regular language is also a regular language ``Regular Languages Are Closed Under Reverse 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

REVERSING DFAs Assume L is a regular language. Let M be a DFA that recognizes L Task: Build a DFA M R that accepts L R If M accepts w, then w describes a directed path in M from start to an accept state.

REVERSING DFAs Assume L is a regular language. Let M be a DFA that recognizes L Task: Build a DFA M R that accepts L R If M accepts w, then w describes a directed path in M from start to an accept state. First Attempt: Try to define M R as M with the arrows reversed. Turn start state into a final state. Turn final states into start states.

M R IS NOT ALWAYS A DFA! It could have many start states Some states may have too many outgoing edges, or none at all!

,

REVERSE, What happens with?

REVERSE, What happens with? We will say that this machine accepts a string if there is some path that reaches an accept state from a start state.

NONDETERMINISM is BORN!, What happens with? We will say that this machine accepts a string if there is some path that reaches an accept state from a start state.

IBM JOURNAL APRIL 959 Turing Award winning paper

NFA EXAMPLES,,, ε At each state, we can have any number of out arrows for each letter σ Σ ε = Σ {ε}

NFA EXAMPLES, ε L(M) = { i j i {,}, j } Possibly many start states

NFA EXAMPLES L(M)={,}

A non-deterministic finite automaton (NFA) is a 5-tuple N = (Q, Σ, δ, Q, F) 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 Σ ε = Σ {ε}

Let w Σ* and suppose w can be written as w... w n where w i Σ ε (ε = empty string) Then N accepts w if there are r, r,..., r n Q such that. r Q 2. r i+ δ(r i, w i+ ) for i =,..., n-, and 3. r n 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).

Deterministic Computation Non-Deterministic Computation reject accept or reject accept

Deterministic Computation Non-Deterministic Computation reject accept or reject accept

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

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

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

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

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: ε ε ε

UNION THEOREM FOR NFAs?

UNION THEOREM FOR NFAs?

NFAs ARE SIMPLER THAN DFAs A DFA that recognizes the language {}:,,

NFAs ARE SIMPLER THAN DFAs An NFA that recognizes the language {}: A DFA that recognizes the language {}:,,

BUT DFAs CAN SIMULATE NFAs! Theorem: Every NFA has an equivalent* DFA Corollary: A language is regular iff it is recognized by an NFA Corollary: L is regular iff L R is regular * N is equivalent to M if L(N) = L (M)

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

For R Q, the ε-closure of R, ε(r) = {q that can be reached from some r R by traveling along zero or more ε arrows} FROM NFA TO DFA 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 }

EXAMPLE OF ε-closure,,,ε,ε q q q 2 ε({q }) = ε({q }) = ε({q 2 }) =

EXAMPLE OF ε-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}, δ, {}, {} ) Construct: Equivalent DFA M N M = (2 {,2,3}, {a,b}, δ, {,3}, ) a b ε a a, b 2 3 ε({}) = {,3}

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

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

N = ( Q, Σ, δ, Q, F ) Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: equivalent DFA M = (Q, Σ, δ, q, F ) a N a b ε 2 a, b 3 q = ε({}) = {,3} δ a b {} {2} {3} {,2} {,3} {2,3} {,2,3}

N = ( Q, Σ, δ, Q, F ) Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: equivalent DFA M = (Q, Σ, δ, q, F ) a N a b ε 2 a, b 3 q = ε({}) = {,3} δ a b {} {2} {3} {,2} {,3} {2,3} {,2,3}

N = ( Q, Σ, δ, Q, F ) Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: equivalent DFA M = (Q, Σ, δ, q, F ) a N a b ε 2 a, b 3 q = ε({}) = {,3} δ a b {} {2} {2} {2,3} {3} {3} {,3} {,2} {2,3} {2,3} {,3} {,3} {2} {2,3} {,2,3} {3} {,2,3} {,2,3} {2,3}

N = ( Q, Σ, δ, Q, F ) Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: equivalent DFA M = (Q, Σ, δ, q, F ) a N a b ε 2 a, b 3 q = ε({}) = {,3} δ a b {} {2} {2} {2,3} {3} {3} {,3} {,2} {2,3} {2,3} {,3} {,3} {2} {2,3} {,2,3} {3} {,2,3} {,2,3} {2,3}

NFAs CAN MAKE PROOFS MUCH EASIER! Remember this on your Homework!

REGULAR LANGUAGES CLOSED UNDER CONCATENATION Concatenation: A B = { vw v A and w B } Given DFAs M and M 2, connect accept states in M to start states in M 2,, L(N) = L(M ) L(M 2 )

REGULAR LANGUAGES CLOSED UNDER CONCATENATION Concatenation: A B = { vw v A and w B } Given DFAs M and M 2, connect accept states in M to start states in M 2, ε, ε L(N) = L(M ) L(M 2 )

REGULAR LANGUAGES CLOSED UNDER CONCATENATION Concatenation: A B = { vw v A and w B } Given DFAs M and M 2, connect accept states in M to start states in M 2, ε, ε L(N) = L(M ) L(M 2 )

RLs ARE CLOSED UNDER STAR Star: A* = { s s k k and each s i A } Let M be a DFA, and let L = L(M) Can construct an NFA N that recognizes L*,

RLs ARE CLOSED UNDER STAR Star: A* = { s s k k and each s i A } Let M be a DFA, and let L = L(M) Can construct an NFA N that recognizes L* ε, ε

RLs ARE CLOSED UNDER STAR Star: A* = { s s k k and each s i A } Let M be a DFA, and let L = L(M) Can construct an NFA N that recognizes L* ε, ε ε

Formally: Input: M = (Q, Σ, δ, q, F) Output: 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

Show: L(N) = L* where L = L(M). L(N) L* 2. L(N) L*

. L(N) L* ( where L = L(M)) 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)

. L(N) L* ( where L = L(M)) 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 = Inductive Step: (w = ε) (w L) Assume N accepts all strings v = v v k L*, v i L and let v = v v k v k+ L*, u j L Since N accepts v v k (by induction) and M accepts v k+, N must accept v

2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L*

2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition

2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition ε accept

2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition ε ε accept

2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition u ε ε v accept

2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition u ε ε u L* By induction v v L accept

2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition u ε ε u L* By induction v v L accept So, w=uv L*

REGULAR LANGUAGES ARE CLOSED UNDER THE REGULAR OPERATIONS Union: A B = { w w A or w B } Intersection: A B = { w w A and w B } Negation: 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 }

WWW.FLAC.WS Read Chapters.3 and.4 of the book for next time