Turing Machines. Chapter 17

Similar documents
MA/CSSE 474 Theory of Computation

The Unsolvability of the Halting Problem. Chapter 19

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

Functions on languages:

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

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

Part I: Definitions and Properties

1 Acceptance, Rejection, and I/O for Turing Machines

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

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

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

Most General computer?

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Decidability: Church-Turing Thesis

Introduction to Turing Machines. Reading: Chapters 8 & 9

ECS 120 Lesson 15 Turing Machines, Pt. 1

TURING MAHINES

CSCC63 Worksheet Turing Machines

Reducability. Sipser, pages

Computable Functions

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

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

Chapter 8. Turing Machine (TMs)

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

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

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar

CS21 Decidability and Tractability

1 Unrestricted Computation

CSE 105 THEORY OF COMPUTATION

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Introduction to Languages and Computation

Chapter 3: The Church-Turing Thesis

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

CPSC 421: Tutorial #1

Decidability: Reduction Proofs

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Turing Machines Part III

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Turing Machines. Lecture 8

Automata Theory CS S-12 Turing Machine Modifications

CS5371 Theory of Computation. Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)

Non-emptiness Testing for TMs

Further discussion of Turing machines

Computability and Complexity

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CSCI 2200 Foundations of Computer Science Spring 2018 Quiz 3 (May 2, 2018) SOLUTIONS

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

Homework Assignment 6 Answers

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

Lecture 12: Mapping Reductions

Undecidable Problems and Reducibility

A Note on Turing Machine Design

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

CS20a: Turing Machines (Oct 29, 2002)

Theory of Computation - Module 4

Theory of Computation

CS20a: Turing Machines (Oct 29, 2002)

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

Turing Machines Part II

CSE 105 THEORY OF COMPUTATION

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

Pushdown Automata. Chapter 12

Equivalent Variations of Turing Machines

Chapter 7 Turing Machines

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

1 Showing Recognizability

Introduction to Turing Machines

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

Computation Histories

ACS2: Decidability Decidability

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

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

V Honors Theory of Computation

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

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

CS154, Lecture 10: Rice s Theorem, Oracle Machines

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

4.2 The Halting Problem

CS5371 Theory of Computation. Lecture 14: Computability V (Prove by Reduction)

Final exam study sheet for CS3719 Turing machines and decidability.

Turing Machine Recap

Computability and Complexity

jflap demo Regular expressions Pumping lemma Turing Machines Sections 12.4 and 12.5 in the text

Theory of Computation

} Some languages are Turing-decidable A Turing Machine will halt on all inputs (either accepting or rejecting). No infinite loops.

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

Universal Turing Machine. Lecture 20

CSE 105 THEORY OF COMPUTATION

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

What languages are Turing-decidable? What languages are not Turing-decidable? Is there a language that isn t even Turingrecognizable?

CSCI3390-Assignment 2 Solutions

THEORY OF COMPUTATION

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

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2016, face-to-face day section Prof. Marvin K. Nakayama

CS4026 Formal Models of Computation

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

CSCE 551 Final Exam, Spring 2004 Answer Key

Transcription:

Turing Machines Chapter 17

Languages and Machines SD D Context-Free Languages Regular Languages reg exps FSMs cfgs PDAs unrestricted grammars Turing Machines

Grammars, SD Languages, and Turing Machines L SD Language Unrestricted Grammar Accepts Turing Machine

Turing Machines Can we come up with a new kind of automaton that has two properties: powerful enough to describe all computable things unlike FSMs and PDAs. simple enough that we can reason formally about it like FSMs and PDAs, unlike real computers.

Turing Machines At each step, the machine must: choose its next state, write on the current square, and move left or right.

A Formal Definition A Turing machine M is a sixtuple (K,,,, s, H): K is a finite set of states; is the input alphabet, which does not contain q; is the tape alphabet, which must contain q and have as a subset. s K is the initial state; H K is the set of halting states; is the transition function: (K - H) to K {, } non-halting tape state tape action state char char (R or L)

