Turing Machines Part One

Similar documents
Turing Machines Part Two

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

A Note on Turing Machine Design

Turing Machines Part II

Turing Machines Part III

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

Finite Automata Part One

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

Turing Machines Part II

Turing Machines Part One

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

Finite Automata Part Two

Most General computer?

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

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

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

The Turing machine model of computation

Complexity Theory Part I

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

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

Introduction to Turing Machines

Turing Machine Variants

Turing Machines. Lecture 8

Decidability and Undecidability

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

Decidable Languages - relationship with other classes.

Computability Theory. CS215, Lecture 6,

Chapter 7 Turing Machines

CS20a: Turing Machines (Oct 29, 2002)

CSE 105 THEORY OF COMPUTATION

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

Computation Histories

Computability and Complexity

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

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

Reducability. Sipser, pages

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

Finite Automata Part One

Finite Automata Part One

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

Exam Computability and Complexity

CS 301. Lecture 17 Church Turing thesis. Stephen Checkoway. March 19, 2018

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

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

Turing Machines, diagonalization, the halting problem, reducibility

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

Nonregular Languages

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

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

Announcements. Problem Set Four due Thursday at 7:00PM (right before the midterm).

Turing Machines Part Three

Finite Automata Part One

CSE 105 Theory of Computation

ECS 120 Lesson 15 Turing Machines, Pt. 1

Intro to Theory of Computation

CS4026 Formal Models of Computation

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

Decidability (What, stuff is unsolvable?)

Introduction to Turing Machines. Reading: Chapters 8 & 9

V Honors Theory of Computation

CSE 105 THEORY OF COMPUTATION

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

CS21 Decidability and Tractability

Complexity Theory Part I

1 Showing Recognizability

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

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

CS154, Lecture 10: Rice s Theorem, Oracle Machines

Turing Machine Recap

CpSc 421 Homework 9 Solution

TURING MAHINES

Further discussion of Turing machines

Decidability (intro.)

Turing machines and linear bounded automata

Decidable and undecidable languages

CpSc 421 Final Exam December 15, 2006

Undecidable Problems and Reducibility

CS20a: Turing Machines (Oct 29, 2002)

CS 21 Decidability and Tractability Winter Solution Set 3

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

Chapter 3: The Church-Turing Thesis

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

ACS2: Decidability Decidability

CSE 105 THEORY OF COMPUTATION

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

Recap from Last Time

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

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

CSE 105 THEORY OF COMPUTATION

Computability Theory

1 Unrestricted Computation

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Non-emptiness Testing for TMs

CS 361 Meeting 26 11/10/17

Theory of Computation

Introduction to Languages and Computation

Turing machines and linear bounded automata

Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess!

SD & Turing Enumerable. Lecture 33: Reductions and Undecidability. Lexicographically Enumerable. SD & Turing Enumerable

Transcription:

Turing Machines Part One

What problems can we solve with a computer?

Regular Languages CFLs Languages recognizable by any feasible computing machine All Languages

That same drawing, to scale. All Languages

The Problem Finite automata accept precisely the regular languages. We may need unbounded memory to recognize context-free languages. e.g. { an b n n N } requires unbounded counting. How do we build an automaton with fnitely many states but unbounded memory?

A Brief History Lesson

<ahem> Technology has solved all of mankind s problems! No more wars or sad ever!

Hilbert s Vision 1900: International Congress of Mathematicians meeting in Paris Proposes 23 unsolved problems as the agenda for the coming years An important theme is not simply proving more theorems, but achieving automation of theoremproving, even theorem generation. Humanity lives in leisure while all Truth fows efortlessly into our hands on a ticker tape! No one shall expel us from the Paradise that Cantor has created! -David Hilbert

Hi there, Reality! Hilbert s agenda is both a spectacular success and a spectacular failure Inspires some of the most impactful theoretical work in mathematical history, human history Brings us heroes like Alan Turing and Kurt Gödel! These incredible results consist of utterly demolishing all the pillars of Hilbert s vision of automated knowledge creation, within just a few years No one shall expel us from the Paradise that Cantor has created! -David Hilbert

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R 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

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R 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

