Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Chapter Six

Turing Machine

5/11/2021 Formal Langauge and Automata 1


Contents
• The standard Turing machine
• Turing machine as machine accepters
• Turing machine as Transducers
• Universal Turing Machines

5/11/2021 Formal Langauge and Automata 2


Turing Machine
• It is a mathematical model of computation that defines
an abstract machine
• manipulates symbols on a strip of tape according to a table of
rules.
• The machine operates on an infinite memory tape divided
into discrete cells.
• A Turing machine is a general example of a CPU that controls all data
manipulation done by a computer, with the canonical machine using
sequential memory to store data.
• More specifically, it is a machine (automaton) capable
of enumerating some arbitrary subset of valid strings of an alphabet;
– these strings are part of a recursively enumerable set.

5/11/2021 Formal Langauge and Automata 3


Recursively Enumerable
Languages
• A language is called Recursively Enumerable
if there is a Turing Machine that accepts on
any input within the language.
• Reminder: A language is called Recursive if
there is a Turing Machine that accepts on any
input within the language and rejects on any
other input.
5/11/2021 Formal Langauge and Automata 4
Recursive vs Recursively
Enumerable Languages
• Recursive languages are also called Decidable
Languages because a Turing Machine can decide
membership in those languages (it can either
accept or reject a string).
• Recursively Enumerable Languages are also called
Recognizable because a Turing Machine can
recognize a string in the language (accept it). It
might not be able to decide if a string is not in the
language since the machine might loop for that
input.

5/11/2021 Formal Langauge and Automata 5


Recursive Languages are also
Recursively Enumerable
Proof:
If L is recursive then there is a Turing Machine
M that decides membership in L:
– M accepts on x if x is in L
– M rejects on x if x is not in L
By definition, M can recognize strings in the
language (accept on those strings).

5/11/2021 Formal Langauge and Automata 6


Cont.…
• More precisely it consists
• A tape
– divided into cells, one next to the other.
– Each cell contains a symbol from some finite alphabet.
– The alphabet contains a special blank symbol (here written as '0') and one
or more other symbols.
– The tape is assumed to be arbitrarily extendable to the left and to the right,
i.e., the Turing machine is always supplied with as much tape as it needs
for its computation.
– Cells that have not been written before are assumed to be filled with the
blank symbol.
• A head
– That can read and write symbols on the tape and
– move the tape left and right one (and only one) cell at a time.

5/11/2021 Formal Langauge and Automata 7


Cont.…
• A state register
– stores the state of the Turing machine, one of finitely many.
– Among these is the special start state with which the state register is
initialized.
– These states, writes Turing, replace the "state of mind" a person
performing computations would ordinarily be in.
– Either erase or write a symbol (replacing aj with aj1).
– Move the head (which is described by dk and can have values: 'L' for one
step left or 'R' for one step right).

5/11/2021 Formal Langauge and Automata 8


Turing Machine

5/11/2021 Formal Langauge and Automata 9


The standard Turing Machine
Definition 9.1
A turing machine M is defined by Control unit
M  (Q,Σ,, δ ,q0 , ,F ),
7 tuples, where Read-write head
Q is the set of internal states,
Σ is the input alphabet, Tape
Γ is a finite set of symbols called δ:Q  Γ  Q  Γ  {L,R}
the tape alphabet,
δ is the transition function,
Example 9.1 The following figure shows the
 Γ is a special symbol called situation before and after the move caused by
the blank, the transition δ(p,a)  (q,d,R).
q0  Q is the initial state,
F  Q is the set of final states. State p State q

Halt state: A Turing machine will halt a b c d b c


whenever it enters a final state or
reaches a configuration for which δ δ(p,a)  (q,d,R) 10
is not defined.
We can think of a Turing machine as a computer.
Processing unit with a
finite memory. Control unit

Read-write head

Tape
A secondary storage of unlimited capacity.

Example 9.2 Consider the Turing machine defined by


