Computability - PowerPoint PPT Presentation

About This Presentation
Title:

Computability

Description:

First shown by Alan Turing in 1936. Before digital computers existed! 8 ... { System.out.println('Alan Turing was a genius.'); 11. haltingTest2. public class ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 25
Provided by: Lapt266
Category:

less

Transcript and Presenter's Notes

Title: Computability


1
Computability
  • CS 101E
  • Spring 2007
  • Michele Co

2
So Far In Class
  • Weve seen the following programming constructs
  • if, if-else, if-else-if
  • switch
  • for
  • while
  • do-while
  • And
  • break
  • continue

These are powerful constructs that allow us
to express many computations
3
Can Computers be Programmed to Solve Any Problem?
  • Yes
  • No
  • Maybe

4
Can Humans Solve Any Problem?
  • Yes
  • No
  • Maybe

5
Epimenides Paradox
  • This statement is false.
  • Proof
  • Let A This statement is false.
  • Assume A is false
  • Then, A must be true
  • Assume A is true
  • Then, A is false
  • No matter what truth value assigned, a
    contradiction is reached!

6
The Halting Problem
7
The Halting problem
  • Given a program P, and input I, will the program
    P ever terminate?
  • Meaning will P(I) loop forever or halt?
  • Can a computer program determine this?
  • Can a human?
  • First shown by Alan Turing in 1936
  • Before digital computers existed!

8
Solving the Halting Problem
  • To solve the halting problem means we create a
    method CheckHalt(P,I)
  • P is the program we are checking for halting
  • I is the input to that program
  • And it will return loops forever or halts
  • Note it must work for any program, not just some
    programs

9
Can a human determine if a program halts?
  • Given a program of 10 lines or less, can a human
    determine if it halts?
  • Assuming no tricks the program is completely
    understandable
  • And assuming the computer works properly, of
    course
  • And we ignore the fact that an int will max out
    at 4 billion

10
haltingTest1
  • public class haltingTest1
  • public static void main(String args)
  • System.out.println("Alan Turing was a
    genius.")

11
haltingTest2
  • public class haltingTest2
  • public static void main(String args)
  • for (int factor 1 factor lt 10 factor )
  • System.out.println("Factor is " factor)

12
haltingTest3
  • public class haltingTest3
  • public static void main(String args)
  • while(true)
  • System.out.println("Hello world!")

13
haltingTest4
  • public class haltingTest4
  • public static void main(String args)
  • int x 10
  • while ( x gt 0 )
  • System.out.println(hello world)
  • x

14
Can Computers be Programmed to Solve Any Problem?
  • Yes
  • No
  • Maybe

15
Can Humans Solve Any Problem?
  • Yes
  • No
  • Maybe

16
Another Problem
  • Perfect Numbers

17
Perfect numbers
  • Numbers whose divisors (not including the number)
    add up to the number
  • 6 1 2 3
  • 28 1 2 4 7 14
  • The list of the first 10 perfect numbers6, 28,
    496, 8128, 33550336, 8589869056, 137438691328,
    2305843008139952128, 26584559915698317446546926159
    53842176, 1915619426082361072947933780843036381309
    97321548169216
  • The last one was 54 digits!
  • All known perfect numbers are even its an open
    (i.e. unsolved) problem if odd perfect numbers
    exist
  • Sequence A000396 in OEIS

18
Odd perfect number search
  • public class searchForOddPerfectNumber
  • public static void main(String args)
  • int n 1 // arbitrary-precision
    integer
  • while (true)
  • int sumOfFactors 0
  • for (int factor 1 factor lt n
    factor)
  • if ((n factor) 0)
  • sumOfFactors
  • sumOfFactors factor
  • // if
  • // for loop
  • // if its a perfect number
  • if (sumOfFactors n)
  • break
  • n n 2

Using int for code clarity. Really need a
larger precision type... BigInteger or larger
19
Can Computers be Programmed to Solve Any Problem?
  • Yes
  • No
  • Maybe

20
Can Humans Solve Any Problem?
  • Yes
  • No
  • Maybe

21
Where does that leave us?
  • If a human cant figure out how to do the halting
    problem, we cant make a computer do it for us
  • It turns out that it is impossible to write such
    a CheckHalt() method
  • But how to prove this?

22
CheckHalt()s non-existence
  • Consider P(I) a program P with input I
  • Suppose that CheckHalt(P,I) exists
  • Tests if P(I) will either loop forever or
    halt
  • A program is a series of bits
  • And thus can be considered data as well
  • Thus, we can call CheckHalt(P,P)
  • Its using the bytes of program P as the input to
    program P

23
CheckHalt()s non-existence
  • Consider a new method
  • Test(P)
  • loops forever if CheckHalt(P,P) prints
    halts
  • halts if CheckHalt(P,P) prints loops
    forever
  • Do we agree that Test() is a valid method?
  • Now run Test(Test)
  • If Test(Test) halts
  • Then CheckHalt(Test,Test) returns loops
    forever
  • Which means that Test(Test) loops forever
  • Contradiction!
  • If Test(Test) loops forever
  • Then CheckHalt(Test,Test) returns halts
  • Which means that Test(Test) halts
  • Contradiction!

24
Why do we care about the halting problem?
  • It was the first algorithm that was shown to not
    be able to exist
  • You can prove an existential by showing an
    example (a correct program)
  • But its much harder to prove that a program can
    never exist
Write a Comment
User Comments (0)
About PowerShow.com