Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Brooks/Cole, 2003 Chapter 17 Theory of Computation.

Similar presentations


Presentation on theme: "©Brooks/Cole, 2003 Chapter 17 Theory of Computation."— Presentation transcript:

1 ©Brooks/Cole, 2003 Chapter 17 Theory of Computation

2 ©Brooks/Cole, 2003 Understand how a simple language with limited statements can solve any problem. Understand how the Turing machine can solve any problem that can be solved by a computer. Understand the Godel number and its importance in the theory of computation. After reading this chapter, the reader should be able to: O BJECTIVES Understand the halting problem as an example of a large set of problems that cannot be solved by a computer.

3 ©Brooks/Cole, 2003 SIMPLE LANGUAGE 17.1

4 ©Brooks/Cole, 2003 Figure 17-1 Statements in simple language Increment statement: incr X Decrement statement: decr X Loop statement: while X { { Actions Actions }

5 ©Brooks/Cole, 2003 Power of the Simple Language The simple language with only three statements is as powerful as any sophisticated language in use today, such as C. Here we show how we can simulate several statements found in some popular languages. We call each simulation a macro and use it in other simulations without the need to repeat code.

6 ©Brooks/Cole, 2003 Macros in the Simple Language First Macro: X  0 Second Macro: X  n while X { decr X } X  0 incr X … incr X

7 ©Brooks/Cole, 2003 Macros in the Simple Language Third Macro: Y  X Y  X Y  0 TEMP  0 while X { incr Y decr X incr TEMP } while TEMP { decr TEMP incr X }

8 ©Brooks/Cole, 2003 Macros in the Simple Language Fourth Macro: Z  X + Y Z  X TEMP  Y while TEMP { incr Z decr TEMP } Fifth Macro: Z  X * Y Z  X * Y Z  0 TEMP  Y while TEMP { Z  Z + X decr TEMP }

9 ©Brooks/Cole, 2003 Macros in the Simple Language Sixth Macro: Z  X ** Y Z  1 TEMP  Y while TEMP { Z  Z * X decr TEMP }

10 ©Brooks/Cole, 2003 Macros in the Simple Language Seventh Macro: comp ( X ) comp ( X ) –complements If the value of X is 0, change it to 1. If it is not 0, change it to 0. TEMP  1 while X { X  0 TEMP  0 } while TEMP { incr X decr TEMP }

11 ©Brooks/Cole, 2003 Macros in the Simple Language Eighth Macro: if X then A1 else A2 if X then A1 else A2 TEMP  X while TEMP { A1 TEMP  0 } TEMP  X comp (TEMP) while TEMP { A2 TEMP  0 }

12 ©Brooks/Cole, 2003 TURING MACHINE 17.2

13 ©Brooks/Cole, 2003 Figure 17-2 Turing machine Turing machine components Tape, read/write head, controller

14 ©Brooks/Cole, 2003 Figure 17-3Tape The Turning machine’s memory is infinite. The tape holds a sequence of characters form the set of characters acceptable by the machine. The machine can accept only a few symbols: #, &, 1, and blank.

15 ©Brooks/Cole, 2003 Read/write head The read/write head points to one symbol (the current symbol) on the tape. The read/write head reads and writes one symbol at a time from the tape. After reading and writing, it moves to the left, to the right, or stays in place.

16 ©Brooks/Cole, 2003 Controller The controller is the theoretical counterpart of the CPU in modern computers. The controller is a finite state automaton, a machine that has a predetermined finite number of states and moves from one state to another based on the input. At any moment, it can be in one of these states.

17 ©Brooks/Cole, 2003 Figure 17-4 Transition state Four states : A, B, C, D. Table 17.1

18 ©Brooks/Cole, 2003 Table 17.1Transitional table Current State Current State ----- A B C D Write Write ---------------- # & 1 same as read blank 1 same as read 1 New State New State ----- B C A B D B D Read Read ------------- 1 or blank # or & 1 not 1 1 not 1 not a blank blank Move Move --------     A program is a modern implementation of the transition table.

19 ©Brooks/Cole, 2003 Simulation of Simple Language Write programs (create transition tables) that implement the statements of the Simple Language. –Increment statement –Decrement statement –Loop statement

20 ©Brooks/Cole, 2003 Figure 17-5 Increment statement Transition diagram for incr X

21 ©Brooks/Cole, 2003 Table 17.2Transitional table for incr X statement Current State Current State --------- StartIncr Forward Added Backward Write Write ---------------- # 1 1 & same as read # New State New State ---------- Forward Added Backward StopIncr Read Read ------------- # 1 & any not # # Move Move --------  

22 ©Brooks/Cole, 2003 Figure 17-6 Steps in incr X statement

23 Figure 17-7 Decrement statement Transition diagram for decr X

24 ©Brooks/Cole, 2003 Table 17.3Transitional table for decr X statement Current State Current State --------- StartDecr Forward Delete Backward Write Write ---------------- # 1 blank & same as read # New State New State ---------- Forward Delete Backward StopDecr Read Read ------------- # 1 & 1 not # # Move Move --------  

25 ©Brooks/Cole, 2003 Figure 17-8 Transition diagram for the loop statement

26 ©Brooks/Cole, 2003 Table 17.4Transitional table for the loop statement Current State Current State --------- StartLoop Check Forward … EndProcess Backward Read Read ------------- # not 1 1 not & & … any not # # Move Move --------    none …  none New State New State --------- Check StopLoop Forward StartProcess … Backward Check Write Write ------------- # same as read 1 same as read & … same as read #

27 ©Brooks/Cole, 2003 Conclusion Any problem that can be solved by the Simple Language can also be solved by the Turing machine. Is there a problem solvable by the Turing machine that is not solvable by the Simple Language? We can not prove it now. Church thesis: the Simple Language and the Turing machine are equivalent. We believe it.

28 ©Brooks/Cole, 2003 GODELNUMBERSGODELNUMBERS 17.3

29 Godel numbers In theoretical computer science, an unsigned number is assigned to every program that can be written in a specific language. –Programs can be used as a single data item as input to another program. –Programs can be referred to by just their integer representations. –The numbering can be used to prove that some problems can not be solved by a computer.

30 ©Brooks/Cole, 2003 Table 17.5Code for symbols used in the Simple Language Symbol --------- 1 2 3 4 5 6 7 8 Hex Code Hex Code ------------- 1 2 3 4 5 6 7 8 Hex Code Hex Code ------------- 1 2 3 4 5 6 7 8 Symbol --------- 9 incr decr while { } x Hex Code Hex Code ------------- 9 A B C D E F

31 ©Brooks/Cole, 2003 Representing a program Example 1 What is the Godel number for the program incr X? What is the Godel number for the program incr X?Solution incr X incr X A F A F 175 (in decimal) 175 (in decimal)

32 ©Brooks/Cole, 2003 Interpreting a number Example 1 Interpret 3058 as a program. Interpret 3058 as a program.Solution 3058 3058 B F 2 B F 2 decr X 2 decr X 2

33 ©Brooks/Cole, 2003 HALTINGPROBLEMHALTINGPROBLEM 17.4

34 Halting problem In programs, a repetition construct may never terminate (halt). For example, the following program never terminates. X  1 while X { }

35 ©Brooks/Cole, 2003 Can you write a program that tests whether or not any program, represented by its Godel number, will terminate? No. A Classical Programming Question: Halting problem

36 ©Brooks/Cole, 2003 Figure 17-9 Halting problem is not solvable Proof by contradiction ( 矛盾証法 ) Step 1: Assume that a program, called Test, exists. Step 1: Assume that a program, called Test, exists.

37 Figure 17-10 Step 2: Create another program called Strange that is made of two parts: –a copy of Test at the beginning –an empty loop at the end

38 ©Brooks/Cole, 2003 Figure 17-11 Now having made the program Strange, we test this program with itself as input.

39 ©Brooks/Cole, 2003 Contradiction If we assume that Test exists, we have the following contradictions: –Strange does not terminate if Strange terminates. –Strange terminates if Strange does not terminate. This proves that the Test program cannot exist. The halting problem is unsolvable.

40 ©Brooks/Cole, 2003 SOLVABLE AND UNSOLVABLE PROBLEMS SOLVABLE AND UNSOLVABLE PROBLEMS 17.5

41 ©Brooks/Cole, 2003 Figure 17-12 Taxonomy of problems

42 ©Brooks/Cole, 2003 Complexity of solvable problems One way to measure the complexity of a solvable problem is to find the number of operations executed by the computer when it runs the program. Big-O notation –For example: n : the number of input data n : the number of input data –Polynomial problems: O(1), O(logn), O(n), O(nlogn), O(n 2 ),…, O(n k ),… –Non-polynomial problems: O(2 n ), O(n!),…

43 ©Brooks/Cole, 2003 Key terms Controller Decrement statement Godel number Hexadecimal digit Increment statement Loop statement macro Non-polynomial problem Polynomial problem Solvable problem Tape Turing machine Unsolvable problem


Download ppt "©Brooks/Cole, 2003 Chapter 17 Theory of Computation."

Similar presentations


Ads by Google