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

Chapter 5 Turing Machines

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

Chapter 5 Turing Machines

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

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

• A Turing machine is a theoretical model of a computer that can


simulate any algorithmic process.

• It was invented by Alan Turing in the 1930s as a way to formalize the


concept of algorithmic computation.

• It is an accepting machine which accepts recursively enumerable


language generated by type-0 grammar.

• A Turing machine consists of a tape divided into cells, each of which


can hold a symbol from a finite alphabet.
Cont…

• 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.

• The transition function: is defined as a table or a set of rules that


specify the next state, the symbol to write, and the direction to move
the head (left or right).
Turing Machine Tuples

• A Turing Machine can be explained through 7-Tuples (Q, T, B, ∑, δ, q0, F).

• Q: is a finite set of states

• 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.

• B: is a Special symbol also called a Blank symbol (initially every cell is


filled with a special symbol except input alphabet)

• ∑: is the input symbols (input tape holds initially input alphabet)


Cont…

• δ: is a transition function is Q × T → Q × T × {L,R}. At any state (Q) when


the Input tape symbol (T) is applied then it will move to new state, Update
the tape symbol (may or may not change) and move head pointer to either
right or left.

• q0: is the initial state.

• F: is the set of final states. If any state of F is reached, input string is


accepted.
Cont…

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 ␣ ␣ ␣ ␣ ␣

a and b are inputs, ␣ is blank space(indicates empty cell)

After applying the A b ␣ ␣ ␣ ␣ ␣


transition function
Transition Diagram for Turing machines

Input symbol Input symbol Direction to Move


to Read to Write Left or Right

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.

o So that, read/write operation can be performed on the tape.


Elements of Turing Machine
1. Input Tape: It has infinite length on which read and writes operation can be
performed.

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.

• Input Symbols (∑) an be in the form of {0,1,a,b, ε, Z0}

• Special Symbols (B) an be in the form of {&, $,],[, #, etc. }

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

• The basic operation on Input Tape are:

o Read/scan symbol below the tap Head

o Update / Write a symbol below the Tap Head

o Move the Tap Head one step LEFT or RIGHT


Computation Result in Turing Machine

• All possible results after performing all operations on input tape are:

o HALT and ACCEPT: It means we reach at accepted state when all


operations are done.

o HALT and REJECT: It means we reach at rejected state when all


operations are done.

o LOOP: it means the machine fails to HALT


Cont…
Rules of Operation -1

At each step of the computation:


o Read the current symbol.
o Update(i.e. write) the same cell (the cell in which the tape pointer is pointing
to).
o Move exactly one cell either Left or Right.
• If you’re at the Left-end of the tape, and trying to move Left, then don’t move.
Stay at the left end.

• If you don’t want to update the cell, just write the same symbol (the same as the
input).
Cont…
Rules of Operation -2

• Control unit is similar to a sort of FSM

• Initial state is required

• Final states( two final states):


1. Accept, or
2. Reject
• Computation can either:
1. HALT and ACCEPT
2. HALT and REJECT
3. LOOP (if the machine fails to HALT
5.2. Construction of TM

• Turing machines can be constructed to solve a wide range of computational


problems. To construct a Turing machine, you need to define the following
components:

• 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 ␣ ␣ ␣

Blank or empty cells


Cont…

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:

1. Change leftmost 0 to X, then Move to the first 1

2. Change 1 to Y, and Move to the leftmost 0

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

We check every 0’s by 1’s and they are equal


X X X X X X ␣
because no more 0’s or 1’s are remain
Cont…
TM design for the above language:
Example 3: Design a TM for the addition of unary numbers

Unary representation: representing numbers using all 1’s

Example: 2 → 11, 3 → 111, 5→11111


2 + 3 = 5
11 + 111 = 11111

• To add these unary numbers:

o Whenever we get input 1, replace by itself and 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 ␣ ␣

As you see in the tape, the result is 11111


Cont…

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␣ Read input 1, then replace by to l, then move to the Right

␣ ␣ 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

␣ ␣ ␣ - ␣ ␣ ␣

␣␣␣-␣␣ Read input -, then replace by 1, then move to the Left

␣ ␣ ␣ 1 ␣ ␣ ␣ As you see in the tape, the result is 1


TM design is:
Exercise: Design a TM for the multiplication of unary numbers

Example: 3 * 2 = 6
111 * 11 = 111111
Recursive Language

• A language L is recursive (decidable) if L is the set of strings accepted by some


Turing Machine (TM) that halts on every input. OR

• A language L is said to be recursive if there exists a Turing machine that will


accept all the strings in L and reject all strings not in L.

• 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

• A language L is recursively enumerable if L is the set of strings accepted by


some TM. OR

• A language L is said to be recursive if there exists a Turing machine that will


accept(and therefore halt) all the strings which are in L.

o But may or may not halt for the input strings which are not in L.

• If L is a recursive enumerable language then −


o If w ∈ L then a TM halts in a final state,
o If w ∉ L then a TM halts in a non-final state or loops forever.
5.3. Turing Decidable

• A language L is said to be decidable if it is a recursive language.

• All decidable languages are decidable, the vice-versa is true.

Partially decidable language:

• A language L is said to be partially decidable if it is a recursively enumerable


language.
5.4. Undecidable problems

• A language L is undecidable if it is not decidable

• An undecidable language may sometimes be partially decidable but not decidable.

• 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

You might also like