ICS-252 Discrete Structure II

  ICS-252 Discrete Structure II Lecture 11

  Assistant Professor, Department of Computer Science & Engineering, University of Hail, KSA.

  Email: [email protected] Email: [email protected]

  ICS ‐252       Dr. Salah Omer, Assistant  Professor,  CSSE, University  of  Hail. 

Outlines

  • Introduction to Turing Machine • Using Turing machines to recognize sets • Using Turing machines to recognize sets

  (DMA 827-831)

  • Computing functions with Turing

  Machines

  • Types of Turing Machines (DMA 831-837) yp g ( )

  ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

Turing Machine

  DFA:

  1) The DFA cannot be used as general models of computation. 2) It does not have any memory 2) It does not have any memory 3) Can not compute functions such as the sum or product of two numbers.

  Turing Machine: In 1930s Alan Turing invented a machine

  called Turing machine. It consists of 1) A control unit, which is in one of finitely many different 1) A control unit which is in one of finitely many different states, together with a tape divided into cells, which is infinite in both directions. ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  3 Turing Machine

  2) Turing machine has read and write capabilities on the tape as control unit moves back and forth along the tape.

  Changing states depending on the tape symbol read. 3) Turing machine has memory and therefore are more powerful than DFA.

  4) Turing machine also can compute functions such as sum or product of two numbers. 5) Turing machine is most general model of computation, It can do whatever computer can do. 6) Turing machine are more powerful than computers because computers have finite memory capabilities. ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

Turing Machine An artistic representation of a Turing machine

  ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  5 Turing Machine Definition: A Turing machine T= (S, I, f, s ) consists of a

  finite set S of states, an alphabet I containing the blank symbol B, a partial function f from S x I to S x I x {R, L},

  Example 1: What is the final tape when the Turing machine T

  defined by the seven five-tuples (s , 0, s , 0, R), (s , 1, s ,

  1

  1, R), (s , B, s , B, R), (s , 0, s , 0, R), (s , 1, s , 0, L), (s ,

  3

  1

  1

  2

  1 B, s , B, R), (s , 1, s , 0, R) is run on the tape shown in

  3

  2

  3 figure 2 (a) (see at page DMA-829).

  Solution: See at page DMA-829. Answer: ( 010000), Finally,

  in the seventh step the machine halts because there is no five-tuple beginning with the pair (s , 0) in the given

  3 description of the machine. ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

Using Turing Machines to recognize Sets

  Definition: Let V be a subset of an alphabet I, A Turing

  machine T= (S, I, f, s ) recognizes a string x in V* if and only if T, starting in the initial position when x is written on the tape, halts in a final state. T is said to recognize a subset A of V* if x recognized by T if and only if x belongs subset A of V if x recognized by T if and only if x belongs to A.

  Example 2: Find a Turing machine that recognizes the set of

  bit strings that have a 1 as their second bit, that is, the regular set (0 U 1)1(0 U 1)* Solution: We want a Turing machine that, starting at the leftmost nonblank tape cell, moves right, and determines whether the second symbol is a 1. If the second symbol is 1, the machine should move into a final state. If the second symbol is not a 1, the machine should not halt or halt in a nonfinal state. ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  7 Using Turing Machines to recognize Sets

  To construct such machine we include the following tuples (s , 0, s , 0, R) and (s , 1, s , 1, R)

  1

  1 state s state s .

  1

  1

  (s , 0, s , 0, R) and (s , 1, s , 1, R)

  1

  2

  1

  3 nd

  To read the 2 symbol If the symbol is 1 then move to the s ,which is final state.

  3 If the symbol is 0 then move to the state s . So it is not final

  2

  state, To solve this we include (s , 0, s , 0, R)

  2

  

2

Because we do not want to recognize the empty string or

  string with one bit, therefore we included (s , B, s , 0, R)

  2 and (s , B, s , 0, R).

  1

  2

Computing Functions withTuring Machines

  The Turing machine T consisting of the 7 tuples listed above will terminate in the final state s m if and only if the bit

  3

  string has at least two bits and the second bit of the input string is 1. if the bit string contains fewer than two bits or if string is 1. if the bit string contains fewer than two bits or if

  nd

  the 2 bit is not 1, then the machine will terminate in the nofinal state s

  Turing machine as a computer of functions from the set of K-tuples of non-negative integers to the set of non-negative integers (such functions are called number theoretic integers (such functions are called number-theoretic functions), but we need a way to represent k-tuples of integers on a tape. For this we use unary representations of integers. We represent the no-negative integer n by a string of n+1 1s , so that for example 0 is represented by the ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  string 1 and 9 Computing Functions withTuring Machines 5 is represented by the string 111111. To represent the k-tuple

  (n , n , n ,……… n ) , we use a string of n + 1 1s, followed

  1

  2 3 k

  1

  by an asterisk, followed by a string of n +1 1s, followed by an asterisk and so on, ending with a string of n an asterisk and so on, ending with a string of n +1 1s. For 1 1s. For

  k k

  example, to represent the four-tuple (2,0,1,3), we use the string 111 * 1 * 11 * 1111.

  Example 4: Construct a Turing machine for adding two non- negative integers. Solution: We need to build a Turing machine T that

  computes the function f(n t th f ti f( , n ) ) = n + n . The pair (n Th i ( , n ) is ) i

  1

  2

  1

  2

  1

  2

  represented by a string of n + 1 1s followed by a asterisk,

  1

  followed by n + 1 1s. The machine T should take this as

  2 an input and produce as output a tape with n + n +1 1s. ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  1

  2

Computing Functions withTuring Machines It will work like this;

  1) The machine starts at the leftmost 1 of the input string, and carries out steps to erase this 1. 2) Halt if n = 0, so that there are no more 1s before the

  1 asterisk, replaces the asterisk with the leftmost remaining 1.

  and then halts.

  3) The following five-tuples can do this job;

  (s , 1, s , B, R) and (s , *, s , B, R)

  1

  1

  3

  (s , 1, s , B, R) and (s , 1, s , 1, R)

  1

  2

  2

  2

  (s , *, s , 1, R)

  2

  3 ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  11 Types of Turing Machines

  Turing machine has the following types; 1) Turing machine with one dimensional tape

  1

  1

  1

  1

  1

  1

  1

  1

  2) Turing machine with two dimensional tape

  V V

  V V

  V H

  1

  1

  1 H H

  1 H

  1

  1

  1

  1

  1 H ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  1

Types of Turing Machines

  3) Turing Machines with Multiple Tapes 4) Nondeterministic Turing Machines: A nondeterministic

  Turing machine is a Turing machine which is like a nondeterministic finite automata, at any state it is in and for , y the tape symbol it is reading, can take any action selecting from a set of specified actions rather than taking one definite predetermined action. Even in the same situation it may take different actions at different times. Here an action means the combination of writing a symbol on the tape, moving the tape head and going to a next state.

  ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  13 Home Work Question 1: see page 837 .

  Thank you for your Attention.

  ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  15 ICS