SlideShare a Scribd company logo
12.2 The Halting Problem
Godel established that no interesting and consistent axiomatic system is capable
of proving all true statements in the system.
Now we consider the analogous question for computing: are there problems for which
no algorithm exists?
Recall these definitions form Chapters 1and 4:
problem: A description of an input and a desired output.
procedure: A specification of a series of actions.
algorithm: A procedure that is guaranteed to always terminate.
A procedure solves a problem if that procedure produces a correct output for
every possible input. If that procedure always terminates, it is an algorithm.
So, the question can be stated as: are there problems for which no procedure exists that
produces the correct output for every possible problem instance in a finite amount of
time?
A problem is computable if there exists an algorithm that solves the problem. It is
important to remember that in order for an algorithm to be a solution for a problem PP,
it must always terminate (otherwise it is not an algorithm) and must always produce the
correct output for all possible inputs to PP.
If no such algorithm exists, the problem is noncomputable.1 are sometimes used to
mean the same things as computable and noncomputable.}
Alan Turing proved that noncomputable problems exist. The way to show
that uncomputable problems exist is to find one, similarly to the way Godel
showed unprovable true statements exist by finding an unprovable true statement.
The problem Turing found is known as the Halting Problem:2
Halting ProblemHalting Problem
Input: A string representing a Python program.
Output: If evaluating the input program would ever finish, output True.
Otherwise, output False.
Suppose we had a procedure halts that solves the Halting Problem. The input tohalts is a
Python program expressed as a string.
For example, halts('(+ 2 3)') should evaluate to True, halts('while True: pass')
should evaluate to False (the Python pass statement does nothing, but is needed to
make the while loop syntactically correct), and
halts('''''' def fibo(n):
if n == 1 or n == 2: return 1
else: return fibo(n-1) + fibo(n-2) fibo(60)
'''''')
should evaluate to True. From the last
example, it is clear that halts cannot be
implemented by evaluating the expression and
outputting True if it terminates.
The problem is knowing when to give up and output False. As we analyzed inChapter 7,
evaluating fibo(60) would take trillions of years; in theory, though, it eventually finishes
so halts should output True.
This argument is not sufficient to prove that halts is noncomputable. It just shows that
one particular way of implementing halts would not work.
To show that halts is noncomputable, we need to show that it is impossible to implement
a halts procedure that would produce the correct output for all inputs in a finite amount
of time.
Here is another example that suggests (but does not prove) the
impossibility ofhalts (where sumOfTwoPrimes is defined as an algorithm that take a
number as input and outputs True if the number is the sum of two prime numbers
andFalse otherwise):
halts('n = 4; while sumOfTwoPrimes(n): n = n + 2')
This program halts if there exists an even number greater than 2 that is not the sum of
two primes.
We assume unbounded integers even though every actual computer has a limit on the
largest number it can represent.
Our computing model, though, uses an infinite tape, so there is no arbitrary limit
on number sizes.
Knowing whether or not the program halts would settle an open problem known
as Goldbach's Conjecture: every even integer greater than 2 can be written as the sum
of two primes.
Christian Goldbach proposed a form of the conjecture in a letter to Leonhard Euler in
1742. Euler refined it and believed it to be true, but couldn't prove it.
With a halts algorithm, we could settle the conjecture using the expression above: if the
result is False, the conjecture is proven; if the result is True, the conjecture is disproved.
We could use a halts algorithm like this to resolve many other open problems.
This strongly suggests there is no halts algorithm, but does not prove it cannot exist.
Proving Noncomputability. Proving non-existence is requires more than
just showing a hard problem could be solved if something exists.
One way to prove non-existence of an XX, is to show that if an XX exists it leads to a
contradiction. We prove that the existence of a halts algorithm leads to a contradiction,
so nohalts algorithm exists.
We obtain the contradiction by showing one input for which the halts procedure could
not possibly work correctly. Consider this procedure:
Defparadox():
if halts('paradox()'): while True: pass
The body of the paradox procedure is an if expression. The consequent expression is a
never-ending loop.
The predicate expression cannot sensibly evaluate to either True or False:
halts(paradox()) ⇒⇒ True: If the predicate expression evaluates to True, the consequent
block is evaluated producing a never-ending loop. Thus, ifhalts('paradox()') evaluates
to True, the evaluation of an application ofparadox never halts. But, this means the result
of halts('paradox()') was incorrect.
halts(paradox()) ⇒⇒ False: If the predicate expression evaluates to False, the
alternate block is evaluated. It is empty, so evaluation terminates. Thus, the
evaluation of paradox() terminates, contradicting the result ofhalts('paradox()').
Either result for halts('paradox()') leads to a contradiction! The only
sensible thing halts could do for this input is to not produce a value. That means
there is no algorithm that solves the Halting Problem.
Any procedure we define to implement halts must sometimes either produce the wrong
result or fail to produce a result at all (that is, run forever without producing a result).
This means the Halting Problem is noncomputable.
There is one important hole in our proof: we argued that because paradox does not make
sense, something in the definition of paradox must not exist and identified halts as
the component that does not exist. This assumes that everything else we
used to define paradox does exist.
This seems reasonable enough---they are built-in to Python so they seem to exist. But,
perhaps the reason paradox leads to a contradiction is because True does not really exist
or because it is not possible to implement an if expression that strictly follows
the Python evaluation rules.
Although we have been using these and they seems to always work fine, we have
no formal model in which to argue that evaluating True always terminates or that
an if expression means exactly what the evaluation rules say it does.
Our informal proof is also insufficient to prove the stronger claim that no
algorithm exists to solve the halting problem.
All we have shown is that no Python procedure exists that solves halts. Perhaps there is
a procedure in some more powerful programming language in which it is possible
to implement a solution to the Halting Problem. In fact, we will see that no more
powerful programming language exists.
A convincing proof requires a formal model of computing. This is why Alan
Turing developed a model of computation.
All we have shown is that no Python procedure exists that solves halts. Perhaps there is
a procedure in some more powerful programming language in which it is possible
to implement a solution to the Halting Problem. In fact, we will see that no more
powerful programming language exists.
A convincing proof requires a formal model of computing. This is why Alan
Turing developed a model of computation.

