Turing Machines Part II

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

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

Most General computer?

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

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

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

CSCC63 Worksheet Turing Machines

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

Introduction to Turing Machines. Reading: Chapters 8 & 9

ECS 120 Lesson 15 Turing Machines, Pt. 1

CS21 Decidability and Tractability

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

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

Introduction to Turing Machines

CS4026 Formal Models of Computation

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Lecture 13: Turing Machine

Part I: Definitions and Properties

Turing Machines. The Language Hierarchy. Context-Free Languages. Regular Languages. Courtesy Costas Busch - RPI 1

1 Unrestricted Computation

where Q is a finite set of states

Griffith University 3130CIT Theory of Computation (Based on slides by Harald Søndergaard of The University of Melbourne) Turing Machines 9-0

Theory of Computation Turing Machine and Pushdown Automata

Chapter 3: The Church-Turing Thesis

Lecture 14: Recursive Languages

Automata Theory CS S-12 Turing Machine Modifications

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm

Further discussion of Turing machines

The Power of One-State Turing Machines

Automata Theory (2A) Young Won Lim 5/31/18

SE 3310b Theoretical Foundations of Software Engineering. Turing Machines. Aleksander Essex

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

Turing Machines. Lecture 8

Chapter 8. Turing Machine (TMs)

CS20a: Turing Machines (Oct 29, 2002)

Turing Machines A Turing Machine is a 7-tuple, (Q, Σ, Γ, δ, q0, qaccept, qreject), where Q, Σ, Γ are all finite

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

Fundamentals of Computer Science

Homework Assignment 6 Answers

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

CSCI3390-Assignment 2 Solutions

Equivalence of TMs and Multitape TMs. Theorem 3.13 and Corollary 3.15 By: Joseph Lauman

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Turing Machine Variants

Busch Complexity Lectures: Turing Machines. Prof. Busch - LSU 1

Computation Histories

1 Showing Recognizability

Introduction to Formal Languages, Automata and Computability p.1/42

An example of a decidable language that is not a CFL Implementation-level description of a TM State diagram of TM

Chapter 7 Turing Machines

Lecture 12: Mapping Reductions

CS20a: Turing Machines (Oct 29, 2002)

The Church-Turing Thesis

Homework 8. a b b a b a b. two-way, read/write

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

More About Turing Machines. Programming Tricks Restrictions Extensions Closure Properties

Computability Theory. CS215, Lecture 6,

Decidability (What, stuff is unsolvable?)

CSE 105 THEORY OF COMPUTATION

Turing Machines. Our most powerful model of a computer is the Turing Machine. This is an FA with an infinite tape for storage.

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

2.6 Variations on Turing Machines

Computability and Complexity

Turing Machines. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

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

Undecidable Problems and Reducibility

CpSc 421 Final Exam December 15, 2006

CpSc 421 Homework 9 Solution

Chapter 1 - Time and Space Complexity. deterministic and non-deterministic Turing machine time and space complexity classes P, NP, PSPACE, NPSPACE

COMPARATIVE ANALYSIS ON TURING MACHINE AND QUANTUM TURING MACHINE

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

UNIT-VIII COMPUTABILITY THEORY

Theory of Computation

CS 21 Decidability and Tractability Winter Solution Set 3

Turing Machines. Wolfgang Schreiner

Chapter Five: Nondeterministic Finite Automata

Turing Machines. Nicholas Geis. February 5, 2015

An example of a decidable language that is not a CFL Implementation-level description of a TM State diagram of TM

Computational Models Lecture 8 1

Turing Machines Part III

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

Theory of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

The Turing machine model of computation

Automata and Computability. Solutions to Exercises

Decision Problems with TM s. Lecture 31: Halting Problem. Universe of discourse. Semi-decidable. Look at following sets: CSCI 81 Spring, 2012

Introduction to Computability

CSE 105 Theory of Computation

Theory of Computation - Module 4

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

6.045J/18.400J: Automata, Computability and Complexity. Quiz 2. March 30, Please write your name in the upper corner of each page.

TWO-WAY FINITE AUTOMATA & PEBBLE AUTOMATA. Written by Liat Peterfreund

Reducability. Sipser, pages

Variants of Turing Machine (intro)

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

CSci 311, Models of Computation Chapter 9 Turing Machines

Automata and Computability. Solutions to Exercises

Turing Machines. Fall The Chinese University of Hong Kong. CSCI 3130: Formal languages and automata theory

CSCE 551 Final Exam, Spring 2004 Answer Key

Transcription:

Turing Machines Part II COMP2600 Formal Methods for Software Engineering Katya Lebedeva Australian National University Semester 2, 2016 Slides created by Katya Lebedeva COMP 2600 Turing Machines 1

Why computer programs are not well-suited to develop a theory of computation? complex language constructs finite memory state of the computation is complicated to represent would need to show that the results for a specific programming language are in fact general We resort to an abstract computing device, the Turing Machine (TM). It represents a simple and universal programming language has an unbounded memory has states of computation that are easy to describe can simulate any known computing device COMP 2600 Turing Machines 2

Definition A Turing Machine has the form (Q,q 0,F, Γ,Σ,Λ, δ), where Q is the finite set of states q 0 Q is the initial state F Q is the set of final/accepting states Γ is the tape alphabet (the finite set of tape symbols) Σ Γ is the input alphabet (the finite set of input symbols) Λ Γ/Σ is the blank symbol δ is a (partial) transition function δ : Q Γ Q Γ {L,R,S} COMP 2600 Turing Machines 3

Transitions δ(q,x) = (p,y,d) means that if M is in state q and the tape head is over symbol x, then changes state to p replaces x with y on the tape moves the head in the direction given by d Note: the TM is deterministic, i.e. for each (q,x) we have at most one move. δ(q,x) can be undefined for some q and x. COMP 2600 Turing Machines 4

Initialisation some input (a finite string w over Σ) is written on the tape every other tape cell is a blank symbol Λ the tape head is positioned on the left-most symbol of w the state is the start state q 0 Acceptance w Σ is accepted by M, if M, when started with w on the tape eventually enters a final state. COMP 2600 Turing Machines 5

Halting A state q is halting for a symbol x Γ if δ(q,x) is not defined. A state q is halting if it is halting for all symbols in Γ. We can assume without loss of generality that all final states are halting. Rejection M rejects a string w in either of the following cases it halts in a non-final state it executes transitions forever, without ever reaching a final state (in this case we say M loops on w ) COMP 2600 Turing Machines 6

Automata vs. Turing Machines Finite State Automata and Pushdown Automata scan over w (from left to right) and accept/reject when they reach the end of w. Turing Machines can move back and forth over w and accept/reject when they halt or reject when they loop forever. COMP 2600 Turing Machines 7

Computer vs. Turing Machine A Turing Machine has an infinite tape. Physical computing devices have finite memory, so they can only exist in a finite number of states. They are Finite State Automata. The number of states can be very, very large: for example 2 4294967296 Physical computers can only approximate Turing Machines :-( If a Turing Machine has a finite tape we can simulate it with an FSA: Just take the finite state control and replicate it for every possible string that could exist on the tape. Combinatorial explosion! For a tape containing 16 binary symbols, we need at least 2 16 states in our FSA! COMP 2600 Turing Machines 8

Random Access Memory saves the day An FSA has no auxiliary store/memory...... this makes them less expressive. A PDA has an auxiliary store...... but we can only directly access the symbol on the top of the stack. A Turing Machine is infinite...... but we have to access the tape sequentially. My laptop is finite...... but accessing a store location requires only a small, constant time.... that s usually enough. COMP 2600 Turing Machines 9

Using States to Remember a Tape Symbol 1 1, L 0 0, L S 0 0, R Λ 0, L Λ Λ, R Λ 1, L U 0 T 0 Λ, R 1 Λ, 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) We use the choice of states U 0 0 0, R U 1 1 1, R or U 1 to remember which symbol has been erased and is to be written Note: We begin in state S, the head points at the first symbol of the given word. The first transition will move the head to the left, replacing the first symbol 1 with 1 or 0 with 0. COMP 2600 Turing Machines 10

Example Define a TM that accepts exactly all strings in L = {w# wt w {0,1} +,t {0,1,#} } Initially... Λ Λ... w... #... #... w...... t... Λ Λ... Idea: remember leftmost symbol and erase it move to leftmost symbol after # s if the two don t match, reject otherwise replace the symbol by #, move left and start again COMP 2600 Turing Machines 11

... Λ Λ... w... #... #... w...... t... Λ Λ... M = (Q,q 0,F,Γ,Σ,Λ,δ) Q = {q 0,q 1,q 2,q 3,q 4,q 5,q 6,q 7 } F = {q 7 } Γ = {0,1,#,Λ} Σ = {0,1,#} COMP 2600 Turing Machines 12

... Λ Λ... w... #... #... w...... t... Λ Λ... erase 0 and start looking for matching 0 δ(q 0,0) = (q 1,Λ,R) erase 1 and start looking for matching 1 δ(q 0,1) = (q 2,Λ,R) COMP 2600 Turing Machines 13

... Λ Λ... w... #... #... w...... t... Λ Λ... skip over 0 s and 1 s until first # is found (remembering 0) δ(q 1,0) = (q 1,0,R) δ(q 1,1) = (q 1,1,R) δ(q 1,#) = (q 3,#,R) skip over 0 s and 1 s until first # is found (remembering 1) δ(q 2,0) = (q 2,0,R) δ(q 2,1) = (q 2,1,R) δ(q 2,#) = (q 4,#,R) COMP 2600 Turing Machines 14

... Λ Λ... w... #... #... w...... t... Λ Λ... skip over # s, look for 0 and replace it with # δ(q 3,#) = (q 3,#,R) δ(q 3,0) = (q 5,#,L) Note: if right after # s a 1 is found, M rejects skip over # s, look for 1 and replace it with # δ(q 4,#) = (q 4,#,R) δ(q 4,0) = (q 5,#,L) Note: if right after # s a 0 is found, M rejects COMP 2600 Turing Machines 15

... Λ Λ... w... #... #... w...... t... Λ Λ... Move left skipping # s: δ(q 5,#) = (q 5,#,L) If to the left of # s a 0 or 1 is found, move to q 6 to skip them too: δ(q 5,0) = (q 6,0,L) δ(q 5,1) = (q 6,1,L) If to the left of # s a Γ is found, accept: δ(q 5,Λ) = (q 7,Λ,R) COMP 2600 Turing Machines 16

... Λ Λ... w... #... #... w...... t... Λ Λ... Move left skipping over 0 s and 1 s and restart δ(q 6,0) = (q 6,0,L) δ(q 6,1) = (q 6,1,L) δ(q 6,Λ) = (q 0,Λ,R) COMP 2600 Turing Machines 17

COMP 2600 Turing Machines 18

0 0,R 1 1,R # #,R # #,L q 0 0 Λ,R start q 1 1 Λ,R 0 0,R 1 1,R # #,R q 3 # #,R 0 #,L 1 #,L Λ Λ,R q 5 q 7 Λ Λ,R q 2 # #,R q 4 0 0,L 1 1,L q 6 COMP 2600 Turing Machines 19 0 0,L 1 1,L

Instanteneous Descriptions A configuration of a TM is represented as α 1 qα 2, where α 1,α 2 Γ and q Q Meaning non-blanc portion of the tape contains α 1 α 2 the machine is in state q the head is positioned on left-most symbol of α 2... Λ Λ α 1 α 2 Λ Λ... ID 1 ID 2 means that there is a transition of M from ID 1 to ID 2 ID 1 ID 2 means that there is a sequence of transitions of M that leads from ID 1 to ID 2 COMP 2600 Turing Machines 20

Transitions for 01##01: q 0 01##01 q 1 1##01 1q 1 ##01 1#q 3 #01 1##q 3 01 1#q 5 ##1 1q 5 ###1 q 5 1###1 q 6 Λ1###1 continued on the next slide! COMP 2600 Turing Machines 21

q 0 1###1 q 2 ###1 #q 4 ##1 ##q 4 #1 ###q 4 1 ##q 5 ## #q 5 ### q 5 #### q 5 Λ#### q 7 #### COMP 2600 Turing Machines 22

Programming Techniques for TMs Some notational conventions make it easier to write TM programs. Idea: Use structured states and tape symbols. Storage in the state Idea: State names are tuples of the form [q,d 1,...,D k ] each D i acts as a stored symbol q is the control portion of the state COMP 2600 Turing Machines 23

Example M = (Q,q 0,F,Γ,Σ,Λ,δ) E = 01 + 10 L(E) = {0,01,011,...,1,10,100,...} Q = {[q i,x] i {a,b},x {0,1, }} = {[q a,0],[q a,1],[q a, ],[q b,0],[q b,1],[q b, ]} q 0 = [q a, ] F = {[q b, ]} Γ = {0,1,Λ} Σ = {0,1} COMP 2600 Turing Machines 24

Meaning of [q i,x]: control portion q a M has not yet read the first input symbol q b M has read the first input symbol data portion x is the first input symbol read COMP 2600 Turing Machines 25

Transitions: M remembers in [q 1,x] that it has read x δ([q a, ],x) = ([q b,x],x,r) for x {0,1} M moves right as long as it sees a symbol different from the first symbol δ([q b,0],1) = ([q b,0],1,r) δ([q b,1],0) = ([q b,1],0,r) M accepts when it reaches the first blanc symbol δ([q b,x],λ) = ([q b, ],Λ,R) for x {0,1} COMP 2600 Turing Machines 26

Multiple tracks Idea: View tape as having multiple tracks, i.e. each symbol in Γ has multiple components:... 0 # Λ...... 1 0 0...... a a c... The symbols on the tape are [ 01 a ], [ #0 a ] and [ Λ0 c ]. COMP 2600 Turing Machines 27

Example L = {ww w {0,1} + } Two stages find the midpoint match symbols To find the midpoint, view the tape as 2 tracks: [ ] [ ] [ ] [ ] [ ] Γ = { ΛΛ, Λ0, Λ1, *1, *0 }... Λ Λ Λ Λ Λ...... 0 1 1 0 1 1... Idea: Put markers on two out-most symbols and move them inwards! COMP 2600 Turing Machines 28

Extensions of the basic TM Multi-tape TM A Multi-tape TM is like an ordinary Turing machine with several tapes. Each tape has its own head. Initially the input w is on tape 1 with the head on the left-most symbol. The other tapes are all blank. Transitions specify behaviour of each head independently: δ(q,x 1,...,x k ) = (p,(y 1,d 1 ),...,(y k,d k )) where x i is the symbol under head i is the new symbol under head i y i d i direction in which head i moves Note: we can simulate a k-tape TM with a 1-tape TM. COMP 2600 Turing Machines 29

Extensions of the basic TM Non-deterministic TM (NTM) In a (deterministic) TM δ(q, x) is unique or undefined. In a NTM, δ(q,x) is a finite set of triplets δ(q,x) = {(p 1,y 1,d 1 ),...,(p m,y m,d m )} At each step, a NTM can non-deterministically choose which transition to make. As for NFA s a NTM accepts if there is a sequence of guesses (non-deterministic choice) that leads to a final state. COMP 2600 Turing Machines 30

Languages and TMs The language recognised by a TM M L(M) = {w Σ q 0 w α 1 pα 2 with p F,α 1,α 2 Γ } The class of languages accepted by TMs is called recursively enumerable languages. for a string w in the language the TM halts on input w in a final state for a string w not in the language the TM either halts in a non-final state or loops forever Those languages for which the TM halts (regardless of whether it accepts or not) are called recursive languages. COMP 2600 Turing Machines 31

Recursive Languages A language L is recursive if L = L(M) for some TM M such that if w L, then M accepts (and therefore halts) if w is not in L, then M eventually halts, although it never enters an accepting state A TM of this type corresponds to an algorithm: a well defined sequence of steps that always finishes and produces an answer. If we think of a language L as a problem, then problem L is called decidable if it is a recursive language; and it is called undecidable if it is not a recursive language. Recursive (or decidable ) languages are not only recursively enumerable but are also accepted by a TM that always halts regardless of whether or not it accepts. COMP 2600 Turing Machines 32