280 likes | 300 Views
Discrete Math II. Howon Kim 2018.10. 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.
E N D
Discrete Math II Howon Kim 2018.10
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 State Machine Reset Coin Coffee Coffee Maker Coin Checker Change Maker Reject • Finite State Machines (FSM) • It consists of a finite number of internal states and transitions among them. • It remembers certain information when it is in a particular state.
DFA(Deterministic Finite Automata) • Definition A deterministic finite automata(DFA) M is specified by a quintuple M = (Q, ∑, , q0, F) where • Qis an alphabet of statesymbols ; • ∑is an alphabet of inputsymbols ; • : Qx ∑Qis a transition function ; • q0Q is the start state; and • FQ is a set of final states. Deterministic : there is one and only one transition to a next state !
Machine-oriented Viewpoint 1 0 1 1 0 Finite Control • Let M = (Q, ∑, , q0, F) be a DFA. We view it as a machine (a primitive computer) • It has an input tape of cells, a read-only head, and a finite control Input tape No memory Read-only head Move the head to the right Initially at the start state & at the leftmost position (current state, tape symbol) (next state) Reading head M = (Q, ∑, , q0, F)
DFA Example a start a a 0 1 2 accept • M = (Q, ∑, , q0, F) Q = { 0, 1, 2 } , ∑ = { a } : Q x∑ Q • (0,a) = 1, (1,a) = 2, (2,a) = 0 q0 = 0 , F = { 2 } • State Diagram
DFA Configuration a p q • Definition Let M = (Q, ∑, , S, F)be a DFA. We say that a word in Q∑*is a configuration of M. It presents the current state of M and the remaining unread input of M. • That is, configuration : what state the DFA is currently in, and what ‘input’ is left to process ! • Definition Let px and qy are two configurations of a DFA M. We write px┣ qy,if x = ay for some a ∑and (p,a) = q. 혹은 (p,x) ┣ (q,y)로 표현 가능:“configuration (p,x) yields configuration (q,y)” y x
Configuration Sequence • Definition For k 1, we write px┣kqy (k-steps of M on px), if 1) k = 1 and px┣ qy or 2) k > 1 and there exists a configuration rz such that px┣ rz and rz┣k-1qy. k-1 transitions p r q … x z y
Configuration Sequence 0 0 1 q0 q1 1 • ┣ : a binary relation on Q∑* • ┣+: transitive closure of┣ (px┣+ qy) • ┣*: reflexive, transitive closure of┣ (px┣*qy) • We say that the sequence of configuration given by px┣* qy is a configuration sequence. Final state은 결국 q0로 감 q0 1010 ┣q1 010 q0 1010 ┣+q1 10 q0 1010 ┣*q0 q0┣*q0 q1에서 one or more move q0에서 zero or more move • ┣* : zero or more moves • ┣+ : one or more moves • reflexive : for all x in X it holds that xRx. (예: “=“) • transitive : for all x, y and z in X it holds that if xRy and yRz then xRz.
Accepted Language • Definition Let M = (Q, ∑, , S, F)be a DFA. We say that a string xin ∑*is accepted by M, if Sx┣* f , for some f in F. We say that Sx┣* f is an accepting configuration sequence. The set of words accepted by M, called the language accepted, defined, or recognized by M is denoted by L(M) and is defined as L(M) = {x|x∑* and Sx┣* f, for some f in F }. Sx yields f
DFA Language That is, deterministic finite automata (DFA) is also known as a deterministic finite acceptor (DFA) ! • DFA Language The notion of acceptance has caused a DFA to stand for deterministic finite acceptor (결정적 유한 인식기). We say that L ∑* is a DFA language if there is a DFA M, with L = L(M). • Equivalence of DFAs Let M1 and M2 be two DFAs. If L(M1) = L(M2), we say that M1, M2 are equivalent.
State Diagram 0 0 1 q0 q1 1 • State Diagram of M = (Q, ∑, , q0, F) state symbols in Q; vertices (원) input symbols in ∑ ; labels : Qx ∑Q: edges with labels (화살표) q0Q: start로 명시된 vertex (구별되는 화살표) FQ : 이중 원 What is theL(M) ? 1이 짝수개인 스트링의 집합
How to construct DFAs • DFA는 다음 두 단계로 만든다 1. 현재 까지 읽은 부분에서 어떤 정보를 기억해야 하는지를 정하고 이 정보를 state로 표시한다. 2. 새로운 input symbol을 읽었을 때 기억해야 하는 정보가 어떻게 바뀌는지를 보고 transition function을 만든다. • 주의할 점 • 중요한 것은 기억해야 하는 정보를 정하는 것이다. • 만들고자 하는 DFA의 기능을 분석하여기억해야 하는 정보를 정리하고 state로 매핑한다.
Example (1) 0 0 1 q0 q1 1 • 1이 짝수개인 string을 accept하는 DFA를 구하라. • 현재까지 읽은 substring에서 1의 개수에 대한 짝수 또는 홀수 여부를 상태로 기억해야 함.
Example (2) 0 0,1 1 0 0 1 0 1 E C D A B accept start 1 • 0101을 substring으로 가지는 string을 accept 하는 DFA를 구하라. • 0101의 prefix중에서 현재까지 read한 부분을 기억해야 함. • 따라서, 0101의 prefix에 해당하는 state를 만들면 됨. Final state
Example (3) 0 0,1 1 0 0 1 0 1 E C D A B start 1 • 0101을 substring으로 갖지 않는string을 accept하는 DFA를 구하라. • 앞 예제에서의 final state와 그 외의 상태를 맞바꾸면 됨. Dead State 한번 들어가면 빠져 나오지 못하는 상태(it is not an accepting state and has no out-going transitions except to itself)
Another Example of Dead States 0 0 1 0 S0 S1 S2 S3 0 1 1 1 SD 0,1 • (010+01)* string을 accept하는 DFA?
Agenda • 1 Automata Theory • 2 Regular Expression & Regular Languages • 3 Finite Automata • DFA(Deterministic Finite Automata) • FA Applications (Logic Design) • 4 Non-deterministic Finite Automata • 5 Grammars & Languages • 6 Theory of Computations
A Modified FA for Logic Design • Def. Modified FA M = ( Q, , , , ) Q : a set of finite states : an input alphabet : an output alphabet : next state function Q Q : an output functionQ (note) DFAM = ( Q ,∑ , , q0 ,F )
An Example of the M-FA S0 S1 S2 S3 S4 S0 S1 S2 S3 SD • (010+01)+string을 accept하는 DFA? M-FA Original DFA input output M = ( {S0,…,S4}, {0,1}, {0,1}, , ) M = ( Q, , , , )
continue (next state fn) (output fn.) 0 1 0 1 S0 S1 S2 S3 S0 S1S4 0 0 S1 S4S2 0 1 S2 S3S4 1 0 S4 S3 S1S2 0 1 S4 S4S4 0 0 • (010+01)+string을 accept하는 DFA? M = ( {S0,…,S4}, {0,1}, {0,1}, , ) State (Transition) Table M = ( Q, , , , )
continue C.S. I N.S. O A B C X A B C Y Q Q+ J K 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 x S0 S1S4 0 0 0 0 0 1 1 0 0 0 0 1 1 x 0 0 1 0 1 0 0 0 1 0 x 1 S1 S4S2 0 1 0 0 1 1 0 1 0 1 1 1 x 0 S2 S3S4 1 0 0 1 0 0 0 1 1 1 S3 S1S2 0 1 0 1 0 1 1 0 0 0 Q Q+ D S4 S4S4 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 1 1 0 1 0 1 0 1 1 1 0 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 0 1 1 1 • State Assignment & F/F Excitation Table no chg set reset no chg J=K=1: toggle
continue CX C.S. I N.S. O AB 1 1 1 A B C X A B C Y 1 1 1 0 0 0 0 0 0 1 0 x x x x x x x x 0 0 0 1 1 0 0 0 1 1 x x x x 0 0 1 0 1 0 0 0 0 0 1 1 0 1 0 1 DB = CX+BC’X’ 0 1 0 0 0 1 1 1 0 1 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 0 1 1 1 1 0 1 1 1 0 1 0 1 x x x x x x x x 1 0 0 0 1 0 0 0 x x x x 1 0 0 1 1 0 0 0 DC = A’C’X’+B’CX’ O = DB • Input Equations DA = A+C’X+B’CX’
continue CP AA’ BB’ CC’ XX’ DA = A+C’X+B’CX’ DB = CX+BC’X’ DC = A’C’X’+B’CX’ O = DB
continue CP AA’ BB’ CC’ XX’ 1 0 1 0 0 1 FA Controller
Another Example S0 S1 S2 S3 S4 S5 • (0+1)*01001을 accept하는 DFA?
Another Example S0 S1 S2 S3 S4 S5 S6 • (0+1)*011101을 accept하는 DFA?