A Simple Turing Machine q acc, R a, R q 0 q 1 The The machine machine is is ed ed 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, R q rej, R a a a a

A Simple Turing Machine q acc, R a, R 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, R q rej, R a a a a

A Simple Turing Machine q acc, R a, R 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, R q rej, R a a a a

A Simple Turing Machine q acc, R a, R 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, R q rej, R a a a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R Each Each transition transition has has the the form form oeidiiwoite,idio oeidiiwoite,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

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R Each Each transition transition has has the the form form oeidiiwoite,idio oeidiiwoite,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

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R Each Each transition transition has has the the form form oeidiiwoite,idio oeidiiwoite,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 Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R Each Each transition transition has has the the form form oeidiiwoite,idio oeidiiwoite,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 Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R Each Each transition transition has has the the form form oeidiiwoite,idio oeidiiwoite,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 Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a

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

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej

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

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

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a a a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej a

A Simple Turing Machine q acc, R a, R q 0 q 1 a, R, R q rej

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

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

A Simple Turing Machine q acc, R a, R q 0 q 1 If If the the TM TM is is ed ed on on the the empty empty string string ε, ε, the the entire entire tape tape is is blank blank and and the the tape tape head head is is positioned positioned at at some some arbitrary arbitrary location location on on the the tape. tape. a, R q rej, R

A Simple Turing Machine q acc, R a, R q 0 q 1 If If the the TM TM is is ed ed on on the the empty empty string string ε, ε, the the entire entire tape tape is is blank blank and and the the tape tape head head is is positioned positioned at at some some arbitrary arbitrary location location on on the the tape. tape. a, R q rej, R

A Simple Turing Machine q acc, R a, R q 0 q 1 If If the the TM TM is is ed ed on on the the empty empty string string ε, ε, the the entire entire tape tape is is blank blank and and the the tape tape head head is is positioned positioned at at some some arbitrary arbitrary location location on on the the tape. tape. a, R q rej, R

The Turing Machine A Turing machine consists of three parts: A finite-sttiteiconntont that issues commands, an infiniteitipe for input and scratch space, and a tipeiheid that can read and write a single tape cell. At each step, the Turing machine writes a symbol to the tape cell under the tape head, changes state, and moves the tape head to the left or to the right.

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 up, the Turing machine begins with an infnite tape of symbols with the input written at some location. The tape head is positioned at the of the input.

Accepting and Rejecting States Unlike DFAs, Turing machines do not stop processing the input when they fnish reading it. Turing machines decide when (and if!) they will accept or reject their input. Turing machines can enter infnite loops and never accept or reject; more on that later...

Determinism Turing machines are deteoministtico: for every combination of a (non-accepting, non-rejecting) state q and a tape symbol a Γ, there must be exactly one transition defned for that combination of q and a. Any transitions that are missing implicitly go straight to a rejecting state. We ll use this later to simplify our designs. q acc, R a, R q 0 q 1 a, R, R q rej

Determinism Turing machines are deteoministtico: for every combination of a (non-accepting, non-rejecting) state q and a tape symbol a Γ, there must be exactly one transition defned for that combination of q and a. Any transitions that are missing implicitly go straight to a rejecting state. We ll use this later to simplify our designs. q acc, R a, R q 0 q 1 a, R This This machine machine is is exactly exactly the the same same as as the the previous previous one. one.

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej Run Run the the TM TM shown shown above above on on the the input input string string bba. bba. What What will will the the tape tape look look like like when when the the TM TM fnishes fnishes running? running? A. b b a B. a a b C. b b a D. a a b E. None of these, or two or more of these. 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, B, B, C, C, D, D, or or E. E.

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej b b a

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej a b a

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej a a a

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej a a b

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej a a b

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej a a b

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej a a b

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej If If M is is a a Turing Turing machine machine with with input input alphabet alphabet Σ, Σ, then then the the tinguigeinfim, tinguigeinfim, denoted denoted L(M), L(M), is is the the set set L(M) L(M) = { { w Σ* Σ* M accepts accepts w } }

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej If If M is is a a Turing Turing machine machine with with input input alphabet alphabet Σ, Σ, then then the the tinguigeinfim, tinguigeinfim, denoted denoted L(M), L(M), is is the the set set L(M) L(M) = { { w Σ* Σ* M accepts accepts w } } Let Let M be be the the above above TM, TM, and and assume assume its its input input alphabet alphabet is is {a, {a, b}. b}. What What is is L (( M)? M)? A. A. { w {a, {a, b}* b}* w ends ends in in a a } B. B. { w {a, {a, b}* b}* w ends ends in in b b } C. C. Ø D. D. None None of of these, these, or or two two or or more more of of these. these. 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, B, B, C, C, or or D. D.

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej a a b

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej b a b

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej b b b

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej b b a

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej b b a

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej b b a

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej b b a

