├── Chap5_Solution ├── Chap5.pdf └── Chap5.tex ├── README.md └── .gitignore /Chap5_Solution/Chap5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sleepycoke/NJU_Com_Models/HEAD/Chap5_Solution/Chap5.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 仅限于学习交流,禁止用于商业用途。由于作者水平有限,错误在所难免,恳请指正。 2 | 3 | 传播此文档时请遵守 https://creativecommons.org/licenses/by-nc-sa/4.0/ 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | Chap5_Solution/.DS_Store 4 | Chap5_Solution/.texpadtmp/Chap5.aux 5 | Chap5_Solution/.texpadtmp/Chap5.log 6 | Chap5_Solution/.texpadtmp/Chap5.out 7 | Chap5_Solution/.texpadtmp/Chap5.synctex.gz 8 | -------------------------------------------------------------------------------- /Chap5_Solution/Chap5.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage{ctex} 3 | \usepackage{fontspec, xunicode, xltxtra} 4 | \usepackage{amssymb} 5 | \usepackage{amsmath} 6 | \usepackage{amsfonts} 7 | \usepackage{mathrsfs} 8 | \usepackage{enumerate} 9 | \usepackage{amsthm} 10 | \usepackage{mathtools} 11 | \usepackage{hyperref} 12 | \usepackage[a4paper,top=30mm,bottom=30mm,left=30mm,right=30mm]{geometry} 13 | 14 | \newcommand{\vv}[0]{\vdash\dashv} 15 | \renewcommand{\today}{\number\year 年 \number\month 月 \number\day 日} 16 | \newcommand*{\pt}[1]{\ensuremath{\underset{\uparrow}{#1}}} 17 | \newcommand{\RA}[0]{{\shortmid\!\Rightarrow}} 18 | \newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor} 19 | \newcommand{\ceil}[1]{\left\lceil #1 \right\rceil} 20 | \def\dotminus{\mathbin{\ooalign{\hss\raise1ex\hbox{.}\hss\cr 21 | \mathsurround=0pt$-$}}} 22 | \setlength\parindent{0pt} 23 | \vspace{-8ex} 24 | %\date{} 25 | \begin{document} 26 | 27 | \title{《计算模型导引》第五章参考答案\footnote{Ver. 0.3. 原答案由宋方敏教授给出手稿, 然后由丁超录入修订补充. 此文档来源为\url{https://github.com/sleepycoke/NJU_Com_Models}}} 28 | \maketitle 29 | 30 | \section*{习题5.1} 31 | 主要思想是先后抹除$\overline x$最后移到$\overline y$的头. 32 | 机器如下: 33 | \begin{center} 34 | 35 | \begin{tabular}{|c|c|c|c|} 36 | \hline 37 | &0&1&解释\\ 38 | \hline 39 | 1&0R2&0R1&抹除第一个$\overline x$并指向$\overline y$头\\ 40 | 2&0R3&1R2&移动到第二个$\overline x$头\\ 41 | 3&0L4&0R3&抹除第二个$\overline x$\\ 42 | 4&0L4&1L5&越过$\overline y$的最后一个1\\ 43 | 5&0R6&1L5&移到$\overline y$头\\ 44 | \hline 45 | \end{tabular} 46 | \end{center} 47 | 48 | 49 | \section*{习题5.2} 50 | 主要思想是每次抹掉输入的一个1对应两个输出各增加一个1. 51 | 即设计机器$M$实现如下功能:\\ 52 | \begin{align*} 53 | M &| 1 : 0\cdots0\pt101^k01^k0\cdots \twoheadrightarrow u : 0\cdots0\pt1^{k+1}01^{k+1}0\cdots\\ 54 | M &| 1 : 0\cdots0\pt1^{l+1}01^k01^k0\cdots \twoheadrightarrow v : 0\cdots0\pt1^l01^{k+1}01^{k+1}0\cdots\\ 55 | \end{align*} 56 | 这里$k\ge 0$, $u$为停机状态. 这样$M[v:=1]$既可实现循环. 57 | 58 | 具体实现如下: 59 | \begin{center} 60 | \begin{tabular}{|c|c|c|c|} 61 | \hline 62 | &0&1&解释\\ 63 | \hline 64 | 1&&0R2&输入移除 1\\ 65 | 2&0R3&1R12&判断输入是否还有1,移到尾部再跳过后面的0\\ 66 | 3&1R4&1R3&输入为0, 那么走第一个分支3-8.将第一个$1^k$后的0改为1\\ 67 | 4&&0R5&将第二个$1^k$的第一个1改为0\\ 68 | 5&1R6&1R5&将第二个$1^k$后的0改为1\\ 69 | 6&1L7&&再添个1\\ 70 | 7&0L8&1L7&跳过$1^{k+1}$\\ 71 | 8&0R9&1L8&移到输入头, 停机\\ 72 | 12&0R13&1R12&输入不为0, 那么走第二个分支12-19.跳过第一个输入\\ 73 | 13&1R14&1R13&将第一个$1^k$后的0改为1\\ 74 | 14&&0R15&将第二个$1^k$的第一个1改为0\\ 75 | 15&1R16&1R15&将第二个$1^k$后的0改为1\\ 76 | 16&1L17&&再添个1\\ 77 | 17&0L18&1L17&跳过$1^{k+1}$\\ 78 | 18&0R19&1L18&再跳过$1^{k+1}$\\ 79 | 19&0R1&1L19&再移到输入头,循环\\ 80 | \hline 81 | \end{tabular} 82 | \end{center} 83 | 84 | \section*{习题5.3} 85 | 大家可能在某些参考资料上看到了如下的乘法图灵机$M_1$,但它并不适用于我们对输入的定义. 实际上, $M_1$接收的输入为$01^x01^y0\cdots$而不是我们定义的$01^{x+1}01^{y+1}\cdots$. 86 | \begin{center} 87 | \begin{tabular}{|c|c|c|c|} 88 | \hline 89 | &0&1&解释\\ 90 | \hline 91 | 1&0R10&0R2&判断$x$是否为0,不为0抹除一个1进入2-8作一次累加\\ 92 | 2&0R3&1R2&移到第一串1的尾部\\ 93 | 3&0L8&0R4&3-7作一次累加,作过$y$次后转到8. 进入4之前抹掉1留作标记给7找回用\\ 94 | 4&0R5&1R4&找到本串1的尾部\\ 95 | 5&1L6&1R5&找到$1^j$的尾部,+1\\ 96 | 6&0L7&1L6&找到$1^{j+1}$的头\\ 97 | 7&1R3&1L7&找到$1^{i}$的头,补回一个1\\ 98 | 8&0L9&1L8&一次累加结束\\ 99 | 9&0R1&1L9&找到第一串1的头\\ 100 | 10&0R11&0R10&抹除第一串1\\ 101 | \hline 102 | \end{tabular} 103 | \end{center} 104 | 我们可以先证明 105 | $$M_1 | 1 : 0\cdots0\pt1^x01^y0\cdots \twoheadrightarrow u : 0\cdots0\pt1^{x*y}0\cdots\\$$ 106 | 而理解$M1$和关键在于理解3-7状态完成了以下操作: 107 | $$M_1 | 3 : 0\cdots0\pt11^i01^j\cdots \twoheadrightarrow 3 : 1\pt1^i01^{j+1}0\cdots\\$$ 108 | 从而$M1$和通过3-8状态完成了以下操作: 109 | $$M_1 | 3 : \pt1^i01^j\cdots \twoheadrightarrow 8 : \pt1^i01^{j+i}0\cdots\\$$ 110 | 即实现了一次累加. 111 | 这样总体上每抹除第一个输入的一个1就,对应一次加法,整体实现了乘法. 112 | 113 | 114 | 最后为了符合我们的输入输出规范,实现机器$M_2$,$M_3$分别实现: 115 | $$M_2 | 1 : 0\pt1^{x+1}01^{y+1}0\cdots \twoheadrightarrow u : 00\pt1^x01^y0\cdots$$ 116 | $$M_3 | 1 : 0\pt1^{x}00\cdots \twoheadrightarrow v : 0\pt1^{x+1}0\cdots$$ 117 | 118 | 这两个机器很容易实现不赘述. 119 | 120 | 从而且乘法机器为 121 | $$M_2\RA M_1\RA M_3$$ 122 | 123 | \section*{习题5.4} 124 | 参照第133页定理5.14,我们需要作一个预处理,添上一个输入$\overline 1$. 具体可以由如下机器$M_3$实现: 125 | \begin{center} 126 | \begin{tabular}{|c|c|c|} 127 | \hline 128 | &0&1\\ 129 | \hline 130 | 1&0R2&1R1\\ 131 | 2&&1R3\\ 132 | 3&1L4&\\ 133 | 4&&1L5\\ 134 | 5&0L6&\\ 135 | 6&0R7&1L6 136 | \\ 137 | \hline 138 | \end{tabular} 139 | \end{center} 140 | 141 | 如书中第134页构造机器$M_1$: 142 | 143 | \begin{center} 144 | \begin{tabular}{|c|c|c|} 145 | \hline 146 | &0&1\\ 147 | \hline 148 | 1&&0R2\\ 149 | 2&0R$4$&1R3\\ 150 | 3&0R4&1R3\\ 151 | 152 | 153 | \hline 154 | \end{tabular} 155 | \end{center} 156 | 157 | 令$M_2$为$M_1 \RA \fbox{double} \RA \fbox{compress} \RA \fbox{shiftl}$,从而\\ 158 | 若$x=0$, 则$M_2|1:0\pt{\overline x} 0 \overline y 0 \cdots \twoheadrightarrow v : 000\pt{\overline y} 0 \cdots$\\ 159 | 若$x>0$, 则$M_2|1:0\pt{\overline x} 0 \overline y 0 \cdots \twoheadrightarrow w : 00{ \overline{\pt x-1}} 0 \overline{g(y)} 0\cdots$, 其中$w$为$M_2$的输出时的状态. \\ 160 | 161 | 令$\fbox{f} = M_2[w:=1]$, $M_3\RA\fbox{f}$即为所求. 162 | 163 | 164 | \section*{习题5.5} 165 | 166 | \begin{itemize} 167 | \item 若$x=0$: 168 | \begin{align*} 169 | 1&:0\pt10000\cdots\tag{1R2}\\ 170 | 2&:01\pt0000\cdots\tag{0L3}\\ 171 | 3&:0\pt10000\cdots\tag{1L3}\\ 172 | 3&:\pt010000\cdots\tag{0L3}\\ 173 | 3&:\pt{\phantom0}010000\cdots\tag{halt}\\ 174 | \end{align*} 175 | \item 若$x>0$: 176 | \begin{align*} 177 | 1&:0\pt11^x0000\cdots\tag{1R2}\\ 178 | 2&:01\pt1^x0000\cdots\tag{0R1}\\ 179 | 1&:010\pt1^{x-1}0000\cdots\tag{1R2}\\ 180 | 2&:0101\pt1^{x-2}0000\cdots\tag{0R1}\\ 181 | &\cdots \tag{1R2, 0R1}\\ 182 | 3&:\overbrace{0101\cdots0\pt1}^{\floor{x/2}+1\text{个01}}0000\cdots\tag{1L3}\\ 183 | &\cdots\tag{0L3, 1L3}\\ 184 | 3&:\overbrace{\pt0101\cdots01}^{\floor{x/2}+1\text{个01}}\cdots010000\cdots\tag{0L3}\\ 185 | 3&:\pt{\phantom0}\overbrace{0101\cdots01}^{\floor{x/2}+1\text{个01}}\cdots010000\cdots\tag{halt}\\ 186 | \end{align*} 187 | \end{itemize} 188 | 总之就是擦除了第偶数个1,然后指向第一个0左边(越界). 189 | \section*{习题5.6} 190 | 易见 191 | $M_2|1:0\pt{\overline x} 0 \overline y 0 \cdots \twoheadrightarrow 1 : 000\pt{\overline y} 0 \cdots$\\ 192 | 从而 193 | $M_2|1:0\pt1^n01^m01^k 0 \overline y 0 \cdots \twoheadrightarrow 1 : 0^{n+m+k+3}\pt0 0 \cdots$(停)\\ 194 | 又易见 195 | $M_2|1:\pt0 0 0 \cdots \twoheadrightarrow 7 : 0\pt1111 0 \cdots$\\ 196 | 于是$M_2|1:0\pt1^n01^m01^k 0 \overline y 0 \cdots \twoheadrightarrow 197 | 7 : 0^{m+n+k+4}\pt1111 0 \cdots$(停) 198 | 199 | \section*{习题5.7} 200 | 201 | 由于$$y=\floor{\sqrt{x}}\Leftrightarrow y \le \sqrt x < y + 1 \Leftrightarrow y^2 \le x < (y+1)^2$$ 202 | 所以 203 | $$f(x) = \mu y. x < (y+1)^2 = \mu y. N^2((sx)\dotminus(sy)^2)$$ 204 | 205 | 首先平方机器$\fbox{sqrt}$可由$\fbox{copy1}\RA\fbox{shiftl}\RA\fbox{multi}$构造,其中$\fbox{multi}$为习题5.3的乘法机器. 然后减法机器也在习题5.11中给出,于是$f$涉及到的机器都已经构造出, 那么$\fbox{f}$是可构造的. 具体构造过程可对照教材实现. 206 | 207 | \section*{习题5.10} 208 | 参照第133页定理5.14,我们需要作一个预处理,添上一个输入$\overline 0$. 具体可以由如下机器$M_3$实现: 209 | \begin{center} 210 | \begin{tabular}{|c|c|c|} 211 | \hline 212 | &0&1\\ 213 | \hline 214 | 1&0R2&1R1\\ 215 | 2&1L3&\\ 216 | 3&0L4&\\ 217 | 4&0R5&1L4 218 | \\ 219 | \hline 220 | \end{tabular} 221 | \end{center} 222 | 接下来再如法构造$\fbox{f}$既可.最后结果为$M_3\RA\fbox f$. 223 | \section*{习题5.11} 224 | 注意到$0\dotminus y = 0,\quad x \dotminus 0 = x, \quad (x+1)\dotminus(y+1) = x \dotminus y$, 我们可以分情况处理. 225 | 机器如下: 226 | \begin{center} 227 | \begin{tabular}{|c|c|c|c|} 228 | \hline 229 | &0&1&解释\\ 230 | \hline 231 | 1&&0R2&将$x$减1\\ 232 | 2&0R3&1R4&判断原$x$是否为0\\ 233 | 3&1O15&0R3&原$x$为0那么把$\overline y$修改为1输出\\ 234 | 4&0R11&1R4&原$x$不为0找到$\overline y$的头\\ 235 | 5&0L6&1R5&找到$\overline y$的尾部\\ 236 | 6&&0L7&将$y$减1\\ 237 | 7&0L10&1L7&找到$\overline x$的尾\\ 238 | 10&0R1&1L10&找到$\overline x$的头,迭代\\ 239 | 11&&1R12&跳过$\overline y$的第一个1\\ 240 | 12&0L13&1R5&判断$y$是否为0\\ 241 | 13&&0L16&原$y$为0,抹掉$\overline y$\\ 242 | 14&0R15&1L14&原$y$为0,找到$\overline x$的头,输出$x$\\ 243 | 15&&&停机\\ 244 | 16&0L14&&前左跳过一个0\\ 245 | \hline 246 | \end{tabular} 247 | \end{center} 248 | 计算过程如下: 249 | \begin{itemize} 250 | \item 若$x=0$: 251 | \begin{align*} 252 | 1&:0\pt10\overline y 000\cdots\tag{0R2}\\ 253 | 2&:00\pt0\overline y 000\cdots\tag{0R3}\\ 254 | 3&:000\pt{\overline y}0000\cdots\tag{0R3}\\ 255 | 3&:0000{\overline {\pt y - 1}}0000\cdots\tag{0R3}\\ 256 | &\cdots\tag{0R3}\\ 257 | 3&:000\cdots\pt00000\cdots\tag{1O15}\\ 258 | 15&:000\cdots\pt10000\cdots\tag{halt} 259 | \end{align*} 260 | \item 若$x>0,\quad y=0$: 261 | \begin{align*} 262 | 1&:0\pt11^x01 000\cdots\tag{0R2}\\ 263 | 2&:00\pt1^x01000\cdots\tag{1R4}\\ 264 | &\cdots\tag{1R4}\\ 265 | 4&:001^{x}\pt01 000\cdots\tag{0R11}\\ 266 | 11&:001^{x}0\pt1 000\cdots\tag{1R12}\\ 267 | 12&:001^{x}01 \pt000\cdots\tag{0L13}\\ 268 | 13&:001^{x}0\pt1 000\cdots\tag{0L16}\\ 269 | 16&:001^{x}\pt00 000\cdots\tag{0L14}\\ 270 | 14&:001^{x-1}\pt10 000\cdots\tag{1L14}\\ 271 | &\cdots\tag{1L14}\\ 272 | 14&:0\pt01^x0 000\cdots\tag{0R15}\\ 273 | 15&:00\pt1^x0 000\cdots\tag{halt}\\ 274 | \end{align*} 275 | \item 若$x>0,\quad y > 0$: 276 | \begin{align*} 277 | 1&:0\pt11^x0\overline y 000\cdots\tag{0R2}\\ 278 | 2&:00\pt1^x0\overline y 000\cdots\tag{1R4}\\ 279 | &\cdots\tag{1R4}\\ 280 | 4&:001^{x}\pt0\overline { y} 000\cdots\tag{0R11}\\ 281 | 11&:001^{x}0\overline { \pt y} 000\cdots\tag{1R12}\\ 282 | 12&:001^{x}01\overline { \pt y-1} 000\cdots\tag{1R5}\\ 283 | &\cdots\tag{1R5}\\ 284 | 5&:001^{x}0\overline {y} \pt000\cdots\tag{0L6}\\ 285 | 6&:001^x01^{y}\pt1 000\cdots\tag{0L7}\\ 286 | 7&:001^x01^{y-1}\pt1 000\cdots\tag{1L7}\\ 287 | &\cdots\tag{1L7}\\ 288 | 7&:001^x\pt0\overline { y} 000\cdots\tag{0L10}\\ 289 | 10&:001^{x-1}\pt101^{y} 000\cdots\tag{1L10}\\ 290 | &\cdots\tag{1L10}\\ 291 | 10&:0\pt01^x01^{y} 000\cdots\tag{0R1}\\ 292 | 1&:00\pt1^x01^{y} 000\cdots\tag{Compute $(x-1)\dotminus(y-1)$ }\\ 293 | \end{align*} 294 | \end{itemize} 295 | \section*{习题5.12} 296 | 欲证$Even$ Turing-可计算,只需构造机器$E$满足: 297 | \begin{align*} 298 | E|&1:0\pt1^{2x+1}0\cdots \twoheadrightarrow u : 0\cdots0\pt10\cdots\\ 299 | E|&1:0\pt1^{2x}0\cdots \twoheadrightarrow u : 0\cdots0\pt110\cdots\\ 300 | \end{align*} 301 | 其中$E(1,u)$无定义. 302 | $E$可如下构造: 303 | \begin{center} 304 | \begin{tabular}{|c|c|c|} 305 | \hline 306 | &0&1\\ 307 | \hline 308 | 1&1L3&0R2\\ 309 | 2&1O4&0R4\\ 310 | 3&1O3&\\ 311 | \hline 312 | \end{tabular} 313 | \end{center} 314 | $E(1,1)$的$E(1,2)$形成循环将成对的1改为0. 若有奇数个1,最后会执行$M(0,2)$停机,输出$\overline 0$.若有偶数个1,最后会执行$M(0,1),M(0,3)$停机, 输出$\overline 1$. 315 | \section*{习题5.17} 316 | 首先0,1显然都不是一个合法的机器编码, 假定输入至少为2. 317 | 318 | 此题的关键在于给定机器$M$的编码$\#M$如何确定其行数. 319 | 解法为: 320 | 321 | 设$M$有$k+1$行,那么显然有$k < \#M$. 322 | 从而设$k = \max z \le \#M, [p_z | \#M]$, 323 | 324 | 一但$k$确定, 那么对于各行的解码过程都是可计算的. 一旦出现不合法的行则解码失败, 全部成功解码则说明输入是一个合法的机器编码, 属于$S$. 325 | 326 | 反过来由于编码和解码是一对逆过程,那么解码失败的输入一定不属于$S$. 327 | 328 | 如果我们承认CT,那么我们已经给出了一个能行的方法判定$S$, 从而$S$是Turing-可计算的. 329 | 330 | 若持有更保守的观点, 那可以通过证明$S$为递归集来证明其Turing-可计算. 过程繁杂从略. 331 | 332 | \section*{习题5.18} 333 | 334 | 335 | 由Taylor公式 336 | $$e=\sum_{i=0}^n\frac{1}{i!}+\frac{e^\theta}{(n+1)!}, \quad 0<\theta<1$$ 337 | \begin{enumerate}[(1)] 338 | \item 339 | 令$f(n) = \floor{e\cdot n!}$, 我们往证$f \in \mathcal{EF}$:\\ 340 | $f(0)=f(1)=2$, 当$n\ge 2$ 341 | $$f(n)=\floor{\left(\sum_{i=0}^n\frac{1}{i!}\right)n!+\frac{e^\theta}{n+1}} = \floor{\sum_{i=0}^n \binom{n}{i} (n-i)!+\frac{e^\theta}{n+1}}$$ 342 | 注意到当$n\ge 2$时$0< \frac{e^\theta}{n+1} < 1$, 从而 343 | $$f(n) = \sum_{i=0}^n \binom{n}{i} (n-i)!$$ 344 | 于是$f \in \mathcal{EF}$. 345 | \item 346 | 令$h(n)=\floor{e\cdot n}$ 347 | 则$h(0)=0,\quad h(n) = \floor{\frac{e\cdot n!}{(n-1)!}} = \floor{\frac{f(n)}{(n-1)!}}\.(*), n \ge 1$. \\ 348 | 从而$h \in \mathcal{EF}$. \\ 349 | 注: 下面给出(*)的证明: \\ 350 | 设$$e\cdot n! = k_1(n-1)! + r_1$$ 351 | $$f(n) = k_2(n-1)! + r_2$$ 352 | 其中$k_1, k_2 \in \mathbb{N},\quad r_1, r_2 \in [0, (n-1)!)$\\ 353 | 由于$f(n)$为整数, 我们有$r_2 \in [0, (n-1)! - 1]$. 354 | 那么 355 | $$r \triangleq e\cdot n! - f(n) = (k_1 - k_2) (n-1)! + (r_1 - r_2) \in [0, 1)$$ 356 | 又$r_1 - r_2 \in [1-(n-1)!, \.(n-1)!\.)$, 从而$k_1 = k_2$. 357 | \item 358 | $$g(1) = 2$$ 359 | $$g(n) = h(10^n) \dotminus h(10^{n\dotminus 1}) \cdot 10, \quad n > 1$$ 360 | 从而$g \in \mathcal{EF}$, 于是$g$可计算。 361 | 362 | \end{enumerate} 363 | 注意到余项的上界$\frac{e}{(n+1)!}$严格单调递减且收敛速度超过指数函数, 此题也可以设计数值算法来求$e$的前$n$位有效数字, 进而通过CT说明$g$可计算. 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | \end{document} --------------------------------------------------------------------------------