9780324788594_PPT_ch12

Invitation to Computer Science
5th Edition
Chapter 12
Models of Computation
Objectives
In this chapter, you will learn about:
• What a model is
• A model of a computing agent
• A model of an algorithm
• Turing machine examples
• The Church-Turing thesis
• Unsolvable problems
Invitation to Computer Science, 5th Edition
2
Introduction
• There are problems that do not have any
algorithmic solution!
• Algorithms
– Carried out by computing agents
Invitation to Computer Science, 5th Edition
3
What Is a Model?
• Models
–
–
–
–
Capture the essence of the real thing
Probably differ in scale from the real thing
Omit some of the details of the real thing
Lack the full functionality of the real thing
Invitation to Computer Science, 5th Edition
4
A Model of a Computing Agent
• Computing agent should be able to:
–
–
–
–
Accept input
Store information in and retrieve it from memory
Take actions according to algorithm instructions
Produce output
Invitation to Computer Science, 5th Edition
5
The Turing Machine
• Turing machine
– Includes a (conceptual) tape that extends infinitely in
both directions
• Alphabet for a given Turing machine
– Always contains a special symbol b (for “blank”)
– Usually contains the symbols 0 and 1 and
sometimes a limited number of other symbols
Invitation to Computer Science, 5th Edition
6
Figure 12.1 A Turing Machine Tape
Invitation to Computer Science, 5th Edition
7
Figure 12.2 A Turing Machine Configuration
Invitation to Computer Science, 5th Edition
8
Figure 12.3 The Next Turing Machine Configuration after
Executing One Instruction
Invitation to Computer Science, 5th Edition
9
The Turing Machine (continued)
• Turing machine
– Can execute a whole sequence of instructions
• Clock governs the action of the machine
–
–
–
–
Can accept input
Can store information in and retrieve it from memory
Can take actions according to algorithm instructions
Can produce output
Invitation to Computer Science, 5th Edition
10
A Model of an Algorithm
• An algorithm must:
– Be a well-ordered collection
– Consist of unambiguous and effectively computable
operations
– Halt in a finite amount of time
– Produce a result
Invitation to Computer Science, 5th Edition
11
Turing Machine Examples
• Turing machine
– Must begin in state 1 on the leftmost nonblank cell
– Machine state 1 must be a state in which 0s are
changed to 1s and 1s are changed to 0s
Invitation to Computer Science, 5th Edition
12
A Bit Inverter
• State diagram
– Visual representation of a Turing machine algorithm
– Circles represent states, and arrows represent
transitions from one state to another
Invitation to Computer Science, 5th Edition
13
Figure 12.4 State Diagram for the Bit
Inverter Machine
Invitation to Computer Science, 5th Edition
14
A Parity Bit Machine
• Odd parity bit
– Extra bit
– Can be attached to the end of a string of bits
Invitation to Computer Science, 5th Edition
15
A Parity Bit Machine (continued)
• The Turing machine program
– (1,1,1,2,R) Even parity state reading 1, change state
– (1,0,0,1,R) Even parity state reading 0, don’t
change state
– (2,1,1,1,R) Odd parity state reading 1, change state
– (2,0,0,2,R) Odd parity state reading 0, don’t change
state
– (1,b,1,3,R) End of string in even parity state, write 1
and go to state 3
– (2,b,0,3,R) End of string in odd parity state, write 0
and go to state 3
Invitation to Computer Science, 5th Edition
16
Figure 12.5 State Diagram for the Parity Bit Machine
Invitation to Computer Science, 5th Edition
17
Machines for Unary Incrementing
• Unary representation of numbers
– Any unsigned whole number n is encoded by a
sequence of n + 1 1s
• Incrementer
– Turing machine that adds 1 to any number
• Turing machine for the incrementer
(1,1,1,1,R) Pass to the right over 1s
(1,b,1,2,R) Add a single 1 at the righthand end of
the string
Invitation to Computer Science, 5th Edition
18
Figure 12.6 State Diagram for Incrementer
Invitation to Computer Science, 5th Edition
19
Machines for Unary Incrementing
(continued)
• The Turing machine program for:
– (1,1,1,1,L) Pass to the left over 1s
– (1,b,1,2,L) Add a single 1 at the lefthand end of the
string
Invitation to Computer Science, 5th Edition
20
Figure 12.7 Time Efficiency for Two Turing
Machine Algorithms for Incrementing
Invitation to Computer Science, 5th Edition
21
A Unary Addition Machine
• Turing machine
– Can be written to perform the addition of two
numbers
• Turing machine program
–
–
–
–
(1,1,b,2,R)
(2,1,b,3,R)
(3,1,1,3,R)
(3,b,1,4,R)
Erase the leftmost 1 and move right
Erase the second 1 and move right
Pass over any 1s until a blank is found
Write a 1 over the blank and halt
Invitation to Computer Science, 5th Edition
22
Figure 12.8 State Diagram for the Addition Machine
Invitation to Computer Science, 5th Edition
23
The Church-Turing Thesis
• Church-Turing Thesis
– If there exists an algorithm to do a symbol
manipulation task, then there exists a Turing
machine to do that task
• Thesis
– Statement advanced for consideration and
maintained by argument
• Theorem
– Ideas that can be proved in a formal, mathematical
way
Invitation to Computer Science, 5th Edition
24
Figure 12.9 Emulating an Algorithm by a Turing Machine
Invitation to Computer Science, 5th Edition
25
Unsolvable Problems
• Problem to investigate
Decide, given any collection of Turing machine
instructions together with any initial tape contents,
whether that Turing machine will ever halt if started
on that tape
Invitation to Computer Science, 5th Edition
26
Figure 12.10 Hypothetical Turing Machine P Running on T* and t
Invitation to Computer Science, 5th Edition
27
Figure 12.11 Hypothetical Turing Machine Q Running
on T* and t
Invitation to Computer Science, 5th Edition
28
Figure 12.12 Hypothetical Turing Machine S Running on S*
Invitation to Computer Science, 5th Edition
29
Unsolvable Problems (continued)
• Unsolvable problems, related to the halting
problem, have the following consequences
– No program can be written to decide whether any
given program always stops eventually, no matter
what the input
– No program can be written to decide whether any
two programs are equivalent
– No program can be written to decide whether any
given program run on any given input will ever
produce some specific output
Invitation to Computer Science, 5th Edition
30
Summary
• Models are an important way of studying physical
and social phenomena
• Church-Turing thesis
– If there exists an algorithm to do a symbol
manipulation task, then there exists a Turing
machine to do that task
• Turing machine
– Can be accepted as an ultimate model of a
computing agent
Invitation to Computer Science, 5th Edition
31
Summary (continued)
• Turing machine program
– Can be accepted as an ultimate model of an
algorithm
• Turing machines
– Define the limits of computability
• Uncomputable or unsolvable problem
– We can prove that no Turing machine exists to solve
the problem
Invitation to Computer Science, 5th Edition
32