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

09StdTuring Part1

The document describes the Turing machine, including: 1) It defines the standard Turing machine model with a tape, read/write head, finite state control, and transition function. 2) Turing machines can act as language acceptors by placing the input string on the tape and transitioning to an accepting state if the string is accepted. 3) An example Turing machine is provided that accepts the language of strings with an equal number of a's and b's.

Uploaded by

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

09StdTuring Part1

The document describes the Turing machine, including: 1) It defines the standard Turing machine model with a tape, read/write head, finite state control, and transition function. 2) Turing machines can act as language acceptors by placing the input string on the tape and transitioning to an accepting state if the string is accepted. 3) An example Turing machine is provided that accepts the language of strings with an equal number of a's and b's.

Uploaded by

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

Chapter 9

The Turing Machine



The Standard Turing Machine
• Definition of a Turing Machine
• Turing Machines as Language
Accepters
• Turing Machines as Transducers

Combining Turing Machines for
Complicated Tasks

Turing's Thesis
Automata
A Finite Automaton has only its states to serve as
memory - very limited in what languages it could
recognize
In a Pushdown Automaton we added a stack to a Finite
Automaton - this gave it better memory, and allowed
it to recognize more languages. But it was still
limited by the nature of the stack.
We could add another stack to a Pushdown Automaton.
This would allow it to accept some non-context free
languages (e.g., anbncn )
Or we could change the stack to a queue. This would
allow other languages to be accepted (e.g., ww).
All of the automata we study in this subject have a
finite number of states.
They differ in the “auxiliary memory” they have and
how it is organized.

DFA finite memory


NFA

DPDA infinite stack memory


PDA

Turing machine infinite tape memory


(tape can be read forwards and
backwards without erasing)
Hierarchy of automata

DTM, NTM

LBA
PDA
DPDA
DFA,
NFA
The Turing Machine
Alan Mathison Turing, b. 1912, d. 1954. Contributed
much to the foundations of computing theory.
Published the Turing machine model in 1937.
Church-Turing Thesis - “Any algorithmic procedure that
can be carried out by a human, a team of humans, or a
machine can be carried out by some Turing machine.”
Unproveable, because we don’t have a precise definition
of what “algorithmic procedure” means, but generally
accepted as true.
Puts a limit on what can be computed.
Alan Turing
• One of the first to conceive a machine
that can run computation
mechanically without human
intervention. We call “algorithmic
computation” now.
• The first to conceive a universal
machine – that can run programs
• Break German Enigma Machine 1912-1954
(encryption) in WWII
• Turing Award: the most prestigious
award in CS
• Bio movie: The Imitation Game, 2015
Turing machine's storage is actually quite simple. It
can be visualized as a single, one-dimensional
array of cells, each of which can hold a single
symbol.
– This array extends indefinitely in both directions
and is therefore capable of holding an unlimited
amount of information.
– The information can be read and changed in any
order.
– We will call such a storage device a tape because
it is analogous to the magnetic tapes used in older
computers.
The Standard Turing Machine
Definition: Turing Machine
The tape on a Turing machine can be thought of as a
linear structure marked off into squares or cells. It is
usually defined as infinite in both directions, but may
be thought of as bounded on the left side, but infinite
on the right. Each cell on the tape on a Turing
machine can hold a symbol from the input alphabet, a
symbol from the tape alphabet (which may include
some symbols which are not in the input alphabet), or
a blank symbol which is distinct from the input
alphabet.
The TM tape head

•The Turing machine has a tape head which reads


from and writes to the tape during each move.
•The tape head can move right or left, or may stay
in the same position.
•The tape head can read a character from the cell
under which it is positioned, or it may write a
character to the cell.
The TM transition function
The TM transition function has the following
form:
(q, X) = (r, Y, D),
This is a partial function
This says that when the TM is in state q, and the
read-write head reads a certain symbol (X) off the
tape, then the TM will change state to state r, write
a Y onto the tape, and move in direction D.
For example, (q1, b) = (q2, , R) means: “We are
currently in state q1; read the cell; it’s a b. now
change state to q2, write a blank, and move right.”b
The TM transition function

The TM transition function can be represented in


the form of a table:

Current Current New New Direction


