Instructor: Aaron Roth

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Introduction to Computability Theory
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
Introduction to Computability Theory
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Finite Automata and Non Determinism
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata (cont.) Prof. Amos Israeli.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Theory of Computing Lecture 22 MAS 714 Hartmut Klauck.
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
REGULAR LANGUAGES.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
Theory of Computation Automata Theory Dr. Ayman Srour.
Nondeterminism Subset Construction ε -Transitions.
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
CIS 262 Automata, Computability, and Complexity Fall Instructor: Aaron Roth
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Lexical analysis Finite Automata
Non Deterministic Automata
Chapter 2 Finite Automata
Recognizer for a Language
Chapter 2 FINITE AUTOMATA.
Hierarchy of languages
Non-Deterministic Finite Automata
CS 154, Lecture 3: DFANFA, Regular Expressions.
Principles of Computing – UFCFA3-30-1
COSC 3340: Introduction to Theory of Computation
Non-Deterministic Finite Automata
CSE322 Definition and description of finite Automata
Non Deterministic Automata
NFAs and Transition Graphs
Finite Automata Reading: Chapter 2.
4b Lexical analysis Finite Automata
4b Lexical analysis Finite Automata
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
Chapter 1 Regular Language
Instructor: Aaron Roth
Instructor: Aaron Roth
Instructor: Aaron Roth
NFAs and Transition Graphs
Instructor: Aaron Roth
Lecture 5 Scanning.
Announcements - P1 part 1 due Today - P1 part 2 due on Friday Feb 1st
CHAPTER 1 Regular Languages
Non Deterministic Automata
Presentation transcript:

Instructor: Aaron Roth aaroth@cis.upenn.edu CIS 262 Automata, Computability, and Complexity Spring 2019 http://www.seas.upenn.edu/~cse262/ Instructor: Aaron Roth aaroth@cis.upenn.edu Lecture: February 6, 2019

Course Logistics Homework 2 is out. Due Wednesday February 20 before class, turned in via GradeScope.

Nondeterministic Automata In state q0, on symbol a, choice of next state is not unique: either q0 or q1 In state q2 cannot process additional symbols (no next state) Deterministic transition function: processing symbol s in state q leads to the unique next state d(q, s) Nondeterministic transition function D maps a state and a symbol to a set of states: if current state is q and symbol is s, next state is chosen from the set D(q, s) a,b a a, b q0 q1 q2

Execution of Nondeterministic Automata a,b q0 a a, b a q0 q1 q2 q0 q1 b How does the machine process input string abab ? Many possible executions/runs corresponding paths in this tree Successful run: All of input processed, and Resulting state is accepting Input accepted if at least one of the runs is successful q0 q2 a q0 q1 b q0 q2

Execution of Nondeterministic Automata a,b q0 a a, b a q0 q1 q2 q0 q1 a How does the machine process input string aabb ? Input rejected if no run is successful q0 q1 q2 b q0 q2 b q0

Language of a Nondeterministic Automaton NFA M accepts a string w if and only if there exists a successful execution of M on w Which strings does the above machine accept ? L(M) = { w | second last symbol of w equal a } a,b a a, b q0 q1 q2

NFA Example S = { A, C, G, T } A, C, G,T A,C, G,T A C C q0 q1 q2 q3 Nondeterministic transition function D : Q x S  2Q D(q0, A) = {q0 , q1}; D(q0, C) = {q0}; D(q1, A) = { }; … What language does this NFA accept ?

NFA Example S = { A, C, G, T } A, C, G,T A,C, G,T A C C q0 q1 q2 q3 Execution of the machine on input ACTACCGA: Alternative to tree of all possible runs: compute the set of possible states after processing each input symbol A {q0 , q1 } C {q0 , q2 } T {q0 } A {q0 , q1 } { q0 } C {q0 , q2 } C {q0 , q3 } G {q0 , q3 } A {q0 , q1 , q3} Accept input if the set of possible states at the end contains a final state

Definition: NFA Syntax A nondeterministic finite automaton (NFA) M consists of a finite set Q of states a finite alphabet S an initial state q0 that belongs to Q a subset F of Q, called accepting/final states a transition function D : Q x S  2Q (if M reads symbol s in state q, the resulting state is some state chosen from the set D(q, s) )

Definition: NFA Semantics Let M = (Q, S, q0, F, D) be an NFA. M accepts the string w = w1 w2 … wk if there exists a sequence of states q0 q1 q2 … qk such that (1) q0 is the initial state, (2) for each i=0, 1, … (k-1), state qi+1 is in D(qi, wi+1), and (3) state qk is in F. L(M) = set of strings w such that M accepts w

Alternative Definition of Acceptance Let M = (Q, S, q0, F, D) be an NFA. Define extended transition function D* : Q x S*  2Q D *(q, w) = set of all possible states where machine can be after processing the string w starting in state q D*(q, e) = { q } D*(q, x. s) = U D(q’, s) M accepts the input w if and only if the intersection of the sets D*(q0, w) and F is non-empty q’ in D*(q,x)

NFA Example Which strings does the above machine accept ? L(M) = { w | second last symbol of w equal a } a,b a a, b a, b q0 q1 q2 q3

NFA Example Draw an NFA that accepts { w | third last symbol of w equal a } Recall: A DFA for this language must have 8 states q0 q1 a a, b q2 a,b q3

Parametric Example = {a, b}. For each k, let Lk = { w | kth symbol from end in w equals a } How many states does an NFA need to accept Lk as a function of k ? a a,b a, b k-1 transitions NFA with (k+1) states can accept Lk Recall: DFA must have 2k states Nondeterminism can lead to succinct descriptions !

