Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 100Lecture 281 CS100J Lecture 27 n Previous Lecture –Interfaces –Comparable –Reflection –super –Re-Reading: n Lewis & Loftus, Section 5.5 n Savitch,

Similar presentations


Presentation on theme: "CS 100Lecture 281 CS100J Lecture 27 n Previous Lecture –Interfaces –Comparable –Reflection –super –Re-Reading: n Lewis & Loftus, Section 5.5 n Savitch,"— Presentation transcript:

1 CS 100Lecture 281 CS100J Lecture 27 n Previous Lecture –Interfaces –Comparable –Reflection –super –Re-Reading: n Lewis & Loftus, Section 5.5 n Savitch, Appendix 7 n This Lecture – –What can be computed? – –What can not be computed? – –Can human capabilities be matched?

2 CS 100Lecture 282 What can be computed? n Church's Thesis: Whatever can be computed can be implemented in the CS100 subset of Java n Pessimists: Terrible – we will never discover any fundamentally more powerful mechanism permitting new things to be computed. n Optimists: Great – we can start immediately trying to program the most difficult problems.

3 CS 100Lecture 283 Is there anything that can not be computed? Yes. There exists a function f: N ->N that is not computable Yes. There exists a function f: N ->N that is not computable. (1) Consider all Java programs of the form: static void main(String [] args) { TokenReader in = new TokenReader(System.in); int x = in.readInt(); /* Let y be f(x), for some f: N->N. */ iny y;... System.out.println(y); } All such programs are enumerable; e.g., they can be listed from smallest to largest, in alphabetical order within each given size. (2) All functions f: N->N that are computed by such programs are enumerable, e.g., just list the functions computed by the above programs and eliminate duplicates. (3) (Cantor) It is impossible to enumerate all functions f: N->N; i.e. any conceivable list naturalsprograms 0first function f 0 1second function f 1 2third function f 2 etc.etc. necessarily omits some function, e.g., f(i) = f i (i)+1. (4) So the list given in (2) must be incomplete. Q.E.D.

4 CS 100Lecture 284 What specifically can not be computed? The Halting Problem [A. M. Turing, 1938] (1)Consider Java programs of the restricted form static void main(String [] args) { TokenReader in = new TokenReader(System.in); String s = in.readString();... } (2)One possible input for such a program is a copy of itself, (say all on one line). (3)Some such programs, given a copy of themselves, loop forever: static void main(String [] args) { TokenReader in = new TokenReader(System.in); String s = in.readString(); while ( s.substring(0,6).equals(”static”)) { } } (4) Other such programs, given a copy of themselves, halt: static void main(String [] args) { TokenReader in = new TokenReader(System.in); String s = in.readString(); }

5 CS 100Lecture 285 (5)Suppose the following program H existed. /* Program H. */ static void main(String [] args) { TokenReader in = new TokenReader(System.in); String s = in.readString() boolean b; /* Set b==true if s is a program that loops when given s as input, else set b==false. */... if ( b ) System.out.println("loops"); else System.out.println("halts"); } Note that for every possible input s, program H prints a message and halts.