state symbol state symbol to move
q0 a q1  R
q1 b q2 a L
TM transition function
•We can label the arcs of a finite state machine to
indicate the moves of the TM:

/ , R
q0 q1

   
a b a
Consider a Turing machine with a move defined as follows:
δ(q 0 , a) = (q 1 , d, R)

Figure shows the situation (a) before the move and (b) after
the move.
Consider the Turing machine defined by
Q = {q 0 , q 1 },
Σ = {a, b},
Γ = {a, b, },
F = {q 1 }
where δ is defined as follows:
1. δ(q 0 , a) = (q 0 , b, R),
2. δ(q 0 , b) = (q 0 , b, R),
3. δ(q 0 , ) = (q 1 , , L).
Linz Figure 9 .3 shows a sequence of moves for this Turing machine:
• It begins in state q 0 with the input positioned over an a.
• When an a is read, transition rule 1 fires, replaces a by b on the tape,
moves right, and stays in state q 0 .
• When a b is read, transition rule 2 fires, leaves b on the tape, moves right,
and stays in state q 0 .
• It continues moving right, replacing each a by a b and leaving each b
unchanged.
• When a blank ( ) is read, transition rule 3 fires, leaves the blank on the
tape, moves left, and enters final state q 1 .
Transition Graph for Turing Machine
we can use transition graphs to represent Turing machines.
We label the edges of the graph with a triple giving (1) the
current tape symbol, (2) the symbol that replaces it, and (3)
the direction in which the read-write head moves.

T G for above example TG for inifinite loop


A standard Turing machine:
1. has a tape that is unbounded in both directions, allowing
any number of left and right moves
2. is deterministic in that δ defines at most one move for
each configuration
3. has no special input or output files. At the initial time,
the tape has some specified content, some of which is
considered input. Whenever the machine halts, some
or all of the contents of the tape is considered output.
Turing Machine as Language
accepters
To process a string, we place the string onto the
tape, where it can be read by the read-write head,
surrounded by blank symbols on the left and right
ends of the input. Once the string is on the tape,
then processing can begin. We don’t need a
separate input string after that.
Accepting a string
There is only one way that a string may be
accepted by a TM: If a move causes the machine
to move into an accepting halt state, then we stop
and accept the string. (There are no moves out of a
halt state.)
This may occur even when we haven’t finished
processing the string yet.
For example, if our TM is processing all the strings
that have aabb in them somewhere, the TM may
halt after processing the 6th character of this string:
bbaabbaaaabbbb
A Turing machine is said to halt whenever it
reaches a configuration for which δ is not
defined; this is possible because δ is a partial
function.
In fact, we will assume that no transitions are
defined for any final state, so the Turing
machine will halt whenever it enters a final
state.
Accepting a string

If T = (Q, , q0, , F) is a Turing machine, and


w  +, w is accepted by T if, starting in the initial
configuration corresponding to input w, T
eventually enters a final acceptance state and halts.
In other words, w is accepted if there exists y and z
* so that
q0w |-T* yqfz, for some qf F
In this situation, we say that T halts on input w.
The language accepted by T is the set L(T) of input
strings on which T halts.
Definition 9.3
Let M= (Q,Σ,Γ,δ;q 0 , ,F) be a Turing machine. Then the
language accepted by M is
Crashing and Halting

There are 2 ways a string may fail to be accepted by a


TM:
1. Crashing
a. If a symbol is found on the tape for which the transition
function is undefined, and the current state is not the
accepting halt state, then we crash.
b. If our TM has a bounded left end, and a move is
specified which causes the machine to move off of the
left end of the tape, then we crash.
2. Looping
a. If an input string causes the TM to enter an infinite
loop, then we loop forever.
If the TM crashes, the string is explicitly rejected.
Exercises
Design a TM that accepts L = {anbn | n  1}
To do this, we can construct the transition
table for the TM. We can use a matrix as a
short-hand representation:
{anbn | n  1}
a b x y
q0
q1,x,R q3,y,R

q1 q1,a,R q2,y,L q1,y,R

q2 q2,a,L q0,x,R q2,y,L

q3 q3,y,R q4, ,R

q4
{anbn | n  1}
 Replace leftmost a with an x and find the first b and
