1 / 37

Discrete Math II

This course covers topics such as automata theory, regular expressions, finite automata, deterministic and non-deterministic finite automata, grammars and languages, and the theory of computations.

angelaberg
Download Presentation

Discrete Math II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Discrete Math II Howon Kim 2018.11

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

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

  4. Finite Automata 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 leastONEpath from the start state to an accepting state whose edge labels spell out the string. 4

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

  6. Examples ( DFA and NFA ) This is non-deterministic accepter since there are two transitions labeled a out of q0 a a q1 q2 q3 a q0 a a q4 q5 a This is non-deterministic since.. • Several edges with the same label originate from one vertex • it has  transition • some transition, such as (q2,0) isunspecified 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 0,1 q1 q2 q0 1  6

  7. 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 oftransition relation Qx(∑{})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

  8. Reference Example) All subsets of {x,y,z} 3: {x,y,z} 2: {x,y}, {y,z}, {x,z} 1: {x}, {y}, {z} 0:   So, number of subsets is 23 • 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 8

  9. 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 A B C 입력없이 {C}에서 {A}로 천이됨 {A} ; start state {B} 0 {C}  {A}1 {A}  {B} 0 {B} 0 {C}  {A}1 9

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

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

  12. 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 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 (*,*) =  12

  13. 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 {A, C} 1 13

  14. 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 statesthat can be reachable from qwithout reading any input symbol (through ) Es(P) : qP E(q) 상태 set에 대한 transition 정의 ! 14

  15. 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} A B C 상태 set에 대한 transition을 기술하기 위해 s를 정의함  입력에 의한 transited state  입력에 의한 transited state sets 15

  16. Extension of  Def. * : Qx* 2Q (i) *(q,) = E(q) (ii) *(q,wa) = Es(s(*(q,w),a)), w  *, a  . Def. 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 16

  17. 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 B 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 {C}  {A}1 17

  18. 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} 18

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

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

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

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

  23. 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” 23

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

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

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

  27. Example : From NFA to DFA [2] 27

  28. Example : From NFA to DFA [3] 28

  29. 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] 29

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

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

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

  33. 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 S0 S1 S2 S3 SD A B C NFA DFA 33

  34. Another Example  = {0,1}상의 정규식 (01+101)*0 으로 표현되는 언어를 accept하는 NFA ? A D B C S0 S2 S3 SD S1 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 34

  35. Proof of L(MNFA) = L(MDFA) 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) . • Definition:* : Qx* 2Q (i) *(q,) = E(q) (ii) *(q,wa) = Es(s(*(q,w),a)), w  *, a  . (ii) *(q,wa) = Es(s(*(q,w),a)) 정의에의해… 위의 |w|<k일때 성립한다고 가정함 w=xa 35

  36. Regular Expression  NFA Theorem 2 There existsa 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. 36

  37. Summary of Conversions NFA DFA Finite Automata RE 37

More Related