Q  {q0 , q1}, δ(q0 ,a)  (q0 ,b,R),
  {a, b}, δ(q0 ,b)  (q0 ,b,R),
  {a, b, }, δ(q0 , )  (q1, ,L),
F  {q1}
q0 q0 q0 q1
11
a a b a b b b b
Example 9.3 Consider the Turing machine defined by
Q  {q0 , q1}, δ(q0 ,a)  (q1,a,R),
  {a, b}, δ(q0 ,b)  (q1,b,R),
  {a, b, }, δ(q0 , )  (q1, ,R),
F  {q1} δ(q1,a)  (q0 ,a,L),
δ(q1,b)  (q0 ,b,L),
δ(q1, )  (q0 , ,L).

It is clear that the machine, whatever the initial information on its


tape, will run forever, with the read-write head moving alternately
right then left, but making no modifications to the tape. This is an
instance of a Turing machine that does not halt. We say that the
machine is in an infinite loop.

5/11/2021 Formal Langauge and Automata 12


What is a Standard Turing machine ?
q0 (initial state) 3. Input (all or q f (final state)
some of them)
a1 a2 an b1 b2 bm
Main feature of the model
1. The tape is unbounded in
both directions, allowing any 4. No special
number of left and right moves. input or Output
(all or some of
2. The Turing machine is them)
deterministic in the sense that ᵟ
defines at most one move for
each configuration.
5/11/2021 Formal Langauge and Automata 13
We denote the following configuration of a Turing machine
q

a1 a2 ak 1 a k ak 1 an

to be a1a2  ak 1qak  an .
A move from one
If δ (q, ak )  ( p, b, L), then we write configuration to
another will be
a1a2  ak 1qak ak 1  an a1a2  pak 1bak 1  an denoted by |
If δ (q, ak )  ( p, b, R), then we write
a1a2  ak 1qak ak 1  an a1a2  ak 1bpak 1  an

The unspecified part of the tape is assumed to contain all blanks;


if the position of blank is relevant, the blank symbol may appear
in the instantaneous description. 14
Turing machine as language accepter
A string w is written on the tap then machine is started in the initial state
Q0 with the read-write head positioning on the left of symbols in w. after sequence
of moves, the TM enters the final state and halts, then w is considered to be accepted.

Definition 9.3
Let M  (Q,Σ,,δ , q0 , ,F ) be a Turing machine. Then the language
accepted by M is
L( M )  {w    : q0 w
*
x1q f x2 for some q f  F , x1 , x2  *} 15
Example 9.6 For Σ  {0,1}, design a Turing machine that accepts the language
denoted by the regular expression 00*.

Solution
(1) Starting at the left end of the input and check if the first one is a 0.
(2) If we reach a blank without encountering anything but 0, we terminate and
accept the string. If the input contains a 1 anywhere, the string is not in L(00*),
and we halt in a non final state.
Q  {q0 , q1}, δ(q0 ,0 )  (q0 ,0,R),
F  {q1} δ(q0 , )  (q1, ,R).

5/11/2021 Formal Langauge and Automata 16


Example 9.7 For Σ  {a, b}, design a Turing machine that accepts the language
L  {a nb n : n  1}.
Solution

Q  {q0 , q1 , q2 , q3 , q4 },
F  {q4 }
  {a, b}
  {a, b, x, y, }
δ(q0 ,a)  (q1,x,R), δ(q 2 ,y)  (q 2 ,y,L), δ(q0 ,y)  (q3 ,y,R),
δ(q1, a)  (q1,a,R), δ(q 2 , a)  (q 2 ,a,L), δ(q3 , y )  (q3 ,y,R),
δ(q1, y )  (q1,y,R), δ(q 2 , x)  (q0 ,x,R), δ(q3 , )  (q 4 , ,R).
δ(q1, b)  (q 2 ,y,L),
a a b b blank

5/11/2021 Formal Langauge and Automata 17


Example: Turing machine M for the language defined by

L=(a*b+a*bc)

5/11/2021 Formal Langauge and Automata 18


