Nondeterminism and Epsilon Transitions

Similar documents
Nondeterministic Finite Automata. Nondeterminism Subset Construction

Regular Expressions and Language Properties

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

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

Nondeterministic Finite Automata

Chapter Five: Nondeterministic Finite Automata

CS 154, Lecture 3: DFA NFA, Regular Expressions

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,

Automata Theory, Computability and Complexity

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

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Chap. 1.2 NonDeterministic Finite Automata (NFA)

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Theory of Computation (I) Yijia Chen Fudan University

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

Lecture 4 Nondeterministic Finite Accepters

Intro to Theory of Computation

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

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

Fooling Sets and. Lecture 5

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

Automata and Languages

Finite Automata and Regular Languages

Nondeterminism. September 7, Nondeterminism

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Nondeterministic Finite Automata

CSE 105 Theory of Computation Professor Jeanne Ferrante

Non-deterministic Finite Automata (NFAs)

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

September 7, Formal Definition of a Nondeterministic Finite Automaton

Closure under the Regular Operations

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

Theory of computation: initial remarks (Chapter 11)

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

Lecture 3: Nondeterministic Finite Automata

Theory of computation: initial remarks (Chapter 11)

The Pumping Lemma and Closure Properties

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

Chapter 5. Finite Automata

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

CMSC 330: Organization of Programming Languages

CS21 Decidability and Tractability

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

Course 4 Finite Automata/Finite State Machines

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Equivalence of CFG s and PDA s

Nondeterministic finite automata

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

UNIT-III REGULAR LANGUAGES

Finite Automata. Finite Automata

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

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

Computer Sciences Department

CPS 220 Theory of Computation REGULAR LANGUAGES

Nondeterministic Finite Automata

Nondeterministic Finite Automata

Deterministic Finite Automaton (DFA)

Sri vidya college of engineering and technology

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

Theory of Computation (II) Yijia Chen Fudan University

CS 208: Automata Theory and Logic

Computational Models Lecture 2 1

Decision, Computation and Language

CSE 105 THEORY OF COMPUTATION

Equivalence of DFAs and NFAs

NP-Completeness and Boolean Satisfiability

CS 455/555: Finite automata

CS243, Logic and Computation Nondeterministic finite automata

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

Uses of finite automata

CSC236 Week 11. Larry Zhang

Theory of Languages and Automata

Extended transition function of a DFA

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

Computational Models #1

Inf2A: Converting from NFAs to DFAs and Closure Properties

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

Deterministic (DFA) There is a fixed number of states and we can only be in one state at a time

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

Deterministic Finite Automata (DFAs)

Homomorphisms and Efficient State Minimization

CS 154 Formal Languages and Computability Assignment #2 Solutions

Deterministic Finite Automata (DFAs)

Theory of Computation

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

Lecture 2: Regular Expression

Lecture 17: Language Recognition

Finite Automata Part Two

CS 322 D: Formal languages and automata theory

Computational Models Lecture 2 1

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 35

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

Finite Automata and Regular Languages (part II)

Lecture 1: Finite State Automaton

CISC 4090 Theory of Computation

Finite Automata Part Two

Finite Automata and Languages

front pad rear pad door

Transcription:

Nondeterminism and Epsilon Transitions Mridul Aanjaneya Stanford University June 28, 22 Mridul Aanjaneya Automata Theory / 3

Challenge Problem Question Prove that any square with side length a power of 2, and one square removed, is tileable with L s. Mridul Aanjaneya Automata Theory 2/ 3

Something to think about... Question Are such tilings always possible? Mridul Aanjaneya Automata Theory 3/ 3

Recap: Deterministic Finite Automata Definition A DFA is a 5-tuple (Q, Σ, δ D, q, F ) consisting of: A finite set of states Q, A set of input alphabets Σ, A transition function δ D : Q Σ Q, A start state q, and A set of accept states F Q. The transition function δ D : Takes two arguments, a state q and an alphabet a. δ D (q,a) = the state the DFA goes to when it is in state q and the alphabet a is received. Mridul Aanjaneya Automata Theory 4/ 3

