Turing Machine
Turing Machine
which performs the action:
RunProgram::
while (PluggedIn and PowerOn)
Execute (PC);
PC := Next (PC);
Implications:
R/W
Control
Head
Tape
a b a b
Figure 1: Schematic of a Turing machine
consumed
Example TM computation
the language
In other words: we want to design such that
, if
We have an input
We cam examine consuming it in any
direction, as long as necessary
We can write to remember anything we want
Zig-zag around to determine whether or
not the corresponding places on the two sides
of match
We can mark the places we have already
visited
works following the strategy specified above:
makes multiple passes over the input with
the read/write head
On each pass matches one of the
characters on each side of symbol
To keep track of which symbols have been
checked crosses off each symbol as it is
examined
If crosses all symbols it accepts,
otherwise it rejects.
Turing Machines p.12/37
= "On input
0 1 1 0 0 0 0 1 1 0 0 0
x 1 1 0 0 0 0 1 1 0 0 0
x 1 1 0 0 0 x 1 1 0 0 0
x 1 1 0 0 0 x 1 1 0 0 0
x x 1 0 0 0 x 1 1 0 0 0
x x x x x x x x x x x x
accept
In other words: when TM is in a state and the head
is over a tape square containing a symbol
where are finite sets and
1. is a set of states
3. is the tape alphabet,
4.
7. is the reject state (sometimes denoted )
Turing Machines p.17/37
Other definitions
Hopcroft and Ullman 1979:
A Turing machine is a 7-tuple
where:
1. is a set of states,
4. , ,
arguments),
6. is the start state,
where
1. is the set of states,
where:
1. is a set of states,
,
5.
such that:
for some ;
Computations
computes as
follows:
receives as input written on the leftmost
squares of the tape; the rest of the tape is blank (i.e., filled with )
The head starts on the leftmost square of the tape
The first blank encountered shows the end of the input
Once it starts, it proceeds by the rules describing
If ever tries to move to the left of the leftmost square the head
Computation continues until enters , at which
points it halts. If neither occurs goes on forever
A configuration
of is a tuple
Configurations are used to formalize machine
computation and are represented by special
symbols
For , , , also denoted
and head is on the first symbol of .
Notation:
tape contains only following the last symbol of . Turing Machines p.22/37
Note:
Example configurations
Consider again the Figure 3 representing a snapshot of TM
recognizing the language .
0 1 1 0 0 0 0 1 1 0 0 0
x 1 1 0 0 0 0 1 1 0 0 0
x 1 1 0 0 0 x 1 1 0 0 0
x 1 1 0 0 0 x 1 1 0 0 0
x x 1 0 0 0 x 1 1 0 0 0
x x x x x x x x x x x x
accept
The following are configurations from from s computations.
In first line
In second line
In third line
In fourth line
In fifth line
In sixth line
where denotes the empty word in
and denotes a crossed symbol.
Formally:
.
; (machine moves
rightward)
2. We say that yields if
; (machine moves
leftward)
Turing Machines p.25/37
Head at one input end
the configuration yields if the transition is left
moving, i.e.,
the configuration yields for the right moving
transition, i.e.,
For the right-hand end, i.e., :
the configuration is equivalent to because we
assume that blanks follow the part of the tape represented in
configuration. Hence we can handle this case as the previous
is the start configuration
configuration
is called the rejecting configuration
sequence of configurations exists
such that:
1. is the start configuration,
2. Each yields denoted ,
3. is an accepting configuration
Note:
though denoted by .
is denoted by and is defined by
accepted by .
Note:
machine is also called the language of .
Turing Machines p.29/37
Turing-recognizable language
a Turing machine that recognizes it
can happen:
1. TM may accept
2. TM may reject
3. TM may loop indefinitely, i.e., TM does not
halt.
Note:looping does not mean that machine repeats the same steps over
and over again; looping may entail any simple or complex behavior that
never leads to a halting state.
Question: is this real? I.e., can you indicate a computation that takes
Turing Machines p.31/37
infinite many steps without repetition?
Fail to accept
A TM fails to accept
by:
1. , i.e., entering , and thus rejecting
When is looping, that is one cannot say if
accepts or rejects because we dont know if will ever enter a
for .
A TM fails to rejects
by:
1. , i.e., entering , and thus accepting
When is looping, that is one cannot say if
accepts or rejects because we dont know if will ever enter a
for .
accepts or
rejects or is looping
on .
Turing Machines p.37/37
Examples of Turing Machines
1. Sweep left to right across the tape crossing off every other
greater than one, the original number could
not have been a power of 2 and machine
rejects
If the number of is one than the original
Rationale:
Formal description of
where:
is described in Figure 1
respectively
Figure 1:
State diagram of
! "!
!
!
s state transition diagram
Examples of Turing Machines p.6/22
Notations
, and is labeled by
, and is labeled by
, and is labeled by
, and is labeled by
On input
Example run
:
Examples of Turing Machines p.8/22
Comments
i.e., in state with head reading ,
the machine goes to , writes , and moves to right
The arrow labeled in means
:
moves to the right when reading a
0 without affecting the tape.
Note: This machines begins by writing a blank over the leftmost zero.
This allows it to find the left-end of the tape in stage 4
It also allows to identify the case when tape contains one zero
only, in stage 2
is the TM that decides
the language
,
is described in Figure 2
respectively
= "On input :
1. Scan the input tape to be sure that it contains a single . If not,
reject
2. Zig-zag across the tape to corresponding positions on either side
of to check whether these positions contain the same symbol. If
they do not, reject. Cross off the symbols as they are checked
3. When all symbols to the left of have been crossed off, check for
the remaining symbols to the right of . If any symbol remain,
reject; otherwise accept"
Figure 2:
Turing machine
State diagram for TM
Examples of Turing Machines p.12/22
More notations
Transitions in states and means that machines
moves to the right as long as 0 or 1 is on the tape.
The machine starts by writing a blank symbol to delimit the
left-hand edge of the tape
Stage 1 is implemented by states through : , , if the first
symbol of input is , and if the first input symbol was .
To simplify the figure we dont show the reject state or transitions
going to reject state. These transitions occur implicitly whenever a
state lacks an outgoing transition for a particular symbol.
Example, on # is such a transition
Note: using different states for input starting with 1 and 0 allows to
="On input string
; reject if it is not
between the s and s crossing off one of each until all s are
are crossed off. If yes accept, otherwise reject." Examples of Turing Machines p.15/22
Analyzing
no writing is necessary as the head moves
from left to right:
1. , ,
2. , ,
3. , ,
the input (this have been seen before)
Note that if the machine tries to move the
head to the left of the left-hand end of the
tape the head remains in the same place.
This feature can be made "the left-hand end
detector" by:
1. Write a special symbol over the current position, while
recording the symbol that it replaced in the control
2. Attempt to move to the left. If the head is still over the special
symbol, the leftward move did not succeed, and the head
must have been at the left-hand end. If the head is over a
different symbol, some symbols are to the left of that position
Examples of Turing Machines p.17/22
on the tape
Note
implementations
Given a list of strings over separated by ,
determine if all strings are different.
A TM that solves this problem accepts the
language
is the TM that solves
the element distinctness problem
works by comparing with , then by
comparing with , and so on
="On input :
stage. Otherwise reject.
2. Scan right to the next and place a second mark on top of it. If
no is encountered before a blank symbol, only was present,
so accept.
3. By zig-zagging, compare the two strings to the right of the marked
-s. If they are equal, reject
4. Move the rightmost of the two marks to the next symbol to the
right. If no symbol is encountered before a blank symbol, move
the leftmost mark to the next to its right and the rightmost mark
of at that location