CS402, Spring 2016
Undecidable Problems Does the following program halts? (1) N : n, total, x, y, z (2) n GetUserInput() (3) total 3 (4) while true (5) for x 1 to total 2 (6) for y 1 to total x 1 (7) z total x y (8) if x n + y n == z n then Halt() (9) total total + 1
Undecidability It would be nice to have an algorithm that could examine any program P and tell whether P would halt. We know that no such algorithm exists.
Halting Problem Theorem 1 (Simplified Halting Problem) Given an arbitrary program P and its input, string I, the halting problem is to write a program H that takes P and I as input, and prints true if P halts on I, and false otherwise. There does not exist a program that can solve the halting problem. That is, halting problem is undecidable.
Halting Problem Proof. Assume that there exists such a program H that can solve the halting problem. Then, using H, we can write the following program Z: Z(String x) (1) if H(x, x) then Loop forever (2) else Halt() Consider the case of Z(Z): Z halts on Z: by the assumption, H will return true. Consequently, Z will loop forever, and will not halt. Contradiction. Z loops forever on Z: by the assumption, H will return false. Consequently, Z will halt. Contradiction. Reductio ad absurdum.
Undecidability of Halting Problem It is undecidable to check whether a Turing machine (TM) will halt if started on a blank tape (halting problem). To prove the undecidability of predicate logic, we give an algorithm which produces a formula A TM in the predicate calculus for every Turing machine, s.t. A TM is valid iff a Turing machine halts. Note that we do not make a Turing machine M for every predicate formula, since it is enough to show that checking some predicate formulas is undecidable. If we have such an algorithm, it is clear that validity check of predicate formula is at least as hard as halting problem (i.e., undecidable).
Undecidability of Halting Problem For the sake of simplicity, let us work with Two Registers Machines (TRM) rathern than the vanilla Turing Machine. That is, we show that there exists such a formula A TRM for each TRM. Theorem 2 (5.42) Given a Turing machine that computes a function f, a two-register machine can be constructed to compute the same function f. Halts(TM) Halts(TRM), Halts(TRM) IsValid(A TRM )
A Two Register Machine, M Definition 1 (5.41) A two-register machine M consists of two registers x and y which can hold natural numbers, and a program P = (L 0,..., L n ) which is a list of instructions. L n is the instruction halt, and for 0 I < n, L i is one of: x x + 1 y y + 1 if x = 0 then goto L j else x x 1, 0 j n if y = 0 then goto L j else y y 1, 0 j n
A Two Register Machine, M An execution sequence of M is a sequence of states s k = (L ik, x, y), where L ik is the current instruction at s k, and x, y are the contents of x and y. s k+1 is obtained from s k by executing L ik. The initial state s 0 = (L i0, m, 0) = (L 0, m, 0) for some m. If for some k, s k = (L n, x, y), the computation of M has halted and M has computed y = f (m).
Example /* This program executes L 1 m times and halts */ L 0 :if x=0 then goto L 2 else x:=x-1 L 1 :if y=0 then goto L 0 else y:=y-1 L 2 :halt Execution with the initial value of x = 2: s 0 (L 0,2,0) s 1 (L 1,1,0) s 2 (L 0,1,0) s 3 (L 1,0,0) s 4 (L 0,0,0) s 5 (L 2,0,0)
Example /* L 0 is repeated infinitely. */ L 0 : x:=x+1 L 1 :if y=0 then goto L 0 else y:=y-1 L 2 :halt Execution with the initial value of x = 0: s 0 (L 0,0,0) s 1 (L 1,1,0) s 2 (L 0,1,0) s 3 (L 1,2,0) s 4 (L 0,2,0)
Validity of Predicate Calculus Theorem 3 (5.43. Church s Theorem) Validity in the predicate calculus is undecidable. Proof. Let M be an arbitrary two-register machine. We will construct a formula S M such that S M is valid iff M terminates when started in the state (L 0, 0, 0). The formula is: S M = ( p 0 (a, a) n 1 i=0 S i ) z 1 z 2 p n (z 1, z 2 )
Validity of Predicate Calculus Proof. Cont. where S i is defined based on L i : L i x x + 1 y y + 1 if x = 0 then goto L j else x x 1 if y = 0 then goto L j else y y 1 S i x y(p i (x, y) p i+1 (s(x), y)) x y(p i (x, y) p i+1 (x, s(y))) x(p i (a, x) p j (a, x)) x y(p i (s(x), y) p i+1 (x, y)) x(p i (x, a) p j (x, a)) x y(p i (x, s(y)) p i+1 (x, y)) Predicates p 0,..., p n correspond to statements in M. The implicit meaning of p i (x, y) is that the computation of M is at L i, and registers contain values x and y. The constant symbol a denotes 0, and the function s is the successor function (s(x) = x + 1).
Validity of Predicate Calculus Proof. Cont.: If M halts then S M is valid. Let s 0,..., s m be a computation of M that halts after m steps; we need to show that S M is valid, that is, that it is true under any interpretation for the formula. However, we need not consider every possible interpretation. If I is an interpretation for S M such that ν I (S i ) = F for some 0 i n 1 or such that ν I (p 0 (a, a)) = F, then trivially ν I (S M ) = T since the antecedent of S M is false. Therefore, we need only consider interpretations that satisfy the antecedent of S M. For such interpretations, we need to show that ν I ( z 1 z 2 p n(z 1, z 2 )) = T. We show by induction on k that ν I ( z 1 z 2 p ik (z 1, z 2 )) = T : If k = 0, trivially, p 0 (a, a) z 1 z 2 p i0 (z 1, z 2 ) z 1 z 2 p 0 (z 1, z 2 ). Let us assume the inductive hypothesis for k 1 and resolve the case when L k 1 is x x + 1. By assumption, the antecedent is true, in particular, its subformula S k 1 : ν I ( x y(p ik 1 (x, y) p ik +1(s(x), y))) = T By the inductive hypothesis: ν I ( z 1 z 2 p ik 1 (z 1, z 2 )) = T From which follows (by applying S k 1 above): ν I ( z 1 z 2 p ik +1(s(z 1 ), z 2 )) = T Let c 1 and c 2 be the domain elements assigned to z 1 and z 2, respectively, such that (succ(c 1 ), c 2 ) P k, where P k is the interpretation of p k and succ is the interpretation of s. Since c 3 = succ(c 1 ) for some domain element c 3, the existentially quantified formula in the consequent is true: ν I ( z 1 z 2 p ik +1(z 1, z 2 )) = T.
Validity of Predicate Calculus Proof. Cont. Note that Ben-Ari (both 2nd and 3rd edition) uses the wrong notation of p k and L k throughout the proof that we just went through (i.e., if M halts then S M is valid). The correct notations are p ik and L ik (both denoting instruction L i at kth state in execution). k is the index of states, while i is the index of instruction (which can be repeated during execution, hence the separate indexing). The induction only works when we separate these two. For example, consider the instruction that we skipped: suppose L i is if x = 0 then goto L j else else y y 1. The corresponding S i is: x(p i (a, x) p j (a, x)) x y(p i (s(x), y) p i+1 (x, y)). When the first conjunct holds (i.e. when x register contains 0), the instruction index suddenly jumps from i to j: following the original notation, the induction does not work, because j may not be i + 1. Once we separate the indices, the induction becomes much simpler. Another minor mistake in the book is that, when presenting the induction, instruction for s k 1 is incorrectly denoted as L k : it should have been L k 1.
Validity of Predicate Calculus Proof. Cont. If S M is valid then M halts: Suppose that S M is valid and consider the interpretation: I = (N, {P 0,..., P n}, {succ}, {0}) where succ is the successor function on N, and (x, y) P i iff (L i, x, y) is reached by the register machine when started in (L 0, 0, 0). We show by induction on the length of the computation that the antecedent of S M is true in I. The initial state is (L 0, 0, 0), so (a, a) P 0 and ν I (p 0 (a, a)) = T. The inductive hypothesis is that in state s k 1 = (L i, x i, y i ), (x i, y i ) P i. The inductive step is again by cases on the type of the instruction Li. For x = x + 1, s k = (L i+1, succ(x i ), y i ) and (succ(x i ), y i ) P i+1 by the definition of P i+1. Since S M is valid, ν I ( z 1 z 2 p n(z 1, z 2 )) = T and ν I (p n(m 1, m 2 )) = T for some m 1, m 2 N. By definition, (m 1, m 2 ) P n means that M halts and computes m 2 = f (0).
Incompleteness Definition 2 (Completeness) Let T (U) be a theory. T (U) is complete if and only if for every closed formula A, U A or U A. T (U) is incomplete iff it is not complete, that is, iff for some closed formula A, U A and U A. Theorem 4 (Gödel s Incompleteness Theorem) Let NT be the number theory (Peano arithmetic). If T (NT ) is consistent, then T (NT ) is incomplete.
Sketch of the Proof Gödel s proof relies on the definition of a mapping, called a Gödel numbering, from logical objects (such as formulas and proofs) to natural numbers. Note the recursive conceptual structure. Gödel first proves the following theorem: Theorem 5 (Provability) There exists a formula A(x, y) in NT with the following property: for any numbers i, j, A(i, j) is true if and only if i is the Gödel number associated with some formula B(x) with one free variable x, and j is the Gödel number associated with the proof of B(i). Furthermore, if A(i, j) is true, then a proof can be constructed for these specific integers, i.e., A(i, j). That is, A(i, j) means that j is the Gödel number for the proof of B(i). But then!
Incompleteness Consider C(x) = y A(x, y), with one free variable x. Let m be the Gödel number for C(x). Then, consider C(m) = y A(m, y), that is, for no y, y is the Gödel number of a proof of C(m)! Theorem 6 (Gödel) If NT is consistent, then C(m) and C(m). Proof. Suppose that C(m) = y A(m, y), and compute n, the Gödel number for this proof. Since this proof exists, A(m, n) is true. However, if C(m) is true, y A(m, y), therefore A(m, n). Contraction to the consistency of NT. Suppose that C(m) = y A(m, y) = ya(m, n). Then, for some n, A(m, n) is true, where n is the Gödel number of the proof of C(m) (the provability theorem). That is, C(m). This contradicts our assumption.