Skip to content

Commit cbd394f

Browse files
committed
50003: Added past papers for sitting 2022 and 2021 and fixed typos
1 parent bebd82d commit cbd394f

15 files changed

+295
-5
lines changed
Binary file not shown.
Binary file not shown.

50003 - Models of Computation/halting_problem/halting_problem.tex

+46
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ \subsection{Uncomputable Functions}
6161

6262
Here we have ended up with the halting problem being uncomputable.
6363

64+
\begin{sidenotebox}{Collatz Conjecture}
65+
A famous example of a simple algorithm not yet determined to terminate on all inputs.
66+
\begin{quote}
67+
\textit{Given some input $n$, how many steps of applying $f$ are required to reach $1$, given:}
68+
\end{quote}
69+
\[f = \begin{cases}
70+
\cfrac{n}{2} & n \text{ is even} \\
71+
3n + 1 & n \text{ is odd} \\
72+
\end{cases}\]
73+
The conjecture states that the sequence from any positive integer $n$ will eventually go to zero. And hence any algorithm generating the sequence will terminate. This remains unproven.
74+
\begin{minted}{haskell}
75+
-- get the sequence for positive integer
76+
-- note we have use Integral (as proven to terminate for all values of fixed size Int)
77+
collatz :: (Integral a) => a -> [a]
78+
collatz 1 = [1]
79+
collatz n
80+
| odd n = n : collatz (n * 3 + 1)
81+
| otherwise = n : collatz (n `div` 2)
82+
83+
limit :: (Integral a) => a -> Int
84+
limit = length . collatz
85+
\end{minted}
86+
\end{sidenotebox}
87+
6488
\subsection{Undecidable Set of Numbers}
6589
Given a set $S \subseteq \mathbb{N}$, its characteristic function is:
6690
\[\chi_S \in \mathbb{N} \to \mathbb{N} \ \ \chi_S(x) \triangleq \begin{cases}
@@ -86,3 +110,25 @@ \subsubsection{The set of total functions is undecidable}
86110
Take set $S_1 \subseteq \mathbb{N}$:
87111
\[S_1 \triangleq \{e | \varphi_e\text{total function}\}\]
88112
If such a register machine exists to compute $\chi_{S_1}$, we can create another register machine, simply checking $0$. Hence as from the previous example, there is no register machine to determine $S_0$, there is none to determine $S_1$.
113+
114+
115+
\begin{exambox}{2biii}{2020/21}
116+
\textit{\dots continued from Q2bii - 2020/21}
117+
\\
118+
\\ Take the machine $M$ in (ii) and use the substitutions to create register machine $K$:
119+
\begin{center}
120+
\begin{tabular}{l p{.8\textwidth}}
121+
$E \triangleq even \ R_0$ & exiting by $\twoheadrightarrow$ if odd, or by $\to$ if even. \\
122+
$H \triangleq R_0 := \sfrac{R_0}{2}$ & exiting by $\twoheadrightarrow$ if odd, or by $\to$ if even. \\
123+
$T \triangleq R_0 := 3 \times R_0 + 1$ & with no $\twoheadrightarrow$ needed. \\
124+
\end{tabular}
125+
\end{center}
126+
Describe what the Register Machine $K$ computing? In particular sketch an execution of $K$ with initially $R_0 = 0, 1, 2, 3, 4$ and $5$.
127+
\end{exambox}
128+
\begin{exambox}{2biv}{2020/21}
129+
\textit{\dots continued from Q2biii - 2020/21}
130+
\\
131+
\\ To the best of our knowledge nobody could yet show that $K$ halts for all
132+
possible initial values of $R_0$. How does this relate to the Halting problem
133+
for RMs?
134+
\end{exambox}

50003 - Models of Computation/introduction/introduction.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ \section{Decision Problems}
8282
Given:
8383
\begin{itemize}
8484
\item A set $S$ of finite data structures of some kind (e.g formulae in first order logic).
85-
\item A property $P$ of elements of $S$ (e.g the porperty of a formula that it has a proof).
85+
\item A property $P$ of elements of $S$ (e.g the property of a formula that it has a proof).
8686
\end{itemize}
8787
The associated decision procedure is:
8888
\\

50003 - Models of Computation/lambda_calculus/lambda_calculus.tex

+28
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,29 @@ \subsection{Pairs}
226226
second(p) &\triangleq \lambapp{p}{\underbrace{(\lambfun{x}{\lambfun{y}{y}})}_\text{second}} \equiv \lambapp{p}{\underbrace{(\lambfun{\lambarg{x}{y}}{y})}_\text{second}}\\
227227
\end{split}\]
228228

