Universal Turing Machine

Slides:



Advertisements
Similar presentations
Turing Machines Memory = an infinitely long tape Persistent storage A read/write tape head that can move around the tape Initially, the tape contains only.
Advertisements

Variants of Turing machines
THE CHURCH-TURING T H E S I S “ TURING MACHINES” Pages COMPUTABILITY THEORY.
The Recursion Theorem Sipser – pages Self replication Living things are machines Living things can self-reproduce Machines cannot self reproduce.
The Big Picture Chapter 3. We want to examine a given computational problem and see how difficult it is. Then we need to compare problems Problems appear.
Foundations of (Theoretical) Computer Science Chapter 3 Lecture Notes (Section 3.2: Variants of Turing Machines) David Martin With.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture11: Variants of Turing Machines Prof. Amos Israeli.
1 Linear Bounded Automata LBAs. 2 Linear Bounded Automata are like Turing Machines with a restriction: The working space of the tape is the space of the.
CS5371 Theory of Computation Lecture 10: Computability Theory I (Turing Machine)
1 Turing Machines. 2 A Turing Machine Tape Read-Write head Control Unit.
Universal Turing Machine
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Birthday Gift from Dad …. … Most Powerful Computer.
CMPS 3223 Theory of Computation Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided.
 Computability Theory Turing Machines Professor MSc. Ivan A. Escobar
TM Design Universal TM MA/CSSE 474 Theory of Computation.
MA/CSSE 474 Theory of Computation More Reduction Examples Non-SD Reductions.
MA/CSSE 474 Theory of Computation Enumerability Reduction.
Computability Construct TMs. Decidability. Preview: next class: diagonalization and Halting theorem.
MA/CSSE 474 Theory of Computation Decision Problems DFSMs.
Turing Machines Chapter 17. Languages and Machines SD D Context-Free Languages Regular Languages reg exps FSMs cfgs PDAs unrestricted grammars Turing.
1 More About Turing Machines “Programming Tricks” Restrictions Extensions Closure Properties.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 3 The Church-Turing Thesis Contents Turing Machines definitions, examples,
1 Turing’s Thesis. 2 Turing’s thesis: Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
1 Turing machines Chapter 4, Smith and Kimber. A Turing machine is an abstraction of a human “computer”. Consists of - control, in the form of states -
Lecture 17 Undecidability Topics:  TM variations  Undecidability June 25, 2015 CSCE 355 Foundations of Computation.
1 Section 13.1 Turing Machines A Turing machine (TM) is a simple computer that has an infinite amount of storage in the form of cells on an infinite tape.
1 Turing Machines and Equivalent Models Section 13.1 Turing Machines.
Overview of the theory of computation Episode 3 0 Turing machines The traditional concepts of computability, decidability and recursive enumerability.
Lecture 24UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 24.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 3 The Church-Turing Thesis Contents Turing Machines definitions, examples,
1 Introduction to Turing Machines
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 12 Mälardalen University 2007.
Unrestricted Grammars
1 Chapter 9 Undecidability  Turing Machines Coded as Binary Strings  Universal Turing machine  Diagonalizing over Turing Machines  Problems as Languages.
Turing Machines Sections 17.6 – The Universal Turing Machine Problem: All our machines so far are hardwired. ENIAC
1 8.4 Extensions to the Basic TM Extended TM’s to be studied: Multitape Turing machine Nondeterministic Turing machine The above extensions make no increase.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY * Read chapter 4 of the book for next time * Lecture9x.ppt.
Theory of Computation Automata Theory Dr. Ayman Srour.
MA/CSSE 474 Theory of Computation Universal Turing Machine Church-Turing Thesis (Winter 2016, these slides were also used for Day 33)
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
Chapter 5 Recursive and recursively enumerable functions Phrase-structure grammars.
MA/CSSE 474 Theory of Computation Universal Turing Machine Church-Turing Thesis Delayed due dates for HWs See updated schedule page. No class meeting.
TM Macro Language MA/CSSE 474 Theory of Computation.
CSE202: Introduction to Formal Languages and Automata Theory
Turing Machines Chapter 17.
(Universal Turing Machine)
Computing with Turing Machines
Turing Machines 2nd 2017 Lecture 9.
CSE 105 theory of computation
Turing Machines Acceptors; Enumerators
COSC 3340: Introduction to Theory of Computation
Turing Machines Chapter 17.
Decidability Turing Machines Coded as Binary Strings
Decidability Turing Machines Coded as Binary Strings
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation
Recall last lecture and Nondeterministic TMs
MA/CSSE 474 Theory of Computation
CSE 105 theory of computation
Subject Name: FORMAL LANGUAGES AND AUTOMATA THEORY
Variants of Turing machines
Variations: Multiple tracks Multiple tapes Non-deterministic
Intro to Theory of Computation
CSE 105 theory of computation
Presentation transcript:

