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

Slides:



Advertisements
Similar presentations
Lexical Analysis IV : NFA to DFA DFA Minimization
Advertisements

CSE 311 Foundations of Computing I
Reducing DFA’s Section 2.4. Reduction of DFA For any language, there are many DFA’s that accept the language Why would we want to find the smallest? Algorithm:
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.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Regular Expressions and DFAs COP 3402 (Summer 2014)
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Summary Showing regular Showing non-regular construct DFA, NFA
Examples for Finite Automata
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
Introduction to Computability Theory
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Fall 2006Costas Busch - RPI1 Regular Expressions.
CS 310 – Fall 2006 Pacific University CS310 Converting NFA to DFA Sections:1.2 Page 54 September 15, 2006.
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 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.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Non-Deterministic Automata Regular Expressions.
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.
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY For next time: Read 2.1 & 2.2.
CSE 311: Foundations of Computing Fall 2014 Lecture 23: State Minimization, NFAs.
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.
Theory of Languages and Automata
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
Lexical Analysis Constructing a Scanner from Regular Expressions.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Lexical Analysis III : NFA to DFA DFA Minimization Lecture 5 CS 4318/5331 Spring 2010 Apan Qasem Texas State University *some slides adopted from Cooper.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
Transition Diagrams Lecture 3 Wed, Jan 21, Building Transition Diagrams from Regular Expressions A regular expression consists of symbols a, b,
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CHAPTER 1 Regular Languages
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
CSE 311 Foundations of Computing I Lecture 27 FSM Limits, Pattern Matching Autumn 2012 CSE
CS 3813: Introduction to Formal Languages and Automata Chapter 2 Deterministic finite automata These class notes are based on material from our textbook,
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
CS 203: Introduction to Formal Languages and Automata
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
CS 154 Formal Languages and Computability February 4 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
1 Chapter Constructing Efficient Finite Automata.
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CSE 311 Foundations of Computing I Lecture 24 FSM Limits, Pattern Matching Autumn 2011 CSE 3111.
98 Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars,
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
1 Lexical Analysis Uses formalism of Regular Languages Uses formalism of Regular Languages Regular Expressions Regular Expressions Deterministic Finite.
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.
Theory of Computation Automata Theory Dr. Ayman Srour.
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.
CS 154 Formal Languages and Computability April 28 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Lecture 15: Theory of Automata:2014 Finite Automata with Output.
Non Deterministic Automata
Non-Deterministic Finite Automata
Non-Deterministic Finite Automata
Transition Diagrams Lecture 3 Fri, Jan 21, 2005.
Presentation transcript:

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

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Corrected DFA Example #1 2 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 11 CS 154: Formal Languages and Computability © R. Mak Corrected Feb. 9 Slide 16 3 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 It should be 10, not 01.

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Assignment #1: Problem 1 4

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Assignment #1: Problem 2 5 The language consists of the strings that are n a ’s followed by n b ’s, n > 0, or the concatenation of two such strings as substrings. The number of a ’s and b ’s in the first substring is independent of the number of a ’s and b ’s in the second substring.

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Assignment #1: Problem 3 6

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Assignment #1: Problem 4 7

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Assignment #1: Problem 5 8

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Assignment #1: Problem 5, cont’d 9

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Assignment #1: Problem 6 10

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Assignment #1: Problem 6, cont’d 11

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Assignment #1: Problem 7 12  The Exercise 7 grammar is not equivalent to the Exercise 2 grammar. For example, the following strings are accepted by the latter but not the former: abaabb aabbab abaabb  These strings require the production rule S  SS.  It is incorrect to replace the rule S  aSbaSb with S  SS in the Exercise 7 grammar. S  aSb does not imply that aSb  S.

Computer Science Dept. Spring 2016: February 11 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. 13

Computer Science Dept. Spring 2016: February 11 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. 14

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak NFA to DFA Conversion Example 15 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 11 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. 16

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak NFA to DFA Conversion Algorithm 1. Label the DFA start state {q 0 }, where q 0 is the NFA start state. 1. Include any NFA state reachable by λ -transitions from the start state. 2. For each DFA state that is missing a transition, compute the transition by combining the NFA transitions for each input symbol. Include any NFA state reachable by λ -transitions after the destination state. 3. Make any DFA state a final state if it combines any NFA state that was final. 17 Label each DFA state by a set of combined NFA states. JFLAP demo

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Equivalent DFAs  A DFA defines a unique language.  But a given language can have many DFAs that define it.  Two DFAs can be equivalent and yet have a different number of states. Equivalent DFAs define the same language. 18

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Equivalent DFAs, cont’d  These two DFAs are equivalent: 19 Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012 For most practical purposes, the DFA with fewer states is desired.

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Distinguishable vs. Indistinguishable States  Consider two states p and q of a DFA and all strings w in Σ*.  If there is path from p to a final state implies there is a path from q to a final state, and  If there is no path from p to a final state implies there is no path from q to a final state,  Then states p and q are indistinguishable.  However, if for any one string w there is a path from p to a final state but no path from q to a final state (or vice versa),  Then the states p and q are distinguishable. 20 Not necessarily the same final state.

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak Reducing the Number of States  Given a DFA, how can we simplify it by reducing the number of states? Of course, we want the simplified DFA to be equivalent to the original one.  One way: Find and combine indistinguishable states.  Plan: First eliminate inaccessible states. Then repeatedly partition the states into equivalence classes of indistinguishable states. 21

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak State Reduction Example #1  From either q 1 or q 2, input 1 and input 01 lead to a final state, so they’re together in another equivalence class.  We can’t partition any further, so make new states out of each equivalence class. 22 q 0 q 1 q 2 | q 3 q 4  Remove inaccessible state q5.  Final states q 3 and q 4 are in one equivalence class: q 0 | q 1 q 2 | q 3 q 4 Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 11 CS 154: Formal Languages and Computability © R. Mak State Reduction Example #2  States q 2 and q 4 are final:   From q 1 and q 3, strings 0 and 1 both lead to final states:   δ(q 4, 0) = q 4 but δ(q 2, 0) = q 1 :  No further partitioning is possible | | 1 3 | | 1 3 | 2 | 4 Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012 JFLAP demo