Finite Automata (contd)

Similar documents
Nondeterministic Finite Automata and Regular Expressions

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

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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

Decision, Computation and Language

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.

Finite Automata and Regular languages

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

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

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

CSE 105 THEORY OF COMPUTATION

Sri vidya college of engineering and technology

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,

Nondeterministic Finite Automata

CSE 105 THEORY OF COMPUTATION

CS 455/555: Finite automata

CS243, Logic and Computation Nondeterministic finite automata

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

CS 154 Introduction to Automata and Complexity Theory

CS 154, Lecture 3: DFA NFA, Regular Expressions

Nondeterminism. September 7, Nondeterminism

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Extended transition function of a DFA

(Refer Slide Time: 0:21)

Chapter Five: Nondeterministic Finite Automata

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

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

Lecture 3: Nondeterministic Finite Automata

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

Finite Automata Part Two

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSC236 Week 11. Larry Zhang

CS21 Decidability and Tractability

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Nondeterministic finite automata

Equivalence of DFAs and NFAs

CSC173 Workshop: 13 Sept. Notes

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

CSC236 Week 10. Larry Zhang

Nondeterministic Finite Automata

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

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

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

Theory of Computation (I) Yijia Chen Fudan University

Computational Theory

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

Theory of Computation (II) Yijia Chen Fudan University

Part I: Definitions and Properties

Chapter Two: Finite Automata

CSE 105 THEORY OF COMPUTATION

Intro to Theory of Computation

Formal Definition of a Finite Automaton. August 26, 2013

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

Formal Languages, Automata and Models of Computation

FINITE STATE MACHINES (AUTOMATA)

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

Computer Sciences Department

Lecture 1: Finite State Automaton

Inf2A: The Pumping Lemma

Inf2A: Converting from NFAs to DFAs and Closure Properties

Finite Automata and Languages

Automata: a short introduction

jflap demo Regular expressions Pumping lemma Turing Machines Sections 12.4 and 12.5 in the text

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

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

Computational Models Lecture 2 1

CISC4090: Theory of Computation

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Takeaway Notes: Finite State Automata

Nondeterministic Finite Automata

Fooling Sets and. Lecture 5

September 7, Formal Definition of a Nondeterministic Finite Automaton

Turing Machines Part III

Theory of Computation

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

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

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

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

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

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

Automata and Languages

Finite Automata. Mahesh Viswanathan

Constructions on Finite Automata

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

Announcements. Problem Set Four due Thursday at 7:00PM (right before the midterm).

CS 208: Automata Theory and Logic

CSCI 2670 Introduction to Theory of Computing

Theory of Computation

Finite Automata. Seungjin Choi

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Advanced Automata Theory 2 Finite Automata

CSE 105 THEORY OF COMPUTATION

Classes and conversions

Finite Automata. Finite Automata

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

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

Transcription:

Finite Automata (contd) CS 2800: Discrete Structures, Fall 2014 Sid Chaudhuri

Recap: Deterministic Finite Automaton A DFA is a 5-tuple M = (Q, Σ, δ, q 0, F) Q is a fnite set of states Σ is a fnite input alphabet (e.g. {0, 1}) δ is a transition function δ : Q Σ Q q 0 Q is the start/initial state F Q is the set of fnal/accepting states 0 Yes 1 1 No 0

A non-deterministic fnite automaton q 0 1 0,1 0,1 q 1 0,1 q 2

A non-deterministic fnite automaton Different transitions from q 0 on input 1 q 0 1 0,1 0,1 q 1 0,1 q 2

A non-deterministic fnite automaton Different transitions from q 0 on input 1 q 0 1 0,1 0,1 q 1 0,1 q 2 An NFA accepts a string x if it can get to an accepting state on input x

A non-deterministic fnite automaton q 0 1 0,1 0,1 q 1 0,1 q 2 What language does this automaton accept?

A non-deterministic fnite automaton q 0 1 0,1 0,1 q 1 0,1 q 2 Answer: All strings ending with 1

Another NFA 1 0,1 0,1 0,1 q 0 q q 0,1 1 2 q 3 What language does this automaton accept?

