Turing Machines COMP1600 / COMP6260. Dirk Pattinson Australian National University. Semester 2, 2017

Similar documents
Turing Machines. COMP2600 Formal Methods for Software Engineering. Katya Lebedeva. Australian National University Semester 2, 2014

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Turing Machines Part II

Most General computer?

Turing machines and linear bounded automata

CS4026 Formal Models of Computation

Turing Machine Variants

CSCE 551: Chin-Tser Huang. University of South Carolina

Automata Theory CS S-12 Turing Machine Modifications

Turing Machines (TM) The Turing machine is the ultimate model of computation.

Part I: Definitions and Properties

CSCI3390-Assignment 2 Solutions

Introduction to Turing Machines

CS20a: Turing Machines (Oct 29, 2002)

Turing machines and linear bounded automata

Chapter 7 Turing Machines

Computability Theory. CS215, Lecture 6,

Turing machines COMS Ashley Montanaro 21 March Department of Computer Science, University of Bristol Bristol, UK

Theory of Computation. Theory of Computation

Harvard CS 121 and CSCI E-121 Lecture 14: Turing Machines and the Church Turing Thesis

Notes for Comp 497 (Comp 454) Week 12 4/19/05. Today we look at some variations on machines we have already seen. Chapter 21

Introduction to Turing Machines. Reading: Chapters 8 & 9

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Turing Machines. Lecture 8

Turing machines and linear bounded automata

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

TURING MAHINES

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

Decidability: Church-Turing Thesis

Fundamentals of Computer Science

CSE 105 Theory of Computation

Models. Models of Computation, Turing Machines, and the Limits of Turing Computation. Effective Calculability. Motivation for Models of Computation

The Turing machine model of computation

Turing Machines Part Two

highlights proof by contradiction what about the real numbers?

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

15-251: Great Theoretical Ideas in Computer Science Lecture 7. Turing s Legacy Continues

Turing Machines Part One

Turing Machines and the Church-Turing Thesis

Turing Machines, diagonalization, the halting problem, reducibility

Chapter 3: The Church-Turing Thesis

Theory of Computing Tamás Herendi

Before We Start. Turing Machines. Languages. Now our picture looks like. Theory Hall of Fame. The Turing Machine. Any questions? The $64,000 Question

Turing Machines Part II

Announcements. Problem Set 6 due next Monday, February 25, at 12:50PM. Midterm graded, will be returned at end of lecture.

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

7.1 The Origin of Computer Science

Homework. Turing Machines. Announcements. Plan for today. Now our picture looks like. Languages

Busch Complexity Lectures: Turing s Thesis. Costas Busch - LSU 1

CS20a: Turing Machines (Oct 29, 2002)

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Introduction to Languages and Computation

Turing Machines Part II

More Turing Machines. CS154 Chris Pollett Mar 15, 2006.

Decidability and Undecidability

Turing Machines. 22c:135 Theory of Computation. Tape of a Turing Machine (TM) TM versus FA, PDA

Turing Machines Part III

Theory of Computation (IX) Yijia Chen Fudan University

Theory of Computation

Languages, regular languages, finite automata

CS151 Complexity Theory. Lecture 1 April 3, 2017

Computability, Undeciability and the Halting Problem

CPSC 421: Tutorial #1

X-machines - a computational model framework.

Turing Machines. Chapter 17

More About Turing Machines. Programming Tricks Restrictions Extensions Closure Properties

Variants of Turing Machine (intro)

1 Showing Recognizability

The Church-Turing Thesis

The Turing Machine. CSE 211 (Theory of Computation) The Turing Machine continued. Turing Machines

Turing Machines Decidability

CSE 105 THEORY OF COMPUTATION

(a) Definition of TMs. First Problem of URMs

COMPARATIVE ANALYSIS ON TURING MACHINE AND QUANTUM TURING MACHINE

UNIT-VIII COMPUTABILITY THEORY

CSE 105 THEORY OF COMPUTATION

UNIT 1 TURING MACHINE

CSci 311, Models of Computation Chapter 9 Turing Machines

Week 2: Defining Computation

Universal Turing Machine. Lecture 20

The tape of M. Figure 3: Simulation of a Turing machine with doubly infinite tape

1 Unrestricted Computation

Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine

Reducability. Sipser, pages

CS187 - Science Gateway Seminar for CS and Math

Theory of Computation Lecture Notes. Problems and Algorithms. Class Information

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

Turing machines Finite automaton no storage Pushdown automaton storage is a stack What if we give the automaton a more flexible storage?

CS21 Decidability and Tractability

Turing Machine properties. Turing Machines. Alternate TM definitions. Alternate TM definitions. Alternate TM definitions. Alternate TM definitions

Sample Project: Simulation of Turing Machines by Machines with only Two Tape Symbols

A Note on Turing Machine Design

Opleiding Informatica

Limits of Computation

Decidability. Human-aware Robotics. 2017/10/31 Chapter 4.1 in Sipser Ø Announcement:

and Models of Computation

Homework Assignment 6 Answers

Lecture notes on Turing machines

The decision problem (entscheidungsproblem), halting problem, & Turing machines. CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Transcription:

Turing Machines COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2017

Catch Up / Drop in Lab When Fridays, 15.00-17.00 Where N335, CSIT Building (bldg 108) Until the end of the semester This is not a tutorial, but we re happy to answer all your questions. No registration or anything required just drop by! 1 / 45

Alan Turing (1912 1954) 2 / 45

Turing s Scientific contributions 1936 1950. 1952. introduces Turing machines and the study of computability introduces the Turing test that turns AI into a concrete research problem current today: in June 2014, Eugene Goostman, a computer programme convinced 33% of judges that it was a 13-year-old boy. Pioneering work on computation in nature; Also. Key figure in the invention of the earliest modern computers. 3 / 45

Turing at War Germany Germans used enigma machines most sophisticated crypto equipment The U.K. code breaking effort assembled at Bletchley park Turing chief scientific genius Achievements cracked secret Enigma code estimated to have shortened world war II by 2 years Fallout may ideas and technologies discovered in Bletchley park fed directly into modern computers Short video https://www.youtube.com/watch?v=s5cjkefb-sm 4 / 45

Death and Legacy 1952 less than 10 years after heroic war efforts for the UK Turing prosecuded for crime of homosexuality sentenced to chemical castration 1954 death by suicide Legacy Now widely recognized as the father of computing Turing award equivalent of Nobel prize UK government apologised for persecution in 2009 2012 officially named the Turing year 5 / 45

Turing Machines Introduction Computability 1936 paper On computable numbers, with an application to the Entscheidungsproblem solved long standing open problem posed by Hilbert changed the world (of mathematics, and computing) simple mathematical device that is able to simulate any computer this device instrumental in solving Hilbert s problem Modern Computers didn t exist in 1936? ENIAC in 1946 generally considered to be the first 6 / 45

Computing as a profession Photo c/o Early Office Museum Archives 7 / 45

A model for computers Computing in 1936 computers not machines, it was a profession. Turing s contribution: mathematical definition of what computers can do. justification: references to state of mind or similar see original paper, Section 9.I (quite readable!) http: //www.cs.virginia.edu/~robins/turing_paper_1936.pdf Turing s model today no computer has been built that is more powerful than Turing s model Turing has discovered the essence of computation Mathematical Models vs Reality no formal proof that the model is the right one but widely accepted new paradigms emerge, e.g. quantum computing 8 / 45

Push Down Automata, reloaded a0 a1 a2....... an read head input tape Finite State Control zk z2 z1 stack memory A PDA with its auxiliary store is almost a whole computer, except we can only directly access the symbol on the top of the stack. 9 / 45

Turing Machines a0 a1 a2....... an read head input tape Finite State Control read write head zk z2 z1 tape memory Generalisation from PDA to Turing machine replace stack memory by tape memory can access arbitrary symbols on tape by moving tape head 10 / 45

Single tape Turing Machines input data scratch space a0 a1 an z0 z1 zk read / write head Finite State Control Simplification. have the same tape both for input and for storage tape is assumed to be infinite in both directions analogy: get more paper if you run out 11 / 45

Turing Machines as language recognisers Deterministic Machines for the time being at every time of the computation, at most one action is possible If there is no action that is legal, the TM halts If a TM halts in a final state, it has accepted the original input. The set of strings accepted by a TM is its language. If it halts in a non-final state, this is an error, i.e. the input is rejected. A TM may also loop forever... Definition. If a language is recognised by a Turing machine, then it is called recursively enumerable. 12 / 45

