CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.

Slides:



Advertisements
Similar presentations
CSE 311 Foundations of Computing I
Advertisements

CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
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.
Compiler Construction
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
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
1 Introduction to Computability Theory Discussion1: Non-Deterministic Finite Automatons Prof. Amos Israeli.
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Fall 2006Costas Busch - RPI1 Deterministic Finite Automata And Regular Languages.
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.
Homework #2 Solutions.
1 Finite Automata. 2 Finite Automaton Input “Accept” or “Reject” String Finite Automaton Output.
1 Languages and Finite Automata or how to talk to machines...
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
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.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
1 Non-Deterministic Automata Regular Expressions.
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Finite Automata Costas Busch - RPI.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
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)
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CS 3813: Introduction to Formal Languages and Automata Chapter 2 Deterministic finite automata These class notes are based on material from our textbook,
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
CS 154 Formal Languages and Computability February 4 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
1.2 Three Basic Concepts Languages start variables Grammars Let us see a grammar for English. Typically, we are told “a sentence can Consist.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
CS 154 Formal Languages and Computability March 8 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability April 12 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability March 17 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
1 Finite Automata. 2 Introductory Example An automaton that accepts all legal Pascal identifiers: Letter Digit Letter or Digit "yes" "no" 2.
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
Theory of Computation Automata Theory Dr. Ayman Srour.
Fall 2004COMP 3351 Finite Automata. Fall 2004COMP 3352 Finite Automaton Input String Output String Finite Automaton.
Languages.
Non Deterministic Automata
Chapter 2 FINITE AUTOMATA.
Non-Deterministic Finite Automata
Non-Deterministic Finite Automata
CSE322 Definition and description of finite Automata
Non Deterministic Automata
Chapter 1 Regular Language
Non Deterministic Automata
Presentation transcript:

CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Review: Automata  An automaton is an abstract model of a digital computer.  An automaton can have: the ability to read symbols from an input file the ability to product output a limited amount of temporary storage a control unit that can be in one state or another 2

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Deterministic Finite Acceptor (DFA)  An acceptor is an automaton that either accepts or rejects input strings.  A deterministic finite acceptor (DFA) is an acceptor that has no temporary storage. It only has internal states in its control unit. Each input symbol uniquely determines a DFA’s move from one state to another according to its transition function. 3

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Languages and DFAs  The set of all strings that the DFA accepts constitutes the language  The DFA represents the language’s rules. 4

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak DFA and Associated Transition Graph  If we have a DFA and its associated transition graph G M, can we treat them both equally?  Theorem 2.1 of the textbook basically says yes. For every q i, q j in Q, and w in Σ + : if and only if there is a path labeled w in G M from q i to q j. Proof by induction on the length of w. 5

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak DFA Example #1  Create a DFA that accepts all strings on {0, 1} that begin and end with the same symbol.  How can an automaton remember what was the beginning symbol of a string?  Have a different set of states depending on the first symbol! 6

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak DFA Example #1, cont’d 7 S 1 0 p1p1 1 1 q1q1 0 0 popo 0 Starts and ends with 0 0 qoqo 1 Starts and ends with 1 1

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak DFA Example #2  Create a DFA that accepts all strings on {0, 1} that do not contain the substring 001.  The basic idea is that if the automaton ever reads 001, it should be in a nonfinal state. Actually, that state should be a trap.  How can the automaton remember the previous two symbols whenever it reads a 1? 8

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak DFA Example #2, cont’d  Again, we must accomplish this with states: A state for having read a 0. A state for having read 00. A state for having read 001.  We can label the states accordingly. 9 Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Regular Languages  A language L is called regular if and only if there exists a DFA M such that L = L(M).  Therefore, to show that a language is regular, all we have to do is find a DFA for it. 10

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Regular Language Example #1  Is the language regular? It is if we can find a DFA for it. 11 After having read the leading a, we don’t know if a subsequent a is the last symbol of the string. So we can actually leave the final state and later return to it. Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Regular Language Example #2  What about ?  And so L 2 is also regular. 12 Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Nondeterministic Finite Acceptors (NFA)  Given an input symbol, a nondeterministic finite acceptor (NFA) has a choice of moves.  An NFA’s transition function can take it to any one state from a set of states: where 13

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Nondeterministic Finite Acceptors, cont’d 14  A transition moves to a subset of states (not to a unique state as in a DFA). 2 Q is the powerset of Q. The set of all subsets of Q.  The second argument of δ can also be λ. We can make a transition without consuming an input symbol.

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Example NFAs 15

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Example NFAs, cont’d 16 The string 10 has two walks, one to q 0 and one to q 2. The string is accepted because q 0 is a final state. Accept either the string aaa or a string with an even number of a ’s. (Simpler than the equivalent DFA.) Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Language Accepted by an NFA  The language L accepted by an NFA is the set of all strings w for which there is a path labeled w from the initial vertex to some final vertex. 17

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Are NFAs More Powerful Than DFAs?  Can NFAs in general accept more languages than DFAs?  A DFA is a restricted kind of NFA.  Therefore, any language accepted by a DFA is also accepted by some NFA. 18

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Are NFAs More Powerful Than DFAs? cont’d  Is there a language accepted by an NFA that cannot be accepted by a DFA?  No: DFAs and NFAs are equally powerful.  For every language accepted by some NFA, there is a DFA that accepts the same language. Therefore, any language accepted by an NFA is regular.  We can convert any NFA into an equivalent DFA. 19

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak NFA to DFA Conversion Example 20 NFADFA Label the states of the new DFA after the set of states that the NFA can be in after each transition. Each state of the DFA must have a transition on each symbol. Refer back to the NFA to derive the transition. combined state Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 9 CS 154: Formal Languages and Computability © R. Mak Why Convert an NFA to a DFA?  An NFA may be easier to construct.  But an NFA is usually not efficient to run.  An NFA may have multiple paths to try for a given input string.  A DFA follows only one path for a given input string. 21