Sei sulla pagina 1di 59

Turing Machines

Turing Machines p.1/37


Informal discussion

A Turing machine (TM) is similar to a finite


automaton with an unlimited and unrestricted
memory
A Turing machine is however a more accurate
model of a general purpose computer
A Turing machine can do everything that a
real computer can do

Note:even a Turing machine cannot solve certain


classes of problems
Turing Machines p.2/37
Real computer

A real computer is a triple


 




 









which performs the action:
RunProgram::
while (PluggedIn and PowerOn)
Execute (PC);
PC := Next (PC);

Implications:

1. Processor = (PC, Instructions)


2. Program is stored in memory as a stream of instructions
3. PC always points to the next instruction to execute
Turing Machines p.3/37
Informal characterization

TM memory: infinite tape


a tape-head that can read/write
TM I/O:
symbols and move around on the tape
TM Processor:a control device that performs
transformations of the symbols written on the
tape while moving the head around.
Comments:

1. What are the similarities to a real computer?


2. What are the differences from a real computer?

Turing Machines p.4/37


Initial condition

Initially the tape contains only the input string


and is blank everywhere else
If TM needs to store info, it may write it on the
tape
To read the info that it has written, TM can
move its head back over its tape
Machine continues computing until it decides
to produce an output

Turing Machines p.5/37


The output

The computation performed by a TM ends up


with an output, which is one of:
accept, reject, or compute forever.

Turing Machines p.6/37


Graphic

Figure 1 shows the schematic of a TM

R/W
Control
Head
Tape


a b a b


Figure 1: Schematic of a Turing machine

Turing Machines p.7/37


TM versus FA

1. A TM can both write on the tape and read


from it;
a FA can only read its input
2. The read/write head of a TM can move both
to the left and to the right;
a FA can move in one direction only
3. The tape of a TM is infinite;
the input of a FA is finite
4. The special states of a TM for rejecting and
accepting the input take immediate effect;
FA terminates when input is entirely
Turing Machines p.8/37

consumed
Example TM computation

Construct a TM that tests the membership in




the language









In other words: we want to design such that

, if 










Note:with regard to a real computer this problem becomes:


construct a program that solve the above problem

Hence, a TM is an algorithm (i.e., a program).

Turing Machines p.9/37


Note

To understand this problem we assume that we


are TMs, i.e., we simulate the actions performed
by TM by ourselves.


We have an input






We cam examine consuming it in any


direction, as long as necessary
We can write to remember anything we want

Turing Machines p.10/37


Strategy

Identify first the character in


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

Turing Machines p.11/37


Design of


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


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."
Turing Machines p.13/37
Illustration, Fig 2


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

Figure 2: Snapshots of 


computing

Turing Machines p.14/37


Preparing a formal definition

The control device (the processor) of a TM


can be in a finite set of states. We denote this
set by Q
The tape (i.e. the memory) of a TM is split
into an infinite number of locations called
squares or cells. Each square can hold a
symbol of a given alphabet,
The tape-head can move to the right (R) or to
the left (L) one square at each step of the
computation performed by the TM.

Note: the input data on which a TM operates come


Turing Machines p.15/37
Transitions

The heart of a formal definition of a TM is the


transition function because it tells how is the
machine going from one step to the next.
The signature of is:











In other words: when TM is in a state and the head




is over a tape square containing a symbol











if the machine replaces with , moves to the










state and moves the head to the left (L)








if the machine replaces with , moves to










the state and moves the head to the right (R)




Turing Machines p.16/37


Formal definition

A Turing machine is a 7-tuple




















where are finite sets and

1. is a set of states


2. is the input alphabet and blank






3. is the tape alphabet,

4.

is the transition function









5. is the initial state







6. is the accept state (sometimes denoted )














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,


2. is a finite set of allowable tape symbols,


3. is a symbol from called blank,





4. , ,


5. ( may be undefined on some








arguments),
6. is the start state,





7. is the set of final states.





Turing Machines p.18/37