229+
\begin{exambox}{2bv}{2020/21}
230+
\textit{\dots continued from 2bvi - 2020/21}
231+
\\
232+
\\ Using Church numerals, give an equivalent $\lambda$-term (program) C, i.e. for all $n > 0$ we have $C \ \underline{n} \to_\beta^* \underline{m} $ if and only if the execution of register machine $K$ also halts with $R_0 = m$ when started with $R_0 = n$.
233+
\\
234+
\\ You can use the pre-defined operations from the lecture ($plus$, $mult$, $succ$,
235+
$pred$, $ifz$, etc.) and also integer division ($div$) and reminder ($rem$). It helps to
236+
use various subroutines.
237+
\end{exambox}
238+
239+
\begin{exambox}{2d}{2021/22}
240+
Consider the following recursively defined sequence of integers $x_i$:
241+
\[\begin{split}
242+
x_0 & = x _ 1 = 1 \\
243+
x_i & = x_{i-2}^2 + 2 x_{i-1} \\
244+
\end{split}\]
245+
Implement this in the $\lambda$-calculus using Church numerals, i.e. write a lambda term $f$ such that $f \ \underline{n}$ reduces to $\underline{x_n}$.
246+
\\
247+
\\ You can use functions defined in the lecture, e.g $plus$, $mult$, $ifz$ etc. It might help to define subroutines.
248+
\\
249+
\\ Sketch the execution of $f \ \underline{2}$ (you can use $\to_\beta^*$ rather than $\to_\beta$).
250+
\end{exambox}
251+
229252
\subsection{Predecessor}
230253
\[\underline{m} = \lambfun{f}{\lambfun{x}{\underbrace{f(\dots (\lambapp{f}{x})}_\text{$m$ times} \dots )}}\]
231254
We cannot remove applications of $f$, however we can use a pair to count up until the successor is $\underline{m}$.
@@ -291,3 +314,8 @@ \section{Combinators}
291314
\[fact \triangleq Y(\lambfun{f}{\lambfun{n}{\lambapp{\lambapp{\lambapp{\text{if zero}}{n}}{\chnum{1}}}{(\lambapp{\lambapp{multiply}{n}}{(\lambapp{f}{(\lambapp{pred}{n})})})}}}) \]
292315
\end{examplebox}
293316

