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

introduction to computer science
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Introduction to Computer Science

CSCI 109

Andrew Goodney

Spring 2018

China – Tianhe-2

Lecture 11: Abstract Machines and Theory Apr 9th, 2018

slide-2
SLIDE 2

Schedule

1

slide-3
SLIDE 3

Abstract machines and theory

uWhat is theoretical computer

science?

uFinite state machines uThe Turing machine

u The Church-Turing thesis u The halting problem

uThe analysis of algorithms uThe analysis of problems

2

Reading:

  • St. Amant Ch. 8
slide-4
SLIDE 4

What is theoretical computer science?

uThe study of what can be computed and

how efficiently it can be computed

uBased on abstract mathematical models uInsight into the behavior of a real

computer… …any real computer

3

slide-5
SLIDE 5

Finite state machines

4

On Off Up Down Down Up

Light switch

Crying Asleep

Awake, not crying

Fed Hungry More hungry Hungry

1 day old infant 10 day old infant

slide-6
SLIDE 6

Finite state machines

5

M=F M+1 M+2 M+3 M+4 F+1 F+2 F+3 F+4 Add M Add M Add M Add F Add F Add F Add M Add M Add M Add M Add F Add F Add F Add M Add F Add F

  • St. Amant pp. 152

Add M Add F

slide-7
SLIDE 7

Finite state machine limitations

uIf a finite state machine with n states is given

n+1 symbols, it will revisit one state at least once

uNo way to tell if revisited state is being visited for

the 1st time or 5th time

uThe pigeonhole principle uProblems 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

slide-8
SLIDE 8

The Turing machine

7

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

  • n the square)

v Do nothing

u The machine can move either one square

to right or left

slide-9
SLIDE 9

Simple Turing Machine with 1 symbol

8

https://vimeo.com/46913004

slide-10
SLIDE 10

Alan Turing

9

slide-11
SLIDE 11

Turing Machine Representation: Table

10

This machine has 4 symbols: 0, 1, _ and * L means the head moves to the left R means the head moves to the right

slide-12
SLIDE 12

Turing Machine Representation: Table

11

slide-13
SLIDE 13

Turing Machine Representation: Table

12

slide-14
SLIDE 14

Turing Machine Representation: Table

13

write_symbol, head_move_direction, state_update

slide-15
SLIDE 15

Turing Machine Representation: Table

14

write_symbol, head_move_direction, state_update

slide-16
SLIDE 16

Same Machine as a State Diagram

15

read_symbol,write_symbol,head_position_move

slide-17
SLIDE 17

Same Machine as a State Diagram

16

read_symbol,write_symbol,head_position_move

slide-18
SLIDE 18

17

slide-19
SLIDE 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

slide-20
SLIDE 20

Behavior of the machine on input 10

19

slide-21
SLIDE 21

20

Behavior of the machine

  • n input 10
slide-22
SLIDE 22

21

Behavior of the machine

  • n input 1010
slide-23
SLIDE 23

What does this Turing machine do?

uChecks 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

slide-24
SLIDE 24

Turing Machine Programming

uWriting programs for a Turing machine is

very tedious

uHowever…

23

slide-25
SLIDE 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

slide-26
SLIDE 26

Problems not ‘effectively computable’

uAre there problems that are not effectively

computable ?

uYes, infinite such problems uCould these be computable someday ? uPerhaps, but not on a Turing-equivalent

computer

25

slide-27
SLIDE 27

A halting question

uDeciding whether a program will halt (terminate) uDoes the following program halt ?

Input number While number is not 0 Print number number = number – 1

26

slide-28
SLIDE 28

The halting problem

uDeciding whether a given program will halt

(terminate) on an arbitrary input

uIn 1936, Turing proved that a general algorithm

to the halting problem for all possible programs

  • ver all possible inputs cannot exist

The halting problem is undecidable

27

slide-29
SLIDE 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)

halter(A,a) if(some complex computation)is true Return Yes else Return No

28

i.e analyze A for input a

slide-30
SLIDE 30

The halting problem is undecidable

uIn 1936, Turing proved that a general

algorithm to the halting problem for all possible programs over all possible inputs cannot exist

uIn other words, a general version of

halter (one that works for all programs and their inputs) does not exist

29

slide-31
SLIDE 31

Proof by contradiction

uAssume that a general version of halter exists uShow that this assumption leads to a contradiction uInvent a new program called clever

clever(program,input) result = halter(program,input) if result is No return Yes else loop forever

30

slide-32
SLIDE 32

Proof by contradiction

uWhat 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

slide-33
SLIDE 33

Proof by contradiction

u If halter says

that clever halts, then clever loops forever (which means it doesn’t halt)

u If halter says

that clever does not halt then clever halts and returns Yes

32

clever(program,input) result=halter(program,input) if result is No return Yes else loop forever

Conclusion: The program halter cannot exist

slide-34
SLIDE 34

Russell’s Paradox

u In a hypothetical small

town:

v There is one male barber v The barber shaves all those

and only those men in town who do not shave themselves

v All men stay clean shaven

either by shaving themselves

  • r going to the barber

u Who shaves the barber?

33

u More generally:

v Let R be the set of all sets

that are not members of themselves

v If R is not a member of itself,

then its definition dictates that it must contain itself, and if it contains itself, then it contradicts its own definition as the set of all sets that are not members

  • f themselves
slide-35
SLIDE 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 tractable

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

slide-36
SLIDE 36

Tractable and Intractable

u Tractable problems (P)

v Sorting a list v Searching an unordered list v Finding a minimum spanning tree

in a graph

35

u Intractable

v Listing all permutations (all

possible orderings) of n numbers

u Might be (in)tractable

v Subset sum: given a set of

numbers, is there a subset that adds up to a given number?

v Travelling salesperson: n cities, n!

routes, find the shortest route These problems have no known polynomial time solution However no one has been able to prove that such a solution does not exist

slide-37
SLIDE 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

slide-38
SLIDE 38

Abstract machines and theory

uWhat is theoretical computer

science?

uFinite state machines uThe Turing machine

u The Church-Turing thesis u The halting problem

uThe analysis of algorithms uThe analysis of problems

37

Reading:

  • St. Amant Ch. 8
slide-39
SLIDE 39

Overview

38

CPU, Memory, Disk, I/O Program Problems Solution: Algorithms + Data Structures Pseudocode Low-level instructions Executions managed by Compile to Low-level instructions Low-level instructions Program Program Program Operating System

slide-40
SLIDE 40

Quiz #6

39

https://bit.ly/2IETg5u