Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy."— Presentation transcript:

1 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

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

3 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

4 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

5 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

6 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

7 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

8 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

9 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 1. 2. for 3. A language is a regular language if some DFA recognizes it. is regular iff DFA M s.t. 9

10 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

11 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

12 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

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

14 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

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

16 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

17 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

18 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

19 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

20 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

21 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 1. 2. for 3. 21

22 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

23 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 3. 4. When N has arrows: can be reached from R through arrows}. 23

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) 24

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) 25

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) 26

27 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.

28 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

29 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

30 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 1.50 30

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

32 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

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

34 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

35 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

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

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

38 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

39 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

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

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

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

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

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

45 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

46 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 2. 3. 4. 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)

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

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

49 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

50 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


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

Similar presentations


Ads by Google