Nondeterminism as a high-level construct q0 q1 In state q0, on reading symbol a, how does the machine know whether to stay in state q0 or go to state q1? One answer: if only of the two possibilities is going to lead to success at the end, then it chooses that A real-world machine/program cannot figure out which possibility is going to succeed, so needs to track all possibilities by maintaining a set of possible current states Nondeterminism is a “logical” or “mathematical” construct with no direct analog in the real world

Why Study Nondeterminism ? If there is no “real-world” analog of nondeterminism construct, namely, make the choice that will lead to success, why bother? First, excellent test case for studying “models of computation” Mathematically well-defined syntax and semantics Valid mathematical question: how does this construct impact computational power Second, turns out to be very important concept Useful in translation from regular expressions Critical to theory of NP-complete problems which includes a large number of natural optimization problems

Does nondeterminism always help ? Draw an NFA that accepts L = { w | count(w,a) is even } DFA for this language: DFAs are a special case of NFAs Above machine is also an NFA for L Is there a smaller/simpler NFA for L ? q0 q1 a b

NFA Example S = { A, C, G, T } Draw NFA for { w | w contains “ACCAC” as a substring } A, C, G,T A,C, G,T A C A C C q0 q1 q2 q3 q4 q5 If input w contains the substring ACCAC then some run does end up in final state q5 If a run does end up in state q5, then w must contain “ACCAC”

NFA Example S = { A, C, G, T } Draw NFA for { w | w contains “ACCAC” as a substring or ends with G } A, C, G,T A,C, G,T C A C A C q0 q1 q2 q3 q4 q5 G q6

Can we design NFAs when there is no DFA ? L = { w | count(w,a) = count(w,b) }, where S = { a, b } We know that L is not regular, that is, there is no DFA for L Can we construct an NFA for L ? Why did DFA construction fail? Strings 𝜖, a, aa, aaa, a4, … all need to lead to “distinct” states Can non-determinism help? More generally, are NFAs “more expressive” than DFAs? Is there an NFA M such that L(M) is not regular?

Compiling an NFA to a DFA Let M = (Q, S, q0, F, D) be an NFA. Goal: to construct a DFA M’ such that M’ accepts w if and only M does How can a deterministic machine track information about all possible executions of M ?

Recap: Set-based Definition of NFA Execution S = { A, C, G, T } A, C, G,T A,C, G,T A C C q0 q1 q2 q3 Execution of the machine on input ACTACCGA: { q0 } A {q0 , q1 } C {q0 , q2 } T {q0 } {q0 , q3 } G {q0 , q1 , q3} To simulate an NFA M, the DFA M’ maintains, as its state, the set of states of M

From NFA to DFA: Subset Construction A, C, G,T A,C, G,T C A C q0 q1 q2 q3 C, G,T A A A C { q0 } { q0 , q1 } { q0 , q2 } C G, T T G Only finitely many states can be generated: all possible subsets of {q0 , q1 , q2 , q3 } suffice

NFA => DFA Let M = (Q, S, q0, F, D) be an NFA. Goal: to construct a DFA M’ such that M’ accepts w if and only M does A state of M’ is a set of states of M: Q’ = 2Q Initial state q’0 of M’ = { q0 } A state is final for M’ if it contains a final state of M: F’ = { S | intersection of S and F is non-empty } Transition function of M’: d’( S, s) = U D(q, s) This construction is called “determinization” or “subset construction” q in S

Correctness of Determinization Let M = (Q, S, q0, F, D) be an NFA. Consider the DFA M’ = (2Q, S , { q0 } , F’, d’), where F’ = { S | intersection of S and F is non-empty } and d’( S, s) = U D(q, s) Prove: L(M) = L(M’) To prove: for all strings w, NFA M accepts w iff DFA M’ accepts w What’s the suitable claim that can be proved by induction on w ? For all strings w, D*(q0 , w) = d’ *({ q0 }, w) that is, the set of states that NFA M can be after processing a string w coincides with the state of DFA M’ after processing w q in S

Example of Determinization a,b b { } { q0 } a,b a,b a b a q0 q1 { q1 } { q0 , q1 } a In above automatically constructed DFA, states { } and {q1} are redundant, since they are “unreachable” from the initial state {q0} Possible optimization: Construct only those states that are reachable from the initial state {q0}

Summary of Determinization For every NFA, there exists an equivalent DFA accepting same language The class of problems solved by DFAs and NFAs is identical, namely, regular languages It is straightforward to write a computer program that implements the NFA to DFA translation If NFA M has k states then the determinized machine M’ has 2k states Some optimizations can result in smaller DFAs in some cases, but such an exponential blow-up is unavoidable in worst-case, for example, Lk = {w | kth symbol from end equals a } has NFA with k+1 states, but every DFA for this language must have at least 2k states

Nondeterministic Automata: Summary NFA model is a generalization of DFA: transition function maps a state and a symbol to a set of states Semantics: NFA accepts a string if one of the many possible executions leads to a final state Nondeterminism does not increase expressiveness: An NFA can be compiled into an equivalent DFA NFAs accept only regular languages NFAs allow more high-level or succinct descriptions

NFAs with e-transitions A number consists of one or more digits 0..9 (but first digit is not 0) and can be optionally preceded by + or - q0 q1 e, +, - 1..9 q2 0..9 Meaning of e-transition: state may change without consuming any input symbol Acceptance as before: a string is accepted as long as some execution succeeds

e-NFAs Transition function D : Q x [ S U { e } ]  2Q Such transitions do not increase expressiveness: An NFA with e-transitions can be compiled into an equivalent DFA by modifying the subset construction e-transitions can allow more natural/succinct description Read the textbook for details