Turing Machine as Transducer
• Transducer is any device that coverts a
signal from one form to other.
• Turing machine
– Converts input to output
– Start with string on the tape
– After acceptance string left on the tape

5/11/2021 Formal Langauge and Automata 19


Computability of Turing Machine
In this section, it is considered that a TM as computing device

Definition 9.4
A function f with domain D is said to be Turing - computable or just
computable if there exists some Turing machine M  (Q,Σ,,q0 , ,F )
such that
q0 w *
M q f f ( w), q f  F,
for all w  D.

5/11/2021 Formal Langauge and Automata 20


Example 9.9 Given two positive integers x and y, design a Turing machine
that computes x  y.
Solution In the tape, represent integers x and y by a number x of 1’s and a
number y of 1’s, and put a 0 between x and y. • Basic idea: Simply remove
Q  {q0 , q1 , q2 , q3 , q4 }, δ(q0 ,1 )  (q 0 ,1,R), the 0 between the two sets
F  {q4 } δ(q0 , 0)  (q1,1,R), of ones.
  {0,1} δ(q1,1)  (q1,1,R), • Read all 1s up to 1st 0
• Replace 0 with 1
  {0,1, } δ(q1, )  (q 2 , ,L), • Remove last 1 1:1,R
δ(q 2 ,1)  (q3 ,0,L),
1:1,R

0:1,R
δ(q3 ,1)  (q3 ,1,L),
δ(q3 , )  (q 4 , ,R). B:B,L

q0111011 * 111q0 011 1:1,L

1111q111 * 111111q1 B:B,R 1:0,L

11111q21
1111q310 * q3 111110
5/11/2021 Formal Langauge and Automata 21
q4111110
TM to add 1 to a binary number

Blank/lambda

5/11/2021 Formal Langauge and Automata 22


Example 9.10 Design a Turing machine that copies strings of 1' s. More presicely,
find a machine that performs the computation q0 w * q f ww, for any w  {1} .

Solution: To solve the problem, we F  {q3 }


implement the following intuitive
process: δ (q0 ,1)  (q0 , x, R ),
1. Replace every 1 by x.
δ (q0 , )  (q1 , , L),
2. Find the rightmost x and replace it with 1.
δ (q1 , x)  (q2 ,1, R ),
3. Travel to the right end of the current δ (q2 ,1)  (q2 ,1, R ),
nonblank region and create a 1 there.
δ (q2 , )  (q1 ,1, L),
4. Repeat Steps 2 and 3 until there are no
more x’s. Assume the string w=11 δ (q1 ,1)  (q1 ,1, L),
The computation performed in this case is δ (q1 , )  (q3 , , R ),

5/11/2021 23
5/11/2021 Formal Langauge and Automata 24
Universal Turing Machines
• Limitation of Turing machine
– Turing Machines are “hardwired”
• they execute only one program
• Real Computers are re-programmable
• Solution: Universal Turing Machine
• Attributes:
– Reprogrammable machine
– Simulates any other Turing Machine
5/11/2021 Formal Langauge and Automata 25
Cont…
• Universal Turing Machine simulates
– any Turing Machine M
• Input of Universal Turing Machine:
– Description of transitions of M
– Input string of M

5/11/2021 Formal Langauge and Automata 26


We describe Turing machine M as a string
of symbols: We encode M as a string of
symbols

5/11/2021 Formal Langauge and Automata 27


5/11/2021 Formal Langauge and Automata 28
5/11/2021 Formal Langauge and Automata 29
• A Turing Machine is described with a binary
string of 0’s and 1’s
Therefore:
• The set of Turing machines forms a language:
• each string of this language is the binary
encoding of a Turing Machine

5/11/2021 Formal Langauge and Automata 30


5/11/2021 Formal Langauge and Automata 31
Reading Assignment
• Context sensitive grammars and
languages
– Context sensitive languages and Linear
bounded automata
– Relation between recursive and context
sensitive languages

5/11/2021 Formal Langauge and Automata 32

You might also like