q acc a b, R b a, R a a, L, L q 0 q 1 b b, L, L q rej b b a Although Although the the tape tape ends ends with with bba bba written written on on it, it, the the original original input input string string was was aab. aab. This This shows shows that that the the TM TM accepts accepts aab, aab, not not bba. bba. So So L ( M) ( M) = { { w {a, {a, b}* b}* w ends ends in in b b } }

Designing Turing Machines Despite their simplicity, Turing machines are very powerful computing devices. Today's lecture explores how to design Turing machines for various languages.

Designing Turing Machines Let Σ = {0, 1} and consider the language L = {0 n 1 n n N }. We know that L is context-free. How might we build a Turing machine for it?

L = {0 n 1 n n N } 0 0 0 1 1 1 0 1 0 1 1 0 0

A Recursive Approach The string ε is in L. The string 0w1 is in L if w is in L. Any string ing with 1 is not in L. Any string ending with 0 is not in L.

A Sketch of the TM 0 0 0 1 1 1

A Sketch of the TM 0 0 1 1 1

A Sketch of the TM 0 0 1 1 1

A Sketch of the TM 0 0 1 1 1

A Sketch of the TM 0 0 1 1 1

A Sketch of the TM 0 0 1 1 1

A Sketch of the TM 0 0 1 1 1

A Sketch of the TM 0 0 1 1 1

A Sketch of the TM 0 0 1 1

A Sketch of the TM 0 0 1 1

A Sketch of the TM 0 0 1 1

A Sketch of the TM 0 0 1 1

A Sketch of the TM 0 0 1 1

A Sketch of the TM 0 0 1 1

A Sketch of the TM 0 1 1

A Sketch of the TM 0 1 1

A Sketch of the TM 0 1 1

A Sketch of the TM 0 1 1

A Sketch of the TM 0 1 1

A Sketch of the TM 0 1

A Sketch of the TM 0 1

A Sketch of the TM 0 1

A Sketch of the TM 0 1

A Sketch of the TM 1

A Sketch of the TM 1

A Sketch of the TM 1

A Sketch of the TM

A Sketch of the TM

0 0 0 1 1 1

0 0 0 1 1 1

Check for 0 0 0 0 1 1 1

Check for 0 0, R 0 0 0 1 1 1

Check for 0 0, R 0 0 1 1 1

Check for 0 0, R Go to end 0 0 1 1 1

Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

Clear a 1, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

1, L Clear a 1, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1 1

1, L Clear a 1, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1

Go to 1, L Clear a 1, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 1 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 0 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R 1

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R

0 0, L 1 1, L Go to 1, L Clear a 1, R, L Check for 0 0, R Go to end 0 0, R 1 1, R

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Another TM Design We've designed a TM for {0 n1 n n N}. Consider this language over Σ = {0, 1}: L = { w Σ* w has the same number of 0s and 1s } This language is also not regular, but it is context-free. How might we design a TM for it?

A Caveat 0 0 0 1 1 1 1 0

A Caveat 0 0 1 1 1 1 0

A Caveat 0 0 1 1 1 1 0

A Caveat 0 0 1 1 1 1 0

A Caveat 0 0 1 1 1 0

A Caveat 0 0 1 1 1 0

A Caveat 0 0 1 1 1 0

A Caveat 0 0 1 1 1 0