Universal Turing Machine MA/CSSE 474 Theory of Computation TM Variations Universal Turing Machine

Your Questions? Previous class days' material Reading Assignments HW 12 or 13 problems Next week's exam Anything else Note the Changes to HW 13

The Macro Language slides from yesterday I left these slides from yesterday here in case we need to refer to any of them.

A Macro language for Turing Machines (1) Define some basic machines ● Symbol writing machines For each x  , define Mx, written as just x, to be a machine that writes x. Read-write head ends up in original position. ● Head moving machines R: for each x  , (s, x) = (h, x, ) L: for each x  , (s, x) = (h, x, ) ● Machines that simply halt: h, which simply halts (don't care whether it accepts). n, which halts and rejects. y, which halts and accepts. You need to learn this simple language. I will use it and I expect you to use it on HW and tests. There is an Mx for each x. To implement Mx requires two TM moves. (s, y) = (s', x, ), (s', z) = (s, z, )

Checking Inputs and Combining Machines Next we need to describe how to: ● Check the tape and branch based on what character we see, and ● Combine the basic machines to form larger ones. To do this, we need two forms: ● M1 M2 ● M1 <condition> M2 Run M1 then M2. If either fails to halt, so does the composite machine. Run M1; if it halts, check condition (usually look for a specific character under the tape head). If true, run M2. If M1 does not halt or if condition is true and M2 does not halt, composite machine does not halt.

Turing Machines Macros Cont'd Example: >M1 a M2 b M3 ● Start in the start state of M1. ● Compute until M1 reaches a halt state. ● Examine the tape and take the appropriate transition. ● Start in the start state of the next machine, etc. ● Halt if any component reaches a halt state and has no place to go. ● If any component fails to halt, then the entire machine may fail to halt.

More macros a M1 M2 becomes M1 a, b M2 b M1 all elems of  M2 becomes M1 M2 or M1M2 Variables M1 all elems of  M2 becomes M1 x  a M2 except a and x takes on the value of the current square M1 a, b M2 becomes M1 x  a, b M2 and x takes on the value of M1 x = y M2 if x = y then take the transition e.g., > x  q Rx if the current square is not blank, go right and copy it. Two ways to implement "variable assignment: Use an area of the tape at the left or right end as a "scratchpad". Have a bunch of duplicate sets of states, each representing "holding" a different tape symbol (usually an input symbol).

Blank/Non-blank Search Machines Find the first blank square to the right of the current square. the left of the current square. Find the first nonblank square to the left of the current square Rq Lq Rq Lq

More Search Machines La Find the first occurrence of a to the left of the current square. Ra,b Find the first occurrence of a or b to the right of the current square. La,b a M1 Find the first occurrence of a or b to the left of the current square, b then go to M1 if the detected character is a; go to M2 if the M2 detected character is b. Lxa,b Find the first occurrence of a or b to the left of the current square and set x to the value found. Lxa,bRx Find the first occurrence of a or b set x to the value found, move one square to the right, and write x (a or b).

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

What does this machine do?

Exercise Initial input on the tape is an integer written in binary, most significant bit first (110 represents 6). Design a TM that replaces the binary representation of n by the binary representation of n+1.

Two Flavors of TMs Recognize a language Compute a function

Turing Machines as Language Recognizers Let M = (K, , , , s, {y, n}). ● M accepts a string w iff (s, qw) |-M* (y, w) for some string w. ● M rejects a string w iff (s, qw) |-M* (n, w) for some string w. M decides a language L  * iff: For any string w  * it is true that: if w  L then M accepts w, and if w  L then M rejects w. A language L is decidable iff there is a Turing machine M that decides it. In this case, we will say that L is in D.

A Deciding Example AnBnCn = {anbncn : n  0} Example: qaabbccqqqqqqqqq Example: qaaccbqqqqqqqqq

Semideciding a Language Let M be the input alphabet to a TM M. Let L  M*. M semidecides L iff, for any string w  M*: ● w  L  M accepts w ● w  L  M does not accept w. M may either: reject or fail to halt. A language L is semidecidable iff there is a Turing machine that semidecides it. We define the set SD to be the set of all semidecidable languages. Another term that is sometimes used tfor this concept is "recursively enumerable"

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

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

Computing Functions Let M = (K, , , , s, {h}). Define M(w) = z iff (s, qw) |-M* (h, qz). Let    be M’s output alphabet. Let f be any function from * to *. M computes f iff, for all w  *: ● If w is an input on which f is defined: M(w) = f(w). ● Otherwise M(w) does not halt. A function f is recursive or computable iff there is a Turing machine M that computes it and that always halts. Notice that the TM's function computes with strings (* to *), not directly with numbers.

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

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

Computing Numeric Functions For any positive integer k, valuek(n) returns the nonnegative integer that is encoded, base k, by the string n. For example: ● value2(101) = 5. ● value8(101) = 65. TM M computes a function f from ℕm to ℕ iff, for some k: valuek(M(n1;n2;…nm)) = f(valuek(n1), … valuek(nm)) Note that the semicolon serves to separate the representations of the arguments

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

Turing Machine Extensions There are many extensions we might like to make to our basic Turing machine model. We can do this becaue: We can show that every extended machine has an equivalent basic machine. We can also place a bound on any change in the complexity of a solution when we go from an extended machine to a basic machine. Some possible extensions: ● Multiple tape TMs ● Nondeterministic TMs

Multiple Tapes

Multiple Tapes The transition function for a k-tape Turing machine: ((K-H) , 1 to (K , 1, {, , } , 2 , 2, {, , } , . , . , k) , k, {, , }) Input: as before on tape 1, others blank. Output: as before on tape 1, others ignored. Note: each tape head is allowed to stay where it is.

Example: Copying a String

Example: Copying a String

Example: Copying a String

Another Two Tape Example: Addition Ask students how they would use multiple tapes to do multiplication of unary numbers. Give them a few minutes.

Adding Tapes Adds No Power Theorem: Let M = (K, , , , s, H) be a k-tape Turing machine for some k > 1. Then there is a standard TM M'= (K', ', ', ', s', H') where   ', and: ● On input x, M halts with output z on the first tape iff M' halts in the same state with z on its tape. ● On input x, if M halts in n steps, M' halts in O(n2) steps. Proof: By construction.

The Representation Alphabet ( ') of M' =   (  {0, 1})k: We treat the single tape as if it is divided into tracks. For each track we need to know the symbols, and the position of the read/write head. 1 indicates "this tape's head is here" and 0 represents "this tape's head is not here". Total number of symbols in tape alphabet for M' : (3 x 2 x 3 x 2) + 3 = 39 Alphabet ( ') of M' =   (  {0, 1})k: q, a, b, (q, 1, q, 1), (a, 0, q ,0), (b, 0, q, 0), …

The Operation of M' 1. Set up the multitrack tape. 2. Simulate the computation of M until (if) M would halt: 2.1 Scan left and store in the state the k-tuple of characters under the read heads. Move back right. 2.2 Scan left and update each track as required by the transitions of M. If necessary, subdivide a new (formerly blank) square into tracks. Move back right. 3. When M would halt, reformat the tape to throw away all but track 1, position the head correctly, then go to M’s halt state.

How Many Steps Does M' Take? Let: w be the input string, and n be the number of steps it takes M to execute. Step 1 (initialization): O(|w|). Step 2 ( computation): Number of passes = n. Work at each pass: 2.1 = 2  (length of tape). = 2  (|w| + n). 2.2 = 2  (|w| + n). Total: O(n  (|w| + n)). Step 3 (clean up): O(length of tape). Total: O(n  (|w| + n)). = O(n2). * * assuming that n ≥ w

Universal Turing Machine

The Universal Turing Machine Problem: All our machines so far are hardwired. ENIAC - 1945

The Universal Turing Machine Problem: All our machines so far are hardwired. Question: Can we build a programmable TM that accepts as input: program input string executes the program, and outputs: output string

The Universal Turing Machine Yes, it’s called the Universal Turing Machine. To define the Universal Turing Machine U we need to: 1. Define an encoding operation for TMs. 2. Describe the operation of U given input <M, w>, the encoding of: ● a TM M, and ● an input string w. One issue. There is no limit on the number of states or tape symbols that a TM can have. But we want to be able to encode any TM with a finite number of symbols.

Encoding a Turing Machine M We need to describe M = (K, , , , s, H) as a string: The states The tape alphabet The transitions

Encoding the States Number the states from 0 to |K|-1 in binary: Let i be log2(|K|). Number the states from 0 to |K|-1 in binary:  Number s, the start state, 0.  Number the others in any order. If t is the binary number assigned to state t, then:  If t is the halting state y, assign it the string yt.  If t is the halting state n, assign it the string nt.  If t is any other state, assign it the string qt.

Example of Encoding the States Suppose M has 9 states. i = 4 s = q0000, Remaining states (where y is 3 and n is 4): q0001, q0010, y0011, n0100, q0101, q0110, q0111, q1000

Encoding a Turing Machine M, Continued The tape alphabet: ay : y  {0, 1}+, |y| = j, and j is the smallest integer such that 2j  ||. Example:  = {q, a, b, c}. j = 2. q = a00 a = a01 b = a10 c = a11

Encoding a Turing Machine M, Continued The transitions: (state, input, state, output, move) Example: (q000,a000,q110,a000,) Specify s as q000. Specify H.

A Special Case We will treat this as a special case: Represent this as (q0)

An Encoding Example Consider M = ({s, q, h}, {a, b, c}, {q, a, b, c}, , s, {h}): <M> = (q00,a00,q01,a00,), (q00,a01,q00,a10,), (q00,a10,q01,a01, ), (q00,a11,q01,a10,), (q01,a00,q00,a01,), (q01,a01,q01,a10,), (q01,a10,q01,a11,), (q01,a11,h10,a01,) state symbol  s q (q,q, ) a (s,b,) b (q,a, ) c (q,b, ) (s,a, ) (q,b,) (h,a, ) state/symbol representation s q00 q q01 h h10 a00 a a01 b a10 c a11

Enumerating Turing Machines Theorem: There exists an infinite lexicographic enumeration of: (a) All syntactically valid TMs. (b) All syntactically valid TMs with specific input alphabet . (c) All syntactically valid TMs with specific input alphabet  and specific tape alphabet . = {(, ), a, q, y, v, I, 1, comma, rightArrow, leftArow} Lexicographically generate all strings in *. Check each to see if it is a valid TM encoding; if so, add it to the list.

Enumerating Turing Machines Proof: Fix  = {(, ), a, q, y, n, 0, 1, comma, , }, ordered as listed. Then: 1. Lexicographically enumerate the strings in *. 2. As each string s is generated, check to see whether it is a syntactically valid Turing machine description. If it is, output it. To restrict the enumeration to symbols in sets  and , check, in step 2, that only alphabets of the appropriate sizes are allowed. We can now talk about the ith Turing machine.

Another Win of Encoding One big win of defining a way to encode any Turing machine M: ● We can talk about operations on programs (TMs).

Example of a Transforming TM T: Input: a TM M1 that reads its input tape and performs some operation P on it. Output: a TM M2 that performs P on an empty input tape.

Encoding Multiple Inputs Let: <x1, x2, …xn> mean a single string that encodes the sequence of individual values: x1, x2, …xn.

The Specification of the Universal TM On input <M, w>, U must: ● Halt iff M halts on w. ● If M is a deciding or semideciding machine, then: ● If M accepts, accept. ● If M rejects, reject. ● If M computes a function, then U(<M, w>) must equal M(w).

How U Works U will use 3 tapes: ● Tape 1: M’s tape. ● Tape 2: <M>, the “program” that U is running. ● Tape 3: M’s state.

The Universal TM Initialization of U: 1. Copy <M> onto tape 2. 2. Look at <M>, figure out what i is, and write the encoding of state s on tape 3. After initialization:

The Operation of U Simulate the steps of M : 1. Until M would halt do: 1.1 Scan tape 2 for a quintuple that matches the current state, input pair. 1.2 Perform the associated action, by changing tapes 1 and 3. If necessary, extend the tape. 1.3 If no matching quintuple found, halt. Else loop. 2. Report the same result M would report. How long does U take? If M would halt in k steps, for eachof those steps, U has to scan through the encoding of M to find the right transition, so O(k |<M>|)

If A Universal Machine is Such a Good Idea … Could we define a Universal Finite State Machine? Such a FSM would accept the language: L = {<F, w> : F is a FSM, and w  L(F) }