Discrete Math II Howon Kim 2017.11.

Slides:



Advertisements
Similar presentations
CSE 311 Foundations of Computing I
Advertisements

4b Lexical analysis Finite Automata
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
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
Introduction to Computability Theory
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.
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)
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.
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
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,
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
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.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Lecture Notes 
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
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 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Fall 2004COMP 3351 Finite Automata. Fall 2004COMP 3352 Finite Automaton Input String Output String Finite Automaton.
Formal Language & Automata Theory
CIS Automata and Formal Languages – Pei Wang
Lexical analysis Finite Automata
Non Deterministic Automata
Chapter 2 Finite Automata
Discrete Math II Howon Kim
Two issues in lexical analysis
Recognizer for a Language
Chapter 2 FINITE AUTOMATA.
Language Recognition (12.4)
Hierarchy of languages
Non-Determinism 12CS45 Finite Automata.
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Non-Deterministic Finite Automata
CS 154, Lecture 3: DFANFA, Regular Expressions.
COSC 3340: Introduction to Theory of Computation
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Non-Deterministic Finite Automata
Nondeterministic Finite Automata
Non Deterministic Automata
CSE 311: Foundations of Computing
Finite Automata Reading: Chapter 2.
4b Lexical analysis Finite Automata
CSCI 2670 Introduction to Theory of Computing
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
4b Lexical analysis Finite Automata
Language Recognition (12.4)
CS21 Decidability and Tractability
Are DFAs and NFAs Equivalent
CSE 311 Foundations of Computing I
CSC312 Automata Theory Transition Graphs Lecture # 9
Chapter 1 Regular Language
Finite-State Machines with No Output
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

Discrete Math II Howon Kim 2017.11

Agenda 1 Automata Theory 2 Regular Expression & Regular Languages 3 Finite Automata DFA(Deterministic Finite Automata) FA Applications 4 Non-deterministic Finite Automata 5 Grammars & Languages 6 Theory of Computations

Overview Set Theory of Strings (Chapter 6.1) Regular Expressions & Regular Languages Finite State Machines Deterministic Finite Automata (DFA) Non-deterministic Finite Automata (NFA) Grammars and Languages Types of Grammars and Languages Associated Machines including Turing Machine Computation Theory NP Problem

Finite Automata Deterministic FA Non-deterministic FA Every state has (at most) one transition on any input character. Non-deterministic FA A state may have more than one transition on an input character. The NFA allows -transitions. (입력없이 천이 가능) The NFA accepts a string if there is at least ONE path from the start state to an accepting state whose edge labels spell out the string. 4

Examples ( DFA and NFA ) 11010 b  d  c  b  c Input String a b c d 5

Examples ( DFA and NFA ) q0 q1 q2 q3 q4 q5 q1 q2 q0 a 0,1 1  This is non-deterministic accepter since there are two transitions labeled a out of q0 This is non-deterministic since.. Several edges with the same label originate from one vertex it has  transition some transition, such as (q2,0) is unspecified in the graph (note: we will use  instead of  in NFA) This is to be interpreted as a transition to the empty set, that is, (q2,0)=  The automaton accepts strings , 1010, 101010 but not 110 and 10100. For 10, even though q2 is not a final state, the string 10 is accepted because one walk leads to a final state 0,1 q1 q2 q0 1  6

NFA Definition A non-deterministic finite automata(NFA) N is specified by a quintuple N = (Q, ∑, , q0, F), where Q : an alphabet of state symbols ; ∑ : an alphabet of input symbols ;  : a subset of transition relation Q x (∑{})  2Q q0  Q is the start state ; and F  Q is a set of final states. The range of is in the powerset 2Q, so that its value is not a single element of Q, but a subset of it ! this subset defines the set of all possible states that can be reached by the transition (note)  : transition function in DFA 7

(Ex) (010+01)* string을 accept하는 NFA? An Example (Ex) (010+01)* string을 accept하는 NFA? N = ( {A,B,C}, {0,1}, , A, {A} ) (A,0)  B (B,1)  C (C,0)  A (C,)  A 입력없이 {C}에서 {A}로 천이됨 {A} ; start state {B} 0 {C}  {A} 1 {A}  {B} 0 {B} 0 A B C 8

An Example 11010 Input String {A} ; start state {A, B} 1 {A, B, C} 1 {A, C} 0 {A, B} 1 (C,1)=  9

NFA Number of subsets Remarks It sometimes convenient to consider the transition relation  as a function  : Q x (∑{})  2Q where the 2Q is the power set(subsets) of Q. (Ex) (010+01)* NFA?  Input 1  A {B}  {A} B {A,C} C A B C 10 http://mathworld.wolfram.com/Subset.html

