content/computability/computability-theory/computability-theory.tex
1% Part: computability2% Chapter: computability-theory34\documentclass[../../../include/open-logic-chapter]{subfiles}56\begin{document}78\olchapter{cmp}{thy}{Computability Theory}910\begin{editorial}11 Material in this chapter should be reviewed and expanded. In12 particular, there are no exercises yet.13\end{editorial}1415\olimport{introduction}1617\olimport{coding-computations}1819\olimport{normal-form}2021\olimport{s-m-n}2223\olimport{universal-part-function}2425\olimport{no-universal-function}2627\olimport{halting-problem}2829\olimport{russells-paradox}3031\olimport{computable-sets}3233\olimport{ce-sets}3435\olimport{equiv-ce-defs}3637\olimport{non-comp-set}3839\olimport{ce-closed-cup-cap}4041\olimport{complement-ce}4243\olimport{reducibility}4445\olimport{prop-reduce}4647\olimport{complete-ce-sets}4849\olimport{k-1}5051\olimport{total}5253\olimport{rice-theorem}5455\olimport{fixed-point-thm}5657\olimport{application-fixed-point}5859\olimport{def-functions-self-reference}6061\OLEndChapterHook6263\end{document}
content/computability/computability-theory/introduction.tex
1% Part: computability2% Chapter: computability-theory3% Section: introduction45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{int}10\olsection{Introduction}1112The branch of logic known as \emph{computability theory} deals with13issues having to do with the computability, or relative computability,14of functions and sets. It is evidence of Kleene's influence15that the subject used to be known as \emph{recursion theory}, and16today, both names are commonly used.1718Let us call a function~$f\colon \Nat \pto \Nat$ \emph{partial19 computable} if it can be computed in some model of computation. If20$f$ is total we will simply say that $f$~is \emph{computable}. A21relation~$R$ with computable characteristic function~$\Char{R}$ is22also called computable. If $f$ and~$g$ are partial functions, we will23write $f(x) \fdefined$ to mean that $f$ is defined at~$x$, i.e., $x$~is24in the domain of~$f$; and $f(x) \fundefined$ to mean the opposite,25i.e., that $f$ is not defined at~$x$. We will use $f(x) \simeq g(x)$26to mean that either $f(x)$ and $g(x)$ are both undefined, or they are27both defined and equal.2829One can explore the theory of computability without having to refer to30a specific model of computation. To do this, one shows that there is a31universal partial computable function~$\fn{Un}(k, x)$. This allows us32to enumerate the partial computable functions. We will adopt the33notation~$\cfind{k}$ to denote the $k$-th unary partial computable34function, defined by $\cfind{k}(x) \simeq \fn{Un}(k, x)$. (Kleene used35$\{ k \}$ for this purpose, but this notation has not been used as36much recently.) Slightly more generally, we can uniformly enumerate37the partial computable functions of arbitrary arities, and we will use38$\cfind{k}[n]$ to denote the $k$-th $n$-ary partial recursive39function.4041If $f(\vec x, y)$ is a total or partial function, then $\umin{y}{f42(\vec x, y)}$ is the function of~$\vec x$ that returns the least~$y$43such that $f(\vec x, y) = 0$, assuming that all of $f(\vec x, 0)$,44\dots, $f(\vec x, y-1)$ are defined; if there is no such $y$,45$\umin{y}{f (\vec x, y)}$ is undefined. If $R(\vec x, y)$ is a46relation, $\umin{y}{R(\vec x, y)}$ is defined to be the least~$y$ such47that $R(\vec x, y)$ is true; in other words, the least~$y$ such that48$1 \tsub \Char{R}(\vec x, y) = 0$.4950To show that a function is computable, there are51two ways one can proceed:52\begin{enumerate}53\item Rigorously: describe a Turing machine or partial recursive54 function explicitly, and show that it computes the function you have55 in mind;56\item Informally: describe an algorithm that computes it, and appeal to57 Church's thesis.58\end{enumerate}59There is no fine line between the two; a detailed description of60an algorithm should provide enough information so that it is61relatively clear how one could, in principle, design the right Turing62machine or sequence of partial recursive definitions. Fully rigorous63definitions are unlikely to be informative, and we will try to find a64happy medium between these two approaches; in short, we will try to65find intuitive yet rigorous proofs that the precise definitions could66be obtained.6768\end{document}
content/computability/computability-theory/coding-computations.tex
1% Part: computability2% Chapter: computability-theory3% Section: coding-computations45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{cod}10\olsection{Coding Computations}1112In every model of computation, it is possible to do the following:13\begin{enumerate}14\item Describe the \emph{definitions} of computable functions in a15 systematic way. For instance, you can think of Turing machine16 specifications, recursive definitions, or programs in a programming17 language as providing these definitions.18\item Describe the complete record of the computation of a function19 given by some definition for a given input. For instance, a Turing20 machine computation can be described by the sequence of21 configurations (state of the machine, contents of the tape) for each22 step of computation.23\item Test whether a putative record of a computation is in fact the24 record of how a computable function with a given definition would be25 computed for a given input (on which the function is26 defined, i.e., the computation halts).27\item Extract from such a description of the complete record of a28 computation the value of the function for a given input. For29 instance, the contents of the tape in the very last step of a30 halting Turing machine computation is the value.31\end{enumerate}3233Using coding, it is possible to assign to each description of a34computable function a numerical \emph{index} in such a way that the35instructions can be recovered from the index in a computable way.36Similarly, the complete record of a computation can be coded by a37single number as well. The resulting arithmetical relation ``$s$~codes38the record of computation of the function with index~$e$ for39input~$x$'' and the function ``output of computation sequence with40code~$s$'' are then computable; in fact, they are primitive recursive.4142This fundamental fact is very powerful, and allows us to prove a43number of striking and important results about computability,44independently of the model of computation chosen.4546\end{document}
content/computability/computability-theory/normal-form.tex
1% Part: computability2% Chapter: computability-theory3% Section: normal-form45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{nfm}10\olsection{The Normal Form Theorem}1112Suppose we can describe definitions of computable functions, and test if13some putative description of the complete record of the computation of14that function on some input is correct. Then it stands to reason that15independently of the model of computation, we can determine the value16of any computable function~$f$ on any input~$x$ as follows:17\begin{enumerate}18 \item Search through all possible descriptions of records of19 computation.20 \item Test if a given record is the record of a computation of~$f(x)$.21 \item Extract the value of~$f(x)$ from the correct record if we have22 found it.23\end{enumerate}24That this is in fact true is the content of Kleene's normal form25theorem.2627\begin{thm}[Kleene's Normal Form Theorem]28\ollabel{thm:normal-form}29There is a primitive recursive relation~$T(e, x, s)$ and a primitive30recursive function~$U(s)$, with the following property: if $f$ is any31partial computable function, then for some~$e$,32\[33f(x) \simeq U(\umin{s}{T(e, x, s)})34\]35for every~$x$.36\end{thm}3738\begin{proof}[Proof Sketch]39For any model of computation one can rigorously define a description40of the computable function~$f$ and code such description using a41natural number~$e$. One can also rigorously define a notion of42``computation sequence'' which records the process of computing the43function with index~$e$ for input~$x$. Such a computation sequence can44likewise be coded as a number~$s$. This can be done in such a way45that46\begin{enumerate}47 \item the relation $T(e, x, s)$, which holds iff a number~$s$ codes the computation48 sequence of the function with index~$e$ on input~$x$, and49 \item the function $U(s)$ which maps a computation sequence coded50 by~$s$ to the end result of that computation51\end{enumerate}52are both computable. In fact, the relation~$T$ and the function~$U$53are primitive recursive.54\end{proof}5556\begin{explain}57In order to give a rigorous proof of the Normal Form Theorem, we would58have to fix a model of computation and carry out the coding of59descriptions of computable functions and of computation sequences in60detail, and verify that the relation~$T$ and function~$U$ are61primitive recursive. For most applications, it suffices that $T$62and~$U$ are computable and that $U$~is total.6364It is probably best to remember the proof of the normal form theorem65in slogan form: $\umin{s}{T(e, x, s)}$ searches for a computation66sequence of the function with index~$e$ on input~$x$, and $U$ returns67the output of the computation sequence if one can be found.68\end{explain}6970If the model of computation is the partial recursive functions (which71is what Kleene originally used), it shows that only a single use of72unbounded search, i.e., a single $\umin{y}{f(\vec x, y)}$ operator is73necessary for the definition of any function. In this sense it shows74that any partial recursive function has a normal form.7576$T$ and $U$ can be used to define the enumeration $\cfind{0}$,77$\cfind{1}$, $\cfind{2}$, \dots. From now on, we will assume that we78have fixed a suitable choice of $T$ and~$U$, and take the equation79\[80\cfind{e}(x) \simeq U(\umin{s}{T(e,x,s)})81\]82to be the \emph{definition} of $\cfind{e}$.8384Here is another useful fact:8586\begin{thm}87Every partial computable function has infinitely many indices.88\end{thm}8990Again, this is intuitively clear. Given any (description of) a91computable function, one can come up with a different description92which computes the same function (input-output pair) but does so,93e.g., by first doing something that has no effect on the computation94(say, test if $0 = 0$, or count to $5$, etc.). The index of the95altered description will always be different from the original96index. Both are indices of the same function, just computed slightly97differently.9899\end{document}
content/computability/computability-theory/s-m-n.tex
1% Part: computability2% Chapter: computability-theory3% Section: s-m-n45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{smn}10\olsection{The $s$-$m$-$n$ Theorem}1112\begin{explain}13The next theorem is known as the ``$s$-$m$-$n$ theorem,'' for a reason14that will be clear in a moment. The hard part is understanding just15what the theorem says; once you understand the statement, it will seem16fairly obvious.17\end{explain}1819\begin{thm}20\ollabel{thm:s-m-n}21 For each pair of natural numbers $n$ and~$m$, there is a primitive22 recursive function~$s^m_n$ such that for every sequence23 $e$, $a_0$, \dots, $a_{m-1}$, $y_0$ ,\dots, $y_{n-1}$, we have24 \[25 \cfind{s^m_n(e, a_0, \dots, a_{m-1})}[n](y_0, \dots, y_{n-1}) \simeq26 \cfind{e}[m+n](a_0, \dots, a_{m-1}, y_0, \dots, y_{n-1}).27\]28\end{thm}2930\begin{explain}31It is helpful to think of $s^m_n$ as acting on \emph{programs}. That32is, $s^m_n$ takes a program~$e$ for an $(m+n)$-ary function, as well33as fixed inputs $a_0$, \dots, $a_{m-1}$; and it returns a program34$s^m_n(x, a_0, \dots, a_{m-1})$ for the $n$-ary function of the35remaining arguments. \iftag{TMs}{It you think of $x$ as the description of a36Turing machine, then $s^m_n(e, a_0, \dots, a_{m-1})$ is the Turing37machine that, on input $y_0$, \dots,~$y_{n-1}$, prepends38$a_0$, \dots,~$a_{m-1}$ to the input string, and runs~$e$. Each $s^m_n$39is then just a primitive recursive function that finds a code for the40appropriate Turing machine.}{}41\end{explain}4243\end{document}44
content/computability/computability-theory/universal-part-function.tex
1% Part: computability2% Chapter: computability-theory3% Section: universal-part-function45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{uni}10\olsection{The Universal Partial Computable Function}1112\begin{thm}13\ollabel{thm:univ-comp}14There is a universal partial computable function~$\fn{Un}(e,x)$. In other15words, there is a function $\fn{Un}(e,x)$ such that:16\begin{enumerate}17\item $\fn{Un}(e,x)$ is partial computable.18\item If $f(x)$ is any partial computable function, then there is a19natural number $e$ such that $f(x) \simeq \fn{Un}(e,x)$ for every~$x$.20\end{enumerate}21\end{thm}2223\begin{proof}24Let $\fn{Un}(e,x) \simeq U(\umin{s}{T(e,x,s)})$, where $U$ and $T$ are25as in Kleene's normal form theorem (\olref[nfm]{thm:normal-form}).26\end{proof}2728\begin{explain}29This is just a precise way of saying that we have an effective30enumeration of the partial computable functions; the idea is that if31we write $f_e$ for the function defined by $f_e(x) = \fn{Un}(e,x)$,32then the sequence $f_0$, $f_1$, $f_2$, \dots includes all the partial33computable functions, with the property that $f_e(x)$ can be computed34``uniformly'' in $e$ and~$x$. For simplicity, we are using a binary35function that is universal for unary functions, but by coding36sequences of numbers we can easily generalize this to more arguments.37For example, note that if $f(x,y,z)$ is a $3$-place partial recursive38function, then the function $g(x) \simeq f((x)_0, (x)_1, (x)_2)$ is a39unary recursive function.40\end{explain}4142\end{document}
content/computability/computability-theory/no-universal-function.tex
1% Part: computability2% Chapter: computability-theory3% Section: no-universal-function45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{nou}10\olsection{No Universal Computable Function}1112Although there is a partial computable function that is total for the13partial computable functions, there is no total computable14function that is universal for the total computable functions. 1516\begin{thm}17\ollabel{thm:no-univ}18There is no universal computable function. In other words, any19function $\fn{Un}'(k, x)$ which is such that if $f(x)$ is a total20computable function, then there is a natural number~$k$ such that21$f(x) = \fn{Un}'(k,x)$ for every~$x$, is not computable.22\end{thm}2324\begin{proof}25The proof is a simple diagonalization: if $\fn{Un}'(k,x)$ were total26and computable, then27\[28d(x) = \fn{Un}'(x, x) + 129\]30would also be total and computable. However, by definition, $d(k)$ is31not equal to $\fn{Un}'(k,k)$. Hence, for every $k$, the values of32$d(x)$ and~$\fn{Un}'(k, x)$ differ for at least one~$x$, namely $x = k$.33\end{proof}3435\begin{explain}36\olref[uni]{thm:univ-comp} above shows that we can get around this37diagonalization argument, but only at the expense of allowing the38universal function to be partial. That is, $\fn{Un}$ is universal for39the total computable functions, it just isn't total. The40diagonalization argument doesn't work in the partial case. 41\end{explain}4243\begin{prob}44 To understand why the diagonalization argument in the proof of45 \olref{thm:no-univ} does not work in the partial46 case, consider the function $f(x) \simeq \fn{Un}(x,x)+1$. Is it47 partial computable? If so, it has an index~$e$, i.e., $f(x) \simeq48 \fn{Un}(e,x)$. What can you say about~$f(e)$?49\end{prob}505152\end{document}
content/computability/computability-theory/halting-problem.tex
1% Part: computability2% Chapter: computability-theory3% Section: halting-problem45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{hlt}10\olsection{The Halting Problem}1112By construction, the universal partial computable13function~$\fn{Un}(e,x)$ is defined if and only if the computation of14the function coded by~$e$ produces a value for input~$x$. It is15natural to ask if we can decide whether this is the case. In fact, it16is not. For the Turing machine model of computation, this means that17whether a given Turing machine halts on a given input is18computationally undecidable. The following theorem is therefore known19as the ``undecidability of the halting problem.'' We will provide two20proofs below. The first continues the thread of our previous21discussion, while the second is more direct.2223\begin{thm}24\ollabel{thm:halting-problem}25Let26\[27h(e, x) =28\begin{cases}291 & \text{if\/ $\fn{Un}(e, x)$ is defined} \\300 & \text{otherwise.}31\end{cases}32\]33Then $h$ is not computable.34\end{thm}3536\begin{proof}37Suppose $h$ is computable. We show that this would let us define a38universal computable function. Define39\[40\fn{Un'}(e,x) =41\begin{cases}42\fn{Un}(e,x) & \text{if $h(e,x) = 1$} \\430 & \text{otherwise.}44\end{cases}45\]46But now $\fn{Un'}(e, x)$ is a total function, and is computable if~$h$47is. For instance, we could define $g$ using primitive recursion, by48\begin{align*}49g(0, e, x) & \simeq 0 \\50g(y+1, e, x) & \simeq \fn{Un}(e,x);51\end{align*}52then53\[54\fn{Un'}(e,x) \simeq g(h(e,x),e,x).55\]56Since $\fn{Un'}(e,x)$ agrees with $\fn{Un}(e,x)$ wherever the latter57is defined, $\fn{Un'}$ is universal for those partial computable58functions that happen to be total. But this contradicts59\olref[nou]{thm:no-univ}.60\end{proof}6162\begin{proof}63Suppose $h(e,x)$ were computable. Define the function $g$ by64\[65g(x) =66\begin{cases}67 0 & \text{if $h(x,x) = 0$} \\68 \fundefined & \text{otherwise.}69\end{cases}70\]71The function $g$ is partial computable. For example, one can define it72as $\umin{y}{h(x,x) = 0}$. So, for some~$e$, $g(x) \simeq \fn{Un}(e,73x)$ for every~$x$. Is $g$ defined at $e$? If it is, then, by the74definition of~$g$, $h(e,e) = 0$ ($h$~can only take the value~$0$ if it75is defined). By the definition of~$h$, this means that $\fn{Un}(e, e)$76is undefined. By our assumption that $g(x) \simeq \fn{Un}(e, x)$77for every~$x$, we have that $g(e)$ is undefined, a contradiction.78On the other hand, if $g(e)$ is undefined, then $h(e,e) \neq 0$, and79so $h(e,e) = 1$. It follows that $\fn{Un}(e, e)$ is defined. But since80$g(x) \simeq \fn{Un}(e, x)$, then $g(e)$ would also be defined. Again,81a contradiction.82\end{proof}8384\begin{tagblock}{TMs}85\begin{explain}86We can describe this argument in terms of Turing machines. Suppose87there were a Turing machine~$H$ that takes as input a description of a88Turing machine~$E$ and an input~$x$, and decides whether or not $E$89halts on input~$x$. Then we could build another Turing machine~$G$90which takes a single input~$x$, runs $H$ to decide if the machine91$M_x$ with index~$x$ halts on input~$x$, and does the opposite. In92other words, if $H$ reports that $M_x$ halts on input~$x$, $G$ goes93into an infinite loop, and if $H$ reports that $M_x$ doesn't halt on94input~$x$, then $G$ just halts. Does $G$ halt on its own index as95input? The argument above shows that it does if and only if it96doesn't---a contradiction. So our supposition that there is a such97Turing machine~$H$ must be false.98\end{explain}99\end{tagblock}100101\end{document}
content/computability/computability-theory/russells-paradox.tex
1% Part: computability2% Chapter: computability-theory3% Section: russells-paradox45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{rus}10\olsection{Comparison with Russell's Paradox}1112It is instructive to compare and contrast the arguments in13this section with Russell's paradox:14\begin{enumerate}15\item Russell's paradox: let $S = \Setabs{x}{x \notin x}$. Then $S16 \in S$ if and only if $X \notin S$, a contradiction.1718 \emph{Conclusion:} There is no such set~$S$. Assuming the existence of a19 ``set of all sets'' is inconsistent with the other axioms of set20 theory.2122\item A modification of Russell's paradox: let $F$ be the ``function''23 from the set of all functions to $\{ 0, 1 \}$, defined by24 \[25 F(f) =26 \begin{cases}27 1 & \text{if $f$ is in the domain of $f$, and $f(f) = 0$} \\28 0 & \text{otherwise}29 \end{cases}30 \]31 A similar argument shows that $F(F) = 0$ if and only if $F(F) = 1$,32 a contradiction.3334 \emph{Conclusion:} $F$ is not a function. The ``set of all35 functions'' is too big to be the domain of a function.3637\item The diagonalization argument: let $f_0$, $f_1$, \dots be the38 enumeration of the partial computable functions, and let $G \colon \Nat \to39 \{ 0, 1 \}$ be defined by40 \[41 G(x) =42 \begin{cases}43 1 & \text{if $f_x(x)\downarrow = 0$} \\44 0 & \text{otherwise}45 \end{cases}46 \]47 If $G$ is computable, then it is the function $f_k$ for some48 $k$. But then $G(k) = 1$ if and only if $G(k) = 0$, a contradiction.4950 \emph{Conclusion:} $G$ is not computable. Note that according to the51 axioms of set theory, $G$ is still a function; there is no paradox52 here, just a clarification.53\end{enumerate}5455That talk of partial functions, computable functions,56partial computable functions, and so on can be confusing. The set of57all partial functions from $\Nat$ to $\Nat$ is a big collection of58objects. Some of them are total, some of them are computable, some are59both total and computable, and some are neither. Keep in mind that60when we say ``function,'' by default, we mean a total function. Thus we61have:62\begin{enumerate}63\item computable functions64\item partial computable functions that are not total65\item functions that are not computable66\item partial functions that are neither total nor computable67\end{enumerate}68To sort this out, it might help to draw a big square representing all69the partial functions from $\Nat$ to $\Nat$, and then mark off two70overlapping regions, corresponding to the total functions and the71computable partial functions, respectively. It is a good exercise to72see if you can describe an object in each of the resulting regions in73the diagram.7475\end{document}
content/computability/computability-theory/computable-sets.tex
1% Part: computability2% Chapter: computability-theory3% Section: computable-sets45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{cps}10\olsection{Computable Sets}1112We can extend the notion of computability from computable functions to13computable sets:1415\begin{defn}16 Let $S$ be a set of natural numbers. Then $S$ is \emph{computable}17 iff its characteristic function~$\Char{S}$ is. In other words,18 $S$~is computable iff the function19\[20\Char{S}(x) =21\begin{cases}221 & \text{if $x \in S$} \\230 & \text{otherwise}24\end{cases}25\]26is computable. Similarly, a relation $R(x_0, \dots, x_{k-1})$ is27computable if and only if its characteristic function is.2829Computable sets and relations are also called \emph{decidable}.30\end{defn}3132\begin{explain}33Notice that we now have a number of notions of computability: for34partial functions, for functions, and for sets. Do not get them35confused!{} \iftag{TMs}{The Turing machine computing a partial function36 returns the output of the function, for input values at which the37 function is defined; the Turing machine computing a set returns38 either $1$ or~$0$, after deciding whether or not the input value is in39 the set or not.}{}40\end{explain}4142\end{document}
content/computability/computability-theory/ce-sets.tex
1% Part: computability2% Chapter: computability-theory3% Section: ce-sets45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{ces}10\olsection{Computably Enumerable Sets}1112\begin{defn}13A set is \emph{computably enumerable} if it is empty or the range of a14computable function.15\end{defn}1617\begin{history}18Computably enumerable sets are also called \emph{recursively19 enumerable} instead. This is the original terminology, and today20both are commonly used, as well as the abbreviations ``c.e.'' and21``r.e.''22\end{history}2324\begin{explain}25You should think about what the definition means, and why the26terminology is appropriate. The idea is that if $S$ is the range of27the computable function~$f$, then28\[29S = \{ f(0), f(1), f(2), \dots \},30\]31and so $f$ can be seen as ``enumerating'' the elements of~$S$. Note32that according to the definition, $f$~need not be an increasing33function, i.e., the enumeration need not be in increasing order. In34fact, $f$ need not even be injective, i.e., repetitions in the35enumeration $f(0)$, $f(1)$, $f(2)$, \dots{} of~$S$ are allowed. For36instance, the constant function $f(x) = 0$ enumerates the set $\{ 037\}$.38\end{explain}3940Any computable set is computably enumerable. To see this, suppose41$S$~is computable. If $S$ is empty, then by definition it is42computably enumerable. Otherwise, let $a$ be any element of43$S$. Define $f$ by44\[45f(x) =46\begin{cases}47x & \text{if $\Char{S}(x) = 1$} \\48a & \text{otherwise.}49\end{cases}50\]51Then $f$ is a computable function, and $S$ is the range of~$f$.5253\end{document}
content/computability/computability-theory/equiv-ce-defs.tex
1% Part: computability2% Chapter: computability-theory3% Section: equiv-ce-defs45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{eqc}1011\olsection[Definitions of C. E. Sets]{Equivalent Defininitions of12 Computably Enumerable Sets}131415The following gives a number of important equivalent statements of16what it means to be computably enumerable.1718\begin{thm}19\ollabel{thm:ce-equiv}20Let $S$ be a set of natural numbers. Then the following are21equivalent:22\begin{enumerate}23\item\ollabel{case:ce} $S$ is computably enumerable.24\item\ollabel{case:ran-pc} $S$ is the range of a \emph{partial} computable function.25\item\ollabel{case:ran-prim} $S$ is empty or the range of a primitive recursive function.26\item\ollabel{case:ce-domain} $S$ is the \emph{domain} of a partial computable function.27\end{enumerate}28\end{thm}2930\begin{explain}31The first three clauses say that we can equivalently take any non-empty32computably enumerable set to be enumerated by either a computable33function, a partial computable function, or a primitive recursive34function. The fourth clause tells us that if $S$ is computably35enumerable, then for some index~$e$,36\[37S = \Setabs{x}{\cfind{e}(x) \fdefined}.38\]39In other words, $S$ is the set of inputs on for which the computation40of $\cfind{e}$ halts. For that reason, computably enumerable sets are41sometimes called \emph{semi-decidable}: if a number is in the set, you42eventually get a ``yes,'' but if it isn't, you never get a ``no''!{}43\end{explain}4445\begin{proof}46Since every primitive recursive function is computable and every47computable function is partial computable, \olref{case:ran-prim}48implies \olref{case:ce} and \olref{case:ce}49implies~\olref{case:ran-pc}. (Note that if $S$ is empty, $S$~is the50range of the partial computable function that is nowhere defined.) If51we show that \olref{case:ran-pc} implies \olref{case:ran-prim}, we52will have shown the first three clauses equivalent.5354So, suppose $S$ is the range of the partial computable function55$\cfind{e}$. If $S$ is empty, we are done. Otherwise, let $a$ be any56element of~$S$. By Kleene's normal form theorem, we can write57\[58\cfind{e}(x) = U(\umin{s}{T(e, x, s)}).59\]60In particular, $\cfind{e}(x) \fdefined$ and $= y$ if and only if there61is an $s$ such that $T(e, x, s)$ and $U(s) = y$. Define $f(z)$ by62\[63f(z) = \begin{cases}64 U((z)_1) & \text{if $T(e, (z)_0, (z)_1)$} \\65 a & \text{otherwise.}66\end{cases}67\]68Then $f$ is primitive recursive, because $T$ and $U$69are. \iftag{TMs}{Expressed in terms of Turing machines, if $z$ codes a70 pair $\tuple{(z)_0, (z)_1}$ such that $(z)_1$ is a halting71 computation of machine~$M_e$ on input $(z)_0$, then $f$ returns the72 output of the computation; otherwise, it returns~$a$.}7374We need to show that $S$ is the range of~$f$, i.e., for any natural75number~$y$, $y \in S$ if and only if it is in the range of~$f$. In the76forwards direction, suppose $y \in S$. Then $y$ is in the range of77$\cfind{e}$, so for some $x$ and~$s$, $T(e,x,s)$ holds and $U(s) = y$.78But then $y = f(\tuple{x,s})$. Conversely, suppose $y$ is in the range79of~$f$. Then either $y = a$, or for some~$z$, $T(e,(z)_0,(z)_1)$ and80$U((z)_1) = y$. Since, in the latter case, $\cfind{e}(x) \fdefined =81y$, either way, $y$ is in~$S$.8283(The notation $\cfind{e}(x) \fdefined = y$ means ``$\cfind{e}(x)$ is84defined and equal to $y$.'' We could just as well use $\cfind{e}(x) =85y$, but the extra arrow is sometimes helpful in reminding us that we86are dealing with a partial function.)8788To finish up the proof of \olref{thm:ce-equiv}, it suffices to show89that \olref{case:ce} and~\olref{case:ce-domain} are equivalent. First,90let us show that \olref{case:ce} implies~\olref{case:ce-domain}.91Suppose $S$ is the range of a computable function~$f$, i.e.,92\[93S = \Setabs{y}{\text{for some $x$, } f(x) = y}.94\]95Let96\[97g(y) = \umin{x}{(f(x) = y)}.98\]99Then $g$ is a partial computable function, and $g(y)$ is defined if100and only if for some~$x$, $f(x) = y$. In other words, the domain of101$g$~is the range of~$f$. \iftag{TMs}{Expressed in terms of Turing102machines: given a Turing machine~$F$ that enumerates the elements103of~$S$, let $G$ be the Turing machine that semi-decides $S$ by104searching through the outputs of~$F$ to see if a given element is in105the set, halts if it is and keeps searching forever if it isn't.}{}106107Finally, to show \olref{case:ce-domain} implies~\olref{case:ce},108suppose that $S$~is the domain of the partial computable109function~$\cfind{e}$, i.e.,110\[111S = \Setabs{x}{\cfind{e}(x) \fdefined}.112\]113If $S$ is empty, we are done; otherwise, let $a$ be any element114of~$S$. Define $f$ by115\[116f(z) = \begin{cases}117(z)_0 & \text{if $T(e,(z)_0,(z)_1)$} \\118a & \text{otherwise.}119\end{cases}120\]121Then, as above, a number $x$ is in the range of~$f$ if and only if122$\cfind{e}(x) \fdefined$, i.e., if and only if $x \in S$. \iftag{TMs}{Expressed123in terms of Turing machines: given a machine $M_e$ that semi-decides124$S$, enumerate the elements of $S$ by running through all possible125Turing machine computations, and returning the inputs that correspond126to halting computations.}{}127\end{proof}128129Clause~\olref{case:ce-domain} of \olref{thm:ce-equiv} provides us with130a convenient way of enumerating the computably enumerable sets: for131each~$e$, let $W_e$ denote the domain of $\cfind{e}$, i.e.,132\[133W_e = \Setabs{x}{\cfind{e}(x) \fdefined}.134\] 135Then if $A$ is any computably enumerable set, $A = W_e$, for some~$e$.136137The following provides yet another characterization of the computably138enumerable sets.139140\begin{thm}141\ollabel{thm:exists-char}142A set $S$ is computably enumerable if and only if there is a143computable relation $R(x,y)$ such that144\[145S = \Setabs{ x }{ \lexists[y][R(x,y)] }.146\]147\end{thm}148149\begin{proof}150In the forward direction, suppose $S$ is computably151enumerable. Then for some $e$, $S = W_e$. For this value of~$e$152we can write $S$ as153\[154S = \Setabs{ x }{ \lexists[y][T(e, x, y)] }.155\]156In the reverse direction, suppose $S = \Setabs{ x }{157 \lexists[y][R(x, y)] }$. Define $f$~by158\[159f(x) \simeq \umin{y}{R(x, y)}.160\]161Then $f$ is partial computable, and $S$ is the domain of~$f$.162\end{proof}163164165\end{document}
content/computability/computability-theory/non-comp-set.tex
1% Part: computability2% Chapter: computability-theory3% Section: non-comp-set45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{ncp}10\olsection{There Are Non-Computable Sets}111213We saw above that every computable set is computably enumerable. Is14the converse true? The following shows that, in general, it is not.1516\begin{thm}\ollabel{thm:K-0}17Let $K_0$ be the set $\Setabs{\tuple{e, x}}{\cfind{e}(x) \fdefined}$.18Then $K_0$ is computably enumerable but not computable.19\end{thm}2021\begin{proof}22To see that $K_0$ is computably enumerable, note that it is the23domain of the function~$f$ defined by24\[25f(z) = \umin{y}{(\len{z} = 2 \land T((z)_0, (z)_1, y))}.26\]27For, if $\cfind{e}(x)$ is defined, $f(\tuple{e, x})$ finds a halting28computation sequence; if $\cfind{e}(x)$ is undefined, so is29$f(\tuple{e, x})$; and if $z$ doesn't even code a pair, then $f(z)$ is30also undefined.3132The fact that $K_0$ is not computable is just the undecidability of33the halting problem, \olref[hlt]{thm:halting-problem}.34\end{proof}3536The set $K_0$ is the set of pairs $\tuple{e,x}$ such that37$\cfind{e}(x) \fdefined$, i.e., $\tuple{e,x} \in K_0$ iff $\cfind{e}$38is defined (halts) on input~$x$, so it is also called the ``halting39set.'' The set $K = \Setabs{e}{\cfind{e}(e) \fdefined}$ is the40``self-halting set.'' It is often used as a canonical undecidable set.4142\begin{thm}\ollabel{thm:K}43The self-halting set $K = \Setabs{e}{\cfind{e}(e) \fdefined}$ is44!!{c.e.} but not decidable.45\end{thm}4647\begin{proof}48 Suppose $K$ is decidable, i.e., its characteristic function49 $\Char{K}$ is computable. Let 50 \[d(e) = \begin{cases}51 1 & \text{if\/ $\Char{K}(e) = 0$}\\52 \fundefined & \text{otherwise.}53 \end{cases}54 \] 55 Let $k$ be the index of~$d$, i.e., $d \simeq \cfind{k}$. Then $d(k)56 \simeq \cfind{k}(k)$. This contradicts the fact that $d(k)57 \fdefined$ iff $\cfind{k}(k) \fundefined$, which follows from the58 definition of~$d$.5960 $K$ is the domain of $f(x) = \umin{y}{T(x,x,y)}$ and so is !!{c.e.}61\end{proof}6263\end{document}
content/computability/computability-theory/ce-closed-cup-cap.tex
1% Part: computability2% Chapter: computability-theory3% Section: ce-closed-cup-cap45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{clo}1011\olsection[Union and Intersection of C.E. Sets]{Computably Enumerable12 Sets are Closed under Union and Intersection}1314The following theorem gives some closure properties on the set of15computably enumerable sets.1617\begin{thm}18Suppose $A$ and $B$ are computably enumerable. Then so are $A \cap B$19and $A \cup B$.20\end{thm}2122\begin{proof}23\olref[eqc]{thm:ce-equiv} allows us to use various characterizations24of the computably enumerable sets. By way of illustration, we will25provide a few different proofs.2627For the first proof, suppose $A$ is enumerated by a computable28function~$f$, and $B$ is enumerated by a computable function~$g$. Let29\begin{align*}30h(x) & = \umin{y}{(f(y) = x \lor g(y) = x)} \text{ and}\\31j(x) & = \umin{y}{(f((y)_0) = x \land g((y)_1) = x)}.32\end{align*}33Then $A \cup B$ is the domain of $h$, and $A \cap B$ is the domain34of~$j$.3536\begin{explain}37Here is what is going on, in computational terms: given38procedures that enumerate $A$ and $B$, we can semi-decide if an39element $x$ is in $A \cup B$ by looking for $x$ in either enumeration;40and we can semi-decide if an element $x$ is in $A \cap B$ for looking41for $x$ in both enumerations at the same time.42\end{explain}4344For the second proof, suppose again that $A$ is enumerated by~$f$ and45$B$ is enumerated by~$g$. Let46\[47k(x) = \begin{cases}48f(x/2) & \text{if $x$ is even} \\49g((x-1)/2) & \text{if $x$ is odd.}50\end{cases}51\]52Then $k$ enumerates $A \cup B$; the idea is that $k$ just alternates53between the enumerations offered by $f$ and~$g$. Enumerating $A \cap54B$ is tricker. If $A \cap B$ is empty, it is trivially computably55enumerable. Otherwise, let $c$ be any element of $A \cap B$, and56define $l$ by57\[58l(x) = \begin{cases}59f((x)_0) & \text{if $f((x)_0) = g((x)_1)$} \\60c & \text{otherwise.}61\end{cases}62\]63In computational terms, $l$ runs through pairs of elements in the64enumerations of $f$ and $g$, and outputs every match it finds;65otherwise, it just stalls by outputting $c$.6667For the last proof, suppose $A$ is the \emph{domain} of the partial68function $m(x)$ and $B$ is the domain of the partial function69$n(x)$. Then $A \cap B$ is the domain of the partial function $m(x) +70n(x)$.7172\begin{explain}73In computational terms, if $A$ is the set of values for which74$m$ halts and $B$ is the set of values for which $n$ halts, $A \cap B$75is the set of values for which both procedures halt.76\end{explain}7778Expressing $A \cup B$ as a set of halting values is more difficult,79because one has to simulate $m$ and $n$ in parallel. Let $d$ be an80index for $m$ and let $e$ be an index for $n$; in other words, $m =81\cfind{d}$ and $n = \cfind{e}$. Then $A \cup B$ is the domain of the82function83\[84p(x) = \umin{y}{(T(d,x,y) \lor T(e,x,y))}.85\]86\begin{explain}87In computational terms, on input $x$, $p$ searches for either a88halting computation for $m$ or a halting computation for $n$, and89halts if it finds either one.90\end{explain}91\end{proof}9293\end{document}
content/computability/computability-theory/complement-ce.tex
1% Part: computability2% Chapter: computability-theory3% Section: complement-ce45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{cmp}10\olsection{Computably Enumerable Sets not Closed under Complement}1112Suppose $A$ is computably enumerable. Is the complement of~$A$,13$\Complement{A} = \Nat \setminus A$, always computably enumerable14as well? The following theorem and corollary show that the answer is15``no.''1617\begin{thm}18\ollabel{thm:ce-comp}19Let $A$ be any set of natural numbers. Then $A$ is computable if and20only if both $A$ and $\Complement{A}$ are computably enumerable.21\end{thm}2223\begin{proof}24The forwards direction is easy: if $A$ is computable, then25$\Complement{A}$ is computable as well ($\Char{A} = 1 \tsub26\Char{\Complement{A}}$), and so both are computably enumerable.2728In the other direction, suppose $A$ and~$\Complement{A}$ are both29computably enumerable. Let $A$ be the domain of~$\cfind{d}$, and let30$\Complement{A}$ be the domain of~$\cfind{e}$. Define $h$ by31\[32h(x) = \umin{s}{(T(d,x,s) \lor T(e,x,s))}.33\]34In other words, on input~$x$, $h$~searches for either a halting35computation of~$\cfind{d}$ or a halting computation of~$\cfind{e}$.36Now, if $x \in A$, it will succeed in the first case, and if $x \in37\Complement{A}$, it will succeed in the second case. So, $h$~is a38total computable function. But now we have that for every~$x$, $x \in39A$ if and only if $T(e, x, h(x))$, i.e., if $\cfind{e}$ is the one40that is defined. Since $T(e, x, h(x))$ is a computable relation,41$A$~is computable.42\end{proof}4344\begin{explain}45It is easier to understand what is going on in informal computational46terms: to decide $A$, on input $x$ search for halting computations of47$\cfind{e}$ and $\cfind{f}$. One of them is bound to halt; if it is $\cfind{e}$,48then $x$ is in~$A$, and otherwise, $x$ is in~$\Complement{A}$.49\end{explain}5051\begin{cor}52\ollabel{cor:comp-k}53$\Complement{K_0}$ is not computably enumerable.54\end{cor}5556\begin{proof}57We know that $K_0$ is computably enumerable, but not computable. If58$\Complement{K_0}$ were computably enumerable, then $K_0$ would be59computable by \olref{thm:ce-comp}, contradicting \olref[ncp]{thm:K-0}.60\end{proof}6162\end{document}
content/computability/computability-theory/reducibility.tex
1% Part: computability2% Chapter: computability-theory3% Section: reducibility45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{red}10\olsection{Reducibility}1112\begin{explain}13We now know that there is at least one set, $K_0$, that is computably14enumerable but not computable. It should be clear that there are15others. The method of reducibility provides a powerful method of16showing that other sets have these properties, without constantly17having to return to first principles.1819Generally speaking, a ``reduction'' of a set $A$ to a set~$B$ is a20method of transforming answers to whether or not !!{element}s are in~$B$21into answers as to whether or not !!{element}s are in~$A$. We will focus22on a notion called ``many-one reducibility,'' but there are many other23notions of reducibility available, with varying properties. Notions of24reducibility are also central to the study of computational25complexity, where efficiency issues have to be considered as well. For26example, a set is said to be ``NP-complete'' if it is in NP and every27NP problem can be reduced to it, using a notion of reduction that is28similar to the one described below, only with the added requirement29that the reduction can be computed in polynomial time.3031We have already used the notion of reduction notion implicitly. Define32the set~$K$ by33\[34K = \Setabs{x}{\cfind{x}(x) \fdefined},35\]36i.e., $K = \Setabs{x}{x \in W_x}$. Our proof that the halting problem37in unsolvable (\olref[hlt]{thm:halting-problem}) shows most directly38that $K$ is not computable. Recall that $K_0$ is the set39\[40K_0 = \Setabs{\tuple{e, x}}{\cfind{e}(x) \fdefined },41\]42i.e., $K_0 = \Setabs{\tuple{x,e}}{x \in W_e}$. It is easy to extend43any proof of the uncomputability of~$K$ to the uncomputability44of~$K_0$: if $K_0$ were computable, we could decide whether or not45!!a{element}~$x$ is in $K$ simply by asking whether or not the pair46$\tuple{x, x}$ is in $K_0$. The function~$f$ which maps $x$ to47$\tuple{x, x}$ is an example of a \emph{reduction} of $K$ to $K_0$.48\end{explain}4950\begin{defn}51Let $A$ and $B$ be sets of natural numbers. A computable52function~$f\colon \Nat \to \Nat$ is a \emph{many-one reduction} of $A$53to~$B$ iff, for every natural number~$x$,54\[55x \in A \quad \text{if and only if} \quad f(x) \in B.56\]57If such a reduction $f$ exists, we say that $A$ is \emph{many-one58reducible} to~$B$, written $A \leq_m B$. If $A$ is many-one reducible59to $B$ and vice-versa, then $A$ and $B$ are said to be \emph{many-one60equivalent}, written $A \equiv_m B$.61\end{defn}6263If the function $f$ in the definition above happens to be injective,64$A$~is said to be \emph{one-one reducible} to~$B$. Most of the65reductions described below meet this stronger requirement, but we will66not use this fact.6768\begin{digress}69It is true, but by no means obvious, that one-one reducibility really70is a stronger requirement than many-one reducibility. In other words,71there are infinite sets $A$ and~$B$ such that $A$ is many-one72reducible to~$B$ but not one-one reducible to~$B$.73\end{digress}7475\end{document}
content/computability/computability-theory/prop-reduce.tex
1% Part: computability2% Chapter: computability-theory3% Section: prop-reduce45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{ppr}10\olsection{Properties of Reducibility}1112We write $A \leq_m B$ if $A$ reduces to~$B$, and this notation13suggests that if $A \leq_m B$, then $A$ is ``no harder than''~$B$ and14that $B$ is ``as hard or harder than''~$A$, and that $\le_m$, like the15usual $\le$ on numbers, orders sets (or decision problems) by their16complexity. The following two propositions support this intuition. The17first one say taht $\le_m$ is transitive.1819\begin{prop}20\ollabel{prop:trans-red}21If $A \leq_m B$ and $B \leq_m C$, then $A \leq_m C$.22\end{prop}2324\begin{proof}25Composing a reduction of $A$ to~$B$ with a reduction of $B$ to26$C$ yields a reduction of $A$ to~$C$.27\end{proof}2829\begin{prob}30Prove \olref{prop:trans-red} by showing that if $f$ and~$g$ are31many-one reductions of $A$ to~$B$ and $B$ to~$C$, respectively, then32$\comp{f}{g}$ is a many-one reduction of $A$ to~$C$.33\end{prob}3435\begin{prop}36\ollabel{prop:reduce}37Let $A$ and $B$ be any sets, and suppose $A \leq_m B$.38\begin{enumerate}39\item If $B$ is computably enumerable, so is~$A$.40\item If $B$ is computable, so is~$A$.41\end{enumerate}42\end{prop}4344\begin{proof}45Let $f$ be a many-one reduction from $A$ to~$B$. For the first46claim, just check that if $B$ is the domain of a partial function~$g$,47then $A$ is the domain of~$\comp{f}{g}$:48\begin{align*}49x \in A & \text{ iff } f(x) \in B \\50& \text{ iff } g(f(x)) \fdefined.51\end{align*}5253For the second claim, remember that if $B$~is computable then $B$54and~$\Complement{B}$ are computably enumerable55(\olref[cmp]{thm:ce-comp}). It is not hard to check that $f$~is also a56many-one reduction of $\Complement{A}$ to $\Complement{B}$, so, by the57first part of this proof, $A$ and~$\Complement{A}$ are !!{computably58enumerable}. So $A$ is computable as well by \olref[cmp]{thm:ce-comp}.59(Alternatively, you can check that $\Char{A} = \comp{f}{\Char{B}}$; so60if $\Char{B}$ is computable, then so is~$\Char{A}$.)61\end{proof}6263\begin{prob}64Suppose $f$ is a many-one reduction of $A$ to~$B$. Show that $f$ is65also a many-one reduction of $\Complement{A}$ to $\Complement{B}$.66\end{prob}6768\begin{prob}69Show that if $f\colon A \to B$ is a many-one reduction, then $\Char{A}70= \comp{f}{\Char{B}}$.71\end{prob}7273\begin{digress}74A more general notion of reducibility called \emph{Turing75reducibility} is useful in other contexts, especially for proving76undecidability results. Note that by \olref[cmp]{cor:comp-k}, the77complement of~$K_0$ is not reducible to~$K_0$, since it is not78computably enumerable. But, intuitively, if you knew the answers to79questions about $K_0$, you would know the answer to questions about80its complement as well. A set $A$ is said to be Turing reducible81to~$B$ if one can determine answers to questions in~$A$ using a82computable procedure that can ask questions about~$B$. This is more83liberal than many-one reducibility, in which (1)~you are only allowed84to ask one question about $B$, and (2)~a ``yes'' answer has to85translate to a ``yes'' answer to the question about $A$, and similarly86for ``no.'' It is still the case that if $A$~is Turing reducible87to~$B$ and $B$~is computable then $A$~is computable as well (though,88as we have seen, the analogous statement does not hold for computable89enumerability).9091You should think about the various notions of reducibility we have92discussed, and understand the distinctions between them. We will,93however, only deal with many-one reducibility in this chapter.94Incidentally, both types of reducibility discussed in the last95paragraph have analogues in computational complexity, with the added96requirement that the Turing machines run in polynomial time: the97complexity version of many-one reducibility is known as \emph{Karp98reducibility}, while the complexity version of Turing reducibility is99known as \emph{Cook reducibility}.100\end{digress}101102\end{document}
content/computability/computability-theory/complete-ce-sets.tex
1% Part: computability2% Chapter: computability-theory3% Section: complete-ce-sets45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{cce}10\olsection{Complete Computably Enumerable Sets}1112\begin{defn}13A set $A$ is a \emph{complete !!{computably enumerable} set}14(under many-one reducibility) if15\begin{enumerate}16\item $A$ is computably enumerable, and17\item for any other computably enumerable set $B$, $B \leq_m A$.18\end{enumerate}19\end{defn}2021In other words, complete computably enumerable sets are the22``hardest'' computably enumerable sets possible. They allow one to23answer questions about \emph{any} computably enumerable set.2425\begin{thm}26$K$, $K_0$, and $K_1$ are all complete computably enumerable sets.27\end{thm}2829\begin{proof}30To see that $K_0$ is complete, let $B$ be any computably31enumerable set. Then for some index $e$,32\[33B = W_e = \Setabs{x}{\cfind{e}(x) \fdefined}.34\]35Let $f$ be the function $f(x) = \tuple{e, x}$. Then for every natural36number $x$, $x \in B$ if and only if $f(x) \in K_0$. In other words, $f$37reduces $B$ to~$K_0$.3839To see that $K_1$ is complete, note that in the proof of40\olref[k1]{prop:k1} we reduced $K_0$ to it. So, by41\olref[ppr]{prop:trans-red}, any computably enumerable set can be42reduced to~$K_1$ as well.4344$K$ can be reduced to $K_0$ in much the same way.45\end{proof}4647\begin{prob}48Give a reduction of $K$ to $K_0$.49\end{prob}5051\begin{digress}52So, it turns out that all the examples of computably enumerable sets53that we have considered so far are either computable, or complete.54This should seem strange!{} Are there any examples of computably55enumerable sets that are neither computable nor complete? The answer56is yes, but it wasn't until the middle of the 1950s that this was57established by Friedberg and Muchnik, independently.58\end{digress}5960\end{document}61
content/computability/computability-theory/k-1.tex
1% Part: computability2% Chapter: computability-theory3% Section: k-145\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{k1}10\olsection{An Example of Reducibility}1112Let us consider an application of \olref[ppr]{prop:reduce}.1314\begin{prop}15\ollabel{prop:k1}16Let17\[18K_1 = \Setabs{e}{\cfind{e}(0) \fdefined}.19\]20Then $K_1$ is computably enumerable but not computable.21\end{prop}2223\begin{proof}24Since $K_1 = \Setabs{e}{\lexists[s][T(e,0,s)]}$, $K_1$ is computably25enumerable by \olref[eqc]{thm:exists-char}.2627To show that $K_1$ is not computable, let us show that $K_0$ is28reducible to it.2930\begin{explain}31This is a little bit tricky, since using $K_1$ we can32only ask questions about computations that start with a particular33input, $0$. Suppose you have a smart friend who can answer questions34of this type (friends like this are known as ``oracles''). Then35suppose someone comes up to you and asks you whether or not $\tuple{e,36 x}$ is in $K_0$, that is, whether or not machine $e$ halts on input37$x$. One thing you can do is build another machine, $e_x$, that, for38\emph{any} input, ignores that input and instead runs~$e$ on input39$x$. Then clearly the question as to whether machine $e$ halts on40input $x$ is equivalent to the question as to whether machine $e_x$41halts on input $0$ (or any other input). So, then you ask your friend42whether this new machine, $e_x$, halts on input $0$; your friend's43answer to the modified question provides the answer to the original44one. This provides the desired reduction of $K_0$ to~$K_1$.45\end{explain}4647Using the universal partial computable function, let $f$48be the 3-ary function defined by49\[50f(x,y,z) \simeq \cfind{x}(y).51\]52Note that $f$ ignores its third input entirely. Pick an index $e$ such53that $f = \cfind{e}[3]$; so we have54\[55\cfind{e}[3](x,y,z) \simeq \cfind{x}(y).56\]57By the $s$-$m$-$n$ theorem, there is a function $s(e,x,y)$ such that, for58every $z$,59\begin{align*}60\cfind{s(e,x,y)}(z) & \simeq \cfind{e}[3](x,y,z) \\61& \simeq \cfind{x}(y).62\end{align*}6364\begin{explain}65In terms of the informal argument above, $s(e,x,y)$ is an index for66the machine that, for any input $z$, ignores that input and computes67$\cfind{x}(y)$.68\end{explain}6970In particular, we have71\[72\cfind{s(e,x,y)}(0) \fdefined \quad \text{if and only if} \quad73\cfind{x}(y) \fdefined.74\]75In other words, $\tuple{x, y} \in K_0$ if and only if $s(e,x,y) \in76K_1$. So the function $g$ defined by77\[78g(w) = s(e,(w)_0,(w)_1)79\]80is a reduction of $K_0$ to~$K_1$.81\end{proof}8283\end{document}
content/computability/computability-theory/total.tex
1% Part: computability2% Chapter: computability-theory3% Section: total45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{tot}10\olsection{Totality is Undecidable}1112Let us consider one more example of using the $s$-$m$-$n$ theorem to show13that something is noncomputable. Let $\fn{Tot}$ be the set of indices14of total computable functions, i.e.15\[16\fn{Tot} = \Setabs{x}{\text{for every $y$, $\cfind{x}(y)\fdefined$}}.17\]1819\begin{prop}20\ollabel{prop:total}21$\fn{Tot}$ is not computable.22\end{prop}2324\begin{proof}25To see that $\fn{Tot}$ is not computable, it suffices to show that $K$26is reducible to it. Let $h(x,y)$ be defined by27\[28h(x,y) \simeq29\begin{cases}300 & \text{if $x \in K$} \\31\fundefined & \text{otherwise}32\end{cases}33\]34Note that $h(x,y)$ does not depend on $y$ at all. It should35not be hard to see that $h$~is partial computable: on input $x, y$, the36we compute~$h$ by first simulating the function~$\cfind{x}$ on input~$x$; if37this computation halts, $h(x,y)$ outputs $0$ and halts. So38$h(x,y)$ is just $\Zero(\umin{s}{T(x,x,s)})$, where $\Zero$ is the constant zero39function.4041Using the $s$-$m$-$n$ theorem, there is a primitive recursive42function~$k(x)$ such that for every $x$ and~$y$,43\[44\cfind{k(x)}(y) =45\begin{cases}460 & \text{if $x \in K$} \\47\fundefined & \text{otherwise}48\end{cases}49\]50So $\cfind{k(x)}$ is total if $x \in K$, and undefined otherwise. Thus,51$k$ is a reduction of $K$ to~$\fn{Tot}$.52\end{proof}5354\begin{digress}55It turns out that $\fn{Tot}$ is not even computably enumerable---its56complexity lies further up on the ``arithmetical hierarchy.'' But we57will not worry about this strengthening here.58\end{digress}5960\end{document}61
content/computability/computability-theory/rice-theorem.tex
1% Part: computability2% Chapter: computability-theory3% Section: rice-theorem45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{rce}10\olsection{Rice's Theorem}1112If you think about it, you will see that the specifics of $\fn{Tot}$13do not play into the proof of \olref[tot]{prop:total}. We designed14$h(x,y)$ to act like the constant function $j(y) = 0$ exactly when $x$15is in $K$; but we could just as well have made it act like any other16partial computable function under those circumstances. This17observation lets us state a more general theorem, which says, roughly,18that no nontrivial property of computable functions is decidable.1920Keep in mind that $\cfind{0}$, $\cfind{1}$, $\cfind{2}$,~\dots is our21standard enumeration of the partial computable functions.2223\begin{thm}[Rice's Theorem]24 Let $C$ be any set of partial computable functions, and let $A =25 \Setabs{n}{\cfind{n} \in C}$. If $A$ is computable, then either $C$26 is empty or $C$ is the set of all the partial computable27 functions.28\end{thm}2930An {\em index set} is a set $A$ with the property that if $n$ and $m$31are indices which ``compute'' the same function, then either both $n$32and $m$ are in $A$, or neither is. It is not hard to see that the33set~$A$ in the theorem has this property. Conversely, if $A$~is an34index set and $C$~is the set of functions computed by these indices,35then $A = \Setabs{n}{\cfind{n} \in C}$.3637\begin{explain}38With this terminology, Rice's theorem is equivalent to saying that no39nontrivial index set is decidable. To understand what the theorem40says, it is helpful to emphasize the distinction between41\emph{programs} (say, in your favorite programming language) and the42functions they compute. There are certainly questions about programs43(indices), which are syntactic objects, that are computable: does this44program have more than 150 symbols? Does it have more than 22 lines?45Does it have a ``while'' statement? Does the string ``hello world''46ever appear as the argument to a ``print'' statement? Rice's theorem47says that no nontrivial question about the program's \emph{behavior}48is computable. This includes questions like these: does the program49halt on input $0$? Does it ever halt? Does it ever output an even50number?51\end{explain}5253\begin{proof}[Proof of Rice's theorem]54Suppose $C$ is neither empty nor the set of all the partial55computable functions, and let $A$ be the set of indices of functions56in~$C$. We will show that if $A$ were computable, we could solve the57halting problem; so $A$~is not computable.5859Without loss of generality, we can assume that the function $f$ which60is nowhere defined is not in $C$ (otherwise, switch $C$ and its61complement in the argument below). Let $g$ be any function in~$C$. The62idea is that if we could decide~$A$, we could tell the difference63between indices computing~$f$, and indices computing~$g$; and then we64could use that capability to solve the halting problem.6566Here's how. Using the universal partial computable functions, we can67define a function68\[69h(x,y) \simeq70\begin{cases}71\text{undefined} & \text{if $\cfind{x}(x) \fundefined$} \\72g(y) & \text{otherwise.}73\end{cases}74\]75To compute $h$, first we try to compute $\cfind{x}(x)$; if that76computation halts, we go on to compute~$g(y)$; and if {\em that}77computation halts, we return the output. More formally, we can write78\[79h(x,y) \simeq \Proj{2}{0}(g(y),\fn{Un}(x,x)).80\]81where $\Proj{2}{0}(z_0, z_1) = z_0$ is the $2$-place projection82function returning the $0$-th argument, which is computable.8384Then $h$ is a composition of partial computable functions, and the right85side is defined and equal to~$g(y)$ just when $\fn{Un}(x,x)$ and86$g(y)$ are both defined.8788Notice that for a fixed~$x$, if $\cfind{x}(x)$ is undefined, then89$h(x,y)$ is undefined for every~$y$; and if $\cfind{x}(x)$ is defined,90then $h(x,y) \simeq g(y)$. So, for any fixed value of~$x$, either91$h(x,y)$ acts just like $f$ or it acts just like $g$, and deciding92whether or not $\cfind{x}(x)$ is defined amounts to deciding which of93these two cases holds. But this amounts to deciding whether or not94$h_x(y) \simeq h(x,y)$ is in~$C$ or not, and if $A$ were computable,95we could do just that.9697More formally, since $h$~is partial computable, it is equal to the98function $\cfind{e}$ for some index~$e$. By the $s$-$m$-$n$ theorem99there is a primitive recursive function~$s$ such that for each~$x$,100$\cfind{s(e,x)}(y) = h_x(y)$. Now we have that for each $x$, if101$\cfind{x}(x) \fdefined$, then $\cfind{s(e,x)}$ is the same function102as~$g$, and so $s(e,x)$ is in $A$. On the other hand, if $\cfind{x}(x)103\uparrow$, then $\cfind{s(e,x)}$ is the same function as~$f$, and so104$s(e,x)$ is not in~$A$. In other words, we have that for every~$x$, $x105\in K$ if and only if $s(e,x) \in A$. If $A$ were computable,106$K$~would be also, which is a contradiction. So $A$ is not computable.107\end{proof}108109Rice's theorem is very powerful. The following immediate corollary110shows some sample applications.111\begin{cor}112The following sets are undecidable.113\begin{enumerate}114\item $\Setabs{x}{\text{$17$ is in the range of $\cfind{x}$}}$115\item $\Setabs{x}{\text{$\cfind{x}$ is constant}}$116\item $\Setabs{x}{\text{$\cfind{x}$ is total}}$117\item $\Setabs{x}{\text{whenever $y < y'$, $\cfind{x}(y) \fdefined$, and118 if $\cfind{x}(y') \fdefined$, then $\cfind{x}(y) < \cfind{x}(y')$}}$119\end{enumerate}120\end{cor}121122\begin{proof}123 These are all nontrivial index sets.124\end{proof}125126\end{document}127
content/computability/computability-theory/fixed-point-thm.tex
1% Part: computability2% Chapter: computability-theory3% Section: fixed-point-thm45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{fix}10\olsection{The Fixed-Point Theorem}1112Let's consider the halting problem again. As temporary13notation, let us write $\gn{\cfind{x}(y)}$ for $\tuple{x, y}$; think of14this as representing a ``name'' for the value $\cfind{x}(y)$. With this15notation, we can reword one of our proofs that the halting problem is16undecidable.1718Question: is there a computable function $h$, with the19following property? For every $x$ and $y$,20\[21h(\gn{\cfind{x}(y)}) =22\begin{cases}231 & \text{if $\cfind{x}(y) \fdefined$} \\240 & \text{otherwise.}25\end{cases}26\]2728Answer: No; otherwise, the partial function29\[30g(x) \simeq31\begin{cases}320 & \text{if $h(\gn{\cfind{x}(x)}) = 0$} \\33\text{undefined} & \text{otherwise}34\end{cases}35\]36would be computable, and so have some index~$e$. But then we have37\[38\cfind{e}(e) \simeq39\begin{cases}400 & \text{if $h(\gn{\cfind{e}(e)}) = 0$} \\41\text{undefined} & \text{otherwise,}42\end{cases}43\]44in which case $\cfind{e}(e)$ is defined if and only if it isn't, a45contradiction.4647Now, take a look at the equation with $\cfind{e}$. There is an instance of48self-reference there, in a sense: we have arranged for the value of49$\cfind{e}(e)$ to depend on $\gn{\cfind{e}(e)}$, in a certain way. The50fixed-point theorem says that we {\em can} do this, in general---not51just for the sake of proving contradictions.5253\olref{lem:fixed-equiv} gives two equivalent ways of stating the54fixed-point theorem. Logically speaking, the fact that the statements55are equivalent follows from the fact that they are both true; but what56we really mean is that each one follows straightforwardly from the57other, so that they can be taken as alternative statements of the same58theorem.5960\begin{lem}61\ollabel{lem:fixed-equiv}62The following statements are equivalent:63\begin{enumerate}64\item For every partial computable function $g(x,y)$, there is an65 index~$e$ such that for every~$y$,66\[67\cfind{e}(y) \simeq g(e,y).68\]69\item For every computable function~$f(x)$, there is an index~$e$ such70 that for every~$y$,71\[72\cfind{e}(y) \simeq \cfind{f(e)}(y).73\]74\end{enumerate}75\end{lem}7677\begin{proof}78$(1) \Rightarrow (2)$: Given $f$, define $g$ by $g(x,y) \simeq79\fn{Un}(f(x),y)$. Use (1) to get an index~$e$ such that for every~$y$,80\begin{align*}81\cfind{e}(y) & = \fn{Un}(f(e),y) \\82& = \cfind{f(e)}(y).83\end{align*}8485$(2) \Rightarrow (1)$: Given $g$, use the $s$-$m$-$n$ theorem to get $f$ such86that for every $x$ and~$y$, $\cfind{f(x)}(y) \simeq g(x,y)$. Use (2) to87get an index~$e$ such that88\begin{align*}89\cfind{e}(y) & = \cfind{f(e)}(y) \\90& = g(e,y).91\end{align*}92This concludes the proof.93\end{proof}9495\begin{explain}96Before showing that statement (1) is true (and hence (2) as well),97consider how bizarre it is. Think of $e$ as being a computer program;98statement (1) says that given any partial computable $g(x,y)$, you can99find a computer program $e$ that computes $g_e(y) \simeq g(e,y)$. In100other words, you can find a computer program that computes a function101that references the program itself.102\end{explain}103104\begin{thm}105The two statements in \olref{lem:fixed-equiv} are106true. Specifically, for every partial computable function $g(x,y)$,107there is an index~$e$ such that for every~$y$,108\[109\cfind{e}(y) \simeq g(e,y).110\]111\end{thm}112113\begin{proof}114The ingredients are already implicit in the discussion of the halting115problem above. Let $\fn{diag}(x)$ be a computable function which for each116$x$ returns an index for the function $f_x(y) \simeq \cfind{x}(x,y)$,117i.e.118\[119\cfind{\fn{diag}(x)}(y) \simeq \cfind{x}(x,y).120\]121Think of $\fn{diag}$ as a function that transforms a program for a 2-ary122function into a program for a 1-ary function, obtained by fixing the123original program as its first argument. The function $\fn{diag}$ can be124defined formally as follows: first define $s$ by125\[126s(x,y) \simeq \fn{Un}^2(x,x,y),127\]128where $\fn{Un}^2$ is a 3-ary function that is universal for partial computable1292-ary functions. Then, by the $s$-$m$-$n$ theorem, we can find a primitive130recursive function $\fn{diag}$ satisfying131\[132\cfind{\fn{diag}(x)}(y) \simeq s(x,y).133\]134135Now, define the function $l$ by136\[137l(x,y) \simeq g(\fn{diag}(x),y).138\]139and let $\gn{l}$ be an index for $l$. Finally, let $e = \fn{diag}(\gn{l})$.140Then for every $y$, we have141\begin{align*}142\cfind{e}(y) & \simeq \cfind{\fn{diag}(\gn{l})}(y) \\143& \simeq \cfind{\gn{l}}(\gn{l}, y) \\144& \simeq l(\gn{l}, y) \\145& \simeq g(\fn{diag}(\gn{l}),y) \\146& \simeq g(e, y),147\end{align*}148as required.149\end{proof}150151\begin{explain}152What's going on? Suppose you are given the task of writing a computer153program that prints itself out. Suppose further, however, that you are154working with a programming language with a rich and bizarre library of155string functions. In particular, suppose your programming language has156a function $\fn{diag}$ which works as follows: given an input157string~$s$, $\fn{diag}$ locates each instance of the symbol `x'158occurring in~$s$, and replaces it by a quoted version of the original159string. For example, given the string160\begin{quote}161\begin{verbatim}162hello x world163\end{verbatim}164\end{quote}165as input, the function returns166\begin{quote}167\begin{verbatim}168hello 'hello x world' world169\end{verbatim}170\end{quote}171as output. In that case, it is easy to write the desired program; you172can check that173\begin{quote}174\begin{verbatim}175print(diag('print(diag(x))'))176\end{verbatim}177\end{quote}178does the trick. For more common programming languages like C++ and179Java, the same idea (with a more involved implementation) still works.180181We are only a couple of steps away from the proof of the fixed-point182theorem. Suppose a variant of the print function $\fn{print}(x,y)$183accepts a string $x$ and another numeric argument $y$, and prints the184string $x$ repeatedly, $y$ times. Then the ``program''185\begin{quote}186\begin{verbatim}187getinput(y);188print(diag('getinput(y); print(diag(x), y)'), y)189\end{verbatim}190\end{quote}191prints itself out $y$ times, on input $y$. Replacing the192$\fn{getinput}$---$\fn{print}$---$\fn{diag}$ skeleton by an193arbitrary function $g(x,y)$ yields194\begin{quote}195\begin{verbatim}196g(diag('g(diag(x), y)'), y)197\end{verbatim}198\end{quote}199which is a program that, on input $y$, runs $g$ on the program itself200and $y$. Thinking of ``quoting'' with ``using an index for,'' we have201the proof above.202203For now, it is o.k.\ if you want to think of the proof as formal204trickery, or black magic. But you should be able to reconstruct the205details of the argument given above. When we prove the incompleteness206theorems (and the related ``fixed-point theorem'') we will discuss207other ways of understanding why it works.208\end{explain}209210\begin{tagblock}{lambda}211\begin{digress}212The same idea can be used to get a ``fixed point'' combinator. Suppose213you have a lambda term $g$, and you want another term $k$ with the214property that $k$ is $\beta$-equivalent to $gk$. Define terms215\[216\fn{diag}(x) = xx217\]218and219\[220l(x) = g(\fn{diag}(x))221\]222using our notational conventions; in other words, $l$ is the term223$\lambd[x][g(xx)]$. Let $k$ be the term $ll$. Then we have224\begin{align*}225k & = (\lambd[x][g(xx)])(\lambd[x][g(xx)]) \\226& \red g((\lambd[x][g(xx)])(\lambd[x][g(xx)])) \\227& = gk.228\end{align*}229If one takes230\[231Y = \lambd[g][((\lambd[x][g(xx)])(\lambd[x][g(xx)]))]232\]233then $Yg$ and $g(Yg)$ reduce to a common term; so $Yg \equiv_\beta234g(Yg)$. This is known as ``Curry's combinator.'' If instead one takes235\[236Y = (\lambd[xg][g(xxg)])(\lambd[xg][g(xxg)])237\]238then in fact $Yg$ reduces to $g(Yg)$, which is a stronger statement.239This latter version of $Y$ is known as ``Turing's combinator.''240\end{digress}241\end{tagblock}242243\end{document}
content/computability/computability-theory/application-fixed-point.tex
1% Part: computability2% Chapter: computability-theory3% Section: applications-fixed-point45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{apf}10\olsection{Applying the Fixed-Point Theorem}1112The fixed-point theorem essentially lets us define partial computable13functions in terms of their indices. For example, we can find an14index $e$ such that for every $y$,15\[16\cfind{e}(y) = e + y.17\]18As another example, one can use the proof of the fixed-point theorem19to design a program in Java or C++ that prints itself out.2021Remember that if for each $e$, we let $W_e$ be the domain of $\cfind{e}$,22then the sequence $W_0$, $W_1$, $W_2$,~\dots enumerates the computably23enumerable sets. Some of these sets are computable. One can ask if24there is an algorithm which takes as input a value $x$, and, if $W_x$25happens to be computable, returns an index for its characteristic26function. The answer is ``no,'' there is no such algorithm:2728\begin{thm}29There is no partial computable function $f$ with the following30property: whenever $W_e$ is computable, then $f(e)$ is defined and31$\cfind{f(e)}$ is its characteristic function.32\end{thm}3334\begin{proof}35Let $f$ be any computable function; we will construct an $e$36such that $W_e$ is computable, but $\cfind{f(e)}$ is not its37characteristic function. Using the fixed point theorem, we can find an38index $e$ such that39\[40\cfind{e}(y) \simeq41\begin{cases}420 & \text{if $y=0$ and $\cfind{f(e)}(0) \fdefined = 0$} \\43\text{undefined} & \text{otherwise.}44\end{cases}45\]46That is, $e$ is obtained by applying the fixed-point theorem to the47function defined by48\[49g(x,y) \simeq50\begin{cases}510 & \text{if $y=0$ and $\cfind{f(x)}(0) \fdefined = 0$} \\52\text{undefined} & \text{otherwise.}53\end{cases}54\]55Informally, we can see that $g$ is partial computable, as follows: on56input $x$ and $y$, the algorithm first checks to see if $y$ is equal57to~$0$. If it is, the algorithm computes $f(x)$, and then uses the58universal machine to compute $\cfind{f(x)}(0)$. If this last computation59halts and returns~$0$, the algorithm returns~$0$; otherwise, the60algorithm doesn't halt.6162But now notice that if $\cfind{f(e)}(0)$ is defined and equal to $0$,63then $\cfind{e}(y)$ is defined exactly when $y$ is equal to $0$, so $W_e =64\{ 0 \}$. If $\cfind{f(e)}(0)$ is not defined, or is defined but not65equal to $0$, then $W_e = \emptyset$. Either way, $\cfind{f(e)}$ is not66the characteristic function of~$W_e$, since it gives the wrong answer67on input $0$.68\end{proof}6970\end{document}
content/computability/computability-theory/def-functions-self-reference.tex
1% Part: computability2% Chapter: computability-theory3% Section: def-functions-self-reference45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{cmp}{thy}{slf}10\olsection{Defining Functions using Self-Reference}1112It is generally useful to be able to define functions in terms of13themselves. For example, given computable functions $k$, $l$, and~$m$,14the fixed-point lemma tells us that there is a partial computable15function~$f$ satisfying the following equation for every~$y$:16\[17f(y) \simeq18\begin{cases}19k(y) & \text{if $l(y) = 0$} \\20f(m(y)) & \text{otherwise.}21\end{cases}22\]23Again, more specifically, $f$~is obtained by letting24\[25g(x,y) \simeq26\begin{cases}27k(y) & \text{if $l(y) = 0$} \\28\cfind{x}(m(y)) & \text{otherwise}29\end{cases}30\]31and then using the fixed-point lemma to find an index~$e$ such that32$\cfind{e}(y) = g(e,y)$.3334For a concrete example, the ``greatest common divisor'' function35$\fn{gcd}(u,v)$ can be defined by36\[37\fn{gcd}(u,v) \simeq38\begin{cases}39v & \text{if $u = 0$} \\40\fn{gcd}(\fn{mod}(v, u), u) & \text{otherwise}41\end{cases}42\]43where $\fn{mod}(v, u)$ denotes the remainder of dividing $v$44by~$u$. An appeal to the fixed-point lemma shows that $\fn{gcd}$ is45partial computable. (In fact, this can be put in the format above,46letting $y$ code the pair $\tuple{u, v}$.) A subsequent induction47on~$u$ then shows that, in fact, $\fn{gcd}$ is total.4849Of course, one can cook up self-referential definitions that are much50fancier than the examples just discussed. Most programming languages51support definitions of functions in terms of themselves, one way or52another. Note that this is a little bit less dramatic than being able53to define a function in terms of an \emph{index} for an algorithm54computing the functions, which is what, in full generality, the55fixed-point theorem lets you do.5657\end{document}