More Related Content

PPTX
Class 36: Halting Problem
PDF
How invariants help writing loops
PPTX
Turing machine and Halting Introduction
PDF
Python If Else | If Else Statement In Python | Edureka
DOCX
C Control Statements.docx
PPTX
Turing Machine
PPT
2009 CSBB LAB 新生訓練
PDF
nuts and bolts of c++
Class 36: Halting Problem
How invariants help writing loops
Turing machine and Halting Introduction
Python If Else | If Else Statement In Python | Edureka
C Control Statements.docx
Turing Machine
2009 CSBB LAB 新生訓練
nuts and bolts of c++

What's hot (20)

PPTX
Python Programming Homework Help
PPTX
Cse lecture-6-c control statement
PPTX
Cse lecture-7-c loop
PDF
Volume 2-issue-6-2205-2207
PPTX
Flow of control by deepak lakhlan
PDF
Skiena algorithm 2007 lecture01 introduction to algorithms
PDF
Invariant-Free Clausal Temporal Resolution
PPTX
5. using variables, data, expressions and constants
PPT
Flow of Control
PDF
Wade not in unknown waters. Part three.
PPTX
Program control statements in c#
PDF
Algorithms notes 2 tutorials duniya
PPTX
Conditionalstatement
PPT
05 Conditional statements
PDF
バンディット問題の理論とアルゴリズムとその実装
PPTX
Claguage 110226222227-phpapp02
PDF
Mp neuron
PDF
Formal Languages and Automata Theory Unit 1
Python Programming Homework Help
Cse lecture-6-c control statement
Cse lecture-7-c loop
Volume 2-issue-6-2205-2207
Flow of control by deepak lakhlan
Skiena algorithm 2007 lecture01 introduction to algorithms
Invariant-Free Clausal Temporal Resolution
5. using variables, data, expressions and constants
Flow of Control
Wade not in unknown waters. Part three.
Program control statements in c#
Algorithms notes 2 tutorials duniya
Conditionalstatement
05 Conditional statements
バンディット問題の理論とアルゴリズムとその実装
Claguage 110226222227-phpapp02
Mp neuron
Formal Languages and Automata Theory Unit 1
Ad

Similar to the halting_problem (20)