6 CS 100Lecture 286 (6)Then the following program H' would also have to exist. /* Program H’. */ static void main(String [] args) { TokenReader in = new TokenReader(System.in); String s = in.readString() boolean b; /* Set b==true if s is a program that loops when given s as input, else set b==false. */... if ( b ) System.out.println(”loops"); else while( true ) { } } (7)Now consider running program H' on input H'. Does it halt or loop? Answer: Neither! Suppose it halts. Then b must be true. But b is true only if s (i.e., H') loops when given s (i.e., H') as input. Contradiction. Suppose it loops. Then b must be false. But b is false only if s (i.e., H') does not loop when given s (i.e., H') as input. Contradiction. (8)Therefore programs H’ and H can not exist.

7 CS 100Lecture 287 Can computers match human capabilities? n How can we answer such a question objectively? Turing Test: Terminal A Person Terminal B Computer If Person A can not tell which terminal the Computer is attached to, the Computer passes the test.

8 CS 100Lecture 288 Eliza Eliza A fanciful attempt to pass the Turing Test n Computer plays psychiatrist. n Program has list of keywords weighted by priority. n n Program finds highest priority keyword in sentence. If none, it bluffs. n Each keyword has list of patterns. n Each pattern has several responses. n Program matches a pattern, then outputs a least recently used response. n n Responses sometimes incorporate sentence fragments with pronouns reversed.

9 CS 100Lecture 289 Sample Eliza Output Men are all alike. IN WHAT WAY. They are always bugging us about something or other. CAN YOU THINK OF A SPECIFIC EXAMPLE. Well, my boyfriend made me come here. YOUR BOYFRIEND MADE YOU COME HERE. He says I'm depressed much of the time. I AM SORRY TO HEAR YOU ARE DEPRESSED. It's true, I am unhappy. DO YOU THINK COMING HERE WILL HELP YOU NOT TO BE UNHAPPY. I need some help, that much seems certain. WHAT WOULD IT MEAN TO YOU IF YOU GOT SOME HELP. Perhaps I could learn to get along with my mother. TELL ME MORE ABOUT YOUR FAMILY. My mother takes care of me. WHO ELSE IN YOUR FAMILY TAKES CARE OF YOU. etc.

10 CS 100Lecture 2810 Natural Language Translation n Ambiguity makes problem very difficult. For example, Time flies like an arrow, fruit flies like a banana. n Translate English into Russian then back into English. The spirit is willing but the flesh is weak. becomes The vodka is ok but the meat is rotten.

11 CS 100Lecture 2811 Can computers solve problems posed in natural language? n High-school algebra word problems. Program reads problem in English, defines variables and sets up equations, then solves equations, and outputs answer in English. College physics word problems. "A 150 pound man is standing 10 feet from the top of a 40 foot ladder. The bottom of the ladder is wedged between the ground and a building, and the top of the ladder is attached to the building by a horizontal rope 15 feet long. What is the tension of the rope?” As above, but also applies appropriate physical laws and outputs illustrative diagram.

12 CS 100Lecture 2812 Can computers solve general problems? n Monkey and banana problems. A monkey is in a room with a chair. Bananas are hanging from the ceiling. The monkey can not reach the bananas while standing on the floor, but can move the chair. The monkey can reach the bananas while standing on the chair when the chair is positioned under the bananas. How can the monkey eat the bananas.

13 CS 100Lecture 2813 Monkeys and bananas problem, continued static void main(String [] args) {... while(bananasPosition != monkeyStomach) choice { choice { if (monkeyAltitude == onChair && chairPosition == underBananas) chairPosition == underBananas) bananasPosition = monkeyStomach; bananasPosition = monkeyStomach; if (monkeyAltitude == onChair) monkeyAltitude = offChair; monkeyAltitude = offChair; if (monkeyAltitude == offChair && monkeyPosition == chairPosition) monkeyPosition == chairPosition) monkeyAltitude = onChair; monkeyAltitude = onChair; if (monkeyAltitude == offChair) monkeyPosition = underBananas; monkeyPosition = underBananas; if (monkeyPosition == chairPosition && monkeyAltitude == offChair) monkeyAltitude == offChair) { monkeyPosition = underBananas; monkeyPosition = underBananas; chairPosition = underBananas; chairPosition = underBananas; } } /* choice */ } /* choice */}

14 CS 100Lecture 2814 Can computers reproduce? John von Neuman's self-reproducing cellular automaton. n Initial Universe: n n Transition Function: f : N 9 -> N 0 0 0 0 0


Download ppt "CS 100Lecture 281 CS100J Lecture 27 n Previous Lecture –Interfaces –Comparable –Reflection –super –Re-Reading: n Lewis & Loftus, Section 5.5 n Savitch,"

Similar presentations


Ads by Google