Presentation is loading. Please wait.

Presentation is loading. Please wait.

Turing Machines Lecture 14-16 Ref. handout page 57 -65.

Similar presentations


Presentation on theme: "Turing Machines Lecture 14-16 Ref. handout page 57 -65."— Presentation transcript:

1 Turing Machines Lecture Ref. handout page

2 Alan Turing Great mathematician The father of the modern computer

3 Alan Turings Statue at Bletchley Park Bletchley Park is near Milton Keynes Half hour from London

4 Historical Notes For a long time it was believed that any mathematical problem could, at least in principle, be proved from the basic axioms 1931, Kurt Gödel proposed the theorem of undecidability – there exist theorems which can neither be proved or disproved Later, Alonso Church and Alan Turing also found other problems which had no algorithmic solution

5 Alan Turing was interested in whether there was a way to define which problems were/were not decidable (computable)? can we create a machine to simulate the human brain so that those computable problems can be solved automatically? , Turing was working on a paper, computable numbers. The Turing machine in this paper turned out to be the simplest prototype of all computers!

6 Turings Idea a+b*x/y thinks State of mind changes reads makes notes

7 The Turing Machines (Infinitely long) tape, one symbol per square control unit Current state Read/Write head......

8 A Turing Machine Conceptualization start reset - -

9 Actions of a Turing Machine Move left/right one square Change state Write a new symbol onto the current tape square depending on current state and current tape symbol

10 State Transitions read write move AB X,Y / L

11 State Transitions – comparing with FA and PDA read write move for TM input value on stack/ op of stack for PDA AB X,Y / L

12 A State Transition Table statereadwritemovenew state 1abL2 2bbL2 2abR3 3abL2 3bcR

13 The Infinite Tape abaca Initial position of read/write head (the left most) Initial data (finite) Blank tape (infinite)

14 A Turing Machine Example Test for a palindrome aabbabbaaa If a then replace with space go to right hand end check for a if not found halt -> error else go to left hand end do the same for b

15 Cont. Transition Table for checking a statereadwritemoveNew state starta findA a b deleteA a b

16 Answer (cont. TM for detecting palindromes) start return no delB yes findB delAfindA a, /R b, /R a,a/R b,b/R a,a/R b,b/R a,a/L b,b/L,/R b, /L a, /L b,b/L a,a/L,/L

17 Memo for In-class test 14 [ /5] questionsmy answers correct answers comments

18 Turing Machine Tricks Write as many y as there are xs before x x x x after x x x x y y y y

19 Answer

20 Unary Numbers 0 x 1 x x 2 x x x 3 x x x x 4 x x x x x 5 x x x x x x x x x x + x x x = x x x x x x ? + ? = ?

21 The Limitations of TMs control unit Control Unit does one thing only hardware specific......

22 The 2-Tape Turing Machine control unit data tape program tape program tape stores the description of a 1-tape TMs transition table

23 The 2-tape TM – The Universal TM control unit Data tape Program tape......

24 2-Tape Transitions statereadwritemovereadwritemovenew state tape 1 tape 2 Includes no move

25 The Emulator control unit data tape program tape extras, e.g. the current state

26 An Example of UTM (Universal Turing Machine) Adding one to a binary number e.g. before after before after before after

27 An Example of UTM Cont. How to go about writing a TM for adding one (a single-tape first)? Idea (algorithm): 1. Move the head to the right most position 2. If the right most is 0, replace it by 1,stop 3. move to left one space 4. If the current value is 0 or a blank replace it by 1, stop 1. Go to step 3

28 An Example of UTM Cont. startcheck stop carry 1,1/R 0,0/R 0,1,_,1, _, /L 0,1,_ 1,0,L A TM which adds one in binary statereadwritemov new state start RRRR check 0 1 L_L_ stop check carry LLLL ____ stop

29 Cont. change to 3-tape TM S 1 1 R S S 0 0 R S S L C Program tape S Data tape Extra tape

30 Whats so Special? UTM The lever – many lifting jobs The wheel – lots of uses UTM – anything you can program

31 Memo for In-class test 15 [ /5] questionsmy answers correct answers comments

32 A Real Computer Control unit: processor Data tape: user memory Program tape: program memory Extra tape: system memory I/O facilities added

33 TMs and Real Computer - 2 Write a TM which simulates a PC Anything a real computer can do,a TM can do TM

34 TMs and Real Computer - 1 Write a Java program which simulates a TM Anything a TM can do, a real computer can do TM

35 The Church-Turing Thesis Anything which can be computed can be computed by a Turing Machine Anything which cant be done by a TM cant be done by any computer corollary

36 So If there is anything a TM cant do it probably cant be done Is there anything which TMs cant do??? But may be a TM can do anything we can imagine (?)

37 Decision Problems It is harder to say what we will never be able to do rather than what we can do (computable). Consider only simpler problems – decision problems where the answer is yea or no. Consider only TMs with two halt states yes and no. A problem is decidable if we can have a TM for it which eventually enters either the yes or no state depending on its input.

38 The Halting Problem In searching of an undecidable problem. The best-known such problem is called the halting problem. Given an arbitrary program with an arbitrary input, can we make a Turing Machine to test whether the program stop or loop forever?

39 The Barber Paradox (by Bertrand Russell ) Once upon a time, a village barber put a notice outside his shop I shave all and only those men in the village who do not shave themselves. Q. Does the barber shave himself?

40 The Barber Paradox U = { every man in the village } S = { men shave themselves } U \ S = { men dont shave themselves} Where does the barber belong to, S or U \ S ?

41 The Barber Paradox – trouble in either ways Assume: the barber does shave himself Any man in this village who shaves himself is not shaved by barber. Therefore, the barber does not shave himself. Assume: the barber doesnt shave himself Any man in this village is shaved by the barber if and only if he is not shaved by himself. Therefore, the barber does shaves himself.

42 Why is the Barber Paradox important? A paradox with importance to mathematical logic and set theory. It was constructed to demonstrate the self- contradictory nature of the elementary set theory It underlies the proof of Alan Turings proof of the undesirability of the halting problem.

43 Program Testing – (another way to look at the halting problem) A Java program is stored in a file The title is called abc.java I have tested abc with different data It always works Its never got into an infinite loop Can I be sure it never will for any input?

44 Automated Program Testing A file containing a program A file of test data Prog Test MyTest infinite loop /halt

45 The Java Prog Test Class public class Prog Test { Public boolean halt(String prog, String data) { if prog halts when given data as input return true; else return false; }

46 Using Prog Test import Prog Text public class MyTest { static public void main(String[] args) {String s = args[0]; if(ProgTest.halt(s,s)) // loop forever while(true) continue; }

47 Running MyTest java MyTest MyTest.java command to run java MyTest (program To test) with itself as data

48 Suppose It Loops static public void main(String[] args) {String s = args[0]; s = MyTest.java if(ProgTest.halt(s,s)) // loop forever while(true) continue; } ProgTest.halt(MyTest.java, MyTest.java)

49 The Dilemma If it halts it loops forever... If it loops forever it halts...

50 The Solution The result is nonsense – MyTest must halt or loop We got into this mess by assuming that ProgTest.halts could be written So ProgTest.halts doesnt (cant) exist.

51 Conclusion ProgTest.halts cant be written No program exists which can tell whether any given program halts for any given data There are some things computer cant do

52 Memo for In-class test 16 [ /5] questionsmy answers correct answers comments


Download ppt "Turing Machines Lecture 14-16 Ref. handout page 57 -65."

Similar presentations


Ads by Google