Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 307cc48

Browse files
committedOct 3, 2023
60029: updated link to register machines frontendas per Yitang's prompt
1 parent 8b1da55 commit 307cc48

File tree

2 files changed

+103
-103
lines changed

2 files changed

+103
-103
lines changed
 
Binary file not shown.

‎50003 - Models of Computation/register_machines/register_machines.tex

+103-103
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ \chapter{Register Machines}
33
\begin{sidenotebox}{Register Machine Simulator}
44
\begin{center}
55
\begin{tabular}{c c}
6-
\href{https://flutter-rm.herokuapp.com/#/}{Register Machine Simulator} & \href{https://github.com/MMZK1526/Haskell-RM}{Repository} \\
6+
\href{ https://mmzk1526.github.io/rm_front_end/}{Register Machine Simulator} & \href{https://github.com/MMZK1526/Haskell-RM}{Repository} \\
77
\end{tabular}
88
\end{center}
9-
This simulator has been developed by Yìtáng Chén to support 50003, make sure to give him a $\bigstar$!
9+
This simulator has been developed by Yìtáng Chén to support 50003, make sure to give him a $\bigstar$!
1010
\end{sidenotebox}
1111
\section{Algorithms}
1212

@@ -22,16 +22,16 @@ \section{Algorithms}
2222
One definition is: \textit{A finite, ordered series of steps to solve a problem.}
2323
\\
2424
\\ Common features of the many definitions of algorithms are:
25-
\begin{center}
26-
\begin{tabular}{l p{.8\textwidth}}
27-
\textbf{Finite} & Finite number of elementary (cannot be broken down further) operations. \\
28-
\textbf{Deterministic} & Next step uniquely defined by the current. \\
29-
\textbf{Terminating}? & May not terminate, but we can see when it does \& what the result is. \\
30-
\end{tabular}
31-
\end{center}
32-
\begin{center}
33-
\includegraphics[width=0.6\textwidth]{register_machines/images/algorithm.drawio.png}
34-
\end{center}
25+
\begin{center}
26+
\begin{tabular}{l p{.8\textwidth}}
27+
\textbf{Finite} & Finite number of elementary (cannot be broken down further) operations. \\
28+
\textbf{Deterministic} & Next step uniquely defined by the current. \\
29+
\textbf{Terminating}? & May not terminate, but we can see when it does \& what the result is. \\
30+
\end{tabular}
31+
\end{center}
32+
\begin{center}
33+
\includegraphics[width=0.6\textwidth]{register_machines/images/algorithm.drawio.png}
34+
\end{center}
3535
\end{definitionbox}
3636

3737
\section{Register Machines}
@@ -41,25 +41,25 @@ \section{Register Machines}
4141
\begin{itemize}
4242
\item Infinitely many registers, each storing a natural number ($\mathbb{N} \triangleq \{0, 1, 2, \dots\}$)
4343
\item Each instruction has a label associated with it.
44-
\end{itemize}
45-
There are 3 instructions:
46-
\begin{center}
47-
\begin{tabular}{l l}
48-
$\inc{i}{m}$ & Add 1 to register $\reglabel{i}$ and then jump to the instruction at $\instrlabel{m}$ \\
49-
$\dec{i}{n}{m}$ & If $\reglabel{i} > 0$ then decrement it and jump to $\instrlabel{n}$, else jump to $\instrlabel{m}$ \\
50-
$\halt$ & Halt the program.
51-
\end{tabular}
52-
\end{center}
44+
\end{itemize}
45+
There are 3 instructions:
46+
\begin{center}
47+
\begin{tabular}{l l}
48+
$\inc{i}{m}$ & Add 1 to register $\reglabel{i}$ and then jump to the instruction at $\instrlabel{m}$ \\
49+
$\dec{i}{n}{m}$ & If $\reglabel{i} > 0$ then decrement it and jump to $\instrlabel{n}$, else jump to $\instrlabel{m}$ \\
50+
$\halt$ & Halt the program.
51+
\end{tabular}
52+
\end{center}
5353
At each point in a program the registers are in a configuration $c = (l, r_0, \dots, r_n)$ (where $r_i$ is the value of $\reglabel{i}$ and $l$ is the instruction label $\instrlabel{l}$ that is about to be run).
5454
\begin{itemize}
5555
\item $c_0$ is the initial configuration, next configurations are $c_1, c_2, \dots$.
5656
\item In a finite computation, the final configuration is the \textbf{halting configuration}.
5757
\item In a \textbf{proper halt} the program ends on a $\halt$.
5858
\item In an \textbf{erroneous halt} the program jumps to a non-existent instruction, the \textbf{halting configuration} is for the instruction immediately before this jump.
59-
\end{itemize}
60-
\begin{center}
61-
\includegraphics[width=0.6\textwidth]{register_machines/images/graphical_register_machine.drawio.png}
62-
\end{center}
59+
\end{itemize}
60+
\begin{center}
61+
\includegraphics[width=0.6\textwidth]{register_machines/images/graphical_register_machine.drawio.png}
62+
\end{center}
6363
\end{definitionbox}
6464

6565
\begin{examplebox}{Sum of three numbers}
@@ -116,9 +116,9 @@ \subsection{Partial Functions}
116116
\[f \subseteq X \times Y \ \text{ and } \ (x,y_1) \in f \land (x, y_2) \in f \Rightarrow y_1 = y_2\]
117117
\begin{center}
118118
\begin{tabular}{l | l}
119-
$f(x) = y$ & $(x,y) \in f$ \\
120-
$f(x)\downarrow$ & $\exists y \in Y . [f(x) = y]$ \\
121-
$f(x)\uparrow$ & $\neg\exists y \in Y . [f(x) = y]$ \\
119+
$f(x) = y$ & $(x,y) \in f$ \\
120+
$f(x)\downarrow$ & $\exists y \in Y . [f(x) = y]$ \\
121+
$f(x)\uparrow$ & $\neg\exists y \in Y . [f(x) = y]$ \\
122122
$X \rightharpoonup Y$ & Set of all \textit{partial functions} from $X$ to $Y$. \\
123123
$X \to Y$ & Set of all \textit{total functions} from $X$ to $Y$. \\
124124
\end{tabular}
@@ -140,9 +140,9 @@ \subsubsection{Projection}
140140
}{
141141
\[\halt\]
142142
}{
143-
\begin{center}
144-
\includegraphics[scale=0.06]{register_machines/images/rm_functions/projection.drawio.png}
145-
\end{center}
143+
\begin{center}
144+
\includegraphics[scale=0.06]{register_machines/images/rm_functions/projection.drawio.png}
145+
\end{center}
146146
}
147147

148148
\subsubsection*{Constant}
@@ -160,9 +160,9 @@ \subsubsection*{Constant}
160160
\end{matrix*}
161161
\]
162162
}{
163-
\begin{center}
164-
\includegraphics[scale=0.06]{register_machines/images/rm_functions/constant.drawio.png}
165-
\end{center}
163+
\begin{center}
164+
\includegraphics[scale=0.06]{register_machines/images/rm_functions/constant.drawio.png}
165+
\end{center}
166166
}
167167

