Red K & S 4.3.1, 4.4. Do Homework 19. Turing Mchine Extensions Turing Mchine Definitions An lterntive definition of Turing mchine: (K, Σ, Γ, δ, s, H): Γ is finite set of llowble tpe symbols. One of these is. Σ is subset of Γ not including, the input symbols. δ is function from: K Γ to K (Γ - { }) {, } stte, tpe symbol, L or R b b Exmple trnsition: ((s, ), (s, b, )) Remember the gol: Do these Differences Mtter? Define device tht is: powerful enough to describe ll computble things, simple enough tht we cn reson formlly bout it Both definitions re simple enough to work with, lthough detils my mke specific rguments esier or hrder. But, do they differ in their power? Answer: No. Consider the differences: One wy or two wy infinite tpe: we're bout to show tht we cn simulte two wy infinite with ours. Rewrite nd move t the sme time: just ffects (linerly) the number of moves it tkes to solve problem. Turing Mchine Extensions In fct, there re lots of extensions we cn mke to our bsic Turing mchine model. They my mke it esier to write Turing mchine progrms, but none of them increse the power of the Turing mchine becuse: We cn show tht every extended mchine hs n equivlent bsic mchine. We cn lso plce bound on ny chnge in the complexity of solution when we go from n extended mchine to bsic mchine. Some possible extensions: Multiple tpes Two-wy infinite tpe Multiple red heds Two dimensionl sheet insted of tpe Rndom ccess mchine Nondeterministic mchine Lecture Notes 23 Turing Mchine Extensions 1
Multiple Tpes b b b b b 1 2 2 1 The trnsition function for k-tpe Turing mchine: ((K-H), Σ 1 to (K, Σ 1' {, }, Σ 2, Σ 2' {, },.,.,.,., Σ k ), Σ k' {, }) Input: input s before on tpe 1, others blnk Output: output s before on tpe 1, others ignored Copying string An Exmple of Two Tpe Mchine b b b b b b b b b b Lecture Notes 23 Turing Mchine Extensions 2
Another Two Tpe Exmple - Addition 1 0 1 ; 1 1 0 0 0 0 0 1 1 0 1 0 1 Adding Tpes Adds No Power Theorem: Let M be k-tpe Turing mchine for some k 1. Then there is stndrd Turing mchine M' where Σ Σ', nd such tht: For ny input string x, M on input x hlts with output y on the first tpe iff M' on input x hlts t the sme hlting stte nd with the sme output on its tpe. If, on input x, M hlts fter t steps, then M' hlts fter number of steps which is O(t ( x + t)). Proof: By construction b 0 0 1 0 0 0 0 b b b 0 1 0 0 0 0 0 Alphbet (Σ') of M' = Σ (Σ {0, 1}) k e.g.,, (, 0,, 0), (, 0,, 1) The Opertion of M' b 0 0 1 0 0 0 0 b b b 0 1 0 0 0 0 0 1. Set up the multitrck tpe: 1) Shift input one squre to right, then set up ech squre ppropritely. 2. Simulte the computtion of M until (if) M would hlt: (strt ech step to the right of the divided tpe) 1) Scn left nd store in the stte the k-tuple of chrcters under the red heds. Move bck right. 2) Scn left nd updte ech trck s required by the trnsitions of M. Move bck right. i) If necessry, subdivide new squre into trcks. 3. When M would hlt, reformt the tpe to throw wy ll but trck 1, position the hed correctly, then go to M's hlt stte. How Mny Steps Does M' Tke? Let: x be the input string, nd t be the number of steps it tkes M to execute. Step 1 (initiliztion) Step 2 ( computtion) Number of psses = t Work t ech pss: Totl = O(t ( x + t)) Step 3 (clen up) Totl = O(t ( x + t)) O( x ) 2.1 = 2 (length of tpe) = 2 ( x + 2 + t) 2.2 = 2 ( x + 2 + t) O(length of tpe) Lecture Notes 23 Turing Mchine Extensions 3
Our current definition: Two-Wy Infinite Tpe b c d Proposed definition: g f e b c d Simultion: Trck 1 b c d Trck 2 e f g The components of PDA: Finite stte controller Input tpe Stck The simultion: Finite stte controller: Input tpe: Stck: Simulting PDA Trck 1 b b (Input) Trck 2 Corresponding to Simulting Turing Mchine with PDA with Two Stcks b # b # b b Lecture Notes 23 Turing Mchine Extensions 4
Rndom Access Turing Mchines A rndom ccess Turing mchine hs: fixed number of registers finite length progrm, composed of instructions with opertors such s red, write, lod, store, dd, sub, jump tpe progrm counter Theorem: Stndrd Turing mchines nd rndom ccess Turing mchines compute the sme things. Furthermore, the number of steps it tkes stndrd mchine is bounded by polynomil in the number of steps it tkes rndom ccess mchine. Nondeterministic Turing Mchines A nondeterministic Turing mchine is quintuple (K, Σ,, s, H) where K, Σ, s, nd H re s for stndrd Turing mchines, nd is subset of ((K - H) Σ) (K (Σ {, })) bb bb bb bb bbb Wht does it men for nondeterministic Turing mchine to compute something? Semidecides - t lest one hlts. Decides -? Computes -? Nondeterministic Semideciding Let M = (K, Σ,, s, H) be nondeterministic Turing mchine. We sy tht M ccepts n input w (Σ - {, })* iff (s, w) yields lest one ccepting configurtion. We sy tht M semidecides lnguge L (Σ - {, })* iff for ll w (Σ - {, })*: w L iff (s, w) yields lest one hlting configurtion. An Exmple L = {w {, b, c, d}* : there re two of t lest one letter} / 2 / / b/ 0 / 1 b/ 3 b h c/ c/ c d/ 4 d/ d 5 Lecture Notes 23 Turing Mchine Extensions 5
M decides lnguge L if, for ll w (Σ - {, })* : 1. ll of M's computtions on w hlt, nd 2. w L iff t lest one of M's computtions ccepts. M computes function f if, for ll w (Σ - {, })* : 1. ll of M's computtions hlt, nd 2. ll of M's computtions result in f(w) Note tht ll of M's computtions hlt iff: Nondeterministic Deciding nd Computing There is nturl number N, depending on M nd w, such tht there is no configurtion C stisfying (s, w) - M N C. An Exmple of Nondeterministic Deciding L = {w {0, 1}* : w is the binry encoding of composite number} M decides L by doing the following on input w: 1. Nondeterministiclly choose two binry numbers 1 < p, q, where p nd q w, nd write them on the tpe, fter w, seprted by ;. 110011;111;1111 2. Multiply p nd q nd put the nswer, A, on the tpe, in plce of p nd q. 110011;1011111 3. Compre A nd w. If equl, go to y. Else go to n. Equivlence of Deterministic nd Nondeterministic Turing Mchines Theorem: If nondeterministic Turing mchine M semidecides or decides lnguge, or computes function, then there is stndrd Turing mchine M' semideciding or deciding the sme lnguge or computing the sme function. Note tht while nondeterminism doesn t chnge the computtionl power of Turing Mchine, it cn exponentilly increse its speed! Proof: (by construction) For semideciding: We build M', which runs through ll possible computtions of M. If one of them hlts, M' hlts Recll the wy we did this for FSMs: simulte being in combintion of sttes. Will this work here? Wht bout: Try pth 1. If it ccepts, ccept. Else Try pth 2. If it ccepts, ccept. Else Lecture Notes 23 Turing Mchine Extensions 6
The Construction At ny point in the opertion of nondeterministic mchine M, the mximum number of brnches is r = K ( Σ + 2) sttes ctions So imgine tble: 1 2 3 r (q1,σ1) (p-,σ-) (p-,σ-) (p-,σ-) (p-,σ-) (p-,σ-) (q1,σ2) (p-,σ-) (p-,σ-) (p-,σ-) (p-,σ-) (p-,σ-) (q1,σn) (q2,σ1) (q K,σn) Note tht if, in some configurtion, there re not r different legl things to do, then some of the entries on tht row will repet. M d : (suppose r = 6) Tpe 1: Input The Construction, Continued Tpe 2: 1 3 2 6 5 4 3 6 M d chooses its 1st move from column 1 M d chooses its 2nd move from column 3 M d chooses its 3rd move from column 2 until there re no more numbers on Tpe 2 M d either: discovers tht M would ccept, or comes to the end of Tpe 2. In either cse, it hlts. M' (the mchine tht simultes M): Tpe 1: Input The Construction, Continued Tpe 2: Copy of Input Tpe 3: 1 3 2 6 5 4 3 6 M d Steps of M': write ε on Tpe 3 until M d ccepts do (1) copy Input from Tpe 1 to Tpe 2 (2) run M d (3) if M d ccepts, exit (4) otherwise, generte lexicogrphiclly next string on Tpe 3. Pss 1 2 3 7 8 9 Tpe3 ε 1 2 6 11 12 2635 Lecture Notes 23 Turing Mchine Extensions 7
Nondeterministic Algorithms Other Turing Mchine Extensions Multiple heds (on one tpe) Emultion strtegy: Use trcks to keep trck of tpe heds. (See book) Multiple tpes, multiple heds Emultion strtegy: Use trcks to keep trck of tpes nd tpe heds. Two-dimensionl semi-infinite tpe Emultion strtegy: Use digonl enumertion of two-dimensionl grid. Use second tpe to help you keep trck of where the tpe hed is. (See book) Two-dimensionl infinite tpe (relly sheet) Emultion strtegy: Use modified digonl enumertion s with the semi-infinite cse. Wht About Turing Mchine Restrictions? Cn we mke Turing mchines even more limited nd still get ll the power? Exmple: We llow tpe lphbet of rbitrry size. Wht hppens if we limit it to: One chrcter? Two chrcters? Three chrcters? Lecture Notes 23 Turing Mchine Extensions 8
Red K & S 5.1 & 5.2. Problem Encoding, TM Encoding, nd the Universl TM Encoding Problem s Lnguge A Turing Mchines deciding lnguge is nlogous to the TM solving decision problem. Problem: Is the number n prime? Instnce of the problem: Is the number 9 prime? Encoding of the problem, n : n s binry number. Exmple: 1001 Problem: Is n undirected grph G connected? Instnce of the problem: Is the following grph connected? 1 2 3 4 5 Encoding of the problem, G : 1) V s binry number 2) A list of edges represented by pirs of binry numbers being the vertex numbers tht the edge connects 3) All such binry numbers re seprted by /. Exmple: 101/1/10/10/11/1/100/10/101 Problem View vs. Lnguge View Problem View: It is unsolvble whether Turing Mchine hlts on given input. This is clled the Hlting Problem. Lnguge View: Let H = { M, w : TM M hlts on input string w} H is recursively enumerble but not recursive. Problem: All our mchines so fr re hrdwired. The Universl Turing Mchine Question: Does it mke sense to tlk bout progrmmble Turing mchine tht ccepts s input progrm input string executes the progrm, nd outputs output string Yes, it's clled the Universl Turing Mchine. Notice tht the Universl Turing mchine semidecides H = { M, w : TM M hlts on input string w} = L(U). To define the Universl Turing Mchine U we need to do two things: 1. Define n encoding opertion for Turing mchines. 2. Describe the opertion of U given n input tpe contining two inputs: encoded Turing mchine M, encoded input string to be given to M. Lecture Notes 24 Problem Encoding, Turing Mchine Encoding, nd the Universl Turing Mchine 1
Encoding Turing Mchine M We need to describe M = (K, Σ, δ, s, H) s string. To do this we must: 1. Encode δ 2. Specify s. 3. Specify H (nd y nd n, if pplicble) 1. To encode δ, we need to: 1. Encode the sttes 2. Encode the tpe lphbet 3. Specify the trnsitions 1.1 Encode the sttes s qs : s {0, 1} + nd s = i nd i is the smllest integer such tht 2 i K Exmple: 9 sttes i = 4 s = q0000, remining sttes: q0001, q0010, q0011, q0100, q0101, q0110, q0111, q1000 Encoding Turing Mchine M, Continued 1.2 Encode the tpe lphbet s s : s {0, 1} + nd s = j nd j is the smllest integer such tht 2 j Σ + 2 (the + 2 llows for nd ) Exmple: Σ = {,,, b} j = 3 = 000 = 001 = 010 = 011 = 100 b = 101 Encoding Turing Mchine M, Continued 1.3 Specify trnsitions s (stte, input, stte, output) Exmple: (q00,000,q11,000) 2. Specify s s q0 i 3. Specify H: Sttes with no trnsitions out re in H. If M decides lnguge, then H = {y, n}, nd we will dopt the convention tht y is the lexicogrphiclly smller of the two sttes. y = q010 n = q011 Encoding Input Strings We encode input strings to mchine M using the sme chrcter encoding we use for M. For exmple, suppose tht we re using the following encoding for symbols in M: symbol Then we would represent the string s = s representtion 000 001 010 011 100 "s" = s = 001100100000100 Lecture Notes 24 Problem Encoding, Turing Mchine Encoding, nd the Universl Turing Mchine 2
An Encoding Exmple Consider M = ({s, q, h}, {,,}, δ, s, {h}), where δ = stte symbol δ s (q, ) s (h, ) s (s, ) q (s, ) q (s, ) q (q, ) stte/symbol s q h representtion q00 q01 q11 000 001 010 011 100 The representtion of M, denoted, "M", M, or sometimes ρ(m) = (q00,100,q01,000), (q00,000,q11,000), (q00,001,q00,011), (q01,100,q00,100), (q01,000,q00,011), (q01,001,q01,011) Another Win of Encoding One big win of defining wy to encode ny Turing mchine M: It will mke sense to tlk bout opertions on progrms (Turing mchines). In other words, we cn tlk bout some Turing mchine T tht tkes nother Turing mchine (sy M 1 ) s input nd trnsforms it into different mchine (sy M 2 ) tht performs some different, but possibly relted tsk. Exmple of trnsforming TM T: Input: mchine M 1 tht reds its input tpe nd performs some opertion P on it. Output: mchine M 2 tht performs P on n empty input tpe: >R x L R M 1 The specifiction for U: U("M" "w") = "M(w)" The Universl Turing Mchine "M ------------------------------ M" "w------------------------w" 1 0 0 0 0 0 0 " " "w--------------------w" 1 0 0 0 0 0 0 "M ---------------------------- M" 1 0 0 0 0 0 0 q 0 0 0 1 Initiliztion of U: 1. Copy "M" onto tpe 2 2. Insert " " t the left edge of tpe 1, then shift w over. 3. Look t "M", figure out wht i is, nd write the encoding of stte s on tpe 3. Lecture Notes 24 Problem Encoding, Turing Mchine Encoding, nd the Universl Turing Mchine 3
Simulte the steps of M: The Opertion of U 0 0 1 0 0 1 0 0 0 0 0 0 "M ---------------------------- M" 1 0 0 0 0 0 0 q 0 0 0 1 1. Strt with the heds: tpe 1: the of the chrcter being scnned, tpe 2: fr left tpe 3: fr left 2. Simulte one step: 1. Scn tpe 2 for qudruple tht mtches current stte, input pir. 2. Perform the ssocited ction, by chnging tpes 1 nd 3. If necessry, extend the tpe. 3. If no qudruple found, hlt. Else go bck to 2. Tpe 1: 001000100100000100 Tpe 2: (q00,000,q11,000), (q00,001,q00,011), (q00,100,q01,000), (q01,000,q00,011), (q01,001,q01,011), (q01,100,q00,100) Tpe 3: q01 An Exmple Result of simulting the next step: Tpe 1: 001000100100000100 Tpe 3: q00 Could we define Universl Finite Stte Mchine? If A Universl Mchine is Such Good Ide Such FSM would ccept the lnguge L = {"F" "w" : F is finite stte mchine, nd w L(F) } Lecture Notes 24 Problem Encoding, Turing Mchine Encoding, nd the Universl Turing Mchine 4