213 lines
7.4 KiB
TeX
213 lines
7.4 KiB
TeX
\documentclass[fontsize=11pt]{article}
|
|
\usepackage{amsfonts}
|
|
\usepackage{amsmath}
|
|
\usepackage{amsthm}
|
|
\usepackage[utf8]{inputenc}
|
|
\usepackage[margin=0.75in]{geometry}
|
|
|
|
\title{CSC110 Assignment 4: Number Theory, Cryptography, and Algorithm Running Time}
|
|
\author{Azalea Gui \& Peter Lin}
|
|
\date{\today}
|
|
|
|
% Some useful LaTeX commands. You are free to use these or not, and also add your own.
|
|
\newcommand{\N}{\mathbb{N}}
|
|
\newcommand{\Z}{\mathbb{Z}}
|
|
\newcommand{\R}{\mathbb{R}}
|
|
\newcommand{\cO}{\mathcal{O}}
|
|
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
|
|
|
|
\begin{document}
|
|
\maketitle
|
|
|
|
\section*{Part 1: Practice with Proofs}
|
|
|
|
\begin{enumerate}
|
|
|
|
\item[1.] Statement to prove:
|
|
|
|
$$\forall a, k, n \in \Z,~ \gcd(a, n) = 1 \Rightarrow \gcd(a + kn, n) = 1$$
|
|
|
|
\begin{proof} : \\
|
|
$d = \gcd(a,n)$ is defined as $(a=0 \land n=0 \implies d=0) \land \\ (a \neq 0 \lor n \neq 0 \implies d | a \land d | n \land (\forall e \in \N, e | a \land e | n \implies e \le d))$ \\
|
|
\\
|
|
Let $a,k,n \in \Z$ \\
|
|
Assume that $\gcd(a,n) = 1$ \\
|
|
Since $d = 1 \neq 0$, this implies that $a \neq 0 \lor n \neq 0$ \\
|
|
Since $a \neq 0 \lor n \neq 0$, we know $1 | a \land 1 | n \land (\forall e_2 \in \N, e_2 | a \land e_2 | n \implies e_2 \le 1)$ is also true. \\
|
|
We need to prove: $(a + kn) \neq 0 \lor n \neq 0 \implies 1 | (a + kn) \land 1 | n \land (\forall e \in \N, e | (a + kn) \land e | n \implies e \le 1)$ \\
|
|
\\
|
|
Suppose $(a + kn) \neq 0 \lor n \neq 0$ \\
|
|
We need to prove: $1 | (a + kn) \land 1 | n \land (\forall e \in \N, e | (a + kn) \land e | n \implies e \le 1)$
|
|
|
|
\begin{enumerate}
|
|
\item[1.] Proving for: $1 | (a + kn)$ \\
|
|
That is: $\exists c \in \Z$ s.t. $(a + kn) = 1 \cdot c$ \\
|
|
Take $c = (a + kn)$ \\
|
|
$(a + kn) = 1 \cdot (a + kn)$ is true.
|
|
|
|
\item[2.] $1 | n$ is given to be true.
|
|
|
|
\item[3.] Proving for $\forall e \in \N, e | (a + kn) \land e | n \implies e \le 1$ \\
|
|
Let $e \in \N$ \\
|
|
Suppose $e | (a + kn) \land e | n$ \\
|
|
$a + kn = ex \land n = ey$ for some $x,y \in \Z$ \\
|
|
$a + key = ex$ for some $x,y \in \Z$ \\
|
|
$a = e(x - ky)$ for some $x,y \in \Z$ \\
|
|
Let $c = (x - ky)$ \\
|
|
By substitution, we now have: $a = ec$ \\
|
|
Therefore, $\exists c \in \Z$ s.t. $a = ec$ is true. \\
|
|
Which means $e | a$ is true. \\
|
|
Since we are given $\forall e_2 \in \N, e_2 | a \land e_2 | n \implies e_2 \le 1$ \\
|
|
Take $e_2 = e$, we now have $e | a \land e | n \implies e \le 1$ \\
|
|
And since we now know $e | a$ and $e | n$, we can conclude $e \le 1$. \\
|
|
Which is what we want to show.
|
|
\end{enumerate}
|
|
|
|
|
|
\end{proof}
|
|
|
|
\item[2.] Statement to prove (we've expanded the definition of Omega for you!):
|
|
|
|
$$\exists c, n_0 \in \R^+,~ \forall n \in \N,~ n \geq n_0 \Rightarrow \log_{3} n - \log_{11} n \geq c \cdot \log_{14} n$$
|
|
|
|
\begin{proof}
|
|
TODO: Your proof goes here.
|
|
\end{proof}
|
|
|
|
\item[3.] Statement to prove (we haven't expanded the definition of Big-O for you, but we encourage you to do so yourself):
|
|
|
|
$$\forall f, g: \N \to \R^{\geq 0},~ g \in \cO(f) \land \big(\forall m \in \N,~ f(m) \geq 1 \big) \Rightarrow g \in \cO(\floor{f})$$
|
|
|
|
\begin{proof}
|
|
TODO: Your proof goes here.
|
|
\end{proof}
|
|
|
|
\end{enumerate}
|
|
|
|
\newpage
|
|
|
|
\section*{Part 2: Generating Coprime Numbers}
|
|
|
|
\begin{enumerate}
|
|
|
|
\item[1.]
|
|
Not to be handed in.
|
|
|
|
\item[2.]
|
|
Complete this part in the provided \texttt{a4\_part2.py} starter file.
|
|
Do \textbf{not} include your solution in this file.
|
|
|
|
\item[3.]
|
|
Prove that each loop invariant holds.
|
|
|
|
\begin{enumerate}
|
|
\item[a.] Loop Invariant 1
|
|
\begin{proof} : \\
|
|
Variables: In this proof, $N$ is the abbreviation for the list \texttt{nums\_so\_far}. \\
|
|
\\
|
|
Assumption 1: The loop invariant 1 is true for the previous iteration. \\
|
|
That is $\forall k_2 \in N, gcd(k_2, 2) = 1 \land gcd(k_2, 3) = 1$ \\
|
|
\\
|
|
Assumption 2: The statement proven in Part 1.1: \\
|
|
$\forall a,k,n \in \Z, gcd(a,n) = 1 \implies gcd(a + kn, n) = 1$ \\
|
|
\\
|
|
We need to prove: $\forall k \in N \cup \{ N[-2] + 6 \}, gcd(k, 2) = 1 \land gcd(k, 3) = 1$ \\
|
|
Which is equivalent to: $\forall k \in N, gcd(k, 2) = 1 \land gcd(k, 3) = 1$ and \\
|
|
$gcd(N[-2] + 6, 2) = 1 \land gcd(N[-2] + 6, 3) = 1$ \\
|
|
\\
|
|
Since the first part is the same as the previous iteration, it is true. \\
|
|
What we need to prove becomes:
|
|
$gcd(N[-2] + 6, 2) = 1 \land gcd(N[-2] + 6, 3) = 1$ \\
|
|
\\
|
|
Pick $k_2 = N[-2] \in N$ \\
|
|
By assumption 1, we know that $gcd(N[-2], 2) = 1$ and $gcd(N[-2], 3) = 1$
|
|
|
|
\begin{enumerate}
|
|
\item[1.] Proving for $gcd(N[-2] + 6, 2) = 1$ \\
|
|
Pick $a = N[-2], k = 3, n = 2$ \\
|
|
Since we know $gcd(N[-2], 2) = 1$, $gcd(a, n) = 1$ is true. \\
|
|
Therefore, by assumption 2, we know that $gcd(a + kn, n) = 1$ is also true. \\
|
|
Substituting the varaibles back, we know $gcd(N[-2] + 6, 2) = 1$.
|
|
\item[2.] Proving for $gcd(N[-2] + 6, 3) = 1$ \\
|
|
Pick $a = N[-2], k = 2, n = 3$ \\
|
|
Since we know $gcd(N[-2], 3) = 1$, $gcd(a, n) = 1$ is true. \\
|
|
Therefore, by assumption 2, we know that $gcd(a + kn, n) = 1$ is also true. \\
|
|
Substituting the varaibles back, we know $gcd(N[-2] + 6, 3) = 1$.
|
|
\end{enumerate}
|
|
\end{proof}
|
|
|
|
\item[b.] Loop Invariant 2
|
|
\begin{proof} : \\
|
|
Variables: In this proof, $N$ is the abbreviation for the list \texttt{nums\_so\_far}, and $|N|$ represents the size of $N$. \\
|
|
\\
|
|
Assumption 1: The loop invariant 2 is true for the previous iteration. \\
|
|
That is $\forall i_2 \in \{ 0, \dots, |N| - 3\}, N[i_2] + 6 = N[i_2 + 2]$ \\
|
|
\\
|
|
Let $M = N \cup \{ N[-2] + 6 \}$ be the list of the current iteration. \\
|
|
We need to prove: $\forall i \in \{0, \dots, |M| - 3\}, M[i] + 6 = M[i + 2] $
|
|
|
|
\begin{enumerate}
|
|
\item[1.] Let $i < |M| - 3$ \\
|
|
Since the new entry added to $M$ is not included in $i$, this case is equivalent to the previous iteration, and we know that is true by assumption 1.
|
|
|
|
\item[2.] Let $i = |M| - 3$ \\
|
|
We need to prove: $M[|M| - 3] + 6 = M[|M| - 3 + 2]$ \\
|
|
That is $M[-3] + 6 = M[-1]$ \\
|
|
\\
|
|
Let's start with a true statement: \\
|
|
$N[-2] = N[-2]$ \\
|
|
Since $M[:-1] = (N \cup \{ N[-2] + 6 \})[:-1] = N$, \\
|
|
$M[:-1][|N| - 2] = M[|N| - 2] = N[-2]$ \\
|
|
Since $M$ has one extra entry than $N$, $|M| = |N| + 1$ \\
|
|
$M[|N| - 2] = M[|N| + 1 - 3] = M[|M| - 3] = M[-3] = N[-2]$ \\
|
|
Add 6 to both sides: \\
|
|
$M[-3] + 6 = N[-2] + 6$ \\
|
|
Since $M[-1] = (N \cup \{ N[-2] + 6 \})[-1] = N[-2] + 6$ is it's last entry, \\
|
|
$M[-3] + 6 = M[-1]$ \\
|
|
Which is what we want to show.
|
|
|
|
\end{enumerate}
|
|
\end{proof}
|
|
|
|
\item[c.] Loop Invariant 3
|
|
\begin{proof}
|
|
TODO: Your proof goes here.
|
|
\end{proof}
|
|
|
|
\item[d.] Loop Invariant 4
|
|
\begin{proof}
|
|
TODO: Your proof goes here.
|
|
\end{proof}
|
|
\end{enumerate}
|
|
|
|
\item[4.]
|
|
Complete this part in the provided \texttt{a4\_part2.py} starter file.
|
|
Do \textbf{not} include your solution in this file.
|
|
|
|
\item[5.]
|
|
Complete this part in the provided \texttt{a4\_part2.py} starter file.
|
|
Do \textbf{not} include your solution in this file.
|
|
\end{enumerate}
|
|
|
|
\newpage
|
|
|
|
\section*{Part 3: Running-Time Analysis}
|
|
|
|
\begin{enumerate}
|
|
\item[1.]
|
|
TODO: Running-time analysis of \texttt{coprime\_to\_2\_and\_3}.
|
|
|
|
\item[2.]
|
|
TODO: Running-time analysis of \texttt{starting\_coprime\_numbers}.
|
|
|
|
\item[3.]
|
|
TODO: Running-time analysis of \texttt{coprime\_to\_all}.
|
|
\end{enumerate}
|
|
|
|
\section*{Part 4: Two New Cryptosystems}
|
|
|
|
Complete this part in the provided \texttt{a4\_part4.py} starter file.
|
|
Do \textbf{not} include your solution in this file.
|
|
|
|
\end{document}
|