Recap: Graph representation of DFA s Nodes correspond to states. Arcs represent transition function. Arc from state p to state q labeled by all those input symbols that have transitions from p to q. Incoming arrow from outside denotes start state. Accept states indicated by double circles. q q 2, q 3 Accepts all binary strings without two consecutive s. Mridul Aanjaneya Automata Theory 5/ 3

Recap: Transition table for DFA s q q q 2 q 2 q q 3 q 3 q 3 q 3 A row for each state, a column for each alphabet. Accept states are starred. Arrow for the start state. q q 2, q 3 Mridul Aanjaneya Automata Theory 6/ 3

Recap: Regular languages Definition A DFA M = (Q, Σ, δ D, q, F ) accepts w if there exists a sequence of states r, r,..., r n in Q with three conditions: r = q δ D (r i, w i+ ) = r i+ for i =,..., n, and r n F Condition says that M starts in the start state q. Condition 2 says that M follows δ D between two states. Condition 3 says that last state is an accept state. We say that M recognizes L if L = {w M accepts w}. Mridul Aanjaneya Automata Theory 7/ 3

Regular Languages: Examples Example Let L = {w w {,} and w, viewed as a binary integer, is divisible by 5.} q q 3 q 4 q q 2 Mridul Aanjaneya Automata Theory 8/ 3

Regular Languages: Examples Example Show that the language of all strings over {, } that do not contain a pair of s that are separated by an odd number of s is regular. a e o, b Mridul Aanjaneya Automata Theory 9/ 3

Regular Languages: Examples Example Show that the language of all strings over {, } that contain an even number of s and s is regular. ee oe eo oo Mridul Aanjaneya Automata Theory / 3

Nondeterminism Deterministic finite automata can only be in one state at any point in time. Recall the definition of the transition function δ D. In contrast, nondeterministic finite automata (NFA s) can be in several states at once! The transition function δ N is a one-to-many function.,,, q q q q 2 3 4 This NFA recognizes strings in {,} containing a in the third position from the end. Mridul Aanjaneya Automata Theory / 3

Transition table q q q,q 2 q 2 q 3 q 3 q 3 q 4 q 4 q 4 q 4 q 4 q is a nondeterministic state with a one-many transition on.,,, q q q q 2 3 4 Intuitively, the NFA always guesses right. Mridul Aanjaneya Automata Theory 2/ 3

Nondeterministic Finite Automata Example An NFA that accepts all strings of the form k where k is a multiple of 2 or 3. q 2 q 3 q q 4 q 5 q 6 Mridul Aanjaneya Automata Theory 3/ 3

Nondeterministic Finite Automata Definition An NFA is a 5-tuple (Q, Σ, δ N, q, F ) consisting of: A finite set of states Q, A set of input alphabets Σ, A transition function δ N : Q Σ P(Q), A start state q, and A set of accept states F Q. Here, Σ denotes the set Σ {}. P(Q) denotes the power set of Q. Mridul Aanjaneya Automata Theory 4/ 3

Transition function of an NFA δ N (q,a) is a set of states. Extend to strings as follows: Basis: δ N (q,) = q Induction: δ N (q,wa) = the union over all states of δ N (p,a), where p δ N (q,w). A string is accepted by an NFA if δ N (q,w) contains at least one state p F. The language of an NFA is the set of strings it accepts. Mridul Aanjaneya Automata Theory 5/ 3

Equivalence of DFA s and NFA s Every DFA is also an NFA by definition. There is simply no nondeterminism. Surprisingly, for every NFA, there is also an equivalent DFA! Two equivalent machines recognize the same language. Nonintuitive, as we d expect NFA s to be more powerful. Useful, as describing an NFA is much simpler. Proof is the subset construction. The number of states of the DFA can be exponential in the number of states of the NFA. Thus, NFA s accept exactly the regular languages. Mridul Aanjaneya Automata Theory 6/ 3

Equivalence of DFA s and NFA s DFA for recognizing strings with a in the third last position. q q q q 5 3 7 q q q q 2 6 4 8 Mridul Aanjaneya Automata Theory 7/ 3

Subset construction Given an NFA (Q,Σ,δ N,q,F ), construct equivalent DFA with: Note: States P(Q) (set of subsets of Q). Inputs Σ. Start state {q }. Final states = all those with a member of F. The DFA states have names that are sets of NFA states. But as a DFA state, an expression like {p,q} must be read as a single symbol. Mridul Aanjaneya Automata Theory 8/ 3

Subset construction Example: We ll construct the DFA for the following NFA which recognizes strings in {,} containing a in the second position from the end.,, a b c Mridul Aanjaneya Automata Theory 9/ 3

Subset construction,, a b c a a,b a,b,c a,c Mridul Aanjaneya Automata Theory 2/ 3

Proof of equivalence: subset construction Show by induction on length of w that δ N (q,w) = δ D ({q },w) Basis: w =. δ N (q,) = δ D ({q },) = {q }. Inductive step: Assume IH is true for all strings shorter than w. Let w = xa, then IH is true for x. Let δ N (q,x) = δ D ({q },x) = S. Let T = the union over all states p in S of δ N (p,a). Then δ N (q,w) = δ D ({q },w) = T (by definition). Mridul Aanjaneya Automata Theory 2/ 3

NFA s with -transitions State-to-state transitions on input. These transitions are spontaneous, and do not consider the input string. B C D A E F Mridul Aanjaneya Automata Theory 22/ 3

Closure of States CL(q) = set of states that can be reached from state q following only arcs labeled. B C D A E F CL(A) = {A}, CL(E) = {B, C, D, E}. Closure of set of states = union of closure of each state. Mridul Aanjaneya Automata Theory 23/ 3

Extended transition function Basis: δ E (q,) = CL(q). Induction: δ E (q,xa) is computed as follows: Start with δ E (q,x) = S. 2 Take the union of CL(δ(p,a)) for all p in S. Intuition: δ E (q,w) is the set of states you can reach from q following a path labeled w with s in between. Mridul Aanjaneya Automata Theory 24/ 3

Example: Extended transition function B C D A E F δ E (A,) = CL(A) = {A}. δ E (A,) = CL(E) = {B, C, D, E}. δ E (A,) = CL(C,D) = {C, D}. Mridul Aanjaneya Automata Theory 25/ 3

Example: Extended transition function B C D A E F Language of an -NFA is the set of strings w such that δ E (q,w) contains a final state. Mridul Aanjaneya Automata Theory 26/ 3

Equivalence of NFA, -NFA Every NFA is an -NFA. It just has no -transitions. Converse requires us to take an -NFA and construct an NFA that accepts the same language. This is done by combining -transitions with the next transition on a real input. Start with an -NFA (Q,Σ,q,F,δ E ) and construct an ordinary NFA (Q,Σ,q,F,δ N ). Mridul Aanjaneya Automata Theory 27/ 3

Equivalence of NFA, -NFA Compute δ N (q,a) as follows: Let S = CL(q). δ N (q,a) is the union over all p in S of δ E (p,a). F = set of states q such that CL(q) contains a state of F. Intuition: δ N incorporates -transitions before using a. Proof of equivalence is by induction on w that CL(δ N (q,w)) = δ E (q,w). Basis: CL(δ N (q,)) = CL(q ) = δ E (q,). Inductive step: Assume IH is true for all x shorter than w. Let w = xa. Then CL(δ N (q,xa)) = CL(δ E (CL(δ N (q,x)),a)) (by definition). But from IH, CL(δ N (q,x)) = δ E (q,x). Hence, CL(δ N (q,w)) = CL(δ E (δ E (q,x),a)) = δ E (q,w). Mridul Aanjaneya Automata Theory 28/ 3

Example B C D A E F B C D A E F Mridul Aanjaneya Automata Theory 29/ 3

Summary DFA s, NFA s and -NFA s all accept exactly the same set of languages: the regular languages. NFA types are easier to design and may have exponentially fewer states than a DFA. But only a DFA can be implemented! Mridul Aanjaneya Automata Theory 3/ 3