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

Similar documents
Lecture 1: Finite State Automaton

Nondeterministic 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,

Theory of Computation (I) Yijia Chen Fudan University

Introduction to Formal Languages, Automata and Computability p.1/51

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

Finite Automata and Regular languages

Inf2A: Converting from NFAs to DFAs and Closure Properties

CS 455/555: Finite automata

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

CMSC 330: Organization of Programming Languages

Chapter Five: Nondeterministic Finite Automata

Chapter 5. 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

Nondeterministic Finite Automata. Nondeterminism Subset Construction

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Automata and Languages

Lecture 3: Nondeterministic Finite Automata

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

Finite Automata. Seungjin Choi

Outline. Summary. DFA -> Regex. Finish off Regex -> e-nfa -> NFA -> DFA -> Regex Minimization/equivalence (Myhill-Nerode theorem)

Closure under the Regular Operations

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Uses of finite automata

CPS 220 Theory of Computation REGULAR LANGUAGES

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Finite Automata and Regular Languages

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

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

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

Lecture 2: Regular Expression

September 7, Formal Definition of a Nondeterministic Finite Automaton

Computational Theory

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

Sri vidya college of engineering and technology

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

Nondeterministic Finite Automata and Regular Expressions

CS21 Decidability and Tractability

Deterministic Finite Automaton (DFA)

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

Equivalence of DFAs and NFAs

Nondeterminism and Epsilon Transitions

Nondeterministic finite automata

Nondeterministic Finite Automata

Nondeterministic Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Finite Automata. Mahesh Viswanathan

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

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

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

Chapter 2: Finite Automata

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

Chap. 1.2 NonDeterministic Finite Automata (NFA)

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

CS243, Logic and Computation Nondeterministic finite automata

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

Theory of Computation

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

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

Course 4 Finite Automata/Finite State Machines

Lecture 17: Language Recognition

Theory of computation: initial remarks (Chapter 11)

Lecture 4 Nondeterministic Finite Accepters

CSC173 Workshop: 13 Sept. Notes

3515ICT: Theory of Computation. Regular languages

Finite Automata and Regular Languages (part III)

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

Equivalence of Regular Expressions and FSMs

Introduction to Finite-State Automata

Closure under the Regular Operations

Fooling Sets and. Lecture 5

Pushdown Automata. Reading: Chapter 6

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

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

Automata: a short introduction

Non-deterministic Finite Automata (NFAs)

CS 154, Lecture 3: DFA NFA, Regular Expressions

Computational Models - Lecture 1 1

Formal Models in NLP

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

Languages. A language is a set of strings. String: A sequence of letters. Examples: cat, dog, house, Defined over an alphabet:

Theory of Computation

Finite Automata - Deterministic Finite Automata. Deterministic Finite Automaton (DFA) (or Finite State Machine)

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

Theory of Computation (II) Yijia Chen Fudan University

Decision, Computation and Language

Intro to Theory of Computation

Theory of Languages and Automata

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

CSC236 Week 11. Larry Zhang

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

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

Nondeterminism. September 7, Nondeterminism

C2.1 Regular Grammars

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Transcription:

Outline Nondeterminism Regular expressions Elementary reductions http://www.cs.caltech.edu/~cs20/a October 8, 2002 1 Determistic Finite Automata A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F) Q is a finite set of states Σ is an alphabet δ : Q Σ Q is a transition function q 0 Q is the initial state F Q is a set of final or accepting states http://www.cs.caltech.edu/~cs20/a October 8, 2002 2 Transition diagrams q0 0 0 q2 1 1 1 1 q1 0 0 q3 Q = {q 0,q 1,q 2,q 3} Σ = {0, 1} δ = State Symbol Goto q 0 0 q 2 q 0 1 q 1 q 1 0 q 3 q 1 1 q 0 q 2 0 q 0 q 2 1 q 3 q 3 0 q 1 q 3 1 q 2 q 0 = q 0 F = {q 0} http://www.cs.caltech.edu/~cs20/a October 8, 2002 3

A finite automaton Read-only tape 0 1 1 0 0 1 0 1 Finite Control Tape head 1. In state q a. read a symbol c b. move the tape head right b. goto state delta(q, c) 2. Accept iff the FA is in a final state after reading the last symbol http://www.cs.caltech.edu/~cs20/a October 8, 2002 4 Definition of regular expressions Let Σ be an alphabet. The regular expressions are defined inductively as follows: is a regular expression denoting {}, ɛ is a regular expression denoting {ɛ}, for each a Σ, a is a regular expression denoting {a}, Assume r and s are regular expressions denoting sets R and S, then rs denotes RS, r + s denoted R S, r denotes R http://www.cs.caltech.edu/~cs20/a October 8, 2002 5 Examples of regular expressions abc denotes {abc}, a b denotes {b, ab, aab, aaab,...}, (a + b) aa(a + b) : all strings containing at least two consecutive a's. (0 (101 01) ) : multiple of 3. all binary numbers that are a http://www.cs.caltech.edu/~cs20/a October 8, 2002 6

