introduction to computer science
play

Introduction to Computer Science CSCI 109 China Tianhe-2 Andrew - PowerPoint PPT Presentation

Introduction to Computer Science CSCI 109 China Tianhe-2 Andrew Goodney Spring 2018 Lecture 11: Abstract Machines and Theory Apr 9th, 2018 Schedule 1 Abstract machines and theory u What is theoretical computer


  1. Introduction to Computer Science CSCI 109 China – Tianhe-2 Andrew Goodney Spring 2018 Lecture 11: Abstract Machines and Theory Apr 9th, 2018

  2. Schedule 1

  3. Abstract machines and theory u What is theoretical computer science? u Finite state machines u The Turing machine Reading: St. Amant Ch. 8 u The Church-Turing thesis u The halting problem u The analysis of algorithms u The analysis of problems 2

  4. What is theoretical computer science? u The study of what can be computed and how efficiently it can be computed u Based on abstract mathematical models u Insight into the behavior of a real computer… … any real computer 3

  5. Finite state machines Up Fed Asleep Crying On Hungry More Down Up Hungry hungry Awake, Off not crying Down 1 day old infant 10 day old infant Light switch 4

  6. Finite state machines Add M Add M Add M Add M M+1 M+2 M+3 M+4 Add M Add F Add F Add F Add F M=F Add F Add F Add F Add F Add M F+1 F+2 F+3 F+4 Add M Add M Add M Add F St. Amant pp. 152 5

  7. Finite state machine limitations u If a finite state machine with n states is given n+1 symbols, it will revisit one state at least once u No way to tell if revisited state is being visited for the 1 st time or 5 th time u The pigeonhole principle u Problems an FSM cannot solve: v Given a string of As and Bs, tell if the number of As and Bs are the same v Tell if a string is a palindrome 6

  8. The Turing machine u An infinite tape, with squares marked on it u Each square can be blank or hold a symbol u A machine moves over the tape u When positioned over a square, the machine can v Read a symbol from the tape v Erase a symbol from the tape v Write a symbol onto the tape (erasing what was on the square) v Do nothing u The machine can move either one square to right or left 7

  9. Simple Turing Machine with 1 symbol https://vimeo.com/46913004 8

  10. Alan Turing 9

  11. Turing Machine Representation: Table This machine has 4 symbols: 0, 1, _ and * L means the head moves to the left R means the head moves to the right 10

  12. Turing Machine Representation: Table 11

  13. Turing Machine Representation: Table 12

  14. Turing Machine Representation: Table write_symbol, head_move_direction, state_update 13

  15. Turing Machine Representation: Table write_symbol, head_move_direction, state_update 14

  16. Same Machine as a State Diagram read_symbol,write_symbol,head_position_move 15

  17. Same Machine as a State Diagram read_symbol,write_symbol,head_position_move 16

  18. 17

  19. Example execution u Assume the machine always begins in state 0 with the head positioned on the rightmost non-blank square u The machine stops when it is in state 4 (called an accept state) u The machine stops when it is in state 5 (called a reject state) u How does the execution look if the tape has an input of 10 written on it at the beginning ? 18

  20. Behavior of the machine on input 10 19

  21. Behavior of the machine on input 10 20

  22. Behavior of the machine on input 1010 21

  23. What does this Turing machine do? u Checks if a binary string has the same number of 1’s and 0’s and enters the accept state if it does, otherwise it enters the reject state. 22

  24. Turing Machine Programming u Writing programs for a Turing machine is very tedious u However… 23

  25. The Church-Turing thesis Turing machines are capable of solving any effectively solvable algorithmic problem Turing machines are thus excellent models for what (all) real computers are capable of doing 24

  26. Problems not ‘effectively computable’ u Are there problems that are not effectively computable ? u Yes, infinite such problems u Could these be computable someday ? u Perhaps, but not on a Turing-equivalent computer 25

  27. A halting question u Deciding whether a program will halt (terminate) u Does the following program halt ? Input number While number is not 0 Print number number = number – 1 26

  28. The halting problem u Deciding whether a given program will halt (terminate) on an arbitrary input u In 1936, Turing proved that a general algorithm to the halting problem for all possible programs over all possible inputs cannot exist The halting problem is undecidable 27

  29. Proof sketch for halting problem u Want to decide if program A halts on input a u Need to write a program, lets call it halter v Inputs: A, a v Output: Yes (if program A halts on input a) or No (if program A does not halt on input a) i.e analyze A for input a halter(A,a) if(some complex computation)is true Return Yes else Return No 28

  30. The halting problem is undecidable u In 1936, Turing proved that a general algorithm to the halting problem for all possible programs over all possible inputs cannot exist u In other words, a general version of halter (one that works for all programs and their inputs) does not exist 29

  31. Proof by contradiction u Assume that a general version of halter exists u Show that this assumption leads to a contradiction u Invent a new program called clever clever(program,input) result = halter(program,input) if result is No return Yes else loop forever 30

  32. Proof by contradiction u What does clever do when given itself as input? clever(program,input) result=halter(program,input) if result is No return Yes else loop forever 31

  33. Proof by contradiction u If halter says clever(program,input) that clever halts, result=halter(program,input) then clever if result is No loops forever (which means it return Yes doesn’t halt) else u If halter says loop forever that clever does not halt then Conclusion: The program clever halts and halter cannot exist returns Yes 32

  34. Russell’s Paradox u In a hypothetical small u More generally: town: v Let R be the set of all sets that are not members of v There is one male barber themselves v The barber shaves all those v If R is not a member of itself, and only those men in town then its definition dictates who do not shave themselves that it must contain itself, v All men stay clean shaven and if it contains itself, then either by shaving themselves it contradicts its own or going to the barber definition as the set of all u Who shaves the barber? sets that are not members of themselves 33

  35. Analysis of problems u Study of algorithms illuminates the study of classes of problems u If a polynomial time algorithm exists to solve a problem then the problem is called tractabl e u If a problem cannot be solved by a polynomial time algorithm then it is called intractable u This divides problems into three groups: v Problems with known polynomial time algorithms v Problems that are proven to have no polynomial-time algorithm v Problems with no known polynomial time algorithm but not yet proven to be intractable 34

  36. Tractable and Intractable u Tractable problems ( P ) u Intractable v Sorting a list v Listing all permutations (all possible orderings) of n numbers v Searching an unordered list v Finding a minimum spanning tree in a graph u Might be (in)tractable v Subset sum: given a set of These problems have no known numbers, is there a subset that polynomial time solution adds up to a given number? However no one has been able to v Travelling salesperson: n cities, n! prove that such a solution does not routes, find the shortest route exist 35

  37. Tractability, Intractability, Undecidability u ‘Properties of problems’ ( NOT ‘properties of algorithms’) u Tractable: problem can be solved by a polynomial time algorithm (or something more efficient) u Intractable: problem cannot be solved by a polynomial time algorithm (all solutions are proven to be more inefficient than polynomial time) u Unknown: not known if the problem is tractable or intractable (no known polynomial time solution, no proof that a polynomial time solution does not exist) u Undecidable: decision problem for which there is (provably) no algorithmic solution on a Turing machine v Non-existence v Not a matter of efficiency 36

  38. Abstract machines and theory u What is theoretical computer science? u Finite state machines u The Turing machine Reading: St. Amant Ch. 8 u The Church-Turing thesis u The halting problem u The analysis of algorithms u The analysis of problems 37

  39. Overview Problem s Low-level Low-level Low-level instructions instructions instructions Solution: Executions Algorithm s + managed by Data Structures Operating System Pseudocode CPU, Memory, Disk, I/O Compile Program Program to Program Program 38

  40. Quiz #6 https://bit.ly/2IETg5u 39

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend