Decision Problems with TM s Look at following sets: Lecture 31: Halting Problem CSCI 81 Spring, 2012 Kim Bruce A TM = { M,w M is a TM and w L(M)} H TM = { M,w M is a TM which halts on input w} TOTAL TM = {M M halts on all inputs} E TM ={M M is a TM and L(M)= } Halting easy for most, but: times3(x: positive integer) = While x 1 do: If x is even then x = x/2. else x = 3x + 1& Universe of discourse Semi-decidable A TM and H TM both semi-decidable using UTM. Show H TM not decidable. Easy to determine if have encoding of a TM, so we ll ignore it when take complements, etc., so our universe of discourse will only consider those with valid TM encodings. Let E be candidate TM to decide H TM. Show can t be right. From E, create TM D s.t. if input w, create <w,w> and simulate E on it (i.e, it treats input as if of form <M,w>) If E rejects then make D accept and if E accepts, D loops forever Now run D on <D,D> If <D,D> H TM then D halts on D, so E rejected <D,D> & <D,D> L(E) If <D,D> H TM then D not halt on D, so E accepted, <D,D> L(E) Either way, L(E) H TM with <D,D> in one but not other. Diagonal Argument
Decidable and Semidecidable If L and its complement are both semidecidable then it is decidable. Corollary: Complement of H TM is not semi-decidable Note, if H TM were decidable then every SD language would be decidable. Lots of other languages not decidable: L 0 = {<M,w> M on w eventually writes a 0}... Undecidability E TM ={M M is a TM and L(M)= } Spose decidable. For each pair <M,w> define machine M w that throws away its input and simulates M on w. Then M w E TM iff <M,w> H TM. Thus could use solution to E TM to solve H TM. Therefore E TM is not decidable. General procedure to show undecidability Reduce halting problem to solving other problem. Proofs are by contradiction Undecidability A Little Harder TOTAL TM ={M M is TM that halts on all inputs} Spose decidable. Use to solve halting! For each pair <M,w> define machine M w that throws away its input and simulates M on w. Then M w TOTAL TM iff <M,w> H TM. Thus could use solution to TOTAL TM to solve H TM. Therefore TOTAL TM is not decidable. L ε = {<M> M halts on empty tape} Given M, w, create machine M w that writes w and then simulates M on that w. Claim <M > L ε iff <M,w> H TM. Therefore L ε not decidable L 0 = { <M,w> M on w eventually prints 0 } L 0 = { M w s.t. M on w eventually prints 0 }
Another Example L ε0 = {<M> M on ε eventually writes a 0} Given M, rewrite to replace any occurrences of 0 in transitions by new character φ. If 0 in input alphabet make a first pass to replace all occurrences of 0 by φ. Modify again so that if it ever goes into a halt state then writes 0 on tape. Call it M One last modification: Erase input, write w, then run M on w. Call new machine M. Claim <M > L ε0 iff <M,w> H TM. Therefore L ε0 not decidable Entscheidungsproblem Turing s solution: First showed universal TM Essentially showed undecidability of halting problem Actually circle-free TM s (related to hmwk 3cd) Showed undecidability of determining if ever write 0 on empty input Can encode TM as a number (we did as string). Showed given TM M, can write a logical formula ψ of predicate logic such that ψ is true iff M writes 0 on ε Contradiction! Therefore not decidable Entscheidungsproblem Turing s solution last step: Given TM M, M and its computation can be described in predicate logic. Primitives: c is code of a configuration, square of tape One config follows from another via transition in M In c, TM is scanning square s, and s contains symbol y Write axioms about execution (depending on M): if M contains transition (p,a,q,b, ) then axiom: if M in config c w/state p, scanning square s containing a, then next config contains state q, s contains b, and M is scanning cell s+1. Entscheidungsproblem More on Turing s solution last step: Given TM M, can write a logical formula ψ of predicate logic such that ψ is true iff M writes 0 on ε input. Let ψ be statement: In some configuration of M starting with ε, some square s contains the symbol o Let φ 1,...,φ n be axioms for M. Then formula is φ 1... φ n ψ Thus M writes 0 on input ε iff φ 1... φ n ψ is provable in predicate calculus. Therefore provability undecidable!
Decidable & Semidecidable The Hierarchy SD D Context-Free Languages Regular Languages Theorem: The set of context-free languages is a proper subset of D. Proof: Every context-free language is decidable, so the context-free languages are a subset of D. There is at least one language, A n B n C n, that is decidable but not context-free. Distinguishing D and SD Outside of SD Most obvious languages in SD also in D A n B n C n = {a n b n c n n 0} {wcw w {a, b}*} {ww w {a, b}*} {w of form x y=z: x,y,z {0, 1}* and, when x, y, and z are viewed as binary numbers, xy = z} Uncountably many languages outside of SD Complement of H TM But already found some in gap, e.g. H TM
Closure Properties Equivalences to SD Theorem: D is closed under complement Proof: Let L ε D. Build TM deciding L... Proof depends on TM deterministic and always halts. What about SD? Not true for H TM A TM M enumerates the language L iff, for some fixed state p of M, L = {w : (s, ε) -M* (p, w)}. Potentia"y infinite computation. A language is Turing-enumerable iff there is a Turing machine that enumerates it. SD & Turing Enumerable SD & Turing Enumerable Theorem: A language is SD iff it is Turing enumerable. Proof: Spose L is Turing enumerable. Show L is SD. Let w be input. Start enumerating L. Every time enter state p, check to see if contents of tape is w. If yes then halt and stop. Otherwise keep going. Obvious proof in other direction not work! Theorem: A language is in SD iff it is Turing enumerable. Proof (cont): Spose L is in SD. Show L can be enumerated. Enumerate all w Σ* lexicographically: ε, a, b, aa, ab, ba, bb,... As each w i is enumerated, start a copy of M to check with w i as input. Execute one step of each M with w i started, excluding those that have halted Whenever an M accepts a w i, output w i. Called dove-tailing
Lexicographically Enumerable M lexicographica"y enumerates L iff M enumerates the elements of L in lexicographic order. A language L is lexicographica"y Turingenumerable iff there is a Turing machine that lexicographically enumerates it. Lexicographically Enumerable Theorem: A language is in D iff it is lexicographically enumerable. Proof: Spose L is in D. Show L can be enumerated lexicographically. Enumerate all w Σ* lexicographically: ε, a, b, aa, ab, ba, bb,... As each w i is enumerated, run M deciding L on w i as input. If M accepts a w i, output w i. Otherwise go to next. Easier here because M always halts Lexicographically Enumerable Theorem: A language is in D iff it is lexicographically enumerable. Proof: Spose L can be enumerated lexicographically. Show L is in D. To determine if w in L: Start enumerating all elts of L lexicographically If w is enumerated, then accept. If go past w in lexicographic order, then reject If halts before getting to w, then also reject. Oops! Second part of proof has a hole. Suppose M lexicographically enumerates L = {a,ba,aba} by enumerating three elements and then continuing forever without ever enumerating another element. Can only happen if L is finite. But all finite languages are decidable. Fixes proof But don t necessarily know whether L is finite!!