Chapter 5 Turing Machines
Chapter 5 Turing Machines
5.1. Standard TM
5.2. Construction of TM
5.3. Turing Decidable and Turing Acceptable
5.4. Undecidable problems
Turing machines
• The Turing machine also has a finite set of states and a transition
function that determines how the machine should move and what
symbol it should write based on the current state and the symbol on the
current cell.
• T: is the input tape that holds the Input and Special symbols. So, Both input
and Special symbols are a subset of input tape T.
Example:
• δ(q0, a) → (q1, A, R), this means currently the machine at state q0. if
the machine reads input symbol a, change the state to q1 and replace
the input by A in the tape, and then move to the Right.
Head Pointer
Initially a b ␣ ␣ ␣ ␣ ␣
Note:
• If we are at the left end of the tape, and trying to move LEFT, then do not move.
Stay at the left end.
• If you do not want to update the Cell, Just WRITE the same symbol in that Cell.
Turing machines Tape
• Turing machine has external memory (tape) with infinite length in both
directions,
o so the machine can move left or right along the tape as needed.
• The machine also has a read/write head that can read the symbol on the
current cell and write a new symbol onto the tape.
2. Input Symbols: The input tape consists of infinite cells on which each cell either
contains input symbol or a special symbol. Special symbol is also called blank
symbol.
3. Head pointer: it is a read/write head pointer which points to cell currently being
read and it can move in both (left and right) directions.
Operation on Input Tape in Turing Machine
• All possible results after performing all operations on input tape are:
• If you don’t want to update the cell, just write the same symbol (the same as the
input).
Cont…
Rules of Operation -2
• Tape: The tape is divided into cells, each of which can hold a symbol. The tape
is initially filled with a blank symbol, and the input to the machine is written on
the tape.
• Head: The head reads and writes symbols on the tape. It can move left or right
along the tape.
Cont…
• States: The machine has a finite set of states, including an initial state and one
or more halting states.
• Transition function: The transition function takes as input the current state and
symbol read by the head, and outputs the new state, symbol to write to the tape,
and direction for the head to move.
Example 1: Design a TM that recognizes the language L = 01*0
Blank symbol
• At state q0, read input 0, and write X to the tape, then move Right
• At state q1, read input 1, then write Y to the tape (repeat), then move Right
• At state q2, read input 0, then write X to the tape, then move Right
• At state q3, read the blank symbol, write a blank symbol, and move Right
Let’s check the input string w = {0110}
Initially
0 1 1 0
0110 Read input 0, then write X to the tape, then move to the Right
X 1 1 0 ␣ ␣ ␣
0110 Read input 1, then write Y to the tape, then move to the Right
X Y 1 0 ␣ ␣ ␣
0110 Read input 1, then write Y to the tape, then move to the Right
X Y Y 0 ␣ ␣ ␣
0110 Read input 0, then write X to the tape, then move to the Right
X Y Y Y X ␣ ␣
0110 Read the blank symbol, then write blank to the tape, then move to the Right
X Y Y Y X ␣ ␣
Cont…
Complete TM design
Blank symbol
Example 1: Design a TM that recognizes the language L = {0n1n , n ≥ 1}
Example {01, 0011, 000111….}. The number of 0’s must be equal with
the number of 1’s.
Algorithm:
3. Repeat the above steps until no more 0’s and 1’s remain
Cont…
Let’s check the 000111
Initially
0 0 0 1 1 1 ␣
In order to check whether they are equal or not, we should compare each
0’s with each 1’s (0’s from the left side and 1’s from the right side)
000111 Read input 0, then write X (replace 0 by X) to the tape, then move to the Right
X 0 0 1 1 1 ␣
X00111 Read input 0, then write 0 itself to the tape, then move to the Right
X 0 0 1 1 1 ␣
Cont…
X00111 Read input 0, then write 0 itself to the tape, then move to the Right
X 0 0 1 1 1 ␣
Read input 1, then write X to the tape, then move to the Left (each 0’s in the left must be compared with
X00111 each 1’s in the right
X 0 0 X 1 1 ␣
X00X11 Read input 0, then write 0 to the tape, then move to the Left
X 0 0 X 1 1 ␣
X00X11 Read input 0, then write 0 to the tape, then move to the Left
X 0 0 X 1 1 ␣
Cont…
X00X11 Read input X, then write X to the tape, then move to the Right
X 0 0 X 1 1 ␣
X00X11 Read input 0, then write X to the tape, then move to the Right
X X 0 X 1 1 ␣
XX0X11 Read input 0, then write 0 to the tape, then move to the Right
X X 0 X 1 1 ␣
XX0X11 Read input X, then write X to the tape, then move to the Right
X X 0 X 1 1 ␣
Cont…
XX0X11 Read input 1, then write X to the tape, then move to the Right
X X 0 X X 1 ␣
XX0X11 Read input 1, then write X to the tape, then move to the Left
X X 0 X X 1 ␣
XX0XX1 Read input 1, then write X to the tape, then move to the Left
X X 0 X X 1 ␣
XX0XX1 Read input X then write X to the tape, then move to the Left
X X 0 X X 1 ␣
Cont…
XX0XX1 Read input 0, then write 0 to the tape, then move to the Left
X X 0 X X 1 ␣
XX0XX1 Read input X, then write X to the tape, then move to the Left
X X 0 X X 1 ␣
XX0XX1 Read input X, then write X to the tape, then move to the Right
X X 0 X X 1 ␣
XX0XX1 Read input X, then write X to the tape, then move to the Right
X X 0 X X 1 ␣
Cont…
XX0XX1 Read input 0, then write X to the tape, then move to the Right
X X X X X 1 ␣
XXXXX1 Read input X, then write X to the tape, then move to the Right
X X X X X 1 ␣
XXXXX1 Read input X, then write X to the tape, then move to the Right
X X X X X 1 ␣
XXXXX1 Read input 1, then write X to the tape, then move to the Right
o Whenever we get the + symbol, replace it with 1 and move to the Right, then
o Replace the last 1 with a blank symbol (unless the result will be 111111)
Cont…
Let’s check the 3 +2 = 111+11
Initially
1 1 1 + 1 1 ␣
111+11 Read input 1, then write 1 to the tape, then move to the Right
1 1 1 + 1 1 ␣
111+11 Read input 1, then write 1 to the tape, then move to the Right
1 1 1 + 1 1 ␣
111+11 Read input 1, then write 1 to the tape, then move to the Right
1 1 1 + 1 1 ␣
Cont…
111+11 Read input +, then write 1 to the tape, then move to the Right
1 1 1 1 1 1 ␣
111+11 Read the 1 symbol, then write 1 to the tape, then move to the Right
1 1 1 1 1 1 ␣
111+11 Read input 1, then write 1 symbol to the tape, then move to the Right
1 1 1 1 1 1 ␣
111+11 Read the blank symbol, then write blank symbol to the tape, then move to the Left
1 1 1 1 1 1 ␣
Cont…
111+11 Read input 1, then write blank symbol to the tape, then move to the Left
1 1 1 1 1 ␣ ␣
TM design is:
Example 2: Design a TM for the subtraction of unary numbers
f(m, n) = { m-n, m ≥ n
0, m < n
Example: 3 - 2 = 1
111 - 11 = 1
Cont…
Let’s check the 3 - 2 = 111-11 = 1
Initially
1 1 1 - 1 1 ␣
111-11 Read leftmost 1, then write blank symbol to the tape, then move to the Right
␣ 1 1 - 1 1 ␣
␣11-11 Read input 1, then write 1 to the tape, then move to the Right
␣ 1 1 - 1 1 ␣
␣11-11 Read input 1, then write 1 to the tape, then move to the Right
␣ 1 1 - 1 1 ␣
Cont…
␣11-11 Read input -, then write - to the tape, then move to the Right
␣ 1 1 - 1 1 ␣
␣11-11 Read input 1, then write 1 to the tape, then move to the Right
␣ 1 1 - 1 1 ␣
␣11-11 Read input 1, then write 1 to the tape, then move to the Right
␣ 1 1 - 1 1 ␣
␣11-11 Read input blank symbol , then write itself to the tape, then move to the Left
␣ 1 1 - 1 1 ␣
Cont…
␣11-11 Read input 1, then replace by blank to the tape, then move to the Left
␣ 1 1 - 1 ␣ ␣
␣11-1␣ Read input 1, then replace by itself, then move to the Left
␣ 1 1 - 1 ␣ ␣
␣11-1␣ Read input -, then replace by to itself, then move to the Left
␣ 1 1 - 1 ␣ ␣
␣11-1␣ Read input 1, then replace by to itself, then move to the Left
␣ 1 1 - 1 ␣ ␣
Cont…
␣11-1␣ Read input 1, then replace by to itself, then move to the Left
␣ 1 1 - 1 ␣ ␣
␣11-1␣ Read blank symbol, then replace by itself, then move to the Right
␣ 1 1 - 1 ␣ ␣
␣␣1-1␣ Read input 1, then replace by blank symbol, then move to the Right
␣ ␣ 1 - 1 ␣ ␣
␣ ␣ 1 - 1 ␣ ␣
Cont…
␣␣1-1␣ Read input -, then replace by itself, then move to the Right
␣ ␣ 1 - 1 ␣ ␣
␣␣1-1␣ Read input 1, then replace by itself, then move to the Right
␣ ␣ 1 - 1 ␣ ␣
␣␣1-1␣ Read input 1, then replace by itself, then move to the Right
␣ ␣ 1 - 1 ␣ ␣
␣␣1-1␣ Read blank symbol, then replace by itself, then move to the Left
␣ ␣ 1 - 1 ␣ ␣
Cont…
␣␣1-1␣ Read input 1, then replace by blank, then move to the Left
␣ ␣ 1 - ␣ ␣ ␣
␣␣1-␣␣ Read input -, then replace by itself, then move to the Left
␣ ␣ 1 - ␣ ␣ ␣
␣␣1-␣␣ Read input -, then replace by itself, then move to the Left
␣ ␣ 1 - ␣ ␣ ␣
␣␣1-␣␣ Read blank symbol, then replace by itself, then move to the Right
␣ ␣ 1 - ␣ ␣ ␣
Cont…
␣␣1-␣␣ Read input 1, then replace by blank, then move to the Right
␣ ␣ ␣ - ␣ ␣ ␣
␣␣␣-␣␣ Read input -, then replace by itself, then move to the Right
␣ ␣ ␣ - ␣ ␣ ␣
␣␣␣-␣␣ Read blank symbol, then replace by itself, then move to the Left
␣ ␣ ␣ - ␣ ␣ ␣
Example: 3 * 2 = 6
111 * 11 = 111111
Recursive Language
• The Turing machine will halt every time and give an answer (accepted or
rejected) for each and every string input.
• If L is a recursive language then −
o If w ∈ L then a TM halts in a final state (Accepted), w is a set of strings
o If w ∉ L then TM halts in a non-final state (Rejected)
Recursive Enumerable Language
o But may or may not halt for the input strings which are not in L.
• If the language is not even partially decidable, then there exists no Turing machine
for that language.
Recursive Language TM always Halt
Recursively Enumerable Language TM will halt sometimes and may not halt
sometimes
Decidable Recursive Language
Partially Decidable Recursively enumerable language
Undecidable No TM for that Language
THE END!
47