Different notation
Fleck 2001:
A Turing machine is a 7-tuple


where




1. is the set of states,


2. is the start state,






3. is the set of recognizing or accepting states.






The other components of are as in Hopcroft and Ullman




Turing Machines p.19/37


TM as a quintuple
Lewis and Papadimitriou (1981) and Kimber and Smith,
(2001)
A Turing machine is a 5-tuple


where:



1. is a set of states,


2. is an alphabet containing (left marker) and (blank), but




,



3. is the initial state,






4. is the set of halting states, and












5.

, the transition functions, is














such that:


for some ;















Turing Machines p.20/37







If for some , then
















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


stays in the leftmost square even though indicate


Computation continues until enters , at which



 











points it halts. If neither occurs goes on forever


Turing Machines p.21/37


Configuration

A configuration

of is a tuple







 






Configurations are used to formalize machine
computation and are represented by special
symbols
For , , , also denoted








, represents the configuration







where current state is , tape contains ,



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

Figure 3: Snapshots of computing


 


Turing Machines p.23/37


Configurations of


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.



Turing Machines p.24/37


Formalizing TM computation

A configuration yields a configuration if


the TM can legally go from to in a
single step
suppose , and


Formally:




.

 

1. We say that yields if









; (machine moves






rightward)
2. We say that yields if



; (machine moves








leftward)
Turing Machines p.25/37
Head at one input end

For the left-hand end, i.e. :


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

Turing Machines p.26/37


Special configurations

If the input of is and initial state is then


is the start configuration





is called the accepting












configuration
is called the rejecting configuration












Note: accepting and rejecting configurations are


also called halting configurations

Turing Machines p.27/37


Accepting an input

A Turing machine accepts the input if a


sequence of configurations exists


such that:


1. is the start configuration,





2. Each yields denoted ,













3. is an accepting configuration


The sequence is al-





Note:




though denoted by .


Turing Machines p.28/37


Language of

The language recognized by a Turing machine









is denoted by and is defined by
















That is, is the set of strings



accepted by .

The language recognized by a Turing




Note:
machine is also called the language of .
Turing Machines p.29/37
Turing-recognizable language

A language is Turing-recognizable if there is


a Turing machine that recognizes it

Turing Machines p.30/37


Note

When we start a TM on an input three cases


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 .






Turing Machines p.32/37


Fail to reject


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 .






Turing Machines p.33/37


Note

Sometimes it is difficult to distinguish a machine


that fail to reject from one that merely takes long-
time to halt.

Turing Machines p.34/37


Decider

A TM that halts on all inputs is called a decider.


Note: a decider always halts, accepting or reject-
ing its input.

Turing Machines p.35/37


Turing-decidability

A decider that recognizes some language is


also said to decide that language
A language is called Turing-decidable or
simple decidable if some TM decides it.

Turing Machines p.36/37


Note

Every decidable language is


Turing-recognizable
Remember: a language is Turing-recognizable
if it is recognized by a TM , i.e :




accepts or 
rejects or is looping


on .


Certain Turing-recognizable languages are


not decidable
Remember: to be decidable means to be
decided by a TM which halts on all inputs, i.e.,
: accepts or rejects .





Turing Machines p.37/37
Examples of Turing Machines

Examples of Turing Machines p.1/22


Higher level descriptions

We can give a formal description to a


particular TM by specifying each of its seven
components
This way a TM can become cumbersome.
Note:To avoid this we use higher level
descriptions which are precise enough for the
purpose of understanding
However, every higher level description is
actually just a short hand for its formal
counterpart.
Examples of Turing Machines p.2/22

Contrast: identify a similar situation with real com-


Example 1

Describe a TM that recognizes the language


 







= "On input string :


1. Sweep left to right across the tape crossing off every other

2. If in stage 1 tape contained a single , accept

3. If in stage 1 tape contained more that a single and the number

of s was odd, reject


4. Return the head to the left-hand of the tape


5. Go to stage 1"

Examples of Turing Machines p.3/22


