Discrete Math II Howon Kim 2019 11 Agenda

  • Slides: 37
Download presentation
Discrete Math II Howon Kim 2019. 11

Discrete Math II Howon Kim 2019. 11

Agenda n 1 Automata Theory n 2 Regular Expression & Regular Languages n 3

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

Language Types by Chomsky Arbitrary, Natural Language Recursively Enumerable Language TM None Context-sensitive Language

Language Types by Chomsky Arbitrary, Natural Language Recursively Enumerable Language TM None Context-sensitive Language Regular Language FA (NFA, DFA) Context-free Language LBA- (linearbounded automata) PDA(Pushdown Automata) 3

Language Types by Chomsky 4

Language Types by Chomsky 4

Overview Set Theory of Strings (Chapter 6. 1) Regular Expressions & Regular Languages Finite

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 5

Context Free Grammar (CFG) Def. 문맥무관(context-free) 문법 G = ( V, , S, P

Context Free Grammar (CFG) Def. 문맥무관(context-free) 문법 G = ( V, , S, P ) Where all production rules have the form A x, A V and x (V )*. V : a finite set of variables nonterminals라고도 함 : an alphabet terminal이라고도 함(we make strings that will be the words of language) S : a start variable, S V P : a set of production rules cf. ) Regular Grammar G = ( V, , S, P ) where all the production rules have the form A w. B or A w, A, B V and w *. 6

Examples (Ex. ) G = ( {S}, {a, b}, S, P ) P :

Examples (Ex. ) G = ( {S}, {a, b}, S, P ) P : S a. S S b. S Used in statement of productions S a S b more compact notation, P: S a. S | b. S | a | b It can produce the word abbab as follows: Used in derivation of word S⇒ ⇒ ⇒ a. S abbab 7

Examples (Ex. ) G = ( {S}, {0, 1}, S, P ) P :

Examples (Ex. ) G = ( {S}, {0, 1}, S, P ) P : S 0 S 1 | . L(G) = { 0 n 1 n | n 0 } (Ex. ) G = ( {S, A}, {a, b, c}, S, P ) P : S a. Sc | A A b. Ac | L(G) = { ambnck | m + n = k, k 0 } 8

Examples (Ex. ) G = ( {S, X, Y}, {a, b}, S, P )

Examples (Ex. ) G = ( {S, X, Y}, {a, b}, S, P ) P: S X|Y The only word we can generate is X Y a. Y | b. Y | a | b It produces (a+b)+ So, CFL(context free language) is (a+b)* (Ex. ) G = ( {S}, {a, b}, S, P ) P : S a. S | b. S | a | b | CFL is (a+b)* The sequence of productions to generate any word is not unique It can generate bab using S ⇒ b. S ⇒bab 9