Another NFA 1 0,1 0,1 0,1 q 0 q q 0,1 1 2 q 3 Answer: All strings with 1 in the penultimate place

Non-deterministic Finite Automaton An NFA is a 5-tuple M = (Q, Σ, δ, q 0, F)

Non-deterministic Finite Automaton An NFA is a 5-tuple M = (Q, Σ, δ, q 0, F) Q is a fnite set of states q 0 q 1 q 2 q 3

Non-deterministic Finite Automaton An NFA is a 5-tuple M = (Q, Σ, δ, q 0, F) Q is a fnite set of states Σ is a fnite input alphabet (e.g. {0, 1}) q 0 q 1 q 2 q 3

Non-deterministic Finite Automaton An NFA is a 5-tuple M = (Q, Σ, δ, q 0, F) Q is a fnite set of states Σ is a fnite input alphabet (e.g. {0, 1}) δ is a transition function δ : Q Σ 2 Q 1 0,1 0,1 0,1 q 2 0,1 q 0 q 1 q 3

Non-deterministic Finite Automaton An NFA is a 5-tuple M = (Q, Σ, δ, q 0, F) Q is a fnite set of states Σ is a fnite input alphabet (e.g. {0, 1}) Only change from DFAs δ is a transition function δ : Q Σ 2 Q 1 0,1 0,1 0,1 q 2 0,1 q 0 q 1 q 3

Non-deterministic Finite Automaton An NFA is a 5-tuple M = (Q, Σ, δ, q 0, F) Q is a fnite set of states Σ is a fnite input alphabet (e.g. {0, 1}) Only change from DFAs δ is a transition function δ : Q Σ 2 Q q 0 Q is the start/initial state 1 0,1 0,1 0,1 q 2 0,1 q 0 q 1 q 3

Non-deterministic Finite Automaton An NFA is a 5-tuple M = (Q, Σ, δ, q 0, F) Q is a fnite set of states Σ is a fnite input alphabet (e.g. {0, 1}) Only change from DFAs δ is a transition function δ : Q Σ 2 Q q 0 Q is the start/initial state F Q is the set of fnal/accepting states 1 0,1 0,1 0,1 q 2 0,1 q 0 q 1 q 3

Non-deterministic Finite Automaton An NFA accepts a string x if it can get to an accepting state on input x

Non-deterministic Finite Automaton An NFA accepts a string x if it can get to an accepting state on input x Think of it as trying many options at once, and hoping one path gets lucky

Non-deterministic Finite Automaton An NFA accepts a string x if it can get to an accepting state on input x Think of it as trying many options at once, and hoping one path gets lucky A transition f (state, symbol) (the empty set) is possible

Non-deterministic Finite Automaton An NFA accepts a string x if it can get to an accepting state on input x Think of it as trying many options at once, and hoping one path gets lucky A transition f (state, symbol) (the empty set) is possible in this case, the NFA treats this as a rejecting path (the string may still reach an accepting state by another path)

Non-deterministic Finite Automaton An NFA accepts a string x if it can get to an accepting state on input x Think of it as trying many options at once, and hoping one path gets lucky A transition f (state, symbol) (the empty set) is possible in this case, the NFA treats this as a rejecting path (the string may still reach an accepting state by another path) A convenient shortcut for our hell/black-hole state

Non-deterministic Finite Automaton Every DFA is an NFA

Non-deterministic Finite Automaton Every DFA is an NFA If we're strict with our notation, we need to replace the transition f (state 1, symbol) state 2 with f (state 1, symbol) {state 2 }

Non-deterministic Finite Automaton Every DFA is an NFA If we're strict with our notation, we need to replace the transition f (state 1, symbol) state 2 with f (state 1, symbol) {state 2 } Every NFA can be simulated by a DFA

Non-deterministic Finite Automaton Every DFA is an NFA If we're strict with our notation, we need to replace the transition f (state 1, symbol) state 2 with f (state 1, symbol) {state 2 } Every NFA can be simulated by a DFA i.e. they accept exactly the same language

Non-deterministic Finite Automaton Every DFA is an NFA If we're strict with our notation, we need to replace the transition f (state 1, symbol) state 2 with f (state 1, symbol) {state 2 } Every NFA can be simulated by a DFA i.e. they accept exactly the same language Exponential blowup: if the NFA has n states, the DFA can require up to 2 n states