Nondeterminism For determistic finite automata, the transition function delta is a function delta : state * symbol -> state For each state, and each symbol, there is a unique next state What if we relax this? In a nondeterministic finite automaton, delta is a transition relation http://www.cs.caltech.edu/~cs20/a October 8, 2002 7 Definition of an NFA A nondeterministic finite automaton is a 5-tuple (Q, Σ,δ,s,F) Q is a finite set of states Σ is an alphabet δ : Q Σ 2 Q is a transition relation s Q is the initial state F Q is a set of final or accepting states http://www.cs.caltech.edu/~cs20/a October 8, 2002 8 The delta relation Note, the following definitions are equivalent: δ : Q Σ 2 Q is a transition relation δ Q Σ Q is a transition relation The transition diagram is often drawn without empty edges: if δ(q, c) ={}, then the machine rejects and we do not draw the edge http://www.cs.caltech.edu/~cs20/a October 8, 2002 9

Example NFA 0,1 0,1 0 q1 0 q2 q0 1 0,1 q3 1 q4 http://www.cs.caltech.edu/~cs20/a October 8, 2002 10 Executions (for DFAs) An execution of a deterministic automaton M = (Q, Σ,δ,q 0,F) is a sequence (q 0,c 0)(q 1,c 1)...(q n 1,c n 1)q n (Q Σ) such that: q 0 is the start state δ(q i,c i ) = q i+1 The execution string s is c 0 c 1...c n 1 If there exists an execution for string s with q n F the automaton accepts and s L(M); otherwiseit rejects http://www.cs.caltech.edu/~cs20/a October 8, 2002 11 Executions (for NFAs) An execution of a nondeterministic automatonm = (Q, Σ,δ,q 0,F) is a sequence (q 0,c 0)(q 1,c 1)...(q n 1,c n 1)q n (Q Σ) such that: q 0 is the start state q i+1 δ(q i,c i ) The execution string s is c 0 c 1...c n 1 If there exists an execution for string s with q n F the automaton accepts and s L(M); otherwiseit rejects http://www.cs.caltech.edu/~cs20/a October 8, 2002 12

A nondeterministic finite automaton Read-only tape 0 1 1 0 0 1 0 1 Finite Control Tape head 1. In state q a. read a symbol c b. move the tape head right b. goto some state in delta(q, c) 2. Accept iff the NFA is in a final state after reading the last symbol http://www.cs.caltech.edu/~cs20/a October 8, 2002 13 Execution models 1. Classical: For each state q and input symbol c, the automaton makes a nontermistic choice among all the possible options δ(q, c); it accepts if it made all the right choices 2. Another choice: At any point, the automaton is in a superposition of states Q 1 For each symbol c, it enters states Q 2 where q 2 Q 2 iff q 1 Q 1.q 2 δ(q 1,c) http://www.cs.caltech.edu/~cs20/a October 8, 2002 14 Extending the transition relation Defining δ: δ(q, ɛ) ={q} δ(q, wa) ={p r δ(q, w).p δ(r, a)} A machine M = (Q, Σ,δ,q 0,F) accepts string s iff δ(q 0,s) F {} http://www.cs.caltech.edu/~cs20/a October 8, 2002 15

Expressive power of NFAs vs. DFAs Every DFA is an NFA NFAs allow more transitions Is the language more expressive? Is there a language L=L(M) for some NFA M, where L<>L(M ) for some DFA M? http://www.cs.caltech.edu/~cs20/a October 8, 2002 16 NFA/DFA Equivalence To prove equivalence of DFAs and NFAs we must do two things: I: For each DFA, produce an NFA that accepts the same language II: For each NFA, produce a DFA that accepts the same language This is called a reduction reduce one construction to another equivalent one We ll do part II; part I is immediate http://www.cs.caltech.edu/~cs20/a October 8, 2002 17 NFA->DFA construction Consider an arbitrary NFA M = (Q, Σ, δ, s, F);construct an equivalent DFA M = (Q, Σ,δ,s,F ) Let Q = 2 Q Let s ={s} Let δ ({q 1,...,q n },c)= n i=1 δ(q i,c) Let F ={t 2 Q t F {}} http://www.cs.caltech.edu/~cs20/a October 8, 2002 18

NFA->DFA construction: verification Theorem δ(s, x) = δ ({s},x) Corollary δ(s, x) F {} δ ({s},x) F {} http://www.cs.caltech.edu/~cs20/a October 8, 2002 19 NFA->DFA construction: base case Theorem δ(s, x) = δ ({s},x) Base case δ(s, ɛ) ={s} =δ ({s},ɛ) http://www.cs.caltech.edu/~cs20/a October 8, 2002 20 NFA->DFA construction: induction step Assume δ(s, x) = δ ({s},x) for some x Prove δ(s, xa) = δ ({s},xa) for any a δ(s, xa) = by definition of δ δ(δ(s, x), a) = by definition of δ p δ(s,x) δ(p, a) = by induction p δ (s,x) δ(p, a) = by definition of δ p δ (s,x) δ ({p},a) = by definition of δ p δ ({s},x) δ ({p},a) = by definition of δ δ (δ ({s},x),a) = by definition of δ δ ({s},xa) http://www.cs.caltech.edu/~cs20/a October 8, 2002 21