(Ex) (010+01)* string을 accept하는 NFA? Examples (Ex) (010+01)* string을 accept하는 NFA? N = ( {A,B,C}, {0,1}, , A, {A} ) (A,0) = {B} (B,1) = {A,C} (C,0) = {A} (C,) = {A,C} (*,) = {*} The others (*,*) =  A B C N = ( {A,B,C}, {0,1}, , A, {C} ) (A,0) = {A}, (A,1) = {A,B} (B,0) = {C}, (B,1) = {C} (*,) = {*}, The others (*,*) =  A B C 11

(Ex) (010+01)* string을 accept하는 NFA? NFA Operation ? (Ex) (010+01)* string을 accept하는 NFA? N = ( {A,B,C}, {0,1}, , A, {A} ) (A,0) = {B} (B,1) = {A,C} (C,0) = {A} (C,) = {A,C} (*,) = {*} The others (*,*) =  A B C {A} ; start state {B} 0 {A, C} 1 {A, B} 0 {B} 0 12

s And Es for a set Def. of s s : 2Q x (   {} )  2Q s(P,a) = qP (q,a) ,where P  Q and a  ({}). Def. of E(q) and Es(P) E(q) : a set of states that can be reachable from q without reading any input symbol (through ) Es(P) : qP E(q) 상태 set에 대한 transition 정의 ! 13

s({A},0) = {B} s({B},1) = {A,C} s({C},0) = {A} s({C},) = {A,C} Examples s({A},0) = {B} s({B},1) = {A,C} s({C},0) = {A} s({C},) = {A,C} s({A,C},0) = {A,B} s({A,C},1) = { } =  E(A) = {A} E(B) = {B} E(C) = {A,C} Es({A}) = {A} Es({A,B}) = {A,B} Es({B,C}) = {A,B,C} 상태 set에 대한 transition을 기술하기 위해 s를 정의함 A B C  입력에 의한 transited state  입력에 의한 transited state sets 14

Extension of  Def. * : Q x *  2Q (i) *(q,) = E(q) (ii) *(q,wa) = Es(s(*(q,w),a)), w  *, a  . A string w is called to be accepted by a NFA N if *(q0,w) contains one or more final states. The set of all the strings that are accepted by the N is called the language of N, L(N). L(N) = { w  * | *(q0,w)  F   } w는 string이므로(포함), transition을 *으로 표기함. 그 결과로 인해 state set이 나오므로, 이에 대한 transition은 s로 표기함 string is also possible as inputs q0 : Start State 15

(010+01)* accept NFA Examples B C Examples (010+01)* accept NFA *(A,0) = Es(s(*(A,),0)) = Es(s(E(A),0)) = Es(s({A},0)) = Es({B}) = {B} *(A,01) = Es(s(*(A,0),1)) = Es(s({B},1)) = Es({A,C}) = {A,C} *(A,010) = {A,B} *(A,0100) = {B} *(A,01001) = {A,C} *(A,1) 한편 = Es(s(*(A,),1)) = Es(s(E(A),1)) = Es(s({A},1)) = Es() =  {A} ; start state {B} 0 {C}  {A} 1 {A}  {B} 0 {B} 0 16

끝에서 두 번째 symbol이 1인 string을 accept 하는 NFA Another example of NFA 끝에서 두 번째 symbol이 1인 string을 accept 하는 NFA A B C *(A,0) = {A} *(A,01) = {A,B} *(A,011) = {A,B,C} ; accepted *(A,0110) = {A,C} ; accepted *(A,01101) = {A,B} *(A,1) = {A,B} *(A,100) = {A} 17

NFA Design Design of NFA is generally easier than that of DFA for a given language (Ex) 0 또는 1이 연이어 세 번 나오는 substring을 갖 는 string들의 집합인 언어 B C D A J F G H 18

NFA Design Design of NFA is generally easier than that of DFA for a given language (Ex) 0 또는 1이 연이어 세 번 나오는 substring을 갖 는 string들의 집합인 언어 B C D A J F G H 19

Another example of NFA Design (Ex)  = {0,1}상의 정규식 (01+101)*0으로 표현되는 언어를 accept하는 NFA ? ( (+1) 01 )* 0 D A B C 20

Equivalence between NFA and DFA For any NFA, there exists an equivalent DFA which accepts the same language. That is, if L is a language accepted by a NFA then  a DFA exists accepting L. The DFA and NFA accept exactly the same set of languages. That is, nondeterminism does not make a finite automaton any more powerful. To show that NFAs and DFAs accept the same class of languages, we should show two things: any language accepted by a DFA can also be accepted by some NFA any language accepted by a NFA can also be accepted by some DFA 21

Equivalence between NFA and DFA To show that any language accepted by a NFA is also accepted by some DFA, we describe an algorithm that takes any NFA and converts it into a DFA that accepts the same language The algorithm is called the “subset construction algorithm” 22

Subset Construction Algorithm What does it do? Given a NFA, it constructs a DFA that accepts the same language What is the key idea? The equivalent DFA simulates the NFA by keeping track of the possible states it could be in. Each state of the DFA corresponds to a subset of the set of states of the NFA  hence, the name of this algorithm. If the NFA has n states, the DFA can have as many as 2n states (why?), although it usually has many less. 23