replace with a y:
(q0,a)=(q1,x,R) (q1,y)=(q1,y,R)
(q1,a)=(q1,a,R) (q1,b)=(q2,y,L)
 Come back to the next left-most a:
(q2,y)=(q2,y,L) (q2,x)=(q0,x,R)
(q2,a)=(q2,a,L)
 Finally, check to see if all input has been processed and the
a’s and b’s balance (and a’s precede the b’s):
(q0,y)= (q3,y,R) (q3, Δ) = (q4, Δ,R)
(q3,y) = (q3,y,R)
Another Turing Machine
Example
Turing machine for the language
n n
{a b }

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 0 ⋄ a a b b ⋄ ⋄

q0

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 1 ⋄ x a b b ⋄ ⋄

q1

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 2 ⋄ x a b b ⋄ ⋄

q1

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 3 ⋄ x a y b ⋄ ⋄

q2

q4 y → y,R y → y,L
y → y,R
a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 4 ⋄ x a y b ⋄ ⋄

q2

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 5 ⋄ x a y b ⋄ ⋄

q0

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 6 ⋄ x x y b ⋄ ⋄

q1

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 7 ⋄ x x y b ⋄ ⋄

q1

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 8 ⋄ x x y y ⋄ ⋄

q2

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 9 ⋄ x x y y ⋄ ⋄

q2

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 10 ⋄ x x y y ⋄ ⋄

q0

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 11 ⋄ x x y y ⋄ ⋄

q3

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 12 ⋄ x x y y ⋄ ⋄

q3

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Time 13 ⋄ x x y y ⋄ ⋄

q4

Halt & Accept

q4 y → y,R y → y,L
y → y,R a → a,R a → a ,L
⋄ → ⋄ ,L

y → y,R a → x,R b → y,L


q3 q0 q1 q2

x → x,R
Observation:

If we modify the
machine for the language n n
{a b }

we can easily construct


a machine for the language n n n
{a b c }
Exercises
 Recall that the following languages are not
context-free.
– {anbncn | n  0}
– {ww | w  {a,b}*}
 In English, describe how a Turing machine
could accept each of these languages
 Try to draw the transition diagrams for the
Turing machines
{anbncn | n  1}

a b c x y z Δ
q0
q1,x,R q4,y,R

q1 q1,a,R q2,y,R q1,y,R

q2 q2,b,R q3,z,L q2,z,R

q3 q3,a,L q3,b,L q0,x,R q3,y,L q3,z,L

q4 q4,y,R q4,z,R q4,Δ,R


In other words:

A function f is computable if
there is a Turing Machine M such that:

qf f (w )

Initial Final
Configuration Configuration

For all w∈D Domain


Turing Machines as Transducers
Turing machines are more than just language accepters.Turing
machines are transducers (as we defined them in Chapter 1).
For acomputation, the
• input consists of all the nonblank symbols on the tape
initially
• output consists of is whatever is on the tape when the
machine halts in a final state
Thus, we can view a Turing machine transducer M as a
implementation of a function f defined by

for some final state q f


In other words:
A function f is computable if
there is a Turing Machine M such that:
qf f (w )

Initial Final
Configuration Configuration
w ∈ D
For all Domain
Example
The function f ( x,y ) =x+y is computable

x,y are integers


We use unary notation to represent the positive integers, i.e., a positive
integer is represented by a sequence of 1’s whose length is equal to the
value of the integer. For example: 1111 = 4
Turing Machine:
Input string: x0 y unary
Output string: xy 0 unary

where 0 separates the two numbers at initiation and after the result at
termination
x y

Start ⋄ 1 1 ⋯ 1 0 1 ⋯ 1 ⋄

q0

initial state

The 0 is the delimiter that


separates the two numbers
x y

Start ⋄ 1 1 ⋯ 1 0 1 ⋯ 1 ⋄

q0 initial state

x+ y

Finish ⋄ 1 1 ⋯ 1 1 0 ⋄

qf final state
The 0 helps when we use
the result for other operations

x+ y

Finish ⋄ 1 1 ⋯ 1 1 0 ⋄

qf final state
Turing machine for function f ( x,y ) =x+y

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Execution Example: Time 0

x y
x= 11 (2)
⋄ 1 1 0 1 1 ⋄