A Caveat 0 1 1 1 0

A Caveat 0 1 1 1 0

A Caveat 0 1 1 1 0 How do we know that this blank isn't one of of the infnitely many blanks after our input string?

A Caveat 0 1 1 1 0

A Caveat 0 1 1 0

A Caveat 0 1 1 0

A Caveat 0 1 1 0

A Caveat 0 1 1 0

A Caveat 1 1 0

A Caveat 1 1 0 How do we know that this blank isn't one of of the infnitely many blanks after our input string?

A Caveat 1 1 0

A Caveat 1 1 0 How do we know that this blank isn't one of of the infnitely many blanks after our input string?

One Solution 0 0 0 1 1 1 1 0

One Solution 0 0 1 1 1 1 0

One Solution 0 0 1 1 1 1 0

One Solution 0 0 1 1 1 1 0

One Solution 0 0 1 1 1 0

One Solution 0 0 1 1 1 0

One Solution 0 0 1 1 1 0

One Solution 0 0 1 1 1 0

One Solution 0 0 1 1 1 0

One Solution 0 0 1 1 1 0

One Solution 0 1 1 1 0

One Solution 0 1 1 1 0

One Solution 0 1 1 1 0

One Solution 0 1 1 0

One Solution 0 1 1 0

One Solution 0 1 1 0

One Solution 0 1 1 0

One Solution 0 1 1 0

One Solution 0 1 1 0

One Solution 0 1 1 0

One Solution 0 1 1 0

One Solution 1 1 0

One Solution 1 1 0

One Solution 1 1 0

One Solution 1 0

One Solution 1 0

0 0 1 1 1 1 0 0

0 0 1 1 1 1 0 0

Find 0/1 0 0 1 1 1 1 0 0

Find 0/1 0, R 0 0 1 1 1 1 0 0

Find 0/1 0, R 0 1 1 1 1 0 0

Find 0/1 0, R Find 1 0 1 1 1 1 0 0

Find 0/1 0, R Find 1 0 0, R 0 1 1 1 1 0 0

Find 0/1 0, R Find 1 0 0, R 0 1 1 1 1 0 0

Find 0/1 0, R Find 1 1, L 0 0, R 0 1 1 1 1 0 0

Find 0/1 0, R Find 1 1, L 0 0, R 0 1 1 1 0 0

Find 0/1 Go home 0, R Find 1 1, L 0 0, R 0 1 1 1 0 0

Find 0/1 Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R 0 1 1 1 0 0

Find 0/1 Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R 0 1 1 1 0 0

Find 0/1 Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R 0 1 1 1 0 0

Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R 0 1 1 1 0 0

Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R 0 1 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R 0 1 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R 0 1 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R 1 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

1, R, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 1 0 0

1, R, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0 0

1, R Find 0, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0 0

1 1, R, R 1, R Find 0, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0 0

1 1, R, R 1, R Find 0, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 1 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R 0

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L 0, R Find 1 1, L 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L, R 0, R Find 1 1, L Accept! 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L, R 0, R Find 1 1, L Accept! 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L, R 0, R Find 1 1, L Accept! 0 0, R, R

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L, R 0, R Find 1 1, L Accept! 0 0, R, R

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

1 1, R, R 1, R Find 0 0, L, R Find 0/1, R Go Go home 0 0, L 1 1, L, L, R 0, R Find 1 1, L Accept! 0 0, R, R

Constant Storage Sometimes, a TM needs to remember some additional information that can't be put on the tape. In this case, you can use similar techniques from DFAs and introduce extra states into the TM's fnite-state control. The fnite-state control can only remember one of fnitely many things, but that might be all that you need!

Time-Out for Announcements!

Problem Set Seven Problem Set Seven is due this Friday at 2:30PM. As always, if you have questions, feel free to stop by ofice hours or ask on Piazza! Problem Set Eight will go out on Friday.

Back to CS103!

Another TM Design We just designed a TM for this language over Σ = {0, 1}: L = { w Σ* w has the same number of 0s and 1s } Let's do a quick review of how it worked.

A Leap of Faith 0 0 0 1 1 1 1 0

