Turing Machines. Lecture 8

Similar documents
Most General computer?

Understanding Computation

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

Decidability: Church-Turing Thesis

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

Decidable Languages - relationship with other classes.

1 Unrestricted Computation

1 Showing Recognizability

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

Introduction to Turing Machines

Lecture Notes: The Halting Problem; Reductions

CSCI3390-Assignment 2 Solutions

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

CS20a: Turing Machines (Oct 29, 2002)

Computability Theory. CS215, Lecture 6,

Lecture 12: Mapping Reductions

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

CS20a: Turing Machines (Oct 29, 2002)

CSCC63 Worksheet Turing Machines

CS21 Decidability and Tractability

CS154, Lecture 10: Rice s Theorem, Oracle Machines

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

CSE 105 THEORY OF COMPUTATION

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

TURING MAHINES

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Introduction to Turing Machines. Reading: Chapters 8 & 9

Turing machine recap. Universal Turing Machines and Undecidability. Alphabet size doesn t matter. Robustness of TM

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

CS4026 Formal Models of Computation

Theory of Computation

Turing Machines, diagonalization, the halting problem, reducibility

Turing Machines Part II

CS151 Complexity Theory. Lecture 1 April 3, 2017

17.1 The Halting Problem

Part I: Definitions and Properties

Limits of Computability

Computation Histories

Decidability. Linz 6 th, Chapter 12: Limits of Algorithmic Computation, page 309ff

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

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

CSCI3390-Lecture 6: An Undecidable Problem

The Unsolvability of the Halting Problem. Chapter 19

CSE 105 THEORY OF COMPUTATION

15-251: Great Theoretical Ideas in Computer Science Fall 2016 Lecture 6 September 15, Turing & the Uncomputable

Non-emptiness Testing for TMs

CpSc 421 Homework 9 Solution

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

Turing Machine Recap

The Turing machine model of computation

Decidability (What, stuff is unsolvable?)

Computability and Complexity

Chapter 3: The Church-Turing Thesis

Decidability and Undecidability

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Lecture 13: Turing Machine

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CSE 2001: Introduction to Theory of Computation Fall Suprakash Datta

Universal Turing Machine. Lecture 20

CSCE 551 Final Exam, Spring 2004 Answer Key

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

Introduction to Languages and Computation

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 16 : Turing Machines

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

Computability and Complexity

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

Computational Models Lecture 8 1

Turing Machine Variants

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 14 : Turing Machines

Undecidability. We are not so much concerned if you are slow as when you come to a halt. (Chinese Proverb)

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

Turing Machines Decidability

Turing Machines Part III

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

Computational Models Lecture 8 1

Computational Models Lecture 8 1

CS 125 Section #10 (Un)decidability and Probability November 1, 2016

Opleiding Informatica

CPSC 421: Tutorial #1

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

CS 21 Decidability and Tractability Winter Solution Set 3

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

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

Homework Assignment 6 Answers

Turing Machines. Reading Assignment: Sipser Chapter 3.1, 4.2

Reading Assignment: Sipser Chapter 3.1, 4.2

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 8 Nancy Lynch

A non-turing-recognizable language

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

Reducability. Sipser, pages

1 Reals are Uncountable

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

Undecidable Problems and Reducibility

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

Turing Machines Part One

CSE 105 THEORY OF COMPUTATION

Theory of Computation (IX) Yijia Chen Fudan University

Complexity Theory Part I

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

Transcription:

Turing Machines Lecture 8 1

Course Trajectory We will see algorithms, what can be done. But what cannot be done? 2

Computation Problem: To compute a function F that maps each input (a string) to an output bit Program: A finitely described process taking a string as input, and outputting a bit (or not halting) P computes F if for every x, P(x) outputs F(x) and halts 3 A program is a finite bit string Programs can be enumerated listed sequentially (say, lexicographically) so that every program appears somewhere in the list The set of all programs is countable. 1 ε 2 0 3 1 4 00 5 01 6 10 7 11 8 000 9 001 10 010 11 011 12 100

Computation Problem: To compute a function F that maps each input (a string) to an output bit Program: A finitely described process taking a string as input, and outputting a bit (or not halting) P computes F if for every x, P(x) outputs F(x) and halts 4 A function assigns a bit to each finite string Corresponds to an infinite bit string The set of all functions is uncountable! As numerous as, say, real numbers in [0,1] 1 ε 0 2 0 0 3 1 1 4 00 0 5 01 1 6 10 1 7 11 0 8 000 0 9 001 1 10 010 1 11 011 0 12 100 1

Computation Problem: To compute a function F that maps each input (a string) to an output bit Program: A finitely described process taking a string as input, and outputting a bit (or not halting) P computes F if for every x, P(x) outputs F(x) and halts There are uncountably many functions! But only countably many programs 5 Almost every function is uncomputable! (non constructive proof)

Course Trajectory We will be looking at what can be computed at all? What cannot be decided (undecidability) 6

What about a particular problems? Given program P, input w: w P Will halt or run into an infinite loop? Halting problem! 7

Halting Problem Undecidable Given program P: P P Write a program that decides if a program halts. Dual view of program as program and as data. 8

Alas! There is no program that solves the Halting Problem! Way to view code as data allows diagonalization proof. 9

Computing What does it mean to compute something? There is no algorithm for the halting problem What does it mean for something to be an algorithm formally? Then I can say For all algorithms 10

A Brief History of Computing Leibnitz (circa 1600): Believed in universal language for encoding any problem (math, philosophy, religion). Thought if you properly encode any problem in binary form, there is a way to calculate an answer (run the algorithm) calculemus! 11

A Brief History of Computing Babbage (circa 1860): built Difference and Analytical Engine (Add, multiply, etc). It marks the transition from mechanised arithmetic to fully-fledged general purpose computation. Hypothesized that any mathematical question can be answered by the analytical engine, suitably encoded. 12

A Brief History of Computing Hilbert (circa 1900): What can we prove in mathematical world? Proving and computing almost identical, proof= trace the program. The Entscheidungsproblem (descision problem): is there an algorithm that takes as input a statement of a first-order logic and answers "Yes" or "No" according to whether the statement is universally valid, i.e., valid in every structure satisfying the axioms. 13

A Brief History of Computing Gödel: no! there is no such algorithm Church: better way to prove it with functional programming 14

Alan Turing British mathematician cryptanalysis during WWII arguably, father of AI, CS Theory several books, movies Mathematically defined computation 15 Invented Turing Machines at 23 (1936). Turing machines can compute everything that is computable. He proved that The Halting Problem has no general algorithm (it is not possible to decide whether a turing machine will ever halt)

Computation Computers were people at that time! The way people do math is write-erase-throw away. Turing proposed to abstract this process. 16

Turing Machine

Turing Machine Finite alphabet Read Write Move +1 or -1 Halt condition

Turing Machine Finite number of internal states Finite alphabet Read Write Was designed as a model of human computation but it models computers as we know them Move +1 or -1 Halt condition Internal state (finite number)

Why do we care? I need a model of computation that is simple enough to convince you that a TM can take as input a description of a TM and simulate it. Python interpreter in Python? Harder to explain Python semantics Will be able to define what can we compute?

TM for Decision Problems M = (Q, Σ, Γ, B, δ, q start,, q accept, q reject ): Γ is a finite tape alphabet. - B or is the blank symbol (special symbol) - Σ is a finite input alphabet Σ Γ\ B Q is a finite set of states q start Q is the initial state 21 q accept, q reject Q accept/reject states Or maybe run forever

TM for Decision Problems M = (Q, Σ, Γ, B, δ, q start,, q accept, q reject ): Γ is a finite tape alphabet. - B or is the blank symbol (special symbol) - Σ is a finite input alphabet Σ Γ\ B Q is a finite set of states q start Q is the initial state q accept, q reject Q accept/reject states 22 Or maybe run forever Transition function: δ : Q Γ (read) Q Γ (write) { L, R }

Turing Machine pink 0 1 0 1 1 tape = string in Γ* followed by infinite stream of we will treat 011111=011111 configuration = state, string (content of tape), and integer (position of tape). (Q,x,i) Q x Γ*x N e.g. (pink, 01011, 5)

Configuration = ID (Instantaneous 24 Description) Contains all necessary information to capture the current configuration of the computation state, tape-contents & head-location Easy-to-read notation: (q,xay,i) x Γ* : tape contents left of the head q Q : state y Γ* : tape contents at & right of the head (till last non-blank) Initial ID: (qstart, input,0) a: symbol TM is about to read

Relations & * on IDs ID1 ID2 iff ID1 evolves into ID2 in one step. e.g., if δ(q, ai) = (qʹ,b, L), then q,a1 a2 ai-1 ai ai+1 an, i) (qʹ,a1 a2 ai-2ai-1 b ai+1 an,i-1) current ID next ID * i s the reflexive & transitive closure of 25 Thus, ID 1 * ID 2 iff M, when run from ID 1, reaches ID 2 after some finite number (0 or more) of moves

Accept/Reject 0 1 0 1 1 In DFAs it was clear when to accept an input string or reject it. TM can: go back and forth over the input overwrite the input write on the tape way past the end of the input need an explicit state

Definition of Acceptance M accepts w iff (qstart,w, 0) * (qaccept,x,i) for some x Γ* Note that M is allowed to accept w without scanning all of w L(M) = {w M accepts w} M does not accept w if starting from the ID qstart w : 1. M halts in qreject, or 2. M crashes (head moves off the tape), or 3. M never stops 27

Deciding/Recognizing a Language L(M) = {w M accepts w} is called the language recognized by M M decides L(M) if on input w L, M halts in qreject If a TM decides the language it recognizes, then, on every input, it halts in qaccept or qreject Easy to change crashes to rejects But turns out the we can t avoid infinite executions! (can t tell if it is going to be infinite) 28

Deciding/Recognizing a Language L(M) = {w M accepts w} is called the language recognized by M M decides L(M) if on input w L, M halts in qreject Fundamental questions of computability: Which languages are recognizable? Which languages are decidable? Recursively Enumerable Language Recursive Language 29

Example Input alphabet : Σ = {0,1} Tape alphabet : Γ = {0,1,0ʹ, 1ʹ, _} What does this TM do? 0 / 0, R 1 / 1, R 0 / 0ʹ, R 1 / 1ʹ, R 0 / 0, L 1 / 1, L _ / 0, L q3 0ʹ / 0, R q1 _ / _, L q2 1ʹ / 1, R 0 / 0, R 1 / 1, R _ / 1, L q4

q1 q2 q4 q2 q3 q2 Example 0 0 1 0ʹ 0 1 0ʹ 0ʹ 1 0ʹ 0ʹ 1ʹ 0ʹ 0ʹ 1ʹ 0ʹ 0ʹ 1 0ʹ 0ʹ 1 1 _ 0ʹ 0ʹ 1 1 _ 0ʹ 0 1 1 _ 0ʹ 0 1 1 _ 0ʹ 0 1 1 _ 0ʹ 0 1 1 0 0ʹ 0 1 1 0 0ʹ 0 1 1 0 0ʹ 0 1 1 0 Input alphabet : Σ = {0,1} Tape alphabet : Γ = {0,1,0ʹ, 1ʹ, _} 0 / 0ʹ, R 1 / 1ʹ, R q1 _ / _, L 0 / 0, L 1 / 1, L q2 _ / 0, L 0ʹ / 0, R 1ʹ / 1, R _ / 1, L 0 / 0, R 1 / 1, R q3 0 / 0, R 1 / 1, R q4

q1 q2 q3 q2 Example 0 0 1 0ʹ 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 _ 0 0 1 1 0 0 _ 0 0 1 1 0 0 _ 0 0 1 1 0 0 _ 0 0 1 1 0 0 _ Maps w to ww R Next? Crashes! Head moves out of the tape. Input alphabet : Σ = {0,1} Tape alphabet : Γ = {0,1,0ʹ, 1ʹ, _} 0 / 0ʹ, R 1 / 1ʹ, R q1 _ / _, L 0 / 0, L 1 / 1, L q2 _ / 0, L 0ʹ / 0, R 1ʹ / 1, R _ / 1, L 0 / 0, R 1 / 1, R q3 0 / 0, R 1 / 1, R q4

What does this TM do? 33

What does this TM do? 0/0,R 0/$,R p0 _/0,L pstart 1/0,R 0/1,R phalt 34 1/$,R p1 _/1,L 1/1,R

q1 q2 q3 q2 Example 0 0 1 0ʹ 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 _ 0 0 1 1 0 0 _ 0 0 1 1 0 0 _ 0 0 1 1 0 0 _ 0 0 1 1 0 0 _ Maps w to ww R Next? Crashes! Head moves out of the tape. Input alphabet : Σ = {0,1} Tape alphabet : Γ = {0,1,0ʹ, 1ʹ, _} 0 / 0ʹ, R 1 / 1ʹ, R q1 _ / _, L 0 / 0, L 1 / 1, L q2 _ / 0, L 0ʹ / 0, R 1ʹ / 1, R _ / 1, L 0 / 0, R 1 / 1, R q3 0 / 0, R 1 / 1, R q4

Avoiding Crashing Given M (that may crash), an equivalent Mʹ which goes to qreject instead of crashing Idea: Rewrite input w to be $w, place the head on the first symbol of w and run M. If head ever scans $, move to qreject (and move the head right) 0/$,R p0 0/0,R _/0,L 0/0,L 1/1.L $/$,R pstart 1/0,R 0/1,R p2 q0 36 1/$,R p1 _/1,L 1/1,R

Shifting by k Positions Can do shift-by-1 k times. But k scans of tape. To shift by k positions to the right in a single scan: Remember last k symbols. Overwrite current cell with symbol from k cells behind _/$,R pʹʹ0 pstart 0/$,R 1/$,R p0 p1 0/$,R 0/0,R 1/1,R 1/$,R 1/$,R p00 p11 1/$,R 1/0,R 1/0,R 0/1,R 0/1,R 0/0,R p01 p10 1/1,R _/0,R _/0,R _/1,R _/1,R pʹ0 pʹ1 _/0,R _/0,R _/1,R _/1,R 0/0,L 1/1.L $/$,R 37 _/$,R pʹʹ1

Binary Addition L = { x#y#z x, y, z {0,1}*, x = y = z, x+y=z in binary } Plan: shift check LSB : 0 1 # 0 1 # 1 0 _ : $ 0 1 # 0 1 # 1 0 : $ 0 # @ 0 # @ 1 _ carry c=0 carry c=1 38 check MSB check finished : $ # @ @ # @ @ carry c=0

Binary Addition L = { x#y#z x, y, z {0,1}*, x = y = z, x+y=z in binary } Shift input w to make it $w. Scan the tape to ensure w matches (0+1)*#(0+1)*#(0+1)* Return head to the left end (right of $) (In finite memory, carry-bit c initialized to 0) Repeat copy the digit to the left of first # into finite state, and overwrite it with # (replace old # by @). If no digit there, accept if carry is 0 & no digits left; else reject. copy the digit to the left of second # into finite state, and move # left (replace old # by @). If no digit there, reject. check if the right most digit is correct. Reject if no digit or if it is not correct; else erase digit and update carry. Move head to the left end (right of $) 39

Verify finished & Accept x=1 Shift & Format Check $/$,R 0 / 0, R 1 / 1, R q0 $/$,R #/@, L 1 /#,R x=0 0 /#,R @ / @, R 0 / 0, R 1 / 1, R #/@, L 1 /#,R 0 /#,R @ / @, R 0 / 0, R 1 / 1, R _/_, L y=1 y=0 $/$,R 0 / _, L c=0 # / #, L @ / @, L 0 / 0, L 1 / 1, L 40 c=1

What can a TM do? Can shift by any number i, by keeping 2 i states to remember what were in the first i places of the tape. Can do simple arithmetic operations, addition, multiplication etc. 41

What can a TM do? L={ 0 i 1 j 0 k i=j=k } is not a CFL! Can be decided by TM (see notes) 42

What can a TM do? A TM can do everything that can be done in a standard programming language (and vice versa) 43