Output Turing Machines as Computing Devices TMs can calculate any computable function. input: a string written onto the tape before the machine starts output: whatever is left on the tape when the machine halts Infinite Tapes aren t a problem computation halts after finitely many steps only finitely many tape cells will be written to 13 / 45

Turing Machine formal definition A Turing Machine has the form (Q, q 0, F, Γ, Σ, Λ, δ), where Q is the set of states, q 0 Q is the initial state and F Q are the final states; Γ is the set of tape symbols, Σ Γ is the set of input symbols, and Λ Γ Σ is the blank symbol. δ is a (partial) transition function δ : Q Γ Q Γ {L, R, S} δ : (state, tape symbol) (new state, new tape symbol, direction) The direction tells the read/write head which way to go next: Left, Right, or Stay. 14 / 45

Running a TM Initialisation. some input (a finite string over Σ) is written on the tape; every other tape cell is a blank Λ; the read/write head sits over the some cell of the input (or over any Λ is the input is ɛ); Running. the state is the start state q 0. in a cycle: read symbol and execute action (state dependent): move/write/change state until a final state is reached (or the machine gets stuck) 15 / 45

Graphical Representation of the Transition Function Λ 1,L S 0 1 1,L S 1 Λ 1,S H (Like FSA, annotate transition edges with commands for accessing tape.) Convention. Numerator: symbol read from tape. Λ means the tape is blank at that position. Denominator: symbol written / direction of head movement. direction one of L, R, S for Left, Right, Stay. 16 / 45

What does it do? Λ 1,L S 0 1 1,L S 1 Adds two to a unary number! 1 1 1 1 1 1 head Λ 1,S Assume the head starts over the input data. First phase scans left. Second phase writes two extra 1s. H 17 / 45

The Convention for Errors Λ 1,L S 0 1 1,L S 1 Λ 1,S H TMs getting Stuck suppose that the input contains a token other than 1. TM would halt in state S 0, as there is no arc telling us what to do if we meet such a token (this is the job of the rightwards scan). this is an error - the input is rejected. S 0 not an accepting state! Language TM accepts precisely {1 n n N}. Alterantive Formulation (not used here) could add an error state that the machine transitions to error state not accepting 18 / 45

What does this one do? 0 0,R Λ Λ,L S 0 1 1,R 0 1,L Λ Λ,R S 1 1 0,L H Questions. Do you see two phases? What does each phase accomplish? 19 / 45

What does this one do? 0 0,R Λ Λ,L S 0 1 1,R 0 1,L Λ Λ,R S 1 1 0,L H Answer. Phase 1: initialisation. Phase 2: computation, in this case, complement a binary number. 20 / 45

Harder Problems? Incrementing a binary number 1 0 0 0 1 0 1 1 You should try this! Adding numbers - need terminators #1 1 0 0 0 1 #1 1 1 0 1 1 # Convenient to write the result before the data. Multiplication - and so on! 21 / 45

Incrementing a binary number Example. Number increment 1 0 0 0 1 0 1 1 Solution: 0 0,R Λ Λ,L S 0 1 1,R 0 1,S S 1 Λ 1,S 1 0,L H 22 / 45

Decrement Example. Number decrement (similar) 0 0,R Λ Λ,L S 0 1 1,R 1 0 0 0 1 0 1 1 1 0,S S 1 0 1,L H Failure (or non-acceptance): If given number is 0 it fails (at state S 1 ), 23 / 45

How to add two numbers? Input. Binary numbers separated by #, say m n {}}{{}}{ 10100101 # 100101010 Operation. Go back and forth between m and n, decrementing one (until this fails) and incrementing the other. decrement m, and increment n, because n will expand leftwards. m gets changed to 00... 0, n is replaced by the sum. Finally, delete the #00 0 on the right. 24 / 45

How to add two numbers? ctd. 1 Λ,R Λ Λ,S 1 S 4 0 1,R # H 0,R #,R # Λ,R Λ 1 Λ,L S 0 0,S S 1 S 2 6 0 0 Λ # 0 1 1,S 1,S 1,L #,L 0,L 1,L S 3 1 0,L 25 / 45