Thought for the Day #1 Find an NFA with n states that can't be simulated by a DFA with less than 2 n states

Every NFA can be simulated by a DFA

Every NFA can be simulated by a DFA p a a q r NFA (fragment)

Every NFA can be simulated by a DFA p a a q r NFA (fragment) DFA (fragment) a {p} {q, r}

Every NFA can be simulated by a DFA p a a q r Subset construction NFA (fragment) DFA (fragment) a {p} {q, r} (This is merely illustrative formal construction on following slides)

Every NFA can be simulated by a DFA NFA Equivalent DFA Specifcation States Alphabet Transition Function Initial State Accepting States

Every NFA can be simulated by a DFA NFA Equivalent DFA Specifcation (Q, Σ, δ, q 0, F) (2 Q, Σ, δ', q' 0, F') States Alphabet Transition Function Initial State Accepting States

Every NFA can be simulated by a DFA NFA Equivalent DFA Specifcation (Q, Σ, δ, q 0, F) (2 Q, Σ, δ', q' 0, F') States Q 2 Q Alphabet Transition Function Initial State Accepting States

Every NFA can be simulated by a DFA NFA Equivalent DFA Specifcation (Q, Σ, δ, q 0, F) (2 Q, Σ, δ', q' 0, F') States Q 2 Q Alphabet Σ Σ Transition Function Initial State Accepting States

Every NFA can be simulated by a DFA NFA Equivalent DFA Specifcation (Q, Σ, δ, q 0, F) (2 Q, Σ, δ', q' 0, F') States Q 2 Q Alphabet Σ Σ Transition Function δ δ'(s, a) = s S δ(s, a) Initial State Accepting States

Every NFA can be simulated by a DFA NFA Equivalent DFA Specifcation (Q, Σ, δ, q 0, F) (2 Q, Σ, δ', q' 0, F') States Q 2 Q Alphabet Σ Σ Transition Function δ δ'(s, a) = s S δ(s, a) Initial State q 0 q' 0 = {q 0 } Accepting States

Every NFA can be simulated by a DFA NFA Equivalent DFA Specifcation (Q, Σ, δ, q 0, F) (2 Q, Σ, δ', q' 0, F') States Q 2 Q Alphabet Σ Σ Transition Function δ δ'(s, a) = s S δ(s, a) Initial State q 0 q' 0 = {q 0 } Accepting States F F' = {S 2 Q S F }

Why NFAs?

Why NFAs? They can be way more compact than DFAs

Why NFAs? They can be way more compact than DFAs 0,1 1 q 0 q 1 0,1 q 3 q 2 0,1 NFA

Why NFAs? They can be way more compact than DFAs 1 1 q 0 q 1 0 1 0 q 000 q 001 q 010 q 011 1 0,1 0,1 0 1 1 0 0 1 q 3 q 2 0,1 0 q 100 q 101 q 110 q 111 0 1 0 1 NFA Equivalent minimal DFA

Why NFAs? They can be way more compact than DFAs 1 1 q 0 q 1 0 1 0 q 000 q 001 q 010 q 011 1 0,1 0,1 0 1 1 0 0 1 q 3 q 2 0,1 0 q 100 q 101 q 110 q 111 0 1 0 1 NFA Equivalent minimal DFA It's easier to directly convert regular expressions ( wildcard search on steroids) to NFAs

Finite automata struggle to count Any FA (deterministic or not) that recognizes the language {1 c } (the single string of c 1's) must have more than c states The parent alphabet is irrelevant (but must of course contain 1)

Proof: FAs struggle to count

Proof: FAs struggle to count Imagine there is some FA M that recognizes the language {1 c } and has c states

Proof: FAs struggle to count Imagine there is some FA M that recognizes the language {1 c } and has c states On input 1 c, M can traverse states q 0, q 1, q 2,, q c

Proof: FAs struggle to count Imagine there is some FA M that recognizes the language {1 c } and has c states On input 1 c, M can traverse states q 0, q 1, q 2,, q c where q c is an accepting state

Proof: FAs struggle to count Imagine there is some FA M that recognizes the language {1 c } and has c states On input 1 c, M can traverse states q 0, q 1, q 2,, q c where q c is an accepting state If M has c states, some state must be repeated in this sequence, say q i = q j with i < j

Proof: FAs struggle to count Imagine there is some FA M that recognizes the language {1 c } and has c states On input 1 c, M can traverse states q 0, q 1, q 2,, q c where q c is an accepting state If M has c states, some state must be repeated in this sequence, say q i = q j with i < j Pigeonhole Principle

Proof: FAs struggle to count Imagine there is some FA M that recognizes the language {1 c } and has c states On input 1 c, M can traverse states q 0, q 1, q 2,, q c where q c is an accepting state If M has c states, some state must be repeated in this sequence, say q i = q j with i < j Let t = j i Pigeonhole Principle

Proof: FAs struggle to count M can take the following steps on input 1 c

Proof: FAs struggle to count M can take the following steps on input 1 c 1. After reading 1 i, M is in state q i

Proof: FAs struggle to count M can take the following steps on input 1 c 1. After reading 1 i, M is in state q i 2. Then it reads 1 t and loops back to q j = q i

Proof: FAs struggle to count M can take the following steps on input 1 c 1. After reading 1 i, M is in state q i 2. Then it reads 1 t and loops back to q j = q i 3. Then it fnishes of by reading 1 c j

Proof: FAs struggle to count M can take the following steps on input 1 c 1. After reading 1 i, M is in state q i 2. Then it reads 1 t and loops back to q j = q i 3. Then it fnishes of by reading 1 c j Step 2 can be repeated indefnitely by inserting copies of 1 t in the string!

Proof: FAs struggle to count M can take the following steps on input 1 c 1. After reading 1 i, M is in state q i 1 t 2. Then it reads 1 t and loops back to q j = q i 3. Then it fnishes of by reading 1 c j Step 2 can be repeated indefnitely by inserting copies of 1 t in the string!

Proof: FAs struggle to count M can take the following steps on input 1 c 1. After reading 1 i, M is in state q i 1 t 2. Then it reads 1 t and loops back to q j = q i 3. Then it fnishes of by reading 1 c j Step 2 can be repeated indefnitely by inserting copies of 1 t in the string! So M also accepts 1 c + t, 1 c + 2t, 1 c + 3t etc

Proof: FAs struggle to count M can take the following steps on input 1 c 1. After reading 1 i, M is in state q i 1 t 2. Then it reads 1 t and loops back to q j = q i 3. Then it fnishes of by reading 1 c j Step 2 can be repeated indefnitely by inserting copies of 1 t in the string! So M also accepts 1 c + t, 1 c + 2t, 1 c + 3t etc which is a contradiction!

Proof: FAs struggle to count M can take the following steps on input 1 c 1. After reading 1 i, M is in state q i 1 t 2. Then it reads 1 t and loops back to q j = q i 3. Then it fnishes of by reading 1 c j Step 2 can be repeated indefnitely by inserting copies of 1 t in the string! So M also accepts 1 c + t, 1 c + 2t, 1 c + 3t etc which is a contradiction! QED

FAs struggle to count 1 j - i Can be repeated! q 0 q i = q j 1 i 1 c - j q c

Generalizing... v Can be repeated! q 0 q i = q j q c u w

Pumping Lemma

Pumping Lemma If M is an FA with k states

Pumping Lemma If M is an FA with k states and M accepts some string x with x k,

Pumping Lemma If M is an FA with k states and M accepts some string x with x k, then there exist strings u, v and w such that

Pumping Lemma If M is an FA with k states and M accepts some string x with x k, then there exist strings u, v and w such that x = uvw,

Pumping Lemma If M is an FA with k states and M accepts some string x with x k, then there exist strings u, v and w such that x = uvw, uv k,

Pumping Lemma If M is an FA with k states and M accepts some string x with x k, then there exist strings u, v and w such that x = uvw, uv k, v 1

Pumping Lemma If M is an FA with k states and M accepts some string x with x k, then there exist strings u, v and w such that x = uvw, uv k, v 1 and uvi w is accepted by M for all i N {0}

Pumping Lemma If M is an FA with k states and M accepts some string x with x k, then there exist strings u, v and w such that x = uvw, uv k, v 1 and uvi w is accepted by M for all i N {0} Exercise: Write out the proof formally!

Why is the pumping lemma useful?

Why is the pumping lemma useful? Used to prove languages cannot be recognized by any FA whatsoever

Why is the pumping lemma useful? Used to prove languages cannot be recognized by any FA whatsoever E.g. the language with all strings of 0's concatenated with equally long strings of 1's, i.e. 0 n 1 n for all n N

Why is the pumping lemma useful? Used to prove languages cannot be recognized by any FA whatsoever E.g. the language with all strings of 0's concatenated with equally long strings of 1's, i.e. 0 n 1 n for all n N FA's don't have unlimited memory, so they can't store the number of 0's they have seen

Proof: 0 n 1 n is not recognized by any FA

Proof: 0 n 1 n is not recognized by any FA We'll prove it by contradiction

Proof: 0 n 1 n is not recognized by any FA We'll prove it by contradiction Assume there is some FA M with k states that accepts a string if it is of the form 0 n 1 n for any n N

Proof: 0 n 1 n is not recognized by any FA We'll prove it by contradiction Assume there is some FA M with k states that accepts a string if it is of the form 0 n 1 n for any n N Consider 0 k 1 k, which is accepted by M

Proof: 0 n 1 n is not recognized by any FA We'll prove it by contradiction Assume there is some FA M with k states that accepts a string if it is of the form 0 n 1 n for any n N Consider 0 k 1 k, which is accepted by M It's longer than k, so by the Pumping Lemma, there exist u, v, w s.t. uvw = 0 k 1 k, uv k and v 1

Proof: 0 n 1 n is not recognized by any FA We'll prove it by contradiction Assume there is some FA M with k states that accepts a string if it is of the form 0 n 1 n for any n N Consider 0 k 1 k, which is accepted by M It's longer than k, so by the Pumping Lemma, there exist u, v, w s.t. uvw = 0 k 1 k, uv k and v 1 and v must consist entirely of 0's (since uv k)

Proof: 0 n 1 n is not recognized by any FA We'll prove it by contradiction Assume there is some FA M with k states that accepts a string if it is of the form 0 n 1 n for any n N Consider 0 k 1 k, which is accepted by M It's longer than k, so by the Pumping Lemma, there exist u, v, w s.t. uvw = 0 k 1 k, uv k and v 1 and v must consist entirely of 0's (since uv k) So M accepts all strings of the form 0 u 0 i v 0 k - uv 1 k, such as 0 u 0 k - uv 1 k, 0 u 0 2 v 0 k - uv 1 k, 0 u 0 3 v 0 k - uv 1 k etc

Proof: 0 n 1 n is not recognized by any FA We'll prove it by contradiction Assume there is some FA M with k states that accepts a string if it is of the form 0 n 1 n for any n N Consider 0 k 1 k, which is accepted by M It's longer than k, so by the Pumping Lemma, there exist u, v, w s.t. uvw = 0 k 1 k, uv k and v 1 and v must consist entirely of 0's (since uv k) So M accepts all strings of the form 0 u 0 i v 0 k - uv 1 k, such as 0 u 0 k - uv 1 k, 0 u 0 2 v 0 k - uv 1 k, 0 u 0 3 v 0 k - uv 1 k etc which are not of the form 0 n 1 n (since v 1)

Proof: 0 n 1 n is not recognized by any FA We'll prove it by contradiction Assume there is some FA M with k states that accepts a string if it is of the form 0 n 1 n for any n N Consider 0 k 1 k, which is accepted by M It's longer than k, so by the Pumping Lemma, there exist u, v, w s.t. uvw = 0 k 1 k, uv k and v 1 and v must consist entirely of 0's (since uv k) So M accepts all strings of the form 0 u 0 i v 0 k - uv 1 k, such as 0 u 0 k - uv 1 k, 0 u 0 2 v 0 k - uv 1 k, 0 u 0 3 v 0 k - uv 1 k etc which are not of the form 0 n 1 n (since v 1) hence proved by contradiction