317+
\begin{exambox}{2c}{2020/21}
318+
Consider the term $\mathbf{Y}' = \mathbf{UU}$ with $\mathbf{U} = \lambfun{\lambarg{u}{x}}{\lambapp{x}{uux}}$.
319+
\\
320+
\\ Why is $\mathbf{Y}$ (and $\mathbf{U}$) a combinator? Show that it is an alternative implementation of the \textit{fixed-point combinator}.
321+
\end{exambox}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="Electron" modified="2023-03-29T16:35:06.583Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.3.0 Chrome/104.0.5112.114 Electron/20.1.3 Safari/537.36" etag="kgj2q-CxBASFb2iELWyN" version="20.3.0" type="device"><diagram id="vkjnaxWTCteoK0d_Y_4M" name="Page-1">5VjLcpswFP0aL+MRUoBkGTt220U6naQvd4dBBjUCUVl+9esrWZeHDHk5SaedeGFzj64u0jnnCpIBGefbdzIqsyuRUD7AKNkOyOUA49D39LcBdhbwCA4tkkqWANYAN+w3BRABumIJXTqJSgiuWOmCsSgKGisHi6QUGzdtIbh71zJKaQe4iSPeRb+xRGUWPat2YfD3lKVZdWcvOLcjeVQlw06WWZSITQsikwEZSyGUvcq3Y8oNeRUvdt70jtF6YZIW6jETJuXPrzM+VdOUba48/GHx48v4BKqsI76CDQ9wwHW90ULosoZXLuR+JPi1MksdDTBB+08bQku1A8oq0BQ4We4FvdAJBJXb9owgNb+TNS30dZSXOijmy9KOcZsztYuwqdcVvlzNKwy1clswEF4vCUuxKhJqiEB6eJMxRW/KKDajG+1bjWUq5zryYOFgRIIgHtc0kOl0RILArENJcUtbI0CLnsE4r/BCFLRe0ppKRbd3CujVttD9REVOldzpFJhAwEjQSucQbhpber5vsaxlyQDyIuiEtC7cmEVfgF+e4B3c8c7k4+frWYd8vWPlMuwyBwz1kBZxlhY6jDVDVOMjwx/TzXkBAzlLEnObXkld0Q9VfQFB/HDoO5LgHkkQ6kpCXksSclQ7LxZz4+hOcz6p43p7Vt9xfzOEb9+OLYg3xIe+6OtVPOzp1lezxum/bA091QDe2zEJPnVPcw/5XYsEf/Ps8Dvk00S/CkEIrLaE0BuVu++GIWN3iGfA2D643DrRro6SC/NmpsM5F/GthaaM15W3TNnCPkSz1khT1QRVUbt4s+L7BdEbFCsZ03uIwP3CScojxdZu/T4VYOonwfZ9VTnk4PEdHuholwWT2q9xh3VQOERh75tAVUpFMqWqU2rvinpDxxslON4o/5NPLIsPPWxf3ida39BDzcdzzwn/Gb7BZ26tv2yc8KnGAX29lrqN1v36NmZzrNY472GzJWI153TUa7kXPGYea7PTV7EZPjs4jvzjbHVYp36OPdtTOmz+OLbpzb8YyOQP</diagram></mxfile>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="Electron" modified="2023-03-29T14:40:26.377Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.3.0 Chrome/104.0.5112.114 Electron/20.1.3 Safari/537.36" etag="qDrcMMquzB1sh32OBwhd" version="20.3.0" type="device"><diagram id="LkFCyconYyp5Kk7kkz8M" name="Page-1">7Vtdd5owGP41XraHJHx5qa5dd9Z9nLlz1l5SSZUNicNQdb9+wSTyZYUigbXDCyUPyUuS9+F53wQcoMly+z50VotPxMX+AGrudoDeDSA0DJ19x8COAxDoFkfmoedyDCTA1PuDBagJNPJcvM5UpIT41FtlwRkJAjyjGcwJQ7LJVnskfvaqK2eOC8B05vhF9Ifn0gVHbWgl+A325gt5ZWAO+ZmlIyuLkawXjks2KQhdDdAkJITyo+V2gv148uS88HbXz5w9dCzEAa3S4E5fhn9C8PQFTD9ejWx3DD/cXkBu5cnxIzHg6ffRt++ix3Qnp4HiLbvIeEGXPgMAO1zTkPzCE+KTkCEBCVjN8aPn+znI8b15wIoz1k3M8PETDqnHJngkTiw9140vM94sPIqnK2cWX3PD6MSwkESBi+MRaLF5ElBBERSXReeZQbx9dlbAYa4ZSTFZYhruWBXZAF4avI1g6AUS/tok7gaawBYpV8t6jmDY/GA7cQI7EH54gU9QwScDaPpUjH/PdT7DDP4dxfRhE4EeHx+QaaYhcx7/fpON19GDxDSJsf6l4BTKr5SF19FKQhcZA6uk5v9CG2hoWdboRdYYR0hjqCKNXph77DIhE0UxqSk/4K1H71LH9/FcsVuBl95txdTtCztZCFhP79KFVKu4mDTbl5J27iiWYlZ88MnsF4euPV92hvc97vBpd7DxkSic4XJBo044x7TsJiu6N8S+Q72nbD+OOUs0/Uq8/S0paGHm1QReQgtZyLQMXUcQQc3EFwBlzfIxCUtpAS8zjrRLLfWBMihJw3wSCob3/DqMuT7lzFYod6COS6IHH4+PEqguMxskHqpIPEsJ8VBOjxjvDGNoIWCbGrLZT33aITMndcBolWZWIRzejG5fS4YSlyeHcI2ur+MbtZkQhKycX44kLnabeYvdaN7yuXo2MoDjPh/JksHoOB0Z1owNSTy4T50pS0cSnb/PyHz36UjVqGAriQoAFlY3Oe2uGgRgPgi0GwPkboDCNRHo10QNaxDoek0EQGHy/08VsiuqENCOO/hMGYJ2blGUc3hlEcrZMXN2VIvQ6TU2CemCzEng+FcJOk7QW0JWwrU/MaU7cfc5ESVVWKhVZGHtpbm4HRISahnRaJiSoK2F+nkKUtwf/ef24vrsN4k0/0zkQXUjj8K9kUOh9b0Rmb6VByCoJAAhbXg5TH8ayYmRnd1/A51myIZypYJ9htxwhgyPbNm0q1N193DfWoZcXaGMVlJkABrKkUGeO6p1qLhde44OfenzoDPyoO71xe7zoCNBulxl1Dwlyu/iAavudqBWYkixyhzeqTkvblVdU2fjFighTKtxy+o2s34jWzty4AqzZ9Sv8xvPnxHsOL5B2OfPL4tsz3m4cR1qSIig3rISqX/77+x1fK9EhZdiulciXTlvzn5C2vOmwJvOV2jQqBnB3tyLo/LfBaURTM2ro4XAM2wogqH8C1+qI1gze4qvf20Gq778w7W75aceyKj72MM69dijYFY126y6bKujXy/cOmqVbXpFtinawUZD4xQt8iJUmW0nzRZEsjbbWDH5KxavnvyhDV39BQ==</diagram></mxfile>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="Electron" modified="2023-03-29T16:57:39.597Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.3.0 Chrome/104.0.5112.114 Electron/20.1.3 Safari/537.36" etag="h6b6yZ-1HQ8nSaDlP3k5" version="20.3.0" type="device"><diagram id="NGGJ3E46u6HnhIqd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/W4RQhjgcIiqqOemPdlkxAtYdI4pWGq3WRz5JVGV27SgBip4lgF5qrPksAcxi467U8HhODTmpof/RMoNZlTyfDqO7dk58bexwWE4l0Coj4OZl+vheTqYvM1B3j03kFRWHtDoeKhzROwcEVR3R95cEacBmdEp9h9wk6Pvz+gm8kj7WwSryr6aJIle0s0l1W0QdlvkL1t1YTpu3LK07yHbnF2L+cl3drITuIi+3Z/Jy5Lm20zR7ib/R+9Tn2vKDC+xc9ED2ebWLxhdTVuwWNaUwWLT+2eBbrcq/ZunoJ8Oir6sMQVVb06w+nk8kOw3T9JEE7q8BfV3qeNkodbws6WSiH3GMolU1zLFTK3PkzeRTftE9+YcIdPMP</diagram></mxfile>
Loading
Loading
Loading