168168
\subsubsection*{Truncated Subtraction}
@@ -181,9 +181,9 @@ \subsubsection*{Truncated Subtraction}
181181
\end{matrix*}
182182
\]
183183
}{
184-
\begin{center}
185-
\includegraphics[scale=0.06]{register_machines/images/rm_functions/truncated_subtraction.drawio.png}
186-
\end{center}
184+
\begin{center}
185+
\includegraphics[scale=0.06]{register_machines/images/rm_functions/truncated_subtraction.drawio.png}
186+
\end{center}
187187
}
188188

189189
\subsubsection*{Integer Division}
@@ -213,9 +213,9 @@ \subsubsection*{Integer Division}
213213
\end{matrix*}
214214
\]
215215
}{
216-
\begin{center}
217-
\includegraphics[scale=0.06]{register_machines/images/rm_functions/integer_division.drawio.png}
218-
\end{center}
216+
\begin{center}
217+
\includegraphics[scale=0.06]{register_machines/images/rm_functions/integer_division.drawio.png}
218+
\end{center}
219219
}
220220
\subsubsection*{Multiplication}
221221
\trisplit{
@@ -236,9 +236,9 @@ \subsubsection*{Multiplication}
236236
\end{matrix*}
237237
\]
238238
}{
239-
\begin{center}
240-
\includegraphics[scale=0.06]{register_machines/images/rm_functions/integer_multiplication.drawio.png}
241-
\end{center}
239+
\begin{center}
240+
\includegraphics[scale=0.06]{register_machines/images/rm_functions/integer_multiplication.drawio.png}
241+
\end{center}
242242
}
243243
\subsubsection*{Exponent of base 2}
244244
\trisplit{
@@ -259,9 +259,9 @@ \subsubsection*{Exponent of base 2}
259259
\end{matrix*}
260260
\]
261261
}{
262-
\begin{center}
263-
\includegraphics[scale=0.06]{register_machines/images/rm_functions/exponent_base_2.drawio.png}
264-
\end{center}
262+
\begin{center}
263+
\includegraphics[scale=0.06]{register_machines/images/rm_functions/exponent_base_2.drawio.png}
264+
\end{center}
265265
}
266266

267267
\begin{exambox}{2bi}{2021/22}
@@ -315,12 +315,12 @@ \section{Encoding Programs as Numbers}
315315
Hence using $H$ on any $B(p)$ we can determine if $p(p)$ halts ($H(B(p)) \Rightarrow \neg H(p(p))$).
316316
\\
317317
\\ Now we consider the case when $p = B$.
318-
\begin{center}
319-
\begin{tabular}{l p{.8\textwidth}}
320-
\textbf{$B(B)$ halts} & Hence $B(B)$ does not halt. Contradiction! \\
321-
\textbf{$B(B)$ does not halt} & Hence $B(B)$ halts. Contradiction! \\
322-
\end{tabular}
323-
\end{center}
318+
\begin{center}
319+
\begin{tabular}{l p{.8\textwidth}}
320+
\textbf{$B(B)$ halts} & Hence $B(B)$ does not halt. Contradiction! \\
321+
\textbf{$B(B)$ does not halt} & Hence $B(B)$ halts. Contradiction! \\
322+
\end{tabular}
323+
\end{center}
324324
Hence by contradiction there is not such algorithm $H$.
325325
\end{definitionbox}
326326
In order to reason about programs consuming/running programs (as in the halting problem), we need a way to encode programs as data. Register machines use natural numbers as values for input, and hence we need a way to encode any register machine as a natural number.
@@ -338,15 +338,15 @@ \subsection{Pairs}
338338
pair, the list, and the Register Machine (RM) instruction it represents, i.e. for
339339
which pair $x, y$ do we have $\langle \langle x, y \rangle \rangle = B$, for which list $\ell$ of numbers do we get
340340
$\ulcorner \ell \urcorner = B$, and for which Register Machine instruction $I$ do we have that
341-
$\ulcorner I \urcorner = B$?
341+
$\ulcorner I \urcorner = B$?
342342
\\
343343
\\ Show your work, e.g. binary representation of your $B$, etc.
344344
\end{exambox}
345345
\begin{exambox}{2a}{2020/21}
346346
State your $CID$ and determine the pair, the list, and the Register Machine (RM)
347347
instruction it represents, i.e. for which pair $x, y$ do we have $\langle \langle x, y \rangle \rangle = $ CID, for
348348
which list $\ell$ of numbers do we get $\ulcorner ell \urcorner = CID$, and for which register-machine
349-
instructions $I$ do we have that $\ulcorner I \urcorner = CID$?
349+
instructions $I$ do we have that $\ulcorner I \urcorner = CID$?
350350
\\
351351
\\ Show your work, e.g. binary representation of your $CID$, etc.
352352
\\
@@ -396,11 +396,11 @@ \section{Gadgets}
396396
\item Operates on registers specified in the name of the gadget (e.g \textit{"Add $\reglabel{1}$ to $\reglabel{2}$"}).
397397
\item Can use scratch registers (assumed to be zero prior to gadget and set to zero by the gadget before it exits - allows usage in loops)
398398
\item We can rename the registers used in gadgets (simply change the registers used in the name (\textit{push $\reglabel{0}$ to $\reglabel{1}$ $\to$ push $\regtemp{X}$ to $\regtemp{Y}$}), and have all scratch registers renamed to registers unused by other parts of the program)
399-
\end{itemize}
399+
\end{itemize}
400400
For example we can create several gadgets in terms of registers that we can rename.
401-
\begin{center}
402-
\includegraphics[width=0.9\textwidth]{register_machines/images/gadget.drawio.png}
403-
\end{center}
401+
\begin{center}
402+
\includegraphics[width=0.9\textwidth]{register_machines/images/gadget.drawio.png}
403+
\end{center}
404404
And then can use these to create larger programs.
405405
\end{definitionbox}
406406

@@ -409,18 +409,18 @@ \section{Gadgets}
409409
\\
410410
\\ Replace some instructions by gadgets as follows:
411411
\[\begin{split}
412-
R_0^+ & \text{ by copy } N \text{ to } O \\
413-
N^+ & \text{ by copy } Y \text{ to } N \\
414-
O^+ & \text{ by push } X \text{ to } O \\
415-
\end{split} \qquad \begin{split}
416-
R_1^- & \text{ by pop } O \text{ to } R_1 \\
417-
R_2^- & \text{ by pop } O \text{ to } R_2 \\
418-
R_3^+ & \text{ by add }R_2 \text{ to } R_1 \\
419-
\end{split} \qquad \begin{split}
420-
R_2^+ & \text{ by push }R_1 \text{ to } N \\
421-
R_1^+ & \text{ by copy } R_2 \text{ to } R_1 \\
422-
\\
423-
\end{split}\]
412+
R_0^+ & \text{ by copy } N \text{ to } O \\
413+
N^+ & \text{ by copy } Y \text{ to } N \\
414+
O^+ & \text{ by push } X \text{ to } O \\
415+
\end{split} \qquad \begin{split}
416+
R_1^- & \text{ by pop } O \text{ to } R_1 \\
417+
R_2^- & \text{ by pop } O \text{ to } R_2 \\
418+
R_3^+ & \text{ by add }R_2 \text{ to } R_1 \\
419+
\end{split} \qquad \begin{split}
420+
R_2^+ & \text{ by push }R_1 \text{ to } N \\
421+
R_1^+ & \text{ by copy } R_2 \text{ to } R_1 \\
422+
\\
423+
\end{split}\]
424424
where for pop gadgets the \textit{empty} exit is identified with $\twoheadrightarrow$ and \textit{done}
425425
with $\to$ and where we have additional registers: $X$ with (constant) value $1$
426426
and $Y$ with (constant) value $2$.
@@ -435,7 +435,7 @@ \section{Gadgets}
435435
\\
436436
\\ What does this register machine compute for $R_0 = n$ and all other registers
437437
set to $0$ (except for $X$ and $Y$), i.e. what does the contents of register $N$ or $O$
438-
represent when the RM terminates?
438+
represent when the RM terminates?
439439
\\
440440
\\Give an interpretation of what the registers are used for/hold.
441441
\end{exambox}
@@ -453,7 +453,7 @@ \subsection{Creating Gadgets}
453453
\\
454454
\\ For example below, we can deduce the result as $L = 2^X(2L + 1)$
455455
\begin{center}
456-
\includegraphics[width=0.9\textwidth]{register_machines/images/rm_analysis.drawio.png}
456+
\includegraphics[width=0.9\textwidth]{register_machines/images/rm_analysis.drawio.png}
457457
\end{center}
458458

459459
\subsection{Invariants}
@@ -463,36 +463,36 @@ \subsection{Invariants}
463463
\\
464464
\\ We could attach invariants to every instruction, however it is usually only necessary to use them at the start, end and for loops (preconditions/postconditions).
465465
\begin{center}
466-
\includegraphics[width=0.4\textwidth]{register_machines/images/rm_analysis_invariants.drawio.png}
466+
\includegraphics[width=0.4\textwidth]{register_machines/images/rm_analysis_invariants.drawio.png}
467467
\end{center}
468468
Our first invariant ($P$) can be defined as:
469469
\[P \equiv (X =x \land L = l \land Z = 0)\]
470470
Next we can use the instructions between invariant to find the states under which the invariants must hold.
471471
\begin{center}
472-
\begin{tabular}{l l p{0.7\textwidth}}
473-
\textbf{1.} & $P[Z-1/Z] \Rightarrow I_1$ & After incrementing $Z$ needs to go to the start of the first loop. \\
474-
\hline
475-
\textbf{2.} & $I_1[L + 1/L, Z - 2/Z] \Rightarrow I_1$ & The loop decrements $L$ and increases $Z$ by two. After each loop iteration, $I_1$ must still hold. \\
476-
\hline
477-
\textbf{3.} & $I_1 \land L = 0 \Rightarrow I_2$ & If $L = 0$ the loop is escaped, and we move to $I_2$. \\
478-
\hline
479-
\textbf{4.} & $I_2[Z+1/Z,L-1/L] \Rightarrow I_2$ & Loop increments $L$ and decrements $Z$ on each iteration, after this, $I_2$ must still hold. \\
480-
\hline
481-
\textbf{5.} & $I_2 \land Z = 0 \Rightarrow I_3$ & Loop ends when $Z = 0$, moves to $I_3$. \\
482-
\hline
483-
\textbf{6.} & $I_3[X+1/X] \Rightarrow I_1$ & Large loop decrements $X$ on each iteration, invariant must hold with the new/decremented $X$. \\
484-
\hline
485-
\textbf{7.} & $I_3 \land X = 0 \Rightarrow Q$ & When the main $X$-decrementing loop is escaped, we move to exit, so $Q$ must hold.
486-
\end{tabular}
472+
\begin{tabular}{l l p{0.7\textwidth}}
473+
\textbf{1.} & $P[Z-1/Z] \Rightarrow I_1$ & After incrementing $Z$ needs to go to the start of the first loop. \\
474+
\hline
475+
\textbf{2.} & $I_1[L + 1/L, Z - 2/Z] \Rightarrow I_1$ & The loop decrements $L$ and increases $Z$ by two. After each loop iteration, $I_1$ must still hold. \\
476+
\hline
477+
\textbf{3.} & $I_1 \land L = 0 \Rightarrow I_2$ & If $L = 0$ the loop is escaped, and we move to $I_2$. \\
478+
\hline
479+
\textbf{4.} & $I_2[Z+1/Z,L-1/L] \Rightarrow I_2$ & Loop increments $L$ and decrements $Z$ on each iteration, after this, $I_2$ must still hold. \\
480+
\hline
481+
\textbf{5.} & $I_2 \land Z = 0 \Rightarrow I_3$ & Loop ends when $Z = 0$, moves to $I_3$. \\
482+
\hline
483+
\textbf{6.} & $I_3[X+1/X] \Rightarrow I_1$ & Large loop decrements $X$ on each iteration, invariant must hold with the new/decremented $X$. \\
484+
\hline
485+
\textbf{7.} & $I_3 \land X = 0 \Rightarrow Q$ & When the main $X$-decrementing loop is escaped, we move to exit, so $Q$ must hold.
486+
\end{tabular}
487487
\end{center}
488488
We can now use these constraints (also called \textit{verification conditions}) to determine an invariant.
489489
\\
490490
\\
491491
\\ For each constraint we do:
492492
\begin{enumerate}
493-
\item Get the basic for (potentially one already derived) for the invariant in question.
494-
\item If there is iteration, iterate to build up a disjunction.
495-
\item Find the pattern, and then re-form the invariant based on it.
493+
\item Get the basic for (potentially one already derived) for the invariant in question.
494+
\item If there is iteration, iterate to build up a disjunction.
495+
\item Find the pattern, and then re-form the invariant based on it.
496496
\end{enumerate}
497497

498498
\subsubsection*{Constraint 1.}
@@ -524,11 +524,11 @@ \subsubsection*{Constraint 6.}
524524
\[I_1 = (X=x-1 \land L = 2l + 1 \land Z = 0) \lor (X = x \land Z + 2L = 2l + 1)\]
525525
We can apply constraint \textbf{2.} on the first part of this disjunction, iterating to get the disjunction:
526526
\[I_1 = (X = x \land Z + 2L = 2l + 1) \lor \left( \begin{matrix}
527-
(X=x-1 \land L = 2l + 1 \land Z = 0) \lor \\
528-
(X=x-1 \land L = 2l + 0 \land Z = 2) \lor \\
529-
(X=x-1 \land L = 2l-1 \land Z = 4) \lor \\
530-
(X=x-1 \land L = 2l-2 \land Z = 8) \lor \dots \\
531-
\end{matrix} \right)\]
527+
(X=x-1 \land L = 2l + 1 \land Z = 0) \lor \\
528+
(X=x-1 \land L = 2l + 0 \land Z = 2) \lor \\
529+
(X=x-1 \land L = 2l-1 \land Z = 4) \lor \\
530+
(X=x-1 \land L = 2l-2 \land Z = 8) \lor \dots \\
531+
\end{matrix} \right)\]
532532
Hence for the second group of disjuncts we have the relation:
533533
\[Z + 2L = 2(2l + 1)\]
534534
Hence we have:
@@ -561,12 +561,12 @@ \section{Universal Register Machine}
561561
\\
562562
\\ It takes the arguments:
563563
\begin{center}
564-
\begin{tabular}{l p{.7\textwidth}}
565-
$\reglabel{0}$ & $= 0$ \\
566-
$\reglabel{1}$ & $= $ the program encoded as a number \\
567-
$\reglabel{2}$ & $= $ the argument list encoded as a number \\
568-
\multicolumn{2}{c}{All other registers zeroed} \\
569-
\end{tabular}
564+
\begin{tabular}{l p{.7\textwidth}}
565+
$\reglabel{0}$ & $= 0$ \\
566+
$\reglabel{1}$ & $= $ the program encoded as a number \\
567+
$\reglabel{2}$ & $= $ the argument list encoded as a number \\
568+
\multicolumn{2}{c}{All other registers zeroed} \\
569+
\end{tabular}
570570
\end{center}
571571
The registers used are:
572572
\begin{center}
@@ -584,5 +584,5 @@ \section{Universal Register Machine}
584584
\end{center}
585585
\inputminted{python}{register_machines/code/universal_register_machine.py}
586586
\begin{center}
587-
\includegraphics[width=0.9\textwidth]{register_machines/images/universal_register_machine.drawio.png}
587+
\includegraphics[width=0.9\textwidth]{register_machines/images/universal_register_machine.drawio.png}
588588
\end{center}

0 commit comments

Comments
 (0)
Please sign in to comment.