Analysis

At each iteration, stage 1 cuts the number of


s in half.


If the resulting number of s is odd and


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


number of zeros must have been a power of


2, so machine accepts.






Rationale:
















Hence, if it means that .







Examples of Turing Machines p.4/22






Formal description of


where:




 

























 










 




 






 


is described in Figure 1


The start, accept, reject are , ,

 







respectively

Examples of Turing Machines p.5/22


 
   

 


Figure 1:

 








   

State diagram of

 


 

 
 
  

 

! "!
 !  

 !










 
 

  
s state transition diagram
Examples of Turing Machines p.6/22
Notations


is denoted by an arrow that starts at , ends at


 

 

 




, and is labeled by

 




is denoted by an arrow that starts at , ends at


 

 

 




, and is labeled by

 




is denoted by an arrow that starts at



, ends at
 

 

 

, and is labeled by






is denoted by an arrow that starts at , ends at



  

 


 



, and is labeled by



Examples of Turing Machines p.7/22



 
   
  


  





 

On input
 



   


 

 
  
  
 

   
   



 

 


Example run





:

 




  
   


  

 
 


 

 

  

 

 
  
  


 
 


 


 


 
  
   


 
  




  

   
Examples of Turing Machines p.8/22
Comments

The arrow labeled in means

 








 
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

Examples of Turing Machines p.9/22


Example 2


is the TM that decides




 
















 




the language













 

 












 

 


,




 










is described in Figure 2


Start, accept, and reject states are ,

 

 




respectively

Examples of Turing Machines p.10/22


High-level description of


= "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"

Note: High-level descriptions of TM-s are also


called implementation descriptions.
Examples of Turing Machines p.11/22
 



  


   


 

 

  




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

implement the matching operation Examples of Turing Machines p.13/22


Note

The transition diagram in Figure 2 is rather


complex.
One can understand better what happens
from the high-level description than from
Figure 2.
Therefore further we will replace transition
diagrams by high-level descriptions, as
initially suggested

Examples of Turing Machines p.14/22


Example 3

is a Turing machine that performs some




elementary arithmetic. It decides the language



















="On input string

1. Scan the input from left to right to be sure that it is a member of


; reject if it is not



2. Return the head at the left-hand end of the tape


3. Cross off an and scan to the right until a occurs. Shuttle




between the s and s crossing off one of each until all s are





gone. If all s have been crossed of and some s remain reject.




4. Restores the crossed off s and repeat stage 3 if there is another




to cross off. If all s are crossed off, determine whether all s





are crossed off. If yes accept, otherwise reject." Examples of Turing Machines p.15/22
Analyzing

In stage 1 operates as a finite automaton;


no writing is necessary as the head moves
from left to right:


1. , ,















  




2. , ,



















3. , ,





  



  

 


 


Examples of Turing Machines p.16/22


Stage 2 finding the left-hand end

Mark the left-hand end by writing a before


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

Stage 3 and stage 4 of have straightforward


implementations

Examples of Turing Machines p.18/22


Element distinctness problem

 


Given a list of strings over separated by ,



determine if all strings are different.
A TM that solves this problem accepts the
language


 




















Examples of Turing Machines p.19/22


Example 4


is the TM that solves






 










the element distinctness problem
works by comparing with , then by










comparing with , and so on












Examples of Turing Machines p.20/22


Informal description

="On input :

1. Place a mark on top of the leftmost tape symbol. If that symbol


was a blank, accept. If that symbol was a continue with the next


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


to the after that. If no is available for the rightmostExamples


mark, all


of Turing Machines p.21/22

strings have been compared, so accept.


Marking tape symbols

In stage two the machine places a mark


above a symbol, in this case.
In the actual implementation the machine has
two different symbols, and in the tape
alphabet


Thus, when machine places a mark above


symbol it actually writes the marked symbol


of at that location


Removing the mark means write the symbol


at the location where the marked symbol was.
Examples of Turing Machines p.22/22

Potrebbero piacerti anche