NFA with epsilon transitions Suppose we add a new twist Allow transitions that require no input Label them epsilon (no input) The automaton may choose to take an epsilon transition without any input Executions include (q_i, epsilon) (q_i+1, _) steps A machine accepts if there exists an execution that accepts http://www.cs.caltech.edu/~cs20/a October 8, 2002 22 Example e-nfa 0 1 2 q0 q1 q2 http://www.cs.caltech.edu/~cs20/a October 8, 2002 23 E-NFA definition A nondeterministic finite automaton with ɛ transitions is a 5-tuple (Q, Σ,δ,s,F) Q is a finite set of states Σ is an alphabet δ : Q (Σ {ɛ}) 2 Q is a transition relation s Q is the initial state F Q is a set of final or accepting states http://www.cs.caltech.edu/~cs20/a October 8, 2002 24

E-NFA->NFA reduction Consider the superposition model If the e-nfa could be in states {q1, q2, qn}, add the states that could be reached by e-transitions from any state qi This is called the e-closure http://www.cs.caltech.edu/~cs20/a October 8, 2002 25 E-closure example 0 1 2 q0 q1 q2 -closure(q0) = { q0, q1, q2 } -closure(q1) = { q1, q2 } -closure(q2) = { q2 } http://www.cs.caltech.edu/~cs20/a October 8, 2002 26 Formal definition Define ɛ-closure(p) = p P ɛ-closure(p) Let δ(q, ɛ) = ɛ-closure(q) Let δ(q, xa) = ɛ-closure(p), wherep ={p r δ(q, w).p δ(r, a)} Define δ(r, a) = r R δ(r, a) Define δ(r, a) = δ(r r R, a) M = (Q, Σ,δ,s,F)accepts string x iff δ(s, x) F {} http://www.cs.caltech.edu/~cs20/a October 8, 2002 27

Reduction Let M = (Q, Σ,δ,s,F) be an NFA with ɛ moves. Construct M = (Q, Σ,δ,s,F ) an NFA without ɛ moves. Let δ (q, a) = δ(q, a) { Let F F {s} if ɛ-closure(s) F {} = F otherwise http://www.cs.caltech.edu/~cs20/a October 8, 2002 28 Proof Prove δ (s, x) = δ(s, x) by induction on the length of x Note that δ (s, ɛ) = δ(s, ɛ) may not be true. Oh well, start the induction at x =1. Base If x =1thenx = a and δ (s, a) = δ(s, a) by definition http://www.cs.caltech.edu/~cs20/a October 8, 2002 29 Induction step Step Suppose x = wa δ (s, wa) = by definition δ (δ (s, w), a) = by induction δ ( δ(s, w), a) = by definition q δ(s,w) δ (q, a) = by definition of δ q δ(s,w) δ(q, a) = by definition of δ δ(s, wa) http://www.cs.caltech.edu/~cs20/a October 8, 2002 30

Summary (so far) Proofs so far Proved NFA->DFA Proved e-nfa->nfa Next, establish total equivalence Prove regex->e-nfa Prove DFA->regex If so, all four are equivalent http://www.cs.caltech.edu/~cs20/a October 8, 2002 31 Definition of regular expressions Let Σ be an alphabet. The regular expressions are defined inductively as follows: is a regular expression denoting {}, ɛ is a regular expression denoting {ɛ}, for each a Σ, a is a regular expression denoting {a}, Assume r and s are regular expressions denoting sets R and S, then rs denotes RS, r + s denoted R S, r denotes R http://www.cs.caltech.edu/~cs20/a October 8, 2002 32 Regex->eNFA Prove by structural induction: induction on the size of the regular expression Base cases: Show the empty RE has an e-nfa Show the RE has an e-nfa Show the a (symbol) RE has an e-nfa Induction: Show (xy) has an e-nfa Show (x + y) has an e-nfa Show x* has an e-nfa http://www.cs.caltech.edu/~cs20/a October 8, 2002 33

Base cases r = r = r = a a http://www.cs.caltech.edu/~cs20/a October 8, 2002 34 Choice Start state Machine 1 Any (originally) final state Machine 2 http://www.cs.caltech.edu/~cs20/a October 8, 2002 35 Concatenation Machine 1 Machine 2 http://www.cs.caltech.edu/~cs20/a October 8, 2002 36

Kleene closure Machine 1 http://www.cs.caltech.edu/~cs20/a October 8, 2002 37 Final proof: DFA->regex Think about it http://www.cs.caltech.edu/~cs20/a October 8, 2002 38