Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.

Slides:



Advertisements
Similar presentations
CSE 311 Foundations of Computing I
Advertisements

4b Lexical analysis Finite Automata
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)
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
CSCI 2670 Introduction to Theory of Computing September 13, 2005.
Applied Computer Science II Chapter 1 : Regular Languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
CS21 Decidability and Tractability
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Introduction to Computability Theory
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.
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: Closure Properties & Regular Expressions Jim Hook Tim Sheard Portland State University.
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 1 Regular Languages Contents Finite Automata (FA or DFA) definitions, examples,
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.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
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)
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
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.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
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.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
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.
CHAPTER 1 Regular Languages
January 9, 2015CS21 Lecture 31 CS21 Decidability and Tractability Lecture 3 January 9, 2015.
Formal Definition of Computation Let M = (Q, ∑, δ, q 0, F) be a finite automaton and let w = w 1 w w n be a string where each wi is a member of the.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CSCI 2670 Introduction to Theory of Computing September 13.
CS 203: Introduction to Formal Languages and Automata
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 0 Introduction Some slides are in courtesy of Prof.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Donghyun (David) Kim Department of Mathematics and Computer Science North Carolina Central University 1 Chapter 4 Decidability Some slides are in courtesy.
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.
Equivalence with FA * Any Regex can be converted to FA and vice versa, because: * Regex and FA are equivalent in their descriptive power ** Regular language.
CSCI 2670 Introduction to Theory of Computing September 7, 2004.
CSCI 2670 Introduction to Theory of Computing September 11, 2007.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Theory of Computation Automata Theory Dr. Ayman Srour.
Lecture 09: Theory of Automata:2014 Asif NawazUIIT, PMAS-Arid Agriclture University Rawalpindi. Kleene’s Theorem and NFA.
Lexical analysis Finite Automata
PROPERTIES OF REGULAR LANGUAGES
Non-Deterministic Finite Automata
4b Lexical analysis Finite Automata
CS21 Decidability and Tractability
4b Lexical analysis Finite Automata
CS21 Decidability and Tractability
Chapter 1 Regular Language
CHAPTER 1 Regular Languages
Presentation transcript:

Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy of Prof. Xinhua Zhuang at Dept. of CECS at University of Missouri-Columbia Spring 2016 CISG 5115 Theory of Computation

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University 1.1 Finite Automata 2

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Finite Automata A computational model is an idealized computer A finite-state machine (or equivalently finite automaton) is a simple computation model with very limited memory space states transition from one state to another 3 Hungry Not Hungry Eat Work State transition diagram EatWork HungryNot Hungry- -Hungry State transition table

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Applications of FSM Controllers: elevators, ovens, stereo systems Logic circuit design: arithmetic and logic units, buffers Programming utilities: lex, grep, awk, perl Text editors: pattern-matching Computers 4

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Characteristics of FSM Operate on strings. A finite set of states. Some states (“accepting” states) cause machine to get excited. The current state entirely dictates the next state. Rules: “If in state, scanning 0, go to state and move right one cell.” If light is on after reading the last character on the input, then M accepts the input. 5

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Graphical Representation of FSM State diagram: a directed graph nodes: states arcs: transitions between states start state: an arrow points at it from nowhere accept state: with double circle. For each state q and symbol, exactly one edge leaving q labeled with a. M accept w ( is accepted by the FSM below) if and only if the path starting from labeled with w ends at a final state. 6

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Formal Definition A DFA is a 5-tuple, where Q : finite set of states : finite input alphabet, transition function : initial state : accept/final states 7

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example of FSM Deterministic Finite Automata (DFA) Produce a unique computation Accept/reject finite strings of symbols (next page) 8

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Language of a Machine M recognizes language A : if A contains all strings that M accepts Def: L ( M ) = “Language accepted by M ” M accepts w A formal definition of “ M accepts w ” if there exists a sequence of states for 3. A language is a regular language if some DFA recognizes it. is regular iff DFA M s.t. 9

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Design of FSM Describe what language a FSM recognizes. Given M, find L ( M ). Examples Given FSM M Given a language L, design M s.t. L ( M ) = L. Method: “reader as automaton” pretending you are the machine figuring out what you need to remember (finite memory) assigning states for crucial information See the textbook for more examples 10

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Operations of Languages Theory of computation: languages and how to manipulate them Regular operations Let A, B be languages. union: concatenation: star: 11

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Properties of Regular Languages A set A is closed under operation P ( x, y ) if Let N = {1, 2, 3, … }, N is closed under, but not under /. The class of regular languages is closed under. If are regular languages, so is. Proof: proof by construction. If are regular, then each of them are accepted by some DFA. We construct a DFA accepting based on. 12

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Proof Assume Construct s.t To make things simple, assume the same 3. : For each and each a, let

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University More Properties of Regular Languages The class of regular languages is closed under concatenation. If are regular languages, so is Proof: not quite easy. Let's introduce a new technique: nondeterminism. 14

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University 1.2 Nondeterminism 15

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Nondeterministic Computation DFA (deterministic FA): the next state is determined exactly based on the current state and the next input symbol. NFA (nondeterministic FA): several choices may exists for the next state. NFA is a generalization of DFA. DFA is a special case of NFA. 16

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Features of NFA A state may have 0, 1, or many moves (arrows) for each symbol. Arrows may be labeled with or. A kind of parallel computation. Given a state and an input alphabet, the machine splits into multiple copies of itself and follows all the possibilities in parallel. 17

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Advantages of NFA Smaller Easier to construct Easier to understand Every NFA can be converted into an equivalent DFA. 18

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Examples of NFA Let A be the language consisting of all strings over {0,1} containing a 1 in the third position from the end. 19

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Formal Definition of a NFA Similar to DFA except the transition function. A NFA is a 5-tuple, where Q: a finite set of states : finite input alphabet : the transition function, where and is the power set over : the initial state : the accept/final states 20

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Formal Definition of Computation of a NFA A formal definition of “ M accepts w ”: if, where, and there exists a sequence of states for 3. 21

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Equivalence Two machines are equivalent if they recognize the same language. Theorem: Every NFA has an equivalent DFA. Proof: proof by construction. 22

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Proof Let be an NFA, and. We construct a DFA s.t.. When N has no arrows: 1. - power set of Q 2.For each and each, let When N has arrows: can be reached from R through arrows}. 23

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example 1.41 Converting NFAs to DFAs NFA (Fig 1.42) 24

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example 1.41 Converting NFAs to DFAs NFA (Fig 1.42) 25

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example 1.41 Converting NFAs to DFAs NFA (Fig 1.42) 26

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example 1.41 Converting NFAs to DFAs NFA (Fig 1.42) For each and each, let 27 is okay. is not okay.

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example 1.41 Converting NFAs to DFAs NFA (Fig 1.42) For each and each, let 28

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Regular Languages Corollary: A language is regular if and only if (iff) some NFA recognize it. Theorem 1.45 The class of regular languages is closed under union operation Proof: Two DFA can be merged into one NFA in parallel. NFA can be converted into an equivalent DFA 29

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Regular Languages – cont’ Theorem 1.47 The class of regular languages is closed under the concatenation operation Proof: Two DFA can be sequentially connected into one NFA. NFA can be converted into an equivalent DFA Theorem 1.47 The class of regular languages is closed under the star operation Proof: See Figure

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University 1.3 Regular Expressions 31

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Regular Expressions Regular expressions were designed to denote regular languages. They are built from a set of primitives using regular operations. Example: Shorthands if 32

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Definition of Regular Expressions f 33

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Examples : all strings that either start with a 0 or end with a 1. : all strings that has at least one 1. : all strings containing 001 : a string of even length : a string whose length is a multiple of three : concatenating the empty set to any set yields the empty set 34

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Applications of Regular Expressions Describing patterns awk, grep, perl vi, emacs Regular expressions in compilers 35

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Regular Expressions and Finite Automata 36

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Regular Expressions and Finite Automata 37

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Converting DFAs into Regular Expressions 1.Convert DFAs into GNFAs GNFA: generalized nondeterministic finite automaton transition arrows: any regular expressions as labels (in addition to regular alphabets) A special form of GNFA (for convenience) the start state: has arrows to all other states, but no in- coming arrow. only a single accept state: has arrows from all other states, but no out-going arrows. other states: at most one arrow between any two states, and to each state itself. 2.Convert GNFAs into regular expressions 38

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Convert GNFAs into Regular Expressions Remove the states in GNFA one at a time. CONVERT ( G ), G is a k -state GNFA (a GNFA having k states) If k = 2, done. If k > 2, select any state (except the start and accept states), remove it and modify the GNFA correspondingly. Example 39

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University The Big Picture 40

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example 41

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example – cont’ 42

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Example – cont’ 43

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University 1.4 Nonregular Languages 44

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Limitation of Regular Languages Certain languages cannot be recognized by any finite automation DFA cannot remember how many 0 are repeated How to prove B is not regular? All regular languages have a special property - pumping lemma 45

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Pumping Lemma Let A be regular. Then such that with such that 1. where If a language L does not satisfies the requirements, it is not regular The lemma state that all strings in the language can be “pumped” if they are at least as long as a certain special value, called the pumping length 46 Suppose p is the number of states in a FA Suppose |s| = n Then, a FA has visited n + 1 states (not necessarily disjoint) Since n ≥ p, and thus n + 1 > p, some state should be repeated (loop)

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Prove Non-regularity Is regular? No. Proof Suppose B is regular and p be the pumping length Choose Because s is a member of B and s has length more than p, the pumping lemma says that s can be split into three pieces,, where for any, the string is in B. (need to show this is not possible at any case) This is not possible! 47

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Prove Non-regularity Is regular? No Proof Suppose C is regular and p be the pumping length Choose Because s is a member of C and s has length more than p, the pumping lemma says that s can be split into three pieces,, where for any, the string is in C. => if, then s is in C. From Condition 3, s has to be divided so that, which implies that y must consist only of 0s, so. If you pick, the pumping lemma does not work 48

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Prove Non-regularity Is regular? No Proof Suppose F is regular and p be the pumping length Let Because s is a member of C and s has length more than p, the pumping lemma says that s can be split into three pieces,, where for any, the string is in C. From Condition 3, s has to be divided so that, which implies that y must consist only of 0s, so. 49

Spring 2016 CISG 5115 Department of Mathematics and Physics Donghyun (David) Kim North Carolina Central University Summary Showing regular construct DFA, NFA construct regular expression show L is the union, concatenation, intersection, … (regular operations) of regular languages. Showing non-regular pumping lemma assume regular, apply closure properties of regular languages and obtain a known non-regular language. 50