Presentation is loading. Please wait.

Presentation is loading. Please wait.

SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes.

Similar presentations


Presentation on theme: "SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes."— Presentation transcript:

1 SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes Java Ch 3: Numerical computation & Function Ch 4: Subroutines & Databases Ch 5: Graphics Ch 6: Simulation Ch 7: Software engineering Part 2 Understanding what a computer is and how it works Ch 8: Machine architecture Ch 9: Language translation Ch 10: Virtual Environment for Computing Ch 11: Security, Privacy, and Wishful thinking Ch 12: Computer Communication Part 3 Advanced topics Ch 13: Program Execution Time Ch 14: Parallel Computation Ch 15: Noncomputability Ch 16: Artificial intelligence

2 SNU OOPSLA Lab. Ch 15. Noncomputability Copyright © SNU OOPSLA Lab.

3 SNU OOPSLA Lab. 3 Table of Contents Noncomputable Functions Programs that Read Programs Solving the Halting Problem Examples of non-computable problems Proof of noncomputability Summary

4 SNU OOPSLA Lab. 4 Noncomputable Functions Certain Problems Not Amenable to Computer Solution Examples given here may seem strained and artificial However, computers have very real limitation Intuitively speaking A class of problems that are unsolvable by any computer within the current paradigm of modern programming A function is computable if a Java program exists that can compute it We want to prove the existence of noncomputable functions

5 SNU OOPSLA Lab. 5 Existence of Noncomputable Functions (1/5) Approach: Matching up Java Programs and Functions E.g., assume 4 functions (f1, f2, f3, f4) and only 3 java programs (p1, p2, p3) Without details, conclude that one function has no program Figure 15.1

6 SNU OOPSLA Lab. 6 Existence of Noncomputable Functions (4/5) Try to Draw Lines Between Functions and Programs Could draw lines from every program to every function (problem) Figure 15.2

7 SNU OOPSLA Lab. 7 Existence of Noncomputable Functions (2/5) Consider all the Java programs that input an integer and return an integer The set of such Java programs is a countable set See page 426 of textbook But as shown in chapter 3, the set of functions that accept integers as input and yield positive numbers as output is uncountable See page 125 of textbook Therefore Some functions (problems) cannot have the corresponding Java programs!

8 SNU OOPSLA Lab. 8 Table of Contents Noncomputable Functions Programs that Read Programs Solving the Halting Problem Examples of non-computable problems Proof of noncomputability Summary

9 SNU OOPSLA Lab. 9 Programs that Read Programs (1/3) Program that input other programs Figure 15.3 Express programs as a single string We can easily write program to see if there is an IF statement in the program. How about, does the program halt?

10 SNU OOPSLA Lab. 10 Programs that Read Programs (2/3) “no while statement in its input program”  halt, otherwise  “Not known whether it halts” String E (String P) { if (p.indexOf( “ while ” ) >= 0) {return “ Not known whether it halts. ” ;} else {return “ Halts on all inputs. ” ;} } Figure 15.4

11 SNU OOPSLA Lab. 11 Programs that Read Programs (3/3) However, what we want is the following function! We want F such that can halt after a finite time with the correct answer Figure 15.5

12 SNU OOPSLA Lab. 12 Table of Contents Noncomputable Functions Programs that Read Programs Solving the Halting Problem Examples of non-computable problems Proof of noncomputability Summary

13 SNU OOPSLA Lab. 13 Solving the Halting Problem (1) Does it halt for all input? DoesItHalt.java, DoesItHalt.html DoesItHalt.javaDoesItHalt.html // input an integer value for k while (k > 1) if ((k/2) * 2 == k) // is k even? k = k / 2; else k = 3 * k + 1;

14 SNU OOPSLA Lab. 14 import awb.*; import java.awt.*; public class DoesItHalt extends java.applet.Applet { TextField mInstruct; IntField gStart; TextArea mResults; int j, k; public void init() { mInstruct = new TextField(60); mInstruct.setText("Enter starting integer:"); gStart = new IntField(10); mResults = new TextArea(10, 50); add(mInstruct); add(gStart); add(mResults); } public boolean action(Event e, Object arg) { int yea; String mak, sty, col, own; if (e.target == gStart) { j = 0; mResults.setText("Trace of the integer value: \n"); k = gStart.getInt(); while (k > 1) { j = j + 1; if ((k/2) * 2 == k) // is k even? { k = k / 2; } else { k = 3 * k + 1; } mResults.appendText("k = " + k + "\n"); } mResults.appendText(j + " steps before halting.\n"); return true; } return false; } DoesItHalt.java

15 SNU OOPSLA Lab. 15 Solving the Halting Problem (2) Try It! e.g. 17: 52 26 13, 40 20 10 5, 16 8 4 2 1 No one knows whether this quits for all inputs. Mathematicians have proven that no one, finite program can check this property for all possible programs

16 SNU OOPSLA Lab. 16 Table of Contents Noncomputable Functions Programs that Read Programs Solving the Halting Problem Examples of non-computable problems Proof of noncompuatbility Summary

17 SNU OOPSLA Lab. 17 Examples of non-computable problems (1/2) Equivalence: Define by same input > same output Use variation of above program; not sure it ends Cannot generally prove equivalence Figure 15.6

18 SNU OOPSLA Lab. 18 Examples of non-computable problems (2/2) To check for property X in the behavior of all other programs is impossible Figure 15.7

19 SNU OOPSLA Lab. 19 Table of Contents Noncomputable Functions Existence of Noncomputable Functions Programs that Read Programs Solving the Halting Problem Examples of non-computable problems Proof of noncompuatbility Summary

20 SNU OOPSLA Lab. 20 Proof (1/4) Proofs by Contradiction (Indirect Proof) Proving non-computability Sketch of proof Find more details in book

21 SNU OOPSLA Lab. 21 Proof (2/4) Assume existence of function halt: String halt(string p, string x); Inputs: p = program, x = input data Returns: If halt  "Halts“ or Unless halt  "Does not halt" Now write: String selfhalt(string p) { String answer; answer = halt (p, p); if (answer.equals(“Halts.”)) {return (“Halts on self.”);} else {return (“Does not halt on self.”);} }

22 SNU OOPSLA Lab. 22 Proof (3/4) String contrary (String p) { String answer; answer = selfhalt(p); if (answer.equals(“Halts on self.”)) {while (true) // go into an infinite loop {answer = “x”} } return “Halt.” // program halts; } Now run contrary on itself

23 SNU OOPSLA Lab. 23 Proof (4/4) We are running contrary on itself. Paradox! If the halt program decides that it halts, it goes into infinite loop and goes on forever. If the halt program decides that it doesn't halt, it quits immediately. Therefore the halt program cannot exist! If the halting problem is computable, then the halt program exist. Since the halt program cannot exist, the halting problem is not computable In general, whole classes of problems on deciding program behavior are non-computable.

24 SNU OOPSLA Lab. 24 What Does It All Mean? Programs cannot do everything

25 SNU OOPSLA Lab. 25 Table of Contents Noncomputable Functions Solving the Halting Problem Examples of non-computable problems Proof of noncomputability Summary

26 SNU OOPSLA Lab. 26 Summary Limit of contemporary programming languages based on the Von Neumann Computer Architecture There are uncomputable problems We proved that the halting problem is uncompuatble Also the cousins of the halting problem (regarding the behavioral property of programs) are all uncomputable

27 SNU OOPSLA Lab. 27 Ch15: Noncomputability Text Review Time


Download ppt "SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes."

Similar presentations


Ads by Google