A Leap of Faith 0 0 1 1 1 1 0

A Leap of Faith 0 0 1 1 1 1 0

A Leap of Faith 0 0 1 1 1 1 0

A Leap of Faith 0 0 1 1 1 0

A Leap of Faith 0 0 1 1 1 0

A Leap of Faith 0 0 1 1 1 0

A Leap of Faith 0 0 1 1 1 0

A Leap of Faith 0 1 1 1 0

A Leap of Faith 0 1 1 1 0

A Leap of Faith 0 1 1 1 0 How do we know that this blank isn't one of of the infnitely many blanks after our input string?

The Solution 0 0 0 1 1 1 1 0

The Solution 0 0 1 1 1 1 0

The Solution 0 0 1 1 1 1 0

The Solution 0 0 1 1 1 1 0

The Solution 0 0 1 1 1 0

The Solution 0 0 1 1 1 0

The Solution 0 0 1 1 1 0

The Solution 0 0 1 1 1 0

The Solution 0 0 1 1 1 0

The Solution 0 0 1 1 1 0

The Solution 0 1 1 1 0

The Solution 0 1 1 1 0

The Solution 0 1 1 1 0

The Solution 0 1 1 0

The Solution 0 1 1 0

The Solution 0 1 1 0

The Solution 0 1 1 0

The Solution 0 1 1 0

The Solution 0 1 1 0

A Diferent Idea

A Diferent Strategy 0 0 0 1 1 1 1 0

A Diferent Strategy 0 0 0 1 1 1 1 0 Could we we sort sort the the characters of of this this string?

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 1: 1: A string of of 0s 0s and and 1s 1s is is sorted if if it it matches the the regex 0 * * 11 * *.

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 1: 1: A string of of 0s 0s and and 1s 1s is is sorted if if it it matches the the regex 0 * * 11 * *.

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 1: 1: A string of of 0s 0s and and 1s 1s is is sorted if if it it matches the the regex 0 * * 11 * *.

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 1: 1: A string of of 0s 0s and and 1s 1s is is sorted if if it it matches the the regex 0 * * 11 * *.

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 1: 1: A string of of 0s 0s and and 1s 1s is is sorted if if it it matches the the regex 0 * * 11 * *.

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 1: 1: A string of of 0s 0s and and 1s 1s is is sorted if if it it matches the the regex 0 * * 11 * *.

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 1: 1: A string of of 0s 0s and and 1s 1s is is sorted if if it it matches the the regex 0 * * 11 * *.

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 1: 1: A string of of 0s 0s and and 1s 1s is is sorted if if it it matches the the regex 0 * * 11 * *.

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 1: 1: A string of of 0s 0s and and 1s 1s is is sorted if if it it matches the the regex 0 * * 11 * *.

A Diferent Strategy 0 0 0 1 1 1 1 0 Observation 2: 2: A string of of 0s 0s and and 1s 1s is is not not sorted if if it it contains 10 10 as as a substring.

A Diferent Strategy 0 0 0 1 1 1 1 1 Observation 2: 2: A string of of 0s 0s and and 1s 1s is is not not sorted if if it it contains 10 10 as as a substring.

A Diferent Strategy 0 0 0 1 1 1 0 1 Observation 2: 2: A string of of 0s 0s and and 1s 1s is is not not sorted if if it it contains 10 10 as as a substring.

A Diferent Strategy 0 0 0 1 1 1 0 1 Observation 2: 2: A string of of 0s 0s and and 1s 1s is is not not sorted if if it it contains 10 10 as as a substring.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 0 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 1 1 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 0 1 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 0 1 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

A Diferent Strategy 0 0 0 1 1 0 1 1 Idea: Repeatedly fnd fnd a copy of of 10 10 and and replace it it with with 01. 01.

Let's Build It!

0 0 1 1 0 0

0 0 1 1 0 0

0* 0 0 1 1 0 0

0* 0 0 1 1 0 0

0 0, R 0* 0 0 1 1 0 0

0 0, R 0* 0 0 1 1 0 0

0 0, R 0* 0 0 1 1 0 0