PDF
An Explanation of the Halting Problem and Its Consequences
PPTX
HALTER PROBLEM IN THEORY OF COMPUTATION.pptx
PPT
Halting Problemof P vesus NP Problems in TOC
PPTX
Incompleteness without Godel Numberings
PPTX
4.6 halting problem
PDF
Undecidabality
PPTX
COMPLEXITY CHAPTER 3 LECTURE FOR FOURTH YEAR.pptx
PPT
proving non-computability
PPT
compatibility and complexity in the IS.ppt
DOCX
Types of Turing Machine .docx
PDF
Impossible Programs
PPTX
Class 35: Self-Reference
PDF
talkx.pdf
DOCX
theory of computation notes for school of engineering
PPTX
Limits of Computation
PPTX
The Limits of Computation
PDF
Computability
PPTX
chapter 2.pptx
PDF
slides3.pdf
PDF
Can machine think like human being : A Godelian perspective
An Explanation of the Halting Problem and Its Consequences
HALTER PROBLEM IN THEORY OF COMPUTATION.pptx
Halting Problemof P vesus NP Problems in TOC
Incompleteness without Godel Numberings
4.6 halting problem
Undecidabality
COMPLEXITY CHAPTER 3 LECTURE FOR FOURTH YEAR.pptx
proving non-computability
compatibility and complexity in the IS.ppt
Types of Turing Machine .docx
Impossible Programs
Class 35: Self-Reference
talkx.pdf
theory of computation notes for school of engineering
Limits of Computation
The Limits of Computation
Computability
chapter 2.pptx
slides3.pdf
Can machine think like human being : A Godelian perspective
Ad

More from Rajendran (20)

PPT
Element distinctness lower bounds
PPT
Scheduling with Startup and Holding Costs
PPT
Divide and conquer surfing lower bounds
PPT
Red black tree
PPT
Hash table
PPT
Medians and order statistics
PPT
Proof master theorem
PPT
Recursion tree method
PPT
Recurrence theorem
PPT
Master method
PPT
Master method theorem
PPT
Hash tables
PPT
Lower bound
PPT
Master method theorem
PPT
Greedy algorithms
PPT
Longest common subsequences in Algorithm Analysis
PPT
Dynamic programming in Algorithm Analysis
PPT
Average case Analysis of Quicksort
PPT
Np completeness
PPT
computer languages
Element distinctness lower bounds
Scheduling with Startup and Holding Costs
Divide and conquer surfing lower bounds
Red black tree
Hash table
Medians and order statistics
Proof master theorem
Recursion tree method
Recurrence theorem
Master method
Master method theorem
Hash tables
Lower bound
Master method theorem
Greedy algorithms
Longest common subsequences in Algorithm Analysis
Dynamic programming in Algorithm Analysis
Average case Analysis of Quicksort
Np completeness
computer languages

Recently uploaded (20)

PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
1_English_Language_Set_2.pdf probationary
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
IGGE1 Understanding the Self1234567891011
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Trump Administration's workforce development strategy
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
HVAC Specification 2024 according to central public works department
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
Computer Architecture Input Output Memory.pptx
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Empowerment Technology for Senior High School Guide
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
1_English_Language_Set_2.pdf probationary
Paper A Mock Exam 9_ Attempt review.pdf.
IGGE1 Understanding the Self1234567891011
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
TNA_Presentation-1-Final(SAVE)) (1).pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Trump Administration's workforce development strategy
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
What if we spent less time fighting change, and more time building what’s rig...
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
HVAC Specification 2024 according to central public works department
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Computer Architecture Input Output Memory.pptx
Hazard Identification & Risk Assessment .pdf
Empowerment Technology for Senior High School Guide
Indian roads congress 037 - 2012 Flexible pavement
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf

the halting_problem

  • 1. 12.2 The Halting Problem Godel established that no interesting and consistent axiomatic system is capable of proving all true statements in the system. Now we consider the analogous question for computing: are there problems for which no algorithm exists? Recall these definitions form Chapters 1and 4: problem: A description of an input and a desired output. procedure: A specification of a series of actions. algorithm: A procedure that is guaranteed to always terminate. A procedure solves a problem if that procedure produces a correct output for every possible input. If that procedure always terminates, it is an algorithm. So, the question can be stated as: are there problems for which no procedure exists that produces the correct output for every possible problem instance in a finite amount of time? A problem is computable if there exists an algorithm that solves the problem. It is important to remember that in order for an algorithm to be a solution for a problem PP, it must always terminate (otherwise it is not an algorithm) and must always produce the correct output for all possible inputs to PP. If no such algorithm exists, the problem is noncomputable.1 are sometimes used to mean the same things as computable and noncomputable.}
  • 2. Alan Turing proved that noncomputable problems exist. The way to show that uncomputable problems exist is to find one, similarly to the way Godel showed unprovable true statements exist by finding an unprovable true statement. The problem Turing found is known as the Halting Problem:2 Halting ProblemHalting Problem Input: A string representing a Python program. Output: If evaluating the input program would ever finish, output True. Otherwise, output False. Suppose we had a procedure halts that solves the Halting Problem. The input tohalts is a Python program expressed as a string. For example, halts('(+ 2 3)') should evaluate to True, halts('while True: pass') should evaluate to False (the Python pass statement does nothing, but is needed to make the while loop syntactically correct), and halts('''''' def fibo(n): if n == 1 or n == 2: return 1 else: return fibo(n-1) + fibo(n-2) fibo(60) '''''') should evaluate to True. From the last example, it is clear that halts cannot be implemented by evaluating the expression and outputting True if it terminates. The problem is knowing when to give up and output False. As we analyzed inChapter 7, evaluating fibo(60) would take trillions of years; in theory, though, it eventually finishes so halts should output True.
  • 3. This argument is not sufficient to prove that halts is noncomputable. It just shows that one particular way of implementing halts would not work. To show that halts is noncomputable, we need to show that it is impossible to implement a halts procedure that would produce the correct output for all inputs in a finite amount of time. Here is another example that suggests (but does not prove) the impossibility ofhalts (where sumOfTwoPrimes is defined as an algorithm that take a number as input and outputs True if the number is the sum of two prime numbers andFalse otherwise): halts('n = 4; while sumOfTwoPrimes(n): n = n + 2') This program halts if there exists an even number greater than 2 that is not the sum of two primes. We assume unbounded integers even though every actual computer has a limit on the largest number it can represent. Our computing model, though, uses an infinite tape, so there is no arbitrary limit on number sizes. Knowing whether or not the program halts would settle an open problem known as Goldbach's Conjecture: every even integer greater than 2 can be written as the sum of two primes. Christian Goldbach proposed a form of the conjecture in a letter to Leonhard Euler in 1742. Euler refined it and believed it to be true, but couldn't prove it.
  • 4. With a halts algorithm, we could settle the conjecture using the expression above: if the result is False, the conjecture is proven; if the result is True, the conjecture is disproved. We could use a halts algorithm like this to resolve many other open problems. This strongly suggests there is no halts algorithm, but does not prove it cannot exist. Proving Noncomputability. Proving non-existence is requires more than just showing a hard problem could be solved if something exists. One way to prove non-existence of an XX, is to show that if an XX exists it leads to a contradiction. We prove that the existence of a halts algorithm leads to a contradiction, so nohalts algorithm exists. We obtain the contradiction by showing one input for which the halts procedure could not possibly work correctly. Consider this procedure: Defparadox(): if halts('paradox()'): while True: pass The body of the paradox procedure is an if expression. The consequent expression is a never-ending loop. The predicate expression cannot sensibly evaluate to either True or False: halts(paradox()) ⇒⇒ True: If the predicate expression evaluates to True, the consequent block is evaluated producing a never-ending loop. Thus, ifhalts('paradox()') evaluates to True, the evaluation of an application ofparadox never halts. But, this means the result of halts('paradox()') was incorrect.
  • 5. halts(paradox()) ⇒⇒ False: If the predicate expression evaluates to False, the alternate block is evaluated. It is empty, so evaluation terminates. Thus, the evaluation of paradox() terminates, contradicting the result ofhalts('paradox()'). Either result for halts('paradox()') leads to a contradiction! The only sensible thing halts could do for this input is to not produce a value. That means there is no algorithm that solves the Halting Problem. Any procedure we define to implement halts must sometimes either produce the wrong result or fail to produce a result at all (that is, run forever without producing a result). This means the Halting Problem is noncomputable. There is one important hole in our proof: we argued that because paradox does not make sense, something in the definition of paradox must not exist and identified halts as the component that does not exist. This assumes that everything else we used to define paradox does exist. This seems reasonable enough---they are built-in to Python so they seem to exist. But, perhaps the reason paradox leads to a contradiction is because True does not really exist or because it is not possible to implement an if expression that strictly follows the Python evaluation rules. Although we have been using these and they seems to always work fine, we have no formal model in which to argue that evaluating True always terminates or that an if expression means exactly what the evaluation rules say it does. Our informal proof is also insufficient to prove the stronger claim that no algorithm exists to solve the halting problem.
  • 6. All we have shown is that no Python procedure exists that solves halts. Perhaps there is a procedure in some more powerful programming language in which it is possible to implement a solution to the Halting Problem. In fact, we will see that no more powerful programming language exists. A convincing proof requires a formal model of computing. This is why Alan Turing developed a model of computation.
  • 7. All we have shown is that no Python procedure exists that solves halts. Perhaps there is a procedure in some more powerful programming language in which it is possible to implement a solution to the Halting Problem. In fact, we will see that no more powerful programming language exists. A convincing proof requires a formal model of computing. This is why Alan Turing developed a model of computation.