Lecture 24 Decidability and Undecidability COT 4420 Theory of Computation Section 12.1 Slides from Prof. Busch Definition: A language L is decidable if there is a Turing machine (decider) M which accepts L and halts on every input string Also known as recursive languages For any string w: w∈ L M halts in an accept state w∉ L M halts in a non-accept state Every decidable language is Recursively Enumerable Sometimes, it is convenient to have Turing machines with single accept and reject states qaccept qreject These are the only halting states We can convert any Turing machine to have single accept and reject states Old machine New machine qaccept x → x ,R x → x ,R x → x ,L x → x ,R Multiple accept states For each tape symbol One accept state x Do the following for each possible halting state: New machine Old machine For each qi Multiple reject states qi x → x, R qreject For all tape symbols x not used for read in the other transitions of qi One reject state For a decidable language L : Decider for L qaccept Input string qreject Decision On Halt: Accept Reject For each input string, the computation halts in the accept or reject state Transform accept state to reject and vice-versa M M′ qaccept ′ qreject qreject qr ′ qaccept qr qa qa Turing Machine M′ On each input string w do: 1. Let M be the decider for L 2. Run M with input string w If M accepts then reject If M rejects then accept Accepts L and halts on every input string Problems • Informally, a “problem” is a yes/no question about an infinite set of possible instances. • Example: “Does graph G have a Hamilton cycle (cycle that touches each node exactly once)? – Each undirected graph is an instance of the “Hamilton-cycle problem.” Problems • Formally, a problem is a language. • Each string encodes some instance. • The string is in the language if and only if the answer to this instance of the problem is “yes.” Decidable Problems • A problem is decidable if there is an algorithm to answer it. – Recall: An “algorithm,” formally, is a TM that halts on all inputs, accepted or not. – Put another way, “decidable problem” = “recursive language.” • Otherwise, the problem is undecidable. Decidable Problems • A problem is decidable if there is an algorithm to answer it. – Recall: An “algorithm,” formally, is a TM that halts on all inputs, accepted or not. – Put another way, “decidable problem” = “recursive language.” • Otherwise, the problem is undecidable. Undecidable Problem • There is no Turing machine that accepts the language and makes a decision (halts) for every input string. (for every input instance) • Machine may make decision for some input strings. (for some input instances) Examples: Undecidable Problems • Can a particular line of code in a program ever be executed? • Is a given context-free grammar ambiguous? • Do two given CFG’s generate the same language? Halting Problem Given the description of a Turing machine M and an input w, does M, when started in the initial configuration q0w, perform a computation that eventually halts? Halting Problem Input: •Turing Machine M •String w Question: Does M halt while processing input string w? Corresponding language: HALTTM = { M ,w : M is a Turing machine that halts on input string w } Theorem: HALTTM is undecidable (The halting problem is unsolvable) Proof: Basic idea: Assume for contradiction that the halting problem is decidable; we will obtain a contradiction Suppose that HALTTM is decidable There exists Turing machine H that solves the halting problem M w H YES M halts on w NO doesn’t halt on M w Construction of H Input Initial tape content wM w H q0 YES M halts on w? NO Encoding of M String w Construction of H’ Construct machine H’: • If H returns YES then loop forever • If H returns NO then halt Construct machine H ′ : H′ H wM w Loop forever YES qa q0 M halts on w? NO If M halts on input w Then Loop Forever Else Halt qb Construction of Construct machine : Input: wM (machine M) • If M halts on input wM then loop forever • Else halt Construct machine wM Copy wM on tape wM wM : H′ If M halts on input wM Then loop forever Else halt Run with input itself Copy on tape If halts on input Then Else loops forever on input halts on input CONTRADICTION!!! H′ Another proof of the halting problem Basic idea: If the halting problem was decidable then every Recursively enumerable language would be recursive/decidable Suppose that HALTTM is decidable There exists Turing machine H that solves the halting problem Input M YES M halts on input w M doesn’t halt on input w H w NO Let L be a recursively enumerable language Let ML be the Turing Machine that accepts L We will prove that L is also decidable: We will describe a Turing machine that accepts L and halts on any input Decider for L Decider for ML w HALTTM ML halts on w? NO YES ML halts Run ML with input w and accepts ML halts and rejects Reject w and halt Accept w and halt Reject w and halt Therefore, L is decidable/recursive Since L is chosen arbitrarily, every Recursively enumerable language is also recursive But we have shown before that there are recursively enumerable languages which are not recursive Contradiction!!!! Therefore, the halting problem is undecidable! We can show: Recursively enumerable HALTTM Recursive/Decidable HALTTM is Recursively enumerable Turing machine that accepts HALTTM : 1. Run M on input w M ,w 2. If M halts on w then accept M ,w The Membership Problem Membership Problem Input: •Turing Machine •String w Question: M Does M accept w ? w∈ L(M ) ? Corresponding language: ATM = { M ,w : M is a Turing machine that accepts string w } Theorem: ATM is undecidable There are M and w for which we cannot decide whether w is in L Suppose that ATM is decidable. Thus, there exists a Turing machine H that solves the membership problem Decider for ATM M w H YES M accepts w NO M rejects w Let L be a Recursively enumerable language Let ML be the Turing Machine that accepts L We will prove that L is also recursive: we will build a decider for L that halts on every input Decider for L ML w Input string Decider for ATM H ML accepts w? YES Accept w (and halt) NO Reject w (and halt) Therefore, L is decidable Since L is chosen arbitrarily, every recursively enumerable language is also decidable/recursive But there is a Recursively enumerable language which is not recursive Contradiction!!!!