Steps of Subset Construction Algorithm The initial state of the DFA is the set of all states the NFA can be in without reading any input. For any state {qi,qj,…,qk} of the DFA and any input a, the next state of the DFA is the set of all states of the NFA that can result as next states if the NFA is in any of the states qi,qj,…,qk when it reads a. This includes states that can be reached by reading a followed by any number of λ-transitions. Use this rule to keep adding new states and transitions until it is no longer possible to do so. The accepting states of the DFA are those states that contain an accepting state of the NFA. 24

Example : From NFA to DFA [1] State 0 and 1 in NFA 25  transition.

Example : From NFA to DFA [2] 26

Example : From NFA to DFA [3] 27

Example : From NFA to DFA NFA의 상태 1과 2에서 입력 a를 생각해보자. 상태 1에서 a 입력받으면 상태 1로 가고 상태2에서 a 입력받으면 상태 0으로 감. 이때, NFA의 상태0과 상태1에 해당하는 DFA 상태가 이전에 정의되었기때문에 아래의 DFA와 같이 됨. NFA의 상태 1과 2에서 입력 b를 생각해보자. 상태 1에서 b 입력받으면 상태 2로 가고 상태 2에서 b 입력받으면 상태 1,2로 감. 이때, NFA의 상태1과 2에 해당하는 DFA 상태가 이전에 상태 {1,2}로 정의 되었기 때문에 옆의 DFA와 같이 됨. [4] 28

Example : From NFA to DFA More detailed example (especially how to assign new state) can be found in the next slide ! [5] 29

Equivalence between NFA and DFA Theorem 1 There exists a DFA for a given NFA such that L(MDFA) = L(MNFA). (Proof) (a) Show a DFA-derivation method from a NFA. (b) Prove that the language of the DFA is equivalent to that of the NFA. 30

Conversion of NFA to DFA Let D = (QD,,,q’,FD) be the derived DFA from a NFA N = (QN,,,q0,FN). q’ = E(q0); QD  q’ ; mark q’; For a marked qP (P( 2QN))  QD and a  , unmark qP; qR = (R = Es(s(P,a))); If qR  QD, then QD  qR; mark qR; (qP,a) = qR; else (qP,a) = qT (= qR  QD); FD = { qD | qD (D)  QD and (D  FN)   } ; (note) S : name of the given set S 31

An Example S0 = E(A) = {A} Es(s(S0,0)) = {B} = S1 Es(s(S0,1)) = { } = Sd Es(s(S1,0)) = { } = Sd Es(s(S1,1)) = {A,C} = S2 Es(s(Sd,0)) = { } = Sd Es(s(Sd,1)) = { } = Sd Es(s(S2,0)) = {A,B} = S3 Es(s(S2,1)) = { } = Sd Es(s(S3,0)) = {B} = S1 Es(s(S3,1)) = {A,C} = S2 NFA A B C S0 S1 S2 S3 SD DFA 32

Another Example S0 = E(A) = {A,B} Es(s(S0,0)) = {C,D} = S1 Es(s(S0,1)) = {B} = S2 Es(s(S1,0)) = { } = Sd Es(s(S1,1)) = {A,B} = S0 Es(s(S2,0)) = {C} = S3 Es(s(S2,1)) = { } = Sd Es(s(Sd,0)) = { } = Sd Es(s(Sd,1)) = { } = Sd Es(s(S3,0)) = { } = Sd Es(s(S3,1)) = {A,B} = S0  = {0,1}상의 정규식 (01+101)*0 으로 표현되는 언어 를 accept하는 NFA ? A B C D S0 S1 S2 S3 SD 33

Proof of L(MNFA) = L(MDFA) (i) *(q,) = E(q) (ii) *(q,wa) = Es(s(*(q,w),a)), w  *, a  . For an input string w, we will show that *(q0,w) = *(E(q0),w) ,where for P  2QN, a  , and x  *, *(P,a)=s(P,a)=Es(s(P,a)) and *(P,xa)=s(*(P,x),a). (i) ||w|| = 0일 때, *(q0,) = *(E(q0),) = E(q0). (ii) ||w|| < k일 때, *(q0,x) = *(E(q0),x) 성립 가정 (iii) ||w|| = k  1일 때, w = xa라고 하자. *(q0,w) = Es(s(*(q0,x),a))이고, *(E(q0),w)=s(*(E(q0),x),a)=Es(s(*(E(q0),x),a)이다. 따라서, (ii)의 가정에 의해 *(q0,w) = *(E(q0),w) . *(q,wa) = Es(s(*(q,w),a)) 정의에의해… by (II) w=xa 34

Regular Expression  NFA Theorem 2 There exists a NFA that accepts the regular language L(r) for a regular expression r. If we can show the corresponding NFA for each type in the definition of a regular expression, then the theorem can be proved. 35

Summary of Conversions Finite Automata NFA DFA RE 36