210 likes | 424 Views
. aaba. acba. aaba. M. G. Reminder. What is it about?. Models of Language Recognition. Models of Language Generation. Machine Models: Automata, that recognize (understand) the languages. a. b. b. b. a. b. a. b. a. a. Deterministic Turing Machines.
E N D
. . . . aaba acba aaba M G Reminder What is it about? Models of Language Recognition Models of Language Generation
Machine Models: Automata, that recognize (understand) the languages
a b b b a b a b a a Deterministic Turing Machines The Turing machine (TM) is a computational model which has a tape of infinite length divided into cells and a finite control unit with a two-way read/write head. In a move (i.e, a computational step) the TM, depending upon the symbol scanned by the head and current state of the control, does the following: (1) Writes a symbol on the tape cell under the head, replacing what was written, (2) changes the state of its control, and (3) moves the head to the left, right or does not move. Read/write tape q0 Two-way read/write head Finite State Control
Deterministic Turing Machines Formally a TM is defined as a 6-tuple M = ( Q, , , , q0 , F ), where • Q is the finite set of states, • is the set of tape symbols (alphabet) including the blank symbol, usually denoted by B (a square box in the text), • is the set of input symbols, which is a subset of , • q0 is the start state, • F is the set of accepting states (FQ ), and • is the transition function which maps QQ {L, N, R},
Deterministic Turing Machines where L, N, and R denote a move to the left, no move, and a move to the right, respectively. The transition function may be undefined for some arguments. In this case we assume that the machine halts. It is assumed that initially an input string x* is written on the tape and the machine is reading the leftmost symbol in the start state q0. Definition : We say a string x is accepted by a TM M if M, given x on the tape, enters an accepting state after some finite number of moves. Definition : The language recognized (or accepted) by a TM M, denoted by L(M), is the set of strings accepted by the machine, i.e., L(M) = { x | M accepts x}.
0 0 0 1 1 1 q0 Example : An idea : Traveling back and forth replace "1" by Y for each "0" replaced by X. The transition function is defined as follows. Construct a deterministic Turing Machine which accepts {0n1n | n 1}.
q1 q2 q3 X X X X X X X X X X X 0 0 0 X X X X 0 0 X 0 0 0 X X 0 Y Y Y Y Y 1 Y Y Y Y 1 1 1 1 Y Y Y Y 1 1 1 1 Y 1 Y 1 1 q1 q2 q3 q1 q2 Transition Fuction (q0, 0) = (q1, X, R) In q0, reading 0, change it to X, (q1, 0) = (q1, 0, R)move to the right searching1 in q1. • (q1, 1) = (q2, Y, L)Reading 1, replace it by Y, and • (q2, 0) = (q2, 0, L) move to the leftin q2searchingX. (q2, X) = (q3, X, R)Reading X, back up in q3 , and (q3, 0) = (q1, X, R)reading 0 repalce it by X. (q1, Y) = (q1, Y, R)In q1, move over Y to the right. (q2, Y) = (q2, Y, L)In q2, move over Y to the left. (q3, Y) = (q4, Y, R) Reading Y, instead of 0, enter q4, (q4, Y) = (q4, Y, R)and move over Y to the right, till (q4, B) = (q5, B, N)there appears blank, and accept in q5. q4 q5
Transition Graph (0,0,L) (Y,Y,L) (0,0,R) (Y,Y,R) Now, the machine is formally defined as follows: M = ( Q, , , , q0 , F ), where Q = {q0, q1, q2, q3, q4, q5}, = {0, 1}, = {0, 1, X, Y, B}, F = {q5}, and is given in terms of one of the above forms, i.e, state transition function, state transition table or state transition graph. (Y,Y,R) q2 (1,Y,L) q1 (X,X,R) (0,X,R) q4 (0,X,R) (B,B,N) q0 (Y,Y,R) start q3 q5
[ a b a a b ] q0 Two-way read/write Restricted Turing Machines (cont’ed) (1) Deterministic linear bounded automata (DLBA): The head cannot cross the left and right boundary markers ([ and ]), i.e., the computation must be done within the range of the input string. Other operations are the same as in the standard TM. Formally a DLBA is defined as a tuple M = (Q, , , , q0, [, ], F), where, excepts for the boundary markers `[' and `]', all the elements of the tuple are defined the same way as for the Turing machines.
a b b a a b q0 One-way read only Stack Z0 Restricted Turing Machines (cont’ed) (2) Deterministic pushdown automata (DPDA): M = ( Q, , , , q0 , Z0, F ) : Q ( { } ) Q *
Restricted Turing Machines (cont’ed) Formally a DPDA is a tuple M = ( Q, , , , q0 , Z0, F ), where Q, , , , q0 , Z0 and F are the set of states, the input alphabet, the stack alphabet, the start state, the bottom of stack symbol and the set of accepting states, respectively. The transition function is a mapping : Q ( { } ) Q * For example ( q, a, Z ) = ( p, ), where q, p Q, a , Z , and is a string of stack symbols written on top of the stack replacing Z. Conventionally, we assume that either • || = 0, i.e., = , means the machine pops the stack top symbol, • || = 1, i.e., rewrites the stack top symbol, or • || = 2, i.e., pushes a symbol on top of the stack.
…… …… … … a b c a b c …… … a b c q r p …… X Y …… X …… Z Restricted Turing Machines (cont’ed) Example: Two transitions ( p, a, Z ) = ( q,YX ) and ( q, b, Y ) = ( r, ) in sequence implies the following.
(input symbol, current stack top/stack top changed) a a a b b b q0 One-way read only (a, a/aa) (, Z0/Z0) Stack (b, a/) Z0 (b, a/) (a, Z0/aZ0) start Examples (a) Construct a DPDA which recognizes {aibi | i > 0 }
(a, Z0/aZ0) (b, a/) (a, a/aa) (a, a/aa) (, Z0/Z0) (b, a/) (b, a/) (a, Z0/Z0) start (b, a/) (a, Z0/aZ0) start Examples (cont’ed) (b) Construct a DPDA which recognizes {aibj | i > j > 0 }
(a, a/aa) (a, Z0/aZ0) (b, Z0/Z0) (b, a/) (b, a/) (a, a/aa) (b, Z0/Z0) (b, a/) (a, Z0/aZ0) (b, a/) (a, Z0/Z0) start start Examples (cont’ed) (c) Construct a DPDA which recognizes {aibj | j > i > 0 }
(, b/) (c, a/) (, a/) (c, b/) (a, a/aa) (, Z0/ Z0) (b, a/ba) (d, b/) (b, b/bb) (a, Z0/aZ0) (, a/a) start (d, b/) Examples (cont’ed) (d) Construct a DPDA which recognizes {aibkci | k, i > 0 } {aibkdk | k, i > 0 } Notice that this machine needs -move, i.e., takes a step without reading the input.
Restricted Turing Machines (cont’ed) The input head should move to the right when it reads the input. The in a transition (q, , Z ) = ( p, ) means the machine does not read the input. We call such transition -move. The input head does not move when it does not read. An important restriction is that a DPDA cannot have both transitions (q, a, Z ) and (q, ,Z)defined. Otherwise, it is a nondeterministic PDA, which will be discussed later. The language accepted by a DPDA M is defined as L(M)={x | M enters an accepting state some time after reading the last symbol of the input x}. Notice that, for an input string x to be accepted, the PDA shouldenter an accepting state and the whole string must be read.
a b a b a b a b ] [ Two-way read only One-way read only q0 q0 Two-way DFA One-way DFA Restricted Turing Machines (cont’ed) (3) Deterministic finite state automata (DFA): A DFA is defined as a tuple M = ( Q, , , , q0 , F ). One-way DFA is a DFA whose head is not allowed to move to the left. The language accepted by a DFA M is defined as L(M) = {x|M enters an accepting state after reading the last symbol of input x}. It is proven that one-way FA's and two-way FA's are equivalent in the sense that they can accept the same languages.
0 1 0 0 1 2 0 1 0 start 1 1 Example Construct a DFA which recognizes the following language; {x | x is a binary number, i.e., x {0, 1}+, which is divisible by 3 } State id indicates current remainder.