0% found this document useful (0 votes)
21 views

Week 2-2

The document discusses Turing machines and their components. A Turing machine consists of an infinite tape divided into squares, a read/write head that can read/write symbols on the tape and move left/right, and a finite state control. The tape serves as memory and the read/write head and states allow the machine to compute by reading/writing symbols and transitioning between states. Examples of Turing machines that invert bits and increment binary numbers are provided.

Uploaded by

Hidayati Aziz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Week 2-2

The document discusses Turing machines and their components. A Turing machine consists of an infinite tape divided into squares, a read/write head that can read/write symbols on the tape and move left/right, and a finite state control. The tape serves as memory and the read/write head and states allow the machine to compute by reading/writing symbols and transitioning between states. Examples of Turing machines that invert bits and increment binary numbers are provided.

Uploaded by

Hidayati Aziz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Turing Machines

Chapter 12 textbook

Prepared by LC Kwek
Edited by NHAA Nov 2019
Objectives

• In this module we will


• explore the limitations of FSM’s
• specify a Turing Machine’s components
• see TM in Operation
• view examples of TM - a bit inverter, a binary number incrementor

2/20
Limitations of FSM (1/3)

• Not all things that can be computed could be computed with an FSA
• FSA below can check for strings a(a|b)*b

a, b

0 1 2
a b
• However, there is no way to build an FSA to check if there are
precisely the same number of a’s and b’s
• Let’s try to build a FSA!

3/20
Limitations of FSM (2/3)

• FSA that accepts 0 a’s and b’s

• FSA that accepts a difference of 0 or 1 a’s and b’s

a a
1a 0 1b
b b

4/20
Limitations of FSM (3/3)

• FSA that accepts a difference of 0, 1, or 2 a’s and b’s

a a a a
2a 1a 0 1b 2b
b b b b

• It is a never-ending process! An infinite state automata is needed!

a a a a a a
... 3a 2a 1a 0 1b 2b 3b ...
b b b b b b

5/20
The Turing Machine (1/8)

• A Turing machine is a theoretical computing machine invented by


Alan Turing (1937) to serve as an idealized model for mathematical
calculation
• It consists of an infinite paper tape, a read/write head and a finite
state machine controller

tape
read/write
FSM head
FSM
controller
controller
6/20
The Turing Machine (2/8)

• Tape
• Infinite length
• Divided into squares where each square is blank or contains one symbol
from a finite alphabet of symbols
• Records input and output
• Serves as memory

• Read/Write head
• Reads: symbols from the tape, one square at a time, usually beginning at the
left-most square that contains a symbol
• Writes: symbol to the tape
• Moves: one square to the right or left or stops

7/20
The Turing Machine (3/8)

• A special FSM controller


• It reads from the current position of the paper tape to obtain its input
• It may write to the current position of the paper tape, leave the symbol
unchanged or erase it
• It may move the read/write head one square to the right or left or leave it in
the same place
• The transitions are labelled with a triple of
• the symbol the head can currently read on the tape
• the symbol the head should write to the tape
• the direction the head should move

8/20
The Turing Machine (4/8)

• Example:
• The controller starts out in state 0 at the left-most non-blank square

A B A A

9/20
The Turing Machine (5/8)

• Example: (cont.)
• If it reads ‘A’, ‘A’ remains unchanged, it moves right, and stays in state 0

A B A A
don’t write

move right

10/20
The Turing Machine (6/8)

• Example: (cont.)
• If it reads ‘B’, it will write an ‘A’, and not move, and change to state 1

ABAA
write ‘A’
don’t move

11/20
The Turing Machine (7/8)

• Example: (cont.)
• It halts as state 1 is an accepting state

AAAA
STO P

12/20
The Turing Machine (8/8)

• Instructions for a TM consist in specified conditions under which the


machine will transition between one state and another
• Each instruction of a TM says something like
if (you are in state i) and (you are reading symbol j) then
write symbol k onto the tape
go to state s
move in direction d

• A shorthand notation for instructions


• Current state, Current symbol, Next symbol, Next state, Direction of move

13/20
Representations of TM (1/2)

• State diagram
• As what we have seen earlier …

• Pseudo-code
• The same TM can be represented as textual program code

0 A then move right, goto 0


B then write A, goto 1
1 halt

14/20
Representations of TM (2/2)

• Table
• It can be also represented as a table
State Input Write Move New state
0 A A > 0
0 B A Stay 1
1 Any Nothing Stay Halt

• Set of tuples
• The items in a tuple are in the same order as the table
(0,A,A,>,0)
(0,B,A,-,1)

15/20
TM in Operation: Source Code
1 #include <stdio.h>
2 #define N 256 Enter string: ABAA
3 void changeBtoAthenStop(char *b); AAAA
4 int main(void){
5 char b[N];
6
7 printf("Enter string: ");
8 fgets(b,N,stdin); /* gets(b); */
9 changeBtoAthenStop(b);
10 fputs(b,stdout);
11 return(0);
12 }
13 void changeBtoAthenStop(char *b){
14 int k=0;
15
16 while(b[k]=='A') k++;
17 b[k]='A';
18 return;
19 }
16/20
Example 1: Bit Inverter

• A bit inverter TM
• Beginning in state 1 on the leftmost non-blank cell, it inverts whatever the
current symbol is by printing its opposite
• It keeps moving right while remaining in state 1

(1,0,>) (0,1,>)
(1,0,1,>,1)
1 (1,1,0,>,1)

• Example: Inverting 011 to 100

0 1 1
1 1 1
1 0 1
1 0 0

17/20
Example 2: Binary Number Incrementor
(1/2)

• A binary number incrementor TM


• It expects a tape that contains a binary number, starting with S, in the
reverse order, i.e., S1 is 1, S01 is 2, S11 is 3 and S001 is 4
• It then repeatedly increments the number
S1_
(' ',1,<)
S01
(0,1,<) S11_
(0,0,<) (1,0,>) S001
(1,1,<) S101
L R
S011
(' ',' ',>) S111_
S0001
(S,S,>)
S1001

18/20
Example 2: Binary Number Incrementer
(2/2)

• A binary number incrementor TM (cont.)


• This can be represented as tuples
(L, , ,>,L)
(L,S,S,>,R)
(L,0,0,<,L)
(L,1,1,<,L)
(R,1,0,>,R)
(R, ,1,<,L)
(R,0,1,<,L)
• The corresponding C code: long x=0; while(1) x++;
• This machine could not be implemented on a real computer. Why?
• You will run out of memory sometime!

19/20
Summary

• Turing Machines can compute anything that is computable


• TM are able to model a computer
• By analogy with modern computers, the tape is the memory and the head is
the microprocessor
• A deterministic TM works as a deterministic computer
• A non-deterministic TM works as a quantum computer

20/20

You might also like