Halting Problem - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Halting Problem

Description:

We construct a program D (with one input of type unsigned int) with the following properties ... The number we use to distinguish program Py from D is this number y ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 21
Provided by: erict9
Learn more at: http://www.cse.msu.edu
Category:

less

Transcript and Presenter's Notes

Title: Halting Problem


1
Lecture 7
  • Halting Problem
  • Fundamental program behavior problem
  • A specific unsolvable problem
  • Diagonalization technique revisited
  • Proof more complex

2
Definition
  • Input
  • Program P
  • Assume the input to program P is a single
    unsigned int
  • This assumption is not necessary, but it
    simplifies some of the following unsolvability
    proof
  • To see the full generality of the halting
    problem, remove this assumption
  • Nonnegative integer x, an input for program P
  • Yes/No Question
  • Does P halt when run on x?

3
Example Input
  • Program with one input of type unsigned int
  • bool main(unsigned int Q)
  • int i2
  • if (Q 0) return false
  • while (iltQ)
  • if (Qi 0) return (false)
  • i
  • return (true)
  • Input x
  • 73

4
Proof that H is not solvable
5
Definition of list L
  • The set of all programs is countably infinite
  • For simplicity, assume these programs have
  • one input
  • the type of this input is an unsigned int
  • This means there exists a list L where
  • each program is on this list
  • the programs will appear on this list by order of
    length
  • length 0 programs first
  • length 1 programs next
  • Simpler compared to last time
  • We built an algorithm D to work with any
    countably infinite list
  • Now, we get to work with this specific list

6
Definition of PH
  • If H is solvable, some program must solve H
  • Let PH be a procedure which solves H
  • We declare it as a procedure because we will use
    PH as a subroutine
  • Declaration of PH
  • bool PH(program P, unsigned int x)
  • In general, the type of x should be the type of
    the input to P
  • Comments
  • We do not know how PH works
  • However, if H is solvable, we can build programs
    which call PH as a subroutine

7
Argument Overview
  • List L contains all programs (with one input of
    type unsigned int)
  • We use list L to specify a pattern of program
    behavior B which is distinct from all real
    program behaviors
  • We construct a program D (with one input of type
    unsigned int) with the following properties
  • D satisfies the specification of program behavior
    B and is thus not on list L
  • D uses PH as a subroutine which means D exists if
    PH exists
  • These two facts imply H is not solvable
  • Since L contains all programs but not D, D must
    not exist
  • Since D exists if PH exists, PH does not exist

8
Visualizing List L of Programs
0
1
2
3
4
...
  • Rows is countably infinite
  • Sp is countably infinite
  • Cols is countably infinite
  • Set of nonnegative integers is countably infinite

P0
P1
P2
P3
P4
...
  • Consider each number to be a feature
  • A program halts or doesnt halt on each integer
  • Several programs may be identical now (e.g.
    several always halt)
  • We have a fixed L this time

9
Specifying a non-existent program behavior B
  • We specify a non-existent program behavior B by
    using a unique feature
  • (number) to differentiate B from Pi

0
1
2
3
4
...
B
P0
NH
H
H
H
H
H
P1
NH
H
H
H
NH
H
P2
NH
NH
NH
NH
NH
H
P3
H
H
NH
NH
NH
H
P4
NH
H
H
H
H
H
...
10
Specification Insufficient
  • Task not complete
  • The previous slide only provides a specification
    B for program D
  • That is, B describes how program D should behave
    in order to not be on the list of all programs
  • We still need to construct an actual program D
    that behaves this way
  • Previous number of languages proof
  • The specification of language D(L) was sufficient
  • We were done at this point

11
Overview of D
  • Program D with input y
  • (type for y unsigned int)
  • Given input y, generate the program (string) Py
  • Run PH on Py and y
  • Guaranteed to halt since PH decides H
  • IF (PH(Py,y)) while (1gt0) else return (yes)

0
1
2
...
D
...
y
P0
H
H
H
P1
H
H
NH
P2
NH
NH
NH
...
Py
H
NH
...
12
Generating Py from y
  • We wont go into this in detail here
  • This was the basis of the question at the bottom
    of slide 21 of lecture 5.
  • This is the main place where our assumption about
    the input type for program P is important
  • for other input types, how to do this would vary

13
Observation
  • For some y, the computed Py of SP will not be a
    legal program
  • In particular, the computed Py will not be the
    yth legal program

0
1
2
...
D
...
i
y
l
H
H
H
a
H
H
NH
b
NH
NH
NH
...
...
P0
...
...
Pi-1
...
14
Code for D and PH
  • bool main(unsigned int y) / main for program D
    /
  • program P generate(y)
  • if (PH(P,y)) while (1gt0) else return (yes)
  • bool PH(program P, unsigned int x)
  • / how PH solves H is unknown /
  • Claims
  • Program D exhibits behavior B
  • Program D exists if PH exists

15
Alternate Proof
  • For every program Py, there is a number y which
    we associate with it
  • The number we use to distinguish program Py from
    D is this number y
  • Using this idea, we can arrive at a contradiction
    without explicitly using the table L
  • The diagonalization is hidden

16
H is not solvable, proof II
  • Assume H is solvable
  • Let PH be the program which solves H
  • Use PH to construct program D which cannot exist
  • Contradiction
  • This means program PH cannot exist.
  • This implies H is not solvable
  • D is the same as before

17
Arguing D cannot exist
  • If D is a program, it must have an associated
    number y
  • What does D do on this number y?
  • 2 cases
  • D halts on y
  • This means PH(D,y) NO
  • Definition of D
  • This means D does not halt on y
  • PH solves H
  • Contradiction
  • This case is not possible

18
Continued
  • D does not halt on this number y
  • This means PH(D,y) YES
  • Definition of D
  • This means D halts on y
  • PH solves H
  • Contradiction
  • This case is not possible
  • Both cases are not possible, but one must be for
    D to exist
  • Thus D cannot exist

19
Implications
  • The Halting Problem is one of the simplest
    problems we can formulate about program behavior
  • We can use the fact that it is unsolvable to show
    that other problems about program behavior are
    also unsolvable
  • This has important implications restricting what
    we can do in the field of software engineering
  • In particular, perfect debuggers/testers do not
    exist
  • We are forced to test programs for correctness
    even though this approach has many flaws

20
Summary
  • Halting Problem definition
  • Basic problem about program behavior
  • Halting Problem is unsolvable
  • We have identified a specific unsolvable problem
  • Diagonalization technique
  • Proof more complicated because we actually need
    to construct D, not just give a specification
Write a Comment
User Comments (0)
About PowerShow.com