50003 - Models of Computation/register_machines/register_machines.tex

+90
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,36 @@ \subsubsection*{Exponent of base 2}
255255
\includegraphics[scale=0.06]{register_machines/images/rm_functions/exponent_base_2.drawio.png}
256256
\end{center}
257257
}
258+
259+
\begin{exambox}{2bi}{2021/22}
260+
Consider the graphical representation of a Register Machine $M$:
261+
\begin{center}
262+
\includegraphics[width=.4\textwidth]{register_machines/images/exam_2bi_2021_2022.drawio.png}
263+
\end{center}
264+
Write down the program/code (list of instructions) for this machine using only a single $\halt$ instruction (at the end of the code).
265+
\end{exambox}
266+
267+
\begin{exambox}{2bi}{2020/21}
268+
Describe (graphically) a Register Machine (RM) gadget which tests if $R_0$ is
269+
even or odd without changing the value of $R_0$ and using only RM
270+
instructions (no gadgets).
271+
\begin{center}
272+
\includegraphics[width=.5\textwidth]{register_machines/images/exam_2bi_2020_2021.drawio.png}
273+
\end{center}
274+
\end{exambox}
275+
276+
\begin{exambox}{2bii}{2020/21}
277+
\textit{Note: This question contains corrections from the original paper}
278+
\\
279+
\\ Consider the graphical representation of register machine $M$:
280+
\begin{center}
281+
\includegraphics[width=.4\textwidth]{register_machines/images/exam_2bii_2020_2021.drawio.png}
282+
\end{center}
283+
Take for $E \equiv R_1^-$, $H \equiv R_2^-$ and $T \equiv R_0^-$.
284+
\\
285+
\\ Write down the program, code or list of instructions for this machine using only a single $\halt$ instruction (at end of the code).
286+
\end{exambox}
287+
258288
\section{Encoding Programs as Numbers}
259289