Notes on the Definition 1. The input tape is infinite in both directions. 2. is a function, not a relation. So this is a definition for deterministic Turing machines. 3. must be defined for all state, input pairs unless the state is a halting state. 4. Turing machines do not necessarily halt (unlike FSM's and PDAs). Why? To halt, they must enter a halting state. Otherwise they loop. 5. Turing machines generate output so they can compute functions.

An Example M takes as input a string in the language: {a i b j, 0 j i}, and adds b s as required to make the number of b s equal the number of a s. The input to M will look like this: The output should be:

The Details K = {1, 2, 3, 4, 5, 6}, = {a, b}, = {a, b, q, $, #}, s = 1, H = {6}, =

Notes on Programming The machine has a strong procedural feel, with one phase coming after another. There are common idioms, like scan left until you find a blank There are two common ways to scan back and forth marking things off. Often there is a final phase to fix up the output. Even a very simple machine is a nuisance to write.

Halting A DFSM M, on input w, is guaranteed to halt in w steps. A PDA M, on input w, is not guaranteed to halt. To see why, consider again M = But there exists an algorithm to construct an equivalent PDA M that is guaranteed to halt. A TM M, on input w, is not guaranteed to halt. And there exists no algorithm to construct one that is guaranteed to do so.

Formalizing the Operation A configuration of a Turing machine M = (K,,, s, H) is an element of: K (( - {q}) *) { } ( * ( - {q})) { } state up scanned after to scanned square scanned square square

Example Configurations (1) (q, ab, b, b) = (q, abbb) (2) (q,, q, aabb) = (q, qaabb) Initial configuration is (s, qw).

Yields (q 1, w 1 ) - M (q 2, w 2 ) iff (q 2, w 2 ) is derivable, via, in one step. For any TM M, let - M * be the reflexive, transitive closure of - M. Configuration C 1 yields configuration C 2 if: C 1 - M * C 2. A path through M is a sequence of configurations C 0, C 1,, C n for some n 0 such that C 0 is the initial configuration and: C 0 - M C 1 - M C 2 - M - M C n. A computation by M is a path that halts. If a computation is of length n or has n steps, we write: C 0 - Mn C n

A Notation for Turing Machines (1) Define some basic machines Symbol writing machines For each x, define M x, written just x, to be a machine that writes x. Head moving machines R: for each x, (s, x) = (h, x, ) L: for each x, (s, x) = (h, x, ) Machines that simply halt: h, which simply halts. n, which halts and rejects. y, which halts and accepts.

Checking Inputs and Combining Machines Next we need to describe how to: Check the tape and branch based on what character we see, and Combine the basic machines to form larger ones. To do this, we need two forms: M 1 M 2 M 1 <condition> M 2

A Notation for Turing Machines, Cont'd Example: >M 1 a M 2 b M 3 Start in the start state of M 1. Compute until M 1 reaches a halt state. Examine the tape and take the appropriate transition. Start in the start state of the next machine, etc. Halt if any component reaches a halt state and has no place to go. If any component fails to halt, then the entire machine may fail to halt.

a M 1 M 2 becomes M 1 a, b M 2 b Shorthands M 1 all elems of M 2 becomes M 1 M 2 or M 1 M 2 Variables M 1 all elems of M 2 becomes M 1 x a M 2 except a and x takes on the value of the current square M 1 a, b M 2 becomes M 1 x a, b M 2 and x takes on the value of the current square if x = y then take the transition M 1 x = y M 2 e.g., > x q Rx if the current square is not blank, go right and copy it.

Some Useful Machines Find the first blank square to the right of the current square. R q Find the first blank square to the left of the current square. L q Find the first nonblank square to the right of the current square. R q Find the first nonblank square to the left of the current square L q

More Useful Machines L a R a,b Find the first occurrence of a to the left of the current square. Find the first occurrence of a or b to the right of the current square. L a,b a M 1 Find the first occurrence of a or b to the left of the current square, b then go to M 1 if the detected character is a; go to M 2 if the M 2 detected character is b. L x a,b L x a,b Rx Find the first occurrence of a or b to the left of the current square and set x to the value found. Find the first occurrence of a or b to the left of the current square, set x to the value found, move one square to the right, and write x (a or b).

Input: qw w {1}* Output: qw 3 An Example Example: q111qqqqqqqqqqqqqq

A Shifting Machine S Input: Output: Example: quqwq quwq qbaqabbaqqqqqqqqqqqq

Turing Machines as Language Recognizers Convention: We will write the input on the tape as: qwq, w contains no qs The initial configuration of M will then be: (s, qw) Let M = (K,,,, s, {y, n}). M accepts a string w iff (s, qw) - M * (y, w ) for some string w. M rejects a string w iff (s, qw) - M * (n, w ) for some string w.

Turing Machines as Language Recognizers M decides a language L * iff: For any string w * it is true that: if w L then M accepts w, and if w L then M rejects w. A language L is decidable iff there is a Turing machine M that decides it. In this case, we will say that L is in D.

A Deciding Example A n B n C n = {a n b n c n : n 0} Example: qaabbccqqqqqqqqq Example: qaaccbqqqqqqqqq

Another Deciding Example WcW = {wcw : w {a, b}*} Example: qabbcabbqqq Example: qacabbqqq

Semideciding a Language Let M be the input alphabet to a TM M. Let L M *. M semidecides L iff, for any string w M *: w L M accepts w w L M does not accept w. M may either: reject or fail to halt. A language L is semidecidable iff there is a Turing machine that semidecides it. We define the set SD to be the set of all semidecidable languages.

Example of Semideciding Let L = b*a(a b)* We can build M to semidecide L: 1. Loop 1.1 Move one square to the right. If the character under the read head is an a, halt and accept. In our macro language, M is:

Example of Semideciding L = b*a(a b)*. We can also decide L: Loop: 1.1 Move one square to the right. 1.2 If the character under the read/write head is an a, halt and accept. 1.3 If it is q, halt and reject. In our macro language, M is:

Computing Functions Let M = (K,,,, s, {h}). Its initial configuration is (s, qw). Define M(w) = z iff (s, qw) - M * (h, qz). Let be M s output alphabet. Let f be any function from * to *. M computes f iff, for all w *: If w is an input on which f is defined: M(w) = f(w). Otherwise M(w) does not halt. A function f is recursive or computable iff there is a Turing machine M that computes it and that always halts.

Example of Computing a Function Let = {a, b}. Let f(w) = ww. Input: qwqqqqqq Output: qwwq Define the copy machine C: qwqqqqqq qwqwq Remember the S machine: quqwq quwq Then the machine to compute f is just >C S L q

Example of Computing a Function Let = {a, b}. Let f(w) = ww. Input: qwqqqqqq Output: qwwq Define the copy machine C: qwqqqqqq qwqwq Remember the S machine: quqwq quwq Then the machine to compute f is just >C S L q

Computing Numeric Functions For any positive integer k, value k (n) returns the nonnegative integer that is encoded, base k, by the string n. For example: value 2 (101) = 5. value 8 (101) = 65. TM M computes a function f from N m to N iff, for some k: value k (M(n 1 ;n 2 ; n m )) = f(value k (n 1 ), value k (n m )).

Computing Numeric Functions Example: succ(n) = n + 1 We will represent n in binary. So n 0 1{0, 1}* Input: qnqqqqqq q1111qqqq Output: qn+1q Output: q10000q

Computing Numeric Functions Example: succ(n) = n + 1 We will represent n in binary. So n 0 1{0, 1}* Input: qnqqqqqq q1111qqqq Output: qn+1q Output: q10000q

Not All Functions Are Computable Let T be the set of all TMs that: Have tape alphabet = {q, 1}, and Halt on a blank tape. Define the busy beaver functions S(n) and (n): S(n): the maximum number of steps that are executed by any element of T with n-nonhalting states, when started on a blank tape, before it halts. (n): the maximum number of 1 s that are left on the tape by any element of T with n-nonhalting states, when it halts. n S(n) (n) 1 1 1 2 6 4 3 21 6 4 107 13 5 47,176,870 4098 6 3 10 1730 1.29 10 865

Why Are We Working with Our Hands Tied Behind Our Backs? Turing machines Are more powerful than any of the other formalisms we have studied so far. Turing machines Are a lot harder to work with than all the real computers we have available. Why bother? The very simplicity that makes it hard to program Turing machines makes it possible to reason formally about what they can do. If we can, once, show that anything a real computer can do can be done (albeit clumsily) on a Turing machine, then we have a way to reason about what real computers can do.