Examples – derivation tree (Ex. ) G = ( {S, A}, {a, b}, S,

Examples – derivation tree (Ex. ) G = ( {S, A}, {a, b}, S, P ) P : S AAA | A A AA | a. A | Ab | a | b S ⇒ AAA ⇒ab. Ab. A a ⇒aba. Ab. A ⇒abaaba S A A A b b a A a Derivation tree a In a derivation tree, the root is the start variable, all internal nodes are labeled with variables, while all leaves are labeled with terminals. The children of an internal node are labeled from left to right with the right-had side of the production used. 10

Pushdown Automata (PDA) Recall that DFAs accept regular languages. We want to design machines

Pushdown Automata (PDA) Recall that DFAs accept regular languages. We want to design machines similar to DFAs that will accept context-free languages. These machines will need to be more powerful. To handle a language like {anbn | n 0}, the machine needs to “remember” the number of as. To do this, we use a stack. A push-down automaton (PDA) is essentially an NFA with a stack.

Pushdown Automata (PDA) Def. of Pushdown (Stack) Automata M = ( Q, , q

Pushdown Automata (PDA) Def. of Pushdown (Stack) Automata M = ( Q, , q 0, F ) Q : a finite set of states : a finite alphabet of tape symbols : a finite alphabet of stack symbols (start symbol = #) : a subset of the transition relation ( Q ( { }) ) to subset Q ( { }) q 0 : a start (initial) state, q 0 Q F : a set of final states, F Q (cf. ) FA M = (Q, ∑, or , q 0, F) 12

Pushdown Automata - transition stack symbol : a subset of the transition relation (

Pushdown Automata - transition stack symbol : a subset of the transition relation ( Q ( { }) ) to subset Q ( { }) Let ((p, a, β), (q, )) Δ be a transition. It means that we Move from state p. Read a from the tape, Pop the string β from the stack, Move to state q, Push string onto the stack. The first three (p, a, β), are “input. ” The last two (q, ) are “output. ” p a, ; q 13

Pushdown Automata – pushing/poping When we push β, we push the symbols of β

Pushdown Automata – pushing/poping When we push β, we push the symbols of β as we read them right to left. When we push the string abc, we push c, then push b, then push a. When we pop , we pop the symbols of as we read them from left to right (reverse order). a b c stack When we pop the string abc, we pop a, then pop b, then pop c. 14

Pushdown Automata – pushing/poping Thus, if we push the string abc and then pop

Pushdown Automata – pushing/poping Thus, if we push the string abc and then pop it, we will get back abc, not cba. If we wanted to reverse the order, we would use three separate transitions: Push a Push b Push c 15

Pushdown Automata – configurations A configuration fully describes the current “state” of the PDA.

Pushdown Automata – configurations A configuration fully describes the current “state” of the PDA. The current state p. The remaining input w. The current stack contents . Thus, a configuration is a triple (p, w, ) (Q, *). 16

Pushdown Automata – computations stack (p, w, ) (Q, *). 17

Pushdown Automata – computations stack (p, w, ) (Q, *). 17

Pushdown Automata – accepting strings There are several equivalent ways of defining acceptance by

Pushdown Automata – accepting strings There are several equivalent ways of defining acceptance by a PDA. One may define acceptance “by final state” only. The input is accepted if and only if the last state is a final state, regardless of whether the stack is empty. One may define acceptance “by empty stack” only. The input is accepted if and only if the stack is empty once the input is processed, regardless of which state the PDA is in. One may define acceptance “ by final state and empty stack ” 19

FA vs. PDA 1 0 1 1 0 FA controller No memory Read-only head

FA vs. PDA 1 0 1 1 0 FA controller No memory Read-only head moves to the right (current state, tape symbol) (next state) Initially at the start state & at the leftmost position 1 0 1 1 0 PDA controller B A # Same structure except the stack (current state, tape symbol, stack symbol) (next state, stack string) Initially (start state, input string w, #) Accept w when the state of PDA after reading w is a final state (Ex) push 1 : ( (p, 0, 0), (q, 10) ) pop 0 : ( (p, 0, 0), (q, ) ) 20

An Example of PDA Find L(M) for the following PDA. M = ( {S,

An Example of PDA Find L(M) for the following PDA. M = ( {S, A, B}, {0, 1}, ={0, #}, , S, {B} ) 스택으로부터 0을 읽기만 하고 쓰지는 않음 : ( (S, 0, #), (S, 0#) ) ; push 0 ( (S, 0, 0), (S, 00) ) ; push 0 ( (S, , #), (B, #) ) ( (S, 1, 0), (A, ) ) ; pop 0 ( (A, , #), (B, #) ) S B Input symbol 0 0 1 1 S A B # 0 0 # A 0 # output to stack Input from stack (push symbol) (pop symbol) 스택이 바닥남 # L(M) = { 0 n 1 n : n 0 } 21

Context-Sensitive Language Def. of Context-sensitive Grammar G = ( V, , S, P )

Context-Sensitive Language Def. of Context-sensitive Grammar G = ( V, , S, P ) Each production rule x y satisfies || x || y || , where x (V )* V (V )* and y (V )*. (Note) Each production rule can be converted into u A v u w v. A is sensitive to u and v. Def) 문맥무관(context-free) 문법 G = ( V, , S, P ) Where all production rules have the form A x, A V and x (V )*. 22

Context-Sensitive Language The reason why we call these grammars contextsensitive is that we can

Context-Sensitive Language The reason why we call these grammars contextsensitive is that we can rewrite the productions of any context-sensitive grammar to be in this form: x. Ay xvy where x, y, and v are strings of any combination of variables and terminals, v is nonnull, and A is a single variable A goes to v in the context of x on the left and y on the right cf. in a context-free grammar, the productions all have a single variable on the left, such as: A aa 23

Context-Sensitive Language However, in a context-sensitive grammar, we might have two rules such as:

Context-Sensitive Language However, in a context-sensitive grammar, we might have two rules such as: a. Aa aba b. Ab bbabb which say that we can replace A with a single b when it is in the middle of two a’s, but we replace it with bab when it is in the middle of two b’s. 24

Context-Sensitive Language Clearly, context-sensitive rules give a grammar more power. A context-sensitive grammar can

Context-Sensitive Language Clearly, context-sensitive rules give a grammar more power. A context-sensitive grammar can use the surrounding characters to decide to do different things with a variable, instead of always having to do the same thing every time. All productions in context-sensitive grammars are non-decreasing or non-contracting; that is, they never result in the length of the intermediate string being reduced. Def. of Context-sensitive Grammar G = ( V, , S, P ) Each production rule x y satisfies || x || y || 25

Linear bounded automaton A Turing machine that has the length of its tape limited

Linear bounded automaton A Turing machine that has the length of its tape limited to the length of the input string is called a linear-bounded automaton (LBA). 26

Turing Machine (TM) It consist of tapes and a controller The read/writable tape-head can

Turing Machine (TM) It consist of tapes and a controller The read/writable tape-head can move to the left and the right # 1 0 1 1 0 FA controller TM controller 1 0 1 1 0 PDA controller B A # 27

Turing Machine Def. Turing Machine M = ( Q, , q 0, H )

Turing Machine Def. Turing Machine M = ( Q, , q 0, H ) Q : a finite set of states : an input alphabet : a tape alphabet (#: blank symbol) : a function (Q-H) Q {L, R, S} q 0 : a start state, q 0 Q Moving tape head to Left, Right, Staying H : a set of halt states, H Q 28

TM Operation 1. TM is a DFA because the is a transition function. 2.

TM Operation 1. TM is a DFA because the is a transition function. 2. L and R in def. of means moving the tape-head to the left and the right, respectively. S means staying the tape -head. 3. TM can operate after reading all the input symbols, while a DFA and a PDA should stop. Thus, a set of halt states should be defined in TM. 4. We assume that the tape-head cannot move to the left at leftmost position of the tape. 29

TM Configuration TM 상황(configuration) ( q, u a v ) q : current state

TM Configuration TM 상황(configuration) ( q, u a v ) q : current state a : symbol at position of tape-head u : left string of a in tape v : right string of a in tape Thus, it is determined by the current state q, contents of the tape, and position of the tapehead. Start configuration : ( q 0, #w ) w : input string 30

An Example Find a TM that defines L={ 0 n 1 n | n

An Example Find a TM that defines L={ 0 n 1 n | n 1}. # 0 0 0 1 1 1 # ; move R until finding a 0 # a 0 0 1 1 1 # ; replace 0 with a & move R to first 1 # a 0 0 b 1 1 # ; replace 1 with b & move L until finding the leftmost 0 #aa 0 b 11# #aa 0 bb 1# #aaabb 1# # a a a b b b # ; no 0 & no 1 halt 즉, 결국 동일한 개수의 0… 0과 1… 1을 읽음 31

M= ({q 0, …, q 5}, {0, 1, a, b, #}, , q 0,

M= ({q 0, …, q 5}, {0, 1, a, b, #}, , q 0, {q 5}) continue Tape alphabet 0 1 state q 0 (q 1, a, R) q 1 (q 1, 0, R) q 2 (q 2, 0, L) a # (q 3, b, R) (q 0, #, R) (q 2, b, L) (q 1, b, R) (q 0, a, R) q 3 q 4 b (q 2, b, L) (q 3, b, R) (q 5, #, S) (q, x)=(q 4, x, S) # 0 0 0 1 1 1 # ; move R until finding a 0 # a 0 0 1 1 1 # ; replace 0 with a & move R to first 1 # a 0 0 b 1 1 # ; replace 1 with b & move L until finding the leftmost 0 #aa 0 b 11# #aa 0 bb 1# #aaabb 1# # a a a b b b # ; no 0 & no 1 halt Def. Turing Machine : M = ( Q, , q 0, H ) Q : a finite set of states : an input alphabet : a tape alphabet (#: blank symbol) : a function (Q-H) Q {L, R, S} q 0 : a start state, q 0 Q H : a set of halt states, H Q 32

An Example # 0 0 0 1 1 1 # ; move R until

An Example # 0 0 0 1 1 1 # ; move R until finding a 0 # a 0 0 1 1 1 # ; replace 0 with a & Head input (1) # : (q 0, #, R); q 0상태에서 # read, 다음상태는 q 0이며, tape head 내용은 #로 대체후(write), Right 이동 move R to first 1 (2) 0: (q 1, a, R): head가 0 read. 다음상태는 q 1이며, 0 a, R이동 # a 0 0 b 1 1 # ; replace 1 with b & move L until finding the leftmost 0 (3) 0: (q 1, 0, R): head가 0 read, 다음상태는 q 1, 0 0, R 이동 #aa 0 b 11# (4) 0: (q 1, 0, R): head가 0 read, 다음상태는 q 1, 0 0, R #aa 0 bb 1# 이동 #aaabb 1# (5) 1: (q 2, b, L): # a a a b b b # ; no 0 & no 1 halt (6) 0: (q 2, 0. L): (7) 0: (q 2, 0, L): (8) a: (q 0, a, R): (9) 0: (q 1, a, R): (10)0: (q 1, 0, R): (11)b: (q 1, b, R): (12)1: (q 2, b, L): 33

# / #, R q 0 0 / a, R b / b, R

# / #, R q 0 0 / a, R b / b, R q 3 b / b, R 0 / 0, R b / b, R 0 / 0, L b / b, L q 1 q 2 1 / b, L a / a, R # / #, S q 5 q 4 q 0 q 1 q 2 q 2 q 0 q 3 q 5 #000111# # 0 0 0 1 1 1 continue # #a 00111# #a 00 b 11# #aa 0 bb 1# #aaabbb# #aaabbb# x / x, S 34

Recursively Enumerable Lang. Def. TM M = ( Q, , q 0, H )

Recursively Enumerable Lang. Def. TM M = ( Q, , q 0, H ) L(M) = { w * | (q 0, #w) ┣*M (h, *) }, h H Thus, L(M) is the set of all the strings that halt the TM. Recursively Enumerable Language L There exists a TM M such that L = L(M). That is, Turing recognizable ! 35

Non-deterministic TM Def. Non-deterministic TM N = ( Q, , q 0, H )

Non-deterministic TM Def. Non-deterministic TM N = ( Q, , q 0, H ) turing machine: a set of rules Q : a finite set of states Non-deterministic that prescribes more than one action for a given situation ! : an input alphabet : a tape alphabet (#: blank) : a subset of ( (Q-H) ) ( Q {L, R, S} ) q 0 : a start state, q 0 Q H : a set of halt states, H Q (cf. ) : a function (Q-H) Q {L, R, S} Deterministic turing machine: one action to be performed for any given situation 36

Language of N-TM Def. N-TM N = ( Q, , q 0, H )

Language of N-TM Def. N-TM N = ( Q, , q 0, H ) L(N) = { w * | (q 0, #w) ┣*N (h, *) }, h H Because the N-TM is non-deterministic, L(N) is the set of all the strings that have at least one transition path to the H. Theorem A TM M can simulate a N-TM N. 37