260290
\begin{definitionbox}{Halting Problem}
@@ -293,6 +323,30 @@ \subsection{Pairs}
293323
$\langle x, y \rangle $ & $= 2^x(2y + 1) - 1$ & $y \ 0 \ 1_1 \dots 1_x$ & Bijection between $\mathbb{N} \times \mathbb{N}$ and $\mathbb{N}$ \\
294324
\end{tabular}
295325
\end{center}
326+
327+
\begin{exambox}{2a}{2021/22}
328+
Either state your birthday or take today's date as $B = YYMMDD$ (i.e. last two
329+
digits of the year, two digits representing month and day each) and determine the
330+
pair, the list, and the Register Machine (RM) instruction it represents, i.e. for
331+
which pair $x, y$ do we have $\langle \langle x, y \rangle \rangle = B$, for which list $\ell$ of numbers do we get
332+
$\ulcorner \ell \urcorner = B$, and for which Register Machine instruction $I$ do we have that
333+
$\ulcorner I \urcorner = B$?
334+
\\
335+
\\ Show your work, e.g. binary representation of your $B$, etc.
336+
\end{exambox}
337+
\begin{exambox}{2a}{2020/21}
338+
State your $CID$ and determine the pair, the list, and the Register Machine (RM)
339+
instruction it represents, i.e. for which pair $x, y$ do we have $\langle \langle x, y \rangle \rangle = $ CID, for
340+
which list $\ell$ of numbers do we get $\ulcorner ell \urcorner = CID$, and for which register-machine
341+
instructions $I$ do we have that $\ulcorner I \urcorner = CID$?
342+
\\
343+
\\ Show your work, e.g. binary representation of your $CID$, etc.
344+
\\
345+
\\ Add eight to your $CID$, i.e. consider $CID+8$, and repeat these three decodings.
346+
\\
347+
\\ Can one be sure that very student in class can (in principle) decode their $CID$s as requested?
348+
\end{exambox}
349+
296350
\subsection{Lists}
297351
We can express lists and right-nested pairs.
298352
\[[x_1, x_2, \dots, x_n] = x_1:x_2:\dots:x_n = (x_1, (x_2, (\dots, x_n) \dots ))\]
@@ -342,6 +396,42 @@ \section{Gadgets}
342396
And then can use these to create larger programs.
343397
\end{definitionbox}
344398

399+
\begin{exambox}{2bii}{2021/22}
400+
\textit{\dots continued from question Q2bi - 2021/22}
401+
\\
402+
\\ Replace some instructions by gadgets as follows:
403+
\[\begin{split}
404+
R_0^+ & \text{ by copy } N \text{ to } O \\
405+
N^+ & \text{ by copy } Y \text{ to } N \\
406+
O^+ & \text{ by push } X \text{ to } O \\
407+
\end{split} \qquad \begin{split}
408+
R_1^- & \text{ by pop } O \text{ to } R_1 \\
409+
R_2^- & \text{ by pop } O \text{ to } R_2 \\
410+
R_3^+ & \text{ by add }R_2 \text{ to } R_1 \\
411+
\end{split} \qquad \begin{split}
412+
R_2^+ & \text{ by push }R_1 \text{ to } N \\
413+
R_1^+ & \text{ by copy } R_2 \text{ to } R_1 \\
414+
\\
415+
\end{split}\]
416+
where for pop gadgets the \textit{empty} exit is identified with $\twoheadrightarrow$ and \textit{done}
417+
with $\to$ and where we have additional registers: $X$ with (constant) value $1$
418+
and $Y$ with (constant) value $2$.
419+
\\
420+
\\ Draw the graphical representation of the resulting RM and describe its
421+
execution with initially: $R_0 = 3$ and all other registers set to $0$ (except for
422+
$X$ and $Y$), use the same labels as in the original RM.
423+
\end{exambox}
424+
425+
\begin{exambox}{2biii}{2021/22}
426+
\textit{\dots continued from Q2bii - 2021/22}
427+
\\
428+
\\ What does this register machine compute for $R_0 = n$ and all other registers
429+
set to $0$ (except for $X$ and $Y$), i.e. what does the contents of register $N$ or $O$
430+
represent when the RM terminates?
431+
\\
432+
\\Give an interpretation of what the registers are used for/hold.
433+
\end{exambox}
434+
345435
\section{Analysing Register Machines}
346436
There is no general algorithm for determining the operations of a register machine (i.e halting problem)
347437
\\

0 commit comments

Comments
 (0)