1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
% Created 2023-11-17 Fri 13:57
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\notindent \notag \usepackage{amsmath} \usepackage[a4paper,margin=1in,portrait]{geometry}
\author{Elizabeth Hunt (A02364151)}
\date{\today}
\title{HW 08}
\hypersetup{
pdfauthor={Elizabeth Hunt (A02364151)},
pdftitle={HW 08},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 28.2 (Org mode 9.7-pre)},
pdflang={English}}
\begin{document}
\maketitle
\tableofcontents
\setlength\parindent{0pt}
\section{Problem One}
\label{sec:orgbeb25aa}
\begin{center}
\includegraphics[width=7cm]{./p1.png}
\end{center}
\section{Problem Two}
\label{sec:orgc078de2}
\begin{center}
\includegraphics[width=7cm]{./p2.png}
\end{center}
\section{Problem Three}
\label{sec:orga508990}
Using the following code proceeding the appendix we receive
\(l(111) = 4\)
\(r(111) = 3\)
\(lt(111) = 12\)
\begin{verbatim}
const p3 = () => {
const x = 111;
const { l, r } = lr(x);
const lt = length(x);
[`l(${x}) = ${l}`, `r(${x}) = ${r}`, `lt(${x}) = ${lt}`].forEach((s) =>
console.log(s)
);
};
p3();
\end{verbatim}
\section{Problem Four}
\label{sec:org7ca236e}
Using the following code proceeding the appendix we receive
\((17)_0 = 0\)
\((17)_1 = 0\)
\((17)_2 = 0\)
\((17)_3 = 0\)
\((17)_4 = 0\)
\((17)_5 = 0\)
\((17)_6 = 0\)
\((17)_7 = 1\)
\((17)_8 = 0\)
\begin{verbatim}
const p4 = () => {
const x = 17;
for (let i = 0; i <= 8; i++)
console.log(`(${x})_${i} = ${access(x, i)}`)
};
p4();
\end{verbatim}
And for all \(i > 8\), \(p_i > 17\) and thus \(p_i^{(t+1)} \nmid x\) for all \(t \ge 0\), and thus the valid set of \(t\)'s,
\(T\), has \(\text{min}(T) = 0\), so \((17)_i = 0\).
\section{Problem Five}
\label{sec:org25e3a57}
We compute the new code:
\([\#(I_1), \#(I_2)]\)
For \(\#(I_1)\):
\(\#(I_1) = \langle a, \langle b, c \rangle \rangle\) where \(a = \#(B1) = 2\), \(b = 1\), \(c = \#(X1) - 1 = 1\), so
\(\#(I_1) = \langle 2, \langle 1, 1 \rangle \rangle = 2^2(2\langle1, 1\rangle + 1) - 1 = 4(11) - 1 = 43\).
For \(\#(I_2)\):
\(\#(I_2) = \langle a, \langle b, c \rangle \rangle\) where \(a = 0\) as there is no label for the instruction, \(b = \#(B1) + 2 = 4\),
\(c = \#(X1) - 1 = 1\), so \(\#(I_2) = \langle 0, \langle 4, 1 \rangle \rangle = 2^0(2\langle 4, 1 \rangle + 1) - 1 = 94\).
Thus:
\([43, 94] = (2^{43})(3^{94}) - 1 = 6218530334586699211614548872374762259672175972138197450751\).
\section{Problem Six}
\label{sec:orgc5e0177}
\subsection{\(\phi\)\textsubscript{5}\textsuperscript{1}(x)}
\label{sec:orgf652342}
\(\phi\)\textsubscript{5}\textsuperscript{1}(x) has source \(5 + 1\) = \(6\) which corresponds to the godel sequence \(2^1 * 3^1 = [1, 1]\). 1 =
\(\langle 1, \langle 0, 0 \rangle \rangle\) which corresponds to an instruction with \(\#(L) = 1\), \(\#(V) = 0\), and an operation
of \(0\):
\begin{verbatim}
[ A1 ] Y <- Y
[ A1 ] Y <- Y
\end{verbatim}
\subsection{\(\phi\)\textsubscript{7}\textsuperscript{1}(x)}
\label{sec:orgd9de496}
\(\phi\)\textsubscript{7}\textsuperscript{1}(x) has source \(7 + 1\) = \(8\) which corresponds to the godel sequence \(2^3 = [3]\). 3 =
\(\langle 2, \langle 0, 0 \rangle \rangle\) which corresponds to an instruction with \(\#(L) = 2\), \(\#(V) = 0\), and an
operation of \(0\):
\begin{verbatim}
[ B1 ] Y <- Y
\end{verbatim}
\subsection{\(\phi\)\textsubscript{11}\textsuperscript{1}(x)}
\label{sec:orge5e7392}
\(\phi\)\textsubscript{11}\textsuperscript{1}(x) has source \(11 + 1\) = \(12\) which corresponds to the godel sequence \(2^2 * 3^1 = [2, 1]\). 2 =
\(\langle 0, \langle 1, 0 \rangle \rangle\) which corresponds to an instruction with \(\#(L) = 0\), \(\#(V) = 0\), and an
operation of \(1\).
And, we already found \(1\) in \(\phi\)\textsubscript{5}\textsuperscript{1}(x):
\begin{verbatim}
Y <- Y + 1
[ A1 ] Y <- Y
\end{verbatim}
\subsection{\(\phi\)\textsubscript{13}\textsuperscript{1}(x)}
\label{sec:org65f2245}
\(\phi\)\textsubscript{13}\textsuperscript{1}(x) has source \(13 + 1\) = \(14\) which corresponds to the godel sequence \(2^1 * 7^1 = [1, 0, 0, 1]\).
And, we already found \(1\) in \(\phi_5^1(x)\), \(0\) is trivially \texttt{Y <- Y} (unlabeled, \(\#(V) = 0\), op = 0).
\begin{verbatim}
[ A1 ] Y <- Y
Y <- Y
Y <- Y
[ A1 ] Y <- Y
\end{verbatim}
\subsection{\(\phi\)\textsubscript{17}\textsuperscript{1}(x)}
\label{sec:orgacbaf8a}
\(\phi\)\textsubscript{17}(x) has source \(17 + 1\) = \(18\) which corresponds to the godel sequence \(2^1 * 3^2 = [1, 2]\).
And, we already found \(1\) in \(\phi_5^1(x)\), and \(2\) in \(\phi\)\textsubscript{11}\textsuperscript{1}(x)
\begin{verbatim}
[ A1 ] Y <- Y
Y <- Y + 1
\end{verbatim}
\section{Problem Seven}
\label{sec:org15f3033}
\begin{enumerate}
\item Let \(m(x_1, x_2) = x_1 * x_2\) which is primitive recursive by proofs in class.
\item Let \(four(x_1) = s(s(s(s(n(x_1)))))\); the successor function composed 4 times on the null function.
\item Then \(f(x_1)\) is \(m(four(x_1), x_1)\) which is an application of composition of primitive recursive functions.
\end{enumerate}
Thus, \(f\) is primitive recursive, and thus computable.
\section{Problem Eight}
\label{sec:org1d07ae0}
We can use the handy identity that \(lcm(x_1, x_2) = \frac{(a * b)}{gcd(a, b)} = \lfloor \frac{(a * b)}{gcd(a, b)} \rfloor\)
since \(gcd(a, b)\) by definition divides \(a * b\).
\begin{enumerate}
\item Define \(gcd(x_1, 0) = x_1\)
\item Let \(R(x_1, x_2)\) be the remainder function when \(x_1\) divides \(x_2\) which is primitive recursive by
the proof found on page 56 of the book.
\item We construct the informal recursion \(gcd(x_1, x_2) = gcd(x_2, R(x_1, x_2))\) by Euclid's Algorithm.
\item Let \(floordiv(x_1, x_2)\) be the floor of the result of division \(\frac{x_1}{x_2}\) which is primitive
recursive by the proof found on page 56 of the book.
\item Let \(m(x_1, x_2) = x_1 * x_2\) which is primitive recursive by proofs in class.
\item Then \(lcm(x_1, x_2) = floordiv(m(x_1, x_2), gcd(x_1, x_2))\) which is an application of composotion of primitive recursive functions.
\end{enumerate}
Then \(lcm\) is primitive recursive.
\section{Appendix}
\label{sec:org7f26251}
\begin{verbatim}
const isPrime = (n) =>
!Array(Math.ceil(Math.sqrt(n)))
.fill(0)
.map((_, i) => i + 2) // first prime is 2
.some((i) => n !== i && n % i === 0);
const primesCache = [2];
const p = (i) => {
if (primesCache.length <= i) {
let x = primesCache.at(-1);
while (primesCache.length <= i) {
if (isPrime(++x)) primesCache.push(x);
}
}
return primesCache.at(i - 1);
};
const lr = (z, maxSearch = 100) => {
let x = 0;
for (let i = 0; i < maxSearch; ++i)
if ((z + 1) % Math.pow(2, i) === 0) x = Math.max(i, x);
const y = ((z + 1) / Math.pow(2, x) - 1) / 2;
return { l: x, r: y };
};
const access = (x, i) => {
if (i === 0 || x === 0) return 0;
const p_i = p(i);
let minT = x;
for (let t = x; t >= 0; t--)
if (x % Math.pow(p_i, t + 1) !== 0) minT = Math.min(t, minT);
return minT;
};
const length = (x) => {
let minI = x;
for (let i = x; i >= 0; i--)
if (
access(x, i) !== 0 &&
Array(x)
.fill(0)
.map((_, j) => j + 1)
.every((j) => j <= i || access(x, j) == 0)
)
minI = Math.min(i, minI);
return minI;
};
\end{verbatim}
\end{document}
|