0 0, R 0* 1 1, R 0 0 1 1 0 0

0 0, R 0* 1 1, R 0 0 1 1 0 0

1 1, R 0 0, R 0* 0*1* 0 0 1 1 0 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 0 1 1 0 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 0 1 1 0 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0?,? 0 0 1 1 0 0

1 1, R 0 0, R 0* 0*1* 1 1, R Based on on what what we re trying to to do, do, what what should this this transition say? say? 0?,? 0 0 1 1 0 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0?,? 0 0 1 1 0 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L 0 0 1 1 0 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L 0 0 1 1 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L Fix 01 0 0 1 1 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L 1 0, L Fix 01 0 0 1 1 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

1 1, R 0 0, R 0* 0*1* 1 1, R, R 0 1, L 0 0, L 1 1, L Go Home 1 0, L Fix 01 0 0 1 0 1 0

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 0 0 1 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 0

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 0 0 0 1 1 1

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 0 0 0 1 0 1

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 0 0 0 1 0 1

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 0 0 0 1 0 1

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 0 0 0 1 0 1

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 0 0 0 1 0 1

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 0 0 0 1 0 1

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 0 0 0 1 0 1

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 0 0 0 1 0 1

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 0 0 0 1 0 1

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 0 0 0 1 0 1

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 0 0 0 1 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

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 0 0 0 0 1 1

Our Our ultimate goal goal here here was was to to sort sort everything so so we we could hand it it of of to to the the machine to to check for for 0 n n 11 n n. Let's rewind the the tape head back back to to the the. 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 0 0 0 0 1 1

To 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 0 0 0 0 1 1

To 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 0 0 0 0 1 1

0 0, L 1 1, L To 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 0 0 0 0 1 1

0 0, L 1 1, L To 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 0 0 0 0 1 1

0 0, L 1 1, L To 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 0 0 0 0 1 1

0 0, L 1 1, L To 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 0 0 0 0 1 1

0 0, L 1 1, L To 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 0 0 0 0 1 1

0 0, L 1 1, L To 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 0 0 0 0 1 1

0 0, L 1 1, L To 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 0 0 0 0 1 1

0 0, L 1 1, L To Start, R Start 0 n 1 n, 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 0 0 0 0 1 1

0 0, L 1 1, L To Start, R Start 0 n 1 n, 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 0 0 0 0 1 1

0 0, L 1 1, L To Start, R Start 0 n 1 n, 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

0 0, L 1 1, L To Start, R Start 0 n 1 n, L 1 1, R 0 0, R 0* 0*1*, R 0 1, L This This is is just just a placeholder. Imagine snapping in in the the entire TM TM for for 0 n n 11 n n into into this this diagram, putting the the state in in the the dashed area. 1 1, R 0 0, L 1 1, L Go Home 1 0, L Fix 01

0 0, L 1 1, L To Start, R Start 0 n 1 n, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, L, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, L, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, L, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, L, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, L, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, L, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, L, 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 0 0 0 0

0 0, L 1 1, L To Start, R Start 0 n 1 n, L, 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

0 0, L 1 1, L To Start, R Start 0 n 1 n, L, 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 This This TM TM will will sort sort any any sequence of of 0s 0s and and 1s, 1s, but but it it might take take a while. Fun Fun problem: design a TM TM that that sorts a string of of 0s 0s and and 1s, 1s, but but does so so while taking way way fewer steps than than this this machine.

TM Subroutines A TM subroutine is a Turing machine that, instead of accepting or rejecting an input, does some sort of processing job. TM subroutines let us compose larger TMs out of smaller TMs, just as you'd write a larger program using lots of smaller helper functions. Here, we saw a TM subroutine that sorts a sequence of 0s and 1s into ascending order.

TM Subroutines Typically, when a subroutine is done running, you have it enter a state marked done with a dashed line around it. When we're composing multiple subroutines together which we'll do in a bit the idea is that we'll snap in some real state for the done state.

What other subroutines can we make?

Next Time Arithmetic Subroutines What else can we do with TMs? The Church-Turing Thesis A scientifc hypothesis about computation. R and RE Languages What does it mean to solve a problem?