y= 11 (2)
q0

Final Result

x+ y
⋄ 1 1 1 1 0 ⋄

q4
Time 0 ⋄ 1 1 0 1 1 ⋄

q0

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 1 ⋄ 1 1 0 1 1 ⋄

q0

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 2 ⋄ 1 1 0 1 1 ⋄

q0

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 3 ⋄ 1 1 1 1 1 ⋄

q1

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 4 ⋄ 1 1 1 1 1 ⋄

q1

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 5 ⋄ 1 1 1 1 1 ⋄

q1

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 6 ⋄ 1 1 1 1 1 ⋄

q2

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 7 ⋄ 1 1 1 1 0 ⋄

q3

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 8 ⋄ 1 1 1 1 0 ⋄

q3

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 9 ⋄ 1 1 1 1 0 ⋄

q3

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 10 ⋄ 1 1 1 1 0 ⋄

q3

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 11 ⋄ 1 1 1 1 0 ⋄

q3

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
q4
Time 12 ⋄ 1 1 1 1 0 ⋄

q4

1 → 1, R 1 → 1, R 1 → 1, L

q0 0 → 1, R q1 ⋄ → ⋄ ,L q2 1 → 0, L q3

⋄ → ⋄ ,R
HALT & accept q4
Combining Turing Machines
Block Diagram

Turing
input Machine output
You can combine several smaller TMs in order to make a
larger, more complicated TM.
The composite of two different TMs, T1 and T2, is written as
T1T2. It would be represented as:
T1  T2
What happens is that T1T2 begins by executing the moves of
T1, up to the point where T1 would halt. Instead of halting,
T1T2 moves to the initial state of T2, where it begins
executing the moves of T2.
If T2 halts, then T1T2 halts. If T1 or T2 crashes, then T1T2
crashes.
You can also make the transition to T2
conditional.
a
T1  T2
Here, T1 would execute its moves up to the
point where it would normally halt. If
the symbol on the tape at that point is an
a, then T1T2 will begin executing the
moves of T2. Otherwise T1T2 will crash
we can compose simpler operations on Turing machines to form
more complex operations

Design a Turing machine that computes the following function:


f (x, y) = x + y, if x ≥ y,
f (x, y) = 0, if x < y.

For simplicity, we assume x and y are positive integers in unary


representation and the value zero is represented by 0, with the rest of
the tape blank.

Figure shows a high-level block diagram of this computation. This


computation consists of a network of three simpler machines:
• a Comparer C to determine whether or not x ≥ y
• an Adder A that computes x + y
• an Eraser E that changes every 1 to a blank
Techniques discussed in this section include use of:
• Top-down stepwise refinement, i.e., starting with a high-level
description and refining it incrementally until we obtain a
description in the actual language
• Block diagrams or pseudocode to state high-level descriptions

*A simple kind of pseudocode is the macroinstruction. A


macroinstruction is a single statement shorthand for a sequence
of lower-level statements

* While each occurrence of a macroinstruction is expanded into


actual code, a subprogram is a single piece of code that is
invoked repeatedly.
Example:
x+ y if x> y

f ( x,y )=
0 if x≤ y

x,y
Adder x+ y

x,y x> y
Comparer

x≤ y Eraser 0
Turing’s Thesis
The Turing thesis is an hypothesis that any computation that can
be carried out by mechanical means can be performed by some
Turing machine.
This is a broad assertion. It is not something we can prove!
The Turing thesis is actually a definition of mechanical
computation: a computation is mechanical if and only if it can be
performed by some Turing machine.
Some arguments for accepting the Turing thesis as the definition of
mechanical computation include:
1. Anything that can be computed by any existing digital computer
can also be computed by a Turing machine.
2. There are no known problems that are solvable by what we
intuitively consider an algorithm for which a Turing machine
program cannot be written.
3. No alternative model for mechanical computation is more
powerful than the Turing machine model.
Definition 9.5 (Algorithm):
An algorithm for a function f : D → R isa Turing machine M ,
which given as input any d ∈ D on its tape, eventually halts with the
correct answer f (d) ∈ R on its tape. Specifically, we can require
that

for all d ∈ D.
To prove that “there exists an algorithm”, we can construct a Turing
machine that computes the result

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy