Turing Machines Part Two

Similar documents
Turing Machines Part One

Turing Machines Part III

Turing Machines Part II

Turing Machines Part II

A Note on Turing Machine Design

Decidability and Undecidability

Turing Machines Part Three

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

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

Introduction to Turing Machines. Reading: Chapters 8 & 9

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

V Honors Theory of Computation

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

Turing Machines Part Three

Turing Machines Part Three

Complexity Theory Part I

Finite Automata Part One

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

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

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

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

Mapping Reducibility. Human-aware Robotics. 2017/11/16 Chapter 5.3 in Sipser Ø Announcement:

1 Showing Recognizability

CSE 105 Theory of Computation

CSE 105 THEORY OF COMPUTATION

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

Most General computer?

Decidable Languages - relationship with other classes.

Turing Machines, diagonalization, the halting problem, reducibility

CS154, Lecture 10: Rice s Theorem, Oracle Machines

CPSC 421: Tutorial #1

CSE 105 THEORY OF COMPUTATION

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

CSE 105 THEORY OF COMPUTATION

Decidable and undecidable languages

Further discussion of Turing machines

Time-bounded computations

CSE 105 THEORY OF COMPUTATION

Nonregular Languages

The Turing machine model of computation

Announcements. Using a 72-hour extension, due Monday at 11:30AM.

CSCI3390-Assignment 2 Solutions

Announcements. Final exam review session tomorrow in Gates 104 from 2:15PM 4:15PM Final Friday Four Square of the quarter!

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

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

Turing Machines and the Church-Turing Thesis

Turing Machine Variants

CS4026 Formal Models of Computation

Complexity Theory Part I

Introduction to Languages and Computation

Reducability. Sipser, pages

ECS 120 Lesson 15 Turing Machines, Pt. 1

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

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

UNIT-VIII COMPUTABILITY THEORY

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

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

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

Finite Automata Part One

Finite Automata Part One

Computability Theory. CS215, Lecture 6,

CS5371 Theory of Computation. Lecture 15: Computability VI (Post s Problem, Reducibility)

CSE 105 THEORY OF COMPUTATION

Turing Machines. Lecture 8

The Church-Turing Thesis

Finite Automata Part Two

TURING MAHINES

Lecture 12: Mapping Reductions

Turing Machine Recap

Part I: Definitions and Properties

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

Lecture 23: Rice Theorem and Turing machine behavior properties 21 April 2009

Exam Computability and Complexity

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CpSc 421 Final Exam December 15, 2006

CS20a: Turing Machines (Oct 29, 2002)

CSE 105 THEORY OF COMPUTATION

Decidability (What, stuff is unsolvable?)

Undecidable Problems and Reducibility

Automata and Computability. Solutions to Exercises

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

Computability Theory

Automata Theory CS S-12 Turing Machine Modifications

Intro to Theory of Computation

Theory of Computation (IX) Yijia Chen Fudan University

CpSc 421 Homework 9 Solution

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

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

CS20a: Turing Machines (Oct 29, 2002)

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

Foundations of

CSE 105 Theory of Computation

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

Automata and Computability. Solutions to Exercises

Computability and Complexity

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

Decidability (intro.)

Turing machines and linear bounded automata

Lecture notes on Turing machines

ACS2: Decidability Decidability

Transcription:

Turing Machines Part Two

Recap from Last Time

Our First Turing Machine q acc a start q 0 q 1 a This This is is the the Turing Turing machine s machine s finiteisttiteiconntont. finiteisttiteiconntont. It It issues issues commands commands that that drive drive the the operation operation of of the the machine. machine. q rej

Our First Turing Machine q acc a start q 0 q 1 a This This is is the the TM s TM s infiniteitipe. infiniteitipe. Each Each tape tape cell cell holds holds a a tipei tipei stymbnt. stymbnt. Initially, Initially, all all (infnitely (infnitely many) many) tape tape symbols symbols are are blank. blank. q rej

Our First Turing Machine q acc a start q 0 q 1 The The machine machine is is started started with with the the inputisttoing inputisttoing written written somewhere somewhere on on the the tape. tape. The The tipeiheid tipeiheid initially initially points points to to the the frst frst symbol symbol of of the the input input string. string. a q rej a a a a

Our First Turing Machine q acc a start q 0 q 1 Like Like DFAs DFAs and and NFAs, NFAs, TMs TMs begin begin execution execution in in their their sttiotisttite. sttiotisttite. a q rej a a a a

Our First Turing Machine q acc a start q 0 q 1 At At each each step, step, the the TM TM only only looks looks at at the the symbol symbol immediately immediately under under the the tipeiheid. tipeiheid. a q rej a a a a

Our First Turing Machine q acc a start q 0 q 1 These These two two transitions transitions originate originate at at the the current current state. state. We re We re going going to to choose choose one one of of them them to to follow. follow. a q rej a a a a

Our First Turing Machine q acc a start q 0 q 1 a Each Each transition transition has has the the form form oeidi iwoite,idio oeidi iwoite,idio and and means means if if symbol symbol oeid oeid is is under under the the tape tape head, head, q replace rej replace it it with with woite woite and and move move the the tape tape head head in in direction direction dio dio (L (L or or R). R). The The symbol symbol denotes denotes a a blank blank cell. cell. a a a a

Our First Turing Machine q acc a start q 0 q 1 Unlike a DFA DFA or or NFA, NFA, a TM TM doesn t stop stop after after reading all all the the input characters. We We keep keep running until until the the machine explicitly says says to to stop. stop. a q rej

Our First Turing Machine q acc a start q 0 q 1 This This special state state is is an an icocoeptingisttite. When a TM TM enters an an accepting state, it it immediately stops running and and accepts whatever the the original input string was was (in (in this this case, aaaa). a q rej

Our First Turing Machine q acc a start q 0 q 1 This This special state is is ai ai oejecotingisttite. When a TM TM enters a rejecting state, it it immediately stops running and and rejects whatever the the original input string was was (in (in this this case, aaaaa). a q rej

Our First Turing Machine q acc a start q 0 q 1 If If the the TM TM is is started on on the the empty string ε, ε, the the entire tape tape is is blank and and the the tape tape head head is is positioned at at some arbitrary location on on the the tape. tape. a q rej

Input and Tape Alphabets A Turing machine has two alphabets: An inputiitphibet Σ. All input strings are written in the input alphabet. A tipeiitphibet Γ, where Σ Γ. The tape alphabet contains all symbols that can be written onto the tape. The tape alphabet Γ can contain any number of symbols, but always contains at least one btinki stymbnt, denoted. You are guaranteed Σ. At startup, the Turing machine begins with an infnite tape of symbols with the input written at some location. The tape head is positioned at the start of the input.

0 0, R 0 0, L 1 1, L Go to start 1, L Clear a 1 start, L 1 q acc rej Check for 0 0, R Go to end 0 0, R 1 1, R q acc

1 1, R, R start 1, R Find 0 0, L, R Find 0/1 Go Go home 0 0, L 1 1, L, L, R 0, R Find 1 1, L Accept! 0 0, R, R Remember Remember that that all all missing missing transitions transitions implicitly implicitly reject. reject.

0 0, L 1 1, L To Start, R Start 0 n 1 n, L start, L 0 0, R 1 1, R 0* 0*1* 1 1, R, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01

New Stuf!

Main Question for Today: Just how powerful are Turing machines?

TM Arithmetic Let's design a TM that, given a tape that looks like this: 1 3 7 4 2 ends up having the tape look like this: 1 7 9 0 0 In other words, we want to build a TM that can add two numbers.

TM Arithmetic There are many ways we could in principle design this TM. We're going to take the following approach: First, we'll build a TM that increments a number. Next, we'll build a TM that decrements a number. Then, we'll combine them together, repeatedly decrementing the second number and adding one to the frst number.

Incrementing Numbers Let's begin by building a TM that increments a number. We'll assume that the tape head points at the start of a number, there is are at least two blanks to the left of the number, and that there's at least one blank at the start of the number. The tape head will end at the start of the number after incrementing it. 9 9 8

Incrementing Numbers go go to to the the end end of of the the number; while (the (the current digit is is 9) 9) { set set the the current digit to to 0; 0; back back up up one one digit; } increment the the current digit; go go to to the the start of of the the number;

start 0 0, R 1 1, R 9 9, R To End, L End??,? Based on on we want this TM to to do, what should this transition say? A. A. 0 9, 9, R B. B. 0 9, 9, L C. C. 9 0, 0, R D. D. 9 0, 0, L E. E. None of of these, or or two or or more of of these. Answer at at PollEv.com/cs103 or or text text CS103 to to 22333 once once to to join, join, then then A, A, B, B, C, C, D, D, or or E. E. 1 2 9 9

0 0, R 1 1, R 9 9, R start To End, L Wrap Nines 9 0, L 0 1, L 1 2, L 2 3, L 8 9, L 1, L done!, R Back Home 0 0, L 1 1, L 9 9, L

Decrementing Numbers Now, let's build a TM that decrements a number. We'll assume that the tape head points at the start of a number, there is at least one blank on each side of the number. The tape head will end at the start of the number after decrementing it. If the number is 0, then the subroutine should somehow signal this rather than making the number negative. 1 0 2

Decrementing Numbers go to the end of the number; if (every digit was 0) { signal that we're done; } while (the current digit is 0) { set the current digit to 9; back up one digit; } decrement the current digit; go to the start of the number;

0 0, R 1 1, R 9 9, R To End, L Wrap Zeros 0 9, L 1 1, R 2 2, R 9 9, R n = 0 1 0, L 2 1, L 3 2, L 9 8, L start, R 0 0, R Nonzero?, L Back Home done!, R Back Home 0 0, L 1 1, L 9 9, L 0 0, L

TM Subroutines Sometimes, a subroutine needs to report back some information about what happened. Just as a function can return multiple diferent values, we'll allow subroutines to have diferent done states. Each state can then be wired to a diferent state, so a TM using the subroutine can control what happens next.

Putting it All Together Our goal is to build a TM that, given two numbers, adds those numbers together. Before: 1 3 7 4 2 After: 1 7 9 0 0

0 0, R 1 1, R... 9 9, R start done To 2 nd num incr, R done, L, R decr To 1 st num Go home n = 0 0 0, L 1 1, L... 9 9, L 0 0, L 1 1, L... 9 9, L done!

Using Subroutines Once you've built a subroutine, you can wire it into another TM with something that, schematically, looks like this: X Y, D sub done Intuitively, this corresponds to transitioning to the start state of the subroutine, then replacing the done state of the subroutine with the state at the end of the transition.

Time-Out for Announcements!

Problem Sets Problem Set Seven was due at 2:30PM today. Using late days, you can extend the deadline to this Sunday at 2:30PM. Problem Set Eight goes out today. It s due the Friday at 2:30PM. Play around with CFGs and Turing machines! We have online tools you ll use to design, test, and submit your grammars and TMs. Hope this helps! Depending on what we manage to get through today, there s a chance that a few topics on the problem set will require content from Monday s lecture. Those problems are clearly marked as such.

Extra Practice Problems 3 Later this evening, we ll post a (massive!) set of practice problems (EPP3) on the course website, with solutions. These problems cover all the topics we ll explore this quarter. Questions involving topics we will cover next week are marked with a star. Feel free to work through any of the problems that seem interesting and to ask questions!

Back to CS103!

Main Question for Today: Just how powerful are Turing machines?

How Powerful are TMs? Regular languages, intuitively, are as powerful as computers with fnite memory. TMs by themselves seem like they can do a fair number of tasks, but it's unclear specifcally what they can do. Let's explore their expressive power.

Real and Ideal Computers A real computer has memory limitations: you have a fnite amount of RAM, a fnite amount of disk space, etc. However, as computers get more and more powerful, the amount of memory available keeps increasing. An idealized computer is like a regular computer, but with unlimited RAM and disk space. It functions just like a regular computer, but never runs out of memory.

Claim 1: Idealized computers can simulate Turing machines. Anything that can be done with a TM can also be done with an unboundedmemory computer.

0 0, R 0 0, L 1 1, L start Go to start q₃ 1, L Clear a 1q₂, L 1 q acc r Check for q₀0 0, R Go to end q₁ 0 0, R 1 1, R q acc a q₀ q₁ q₂ q₃ 0 q₁ R q r 1 R q a R q₁ 0 R q₁ 1 R q₂ L q r 0 R q₃ L q r R q₃ 0 L q₃ 1 L q₀ R

Simulating a TM To simulate a TM, the computer would need to be able to keep track of the fnite-state control, the current state, the position of the tape head, and the tape contents. The tape contents are infnite, but that's because there are infnitely many blanks on both sides. We only need to store the interesting part of the tape (the parts that have been read from or written to so far.) 1 7 9 0 0

Claim 2: Turing machines can simulate idealized computers. Anything that can be done with an unbounded-memory computer can be done with a TM.

What We've Seen TMs can implement loops (basically, every TM we've seen). make function calls (subroutines). keep track of natural numbers (written in unary or in decimal on the tape). perform elementary arithmetic (equality testing, multiplication, addition, increment, decrement, etc.). perform if/else tests (diferent transitions based on diferent cases).

What Else Can TMs Do? Maintain variables. Have a dedicated part of the tape where the variables are stored. We've seen this before: take a look at our machine for increment/decrement. Maintain arrays and linked structures. Divide the tape into diferent regions corresponding to memory locations. Represent arrays and linked structures by keeping track of the ID of one of those regions.

A CS107 Perspective Internally, computers execute by using basic operations like simple arithmetic, memory reads and writes, branches and jumps, register operations, etc. Each of these are simple enough that they could be simulated by a Turing machine.

A Leap of Faith It may require a leap of faith, but anything you can do a computer (excluding randomness and user input) can be performed by a Turing machine. The resulting TM might be colossal, or really slow, or both, but it would still faithfully simulate the computer. We're going to take this as an article of faith in CS103. If you curious for more specifc details of how to do this, come talk to me after class. This This is is quite quite a bold bold claim claim to to make. make. What s What s an an example example of of something something your your computer computer can can do do that that you re you re convinced convinced a Turing Turing machine machine couldn t couldn t do? do? Answer Answer at at PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then your your answer. answer.

Just how powerful are Turing machines?

Efective Computation An efective method of computation is a form of computation with the following properties: The computation consists of a set of steps. There are fxed rules governing how one step leads to the next. Any computation that yields an answer does so in fnitely many steps. Any computation that yields an answer always yields the correct answer. This is not a formal defnition. Rather, it's a set of properties we expect out of a computational system.

The Church-Turing Thesis claims that every efective method of computation is either equivalent to or weaker than a Turing machine. This is not a theorem it is a falsifable scientifc hypothesis. And it has been thoroughly tested! - Ryan Williams

Regular Languages CFLs Problems Solvable by Any Feasible Computing Machine All Languages

Regular Languages CFLs Problems solvable by Turing Machines All Languages

TMs Computers Because Turing machines have the same computational powers as regular computers, we can (essentially) reason about Turing machines by reasoning about actual computer programs. Going forward, we're going to switch back and forth between TMs and computer programs based on whatever is most appropriate. In fact, our eventual proofs about the existence of impossible problems will involve a good amount of pseudocode. Stay tuned for details!

Strings, Languages, Encodings, and Problems

What problems can we solve with a computer? What kind of computer?

What problems can we solve with a computer? What does it mean to solve a problem?

The Hailstone Sequence Consider the following procedure, starting with some n N, where n > 0: If n = 1, you are done. If n is even, set n = n / 2. Otherwise, set n = 3n + 1. Repeat. Question: Given a number n, does this process terminate?

52 11 34 17 26 13 40 20 10 16 8 If If n = 1, 1, stop. stop. If If n is is even, even, set set n = n // 2. 2. Otherwise, set set n = 3n 3n + 1. 1. Repeat. Repeat. 5 4 2 1

The Hailstone Sequence Let Σ = {1} and consider the language L = { 1 n n > 0 and the hailstone sequence terminates for n }. Could we build a TM for L?

The Hailstone Turing Machine We can build a TM that works as follows: If the input is ε, reject. While the string is not 1: If the input has even length, halve the length of the string. If the input has odd length, triple the length of the string and append a 1. Accept.

The Hailstone Turing Machine 1 1 1 1 1 If If the the input input is is ε, ε, reject. reject. While While the the input input is is not not 1: 1: If If the the input input has has even even length, length, halve halve the the length length of of the the string. string. If If the the input input has has odd odd length, length, triple triple the the length length of of the the string string and and append append a 1. 1. Accept. Accept.

Does this Turing machine accept all nonempty strings?

The Collatz Conjecture It is unknown whether this process will terminate for all natural numbers. In other words, no one knows whether the TM described in the previous slides will always stop running! The conjecture (unproven claim) that this always terminates is called the Collatz Conjecture.

The Collatz Conjecture Mathematics may not be ready for such problems. - Paul Erdős The fact that the Collatz Conjecture is unresolved is useful later on for building intuitions. Keep this in mind!

An Important Observation Unlike fnite automata, which automatically halt after all the input is read, TMs keep running until they explicitly enter an accept or reject state. As a result, it s possible for a TM to run forever without accepting or rejecting. This leads to several important questions: How do we formally defne what it means to build a TM for a language? What implications does this have about problemsolving?

Very Important Terminology Let M be a Turing machine. M accepts a string w if it enters an accept state when run on w. M rejects a string w if it enters a reject state when run on w. M loops infnitely (or just loops) on a string w if when run on w it enters neither an accept nor a reject state. M does not accept w if it either rejects w or loops infnitely on w. M does not reject w w if it either accepts w or loops on w. M halts on w if it accepts w or rejects w. does not reject does not accept Accept Loop Reject halts

The Language of a TM The language of a Turing machine M, denoted L( M), is the set of all strings that M accepts: L(M) = { w Σ* M accepts w } Let Let M be be a TM TM with with input input alphabet alphabet Σ and and let let w Σ* Σ* be be a string string where where w L (( M). M). How How many many of of the the following following are are not not possible? possible? M accepts accepts w. w. M rejects rejects w. w. M loops loops on on w. w. M does does not not accept accept w. w. M does does not not reject reject w. w. M halts halts on on w. w. Answer Answer at at PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then a a number. number.

The Language of a TM The language of a Turing machine M, denoted L( M), is the set of all strings that M accepts: L(M) = { w Σ* M accepts w } For any w L( M), M accepts w. For any w L( M), M does not accept w. M might reject, or it might loop forever. A language is called recognizable if it is the language of some TM. A TM M where L( M) = L is called a recognizer for L. Notation: the class RE is the set of all recognizable languages. L RE L is recognizable

What do you think? Does that correspond to what you think it means to solve a problem?

Deciders Some Turing machines always halt; they never go into an infnite loop. If M is a TM and M halts on every possible input, then we say that M is a decider. For deciders, accepting is the same as not rejecting and rejecting is the same as not accepting. does not reject does not accept Accept Reject halts (always)

Decidable Languages A language L is called decidable if there is a decider M such that L( M) = L. Equivalently, a language L is decidable if there is a TM M such that If w L, then M accepts w. If w L, then M rejects w. The class R is the set of all decidable languages. L R L is decidable

Examples of R Languages All regular languages are in R. See Problem Set Eight! { 0 n1 n n N } is in R. The TM we built is a decider. All CFLs are in R. Proof is tricky; check Sipser for details. (This is why it's possible to build the CFG tool online!)

Why R Matters If a language is in R, there is an algorithm that can decide membership in that language. Run the decider and see what it says. If there is an algorithm that can decide membership in a language, that language is in R. By the Church-Turing thesis, any efective model of computation is equivalent in power to a Turing machine. Therefore, if there is any algorithm for deciding membership in the language, there is a decider for it. Therefore, the language is in R. A language is in R if and only if there is an algorithm for deciding membership in that language.

R and RE Languages Every decider is a Turing machine, but not every Turing machine is a decider. This means that R RE. Hugely important theoretical question: R RE That is, if you can just confrm yes answers to a problem, can you necessarily solve that problem?

Which Picture is Correct? R Regular Languages CFLs RE All Languages

Which Picture is Correct? Regular Languages CFLs R RE All Languages

Unanswered Questions Why exactly is RE an interesting class of problems? What does the R RE question mean? Is R = RE? What lies beyond R and RE? We'll see the answers to each of these in due time.