How to multiply two numbers? Input. as for addition }{{} p # } 10100101 {{} n # 100101010 }{{} m Operation. Repeatedly decrement m (until this fails) and add n to p (p is initially blank) Must modify the addition routine to not erase the number n being added. Modification of addition routine Two new tape symbols, 0 and 1. Before each addition stage, change all the 1s in n to 1. When decrementing n, swap 0s and 1s as usual, but keep the primes. When finished adding n to p, go back and use the primes to restore n. Observation. this is very tedious but the model is simple and easy to analyse tricks that you see here are typical 26 / 45

Programming Issues Data Data Types and Gadgets not present in the model but can be simulated... Numbers. Usually use unary or binary for integers. Vocabulary. Can be arbitrary, and {0, 1} suffice. Characters are represented as strings of bits. Variables, Arrays, Files Use markers on the tape to separate values. 27 / 45

Programming Issues Control Common Idioms. Scan to blank, or to find, insert, delete a symbol. Use control states to remember information In particular, we often need to remember a symbol, to write it elsewhere: this typically requires a set of states, one per symbol Composition If you have a TM to multiply by 3 and one to multiply by 5, put them together to multiply by 15. Decisions (conditional computation) As we have seen, we can branch on 0 or 1 (or T or F). Loops of course. 28 / 45

Using States to Remember a Tape Symbol 1 1, L S 0 0, R Λ 0, L Λ Λ, R U 0 T 0 Λ, R 1 1, R Given a string of 0 or 1 surrounded by blanks, this machine repeatedly forever erases the leftmost bit, and writes it on the right hand end. (Not so useful, but illustrates the point) 0 0, L Λ 1, L 0 0, R 1 Λ, R U 1 1 1, R We use the choice of states U 0 or U 1 to remember which symbol has been erased and is to be written 29 / 45

Universal Turing Machines and Turing Completeness We can construct a TM to simulate any conventional computer. (Cost effectiveness is not brilliant.) From this point, just think of a TM as like a computer program (with a machine that will run it) We can construct a TM that first reads a description of some other TM and then simulates it. This is a universal TM. (Think of a Haskell program whose purpose is to read any other Haskell program and run that) Turing machines can simulate themselves. Turing machines can compute properties of themselves. Any computing device which can simulate a universal Turing Machine is also called universal or Turing Complete. 30 / 45

Church-Turing Thesis Church-Turing Thesis. If a function is computable, then it can be calculated by a Turing machine. Equivalent Formulation. if a problem can be solved by an algorithm, then it can be solved by a Turing machine. This is a Thesis. more a definition than a theorem can never be proved: what does algorithmic mean? however, there s lots of evidence Evidence. all other definitions of the term computable give the same class of computable functions there are many: λ-calculus, register machines, while programs, etc. 31 / 45

Church and λ-calculus Example. The (untyped) λ-calculus proposed by Alonzo Church (the Church in the Church-Turing thesis) in 1932, even before Turing s paper Rosser showed that both notions are equivalent Equivalence. (Rosser, 1939) if a function is computable by a Turing machine, then it is computable in the λ-calculus... and vice versa simulation of the respective formalism in the other approach. 32 / 45

Can real computers simulate Turing Machines? Differences between computers and Turing machines A Turing Machine has an infinite tape. real computers have finite memory (sometimes a lot, but nowhere near infinite) physical devices necessarily have finite memory. They re more like finite automata.... but the number of states can be very, very large. How big is 2 4294967296? physical computers are an approximation of TMs. Intuitive Understanding Turing machine model feels closer to what we can program e.g. we can recognise the language {a n b n n 0} if the real machines runs out of memory... we can always buy more this is about computation in principle 33 / 45

Church-Turing Thesis: Argument 1 Turing Machines emulate humans. comparision how humans perform tasks Turing s computers only perform TM operations: writing, reading, refocussing (state change) TMs are finite like humans can t do infinite operations, e.g. work with infinitely many symbols can t read the whole infinite tape Taken together convincing (in the 1930s) that Turing s model is correct but no mathematical evidence (yet) 34 / 45

Church-Turing Thesis: Argument 2 Stability of the TM Model. adding features doesn t make more functions computable Multi-tape. have extra tapes to store data easier to program, but no extra power (single-tape can simulate multi-tape) Multi-head. have more than one head, heads cam move independently heads can access multiple symbols at once again, no extra power Non-determinism. (as for nfa s) tm can make one of several possible next moves tm can guess the right next move may make it faster, but cannot compute more functions. 35 / 45

Church-Turing Thesis: Argument 3 Many Models of Computation plenty of different definitions of what computable may mean different purposes, different contexts Main Insight. any (reasonable) model of computation can compute precisely the same functions as the TM model. reasonable in the sense of modelled on mechanical computation Examples. Lambda-Calculus (Church, 1932) Post-Systems (Post, 1939) Register Machines... Doesn t include models based on physical phenomena... or biology, or... 36 / 45

Argument 3B: Grammars Theorem. Any language that is generated by a grammar can be recognised by a Turing machine. Proof (Sketch) write the start symbol S onto the tape (say, right of our input) search through all possible derivations from S each time we reach a sentence, check whether it matches the input Acceptance. if the grammar finds the input, we will find a derivation if the grammar does not generate the input, we may loop forever (and not accept) 37 / 45

Argument 3B grammars ctd Unresricted Grammars. Have productions of the form α β where β is arbitrary, and α contains at least one non-terminal. Theorem. For any TM, there exists a grammar that generates precisely the words that the TM accepts. Proof (Sketch) non-terminals (of the grammar) are states of the TM run TM backwards (we are interested in inputs, not outputs) TM Transition. 0 1,R T U Grammar Production. 1U T 0. (Detail missing, e.g. how to handle blanks) 38 / 45

Argument 3C Computers & Programming Languages Observation. no computer ever invented could do things that a TM can t do no programming language can do more than a TM back-and-forth translation TM PL Common Terminology. A programming language that can compute every function that can be computed by a Turing machine is called Turing complete. Examples. The languages that you know: Haskell, Java, Phython,... even the simple while language that we used for Hoare logic implement TM simulator in your favourite programming language 39 / 45

Argument 3D John Conway s Game of Life Game of Life. infinite 2d grid finitely many cells marked alive, all others are dead Rules of the Game. iterate through generations live cells with fewer than two live neighbours die (under-population) live cells with more than three live neighbours die (over-population); dead cells with exactly three live neighbours come alive (reproduction); all other cells stay as they are. Emergent Behaviour. visualised by GoL, many interesting forms analogy of complex behaviour emerging from simple rules 40 / 45

Argument 3D John Conway s Game of Life ctd. From TM s to Conway s Game can implement Game of Life on a Turing machine lots of coding, in particular 2d grid onto 1d tape From Conway s Game to TMs (Paul Rendell, 2011) showed that GoL can simulate turing machines comes down to clever choice of initial configurations see http://rendell-attic.org/gol/turing_js_r.gif 41 / 45

Metaprograms Metaprograms are programs that have other programs as input or output. Examples Lexical analysers and parser generators SPARK Examiner, which automatically proves correctness properties of programs written in SPARK Ada; Code generation which automatically produces codes from e.g. a Z specification or a formal proof Next Goal. Scrutinize TMs that take TMs as input. main goal: halting problem 42 / 45

Coding a TM onto tape Coding of a TM as binary strings can be written onto a tape just code the transition function States are ordered S 1, S 2,..., S k, where S 1 is the start state and S 2 the unique final state Tape Symbols are ordered X 1, X 2, X 3,..., X l where X 1 is 0, X 2 is 1, and X 3 is Λ. Directions {L, R, S} as D 1, D 2, D 3 respectively. Transitions δ(s i, X j ) = (S k, X l, D m ) mapped to 0 i 1 0 j 1 0 k 1 0 l 1 0 m (the 0s carry information, the 1s act as separators.) 43 / 45

Coding a TM onto tape ctd. Coding of all transitions. A TM with transitions C 1,..., C n is codes as C 1 11 C 2 11 11 C n (11 is used as a separator for transitions) Additional Input. code for a TM, and additional string use 111 to separate TM and string input 44 / 45

Coding a TM onto tape example Λ 1,R S 1 1 1,R S 3 Λ 1,S S 2 The transitions are 0 1 00 1 0 1 00 1 00 0 1 000 1 000 1 00 1 00 000 1 000 1 00 1 00 1 000 Recall: States, Symbols, Directions. So the TM as a whole is encoded by the binary string 010010100100 11 010001000100100 11 00010001001001000 45 / 45