% Standard Article Definition
\documentclass[]{article}

% Page Formatting
\usepackage[margin=1in]{geometry}
\setlength\parindent{0pt}

% Graphics
\usepackage{graphicx}

% Math Packages
\usepackage{physics}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{mathtools}

% Extra Packages
\usepackage{listings}
\usepackage{hyperref}

% Section Heading Settings
\usepackage{enumitem}
\renewcommand{\theenumi}{\alph{enumi}}
\renewcommand*{\thesection}{Problem \arabic{section}}
\renewcommand*{\thesubsection}{\alph{subsection})}
\renewcommand*{\thesubsubsection}{\quad \quad \roman{subsubsection})}

%Custom Commands
\newcommand{\Rel}{\mathcal{R}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}

\newcommand{\toI}{\xrightarrow{\textsf{\tiny I}}}
\newcommand{\toS}{\xrightarrow{\textsf{\tiny S}}}
\newcommand{\toB}{\xrightarrow{\textsf{\tiny B}}}

\newcommand{\divisible}{ \ \vdots \ }
\newcommand{\st}{\ : \ }

% Theorem Definition
\newtheorem{definition}{Definition}
\newtheorem{assumption}{Assumption}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{proposition}{Proposition}
\newtheorem{example}{Example}

%opening
\title{MATH 5301 Elementary Analysis - Final Exam}
\author{Jonas Wagner}
\date{2021, December 7\textsuperscript{th}}

\begin{document}

\maketitle

% Problem 1 ----------------------------------------------
\section{}
For each $n \in \N$ define the set
\[
    Q_n := \qty{
        \frac{1}{pq} \st 0 < p < q \leq n; \ p + q > n; \ \textnormal{gcd}(p,q) = 1
    }
\]
Let $f(n)$ be the sum of all elements of $Q_n$.

Find $\inf_n f(n)$.

\begin{definition}\label{def:pblm1_Qn}
    Let the set $Q_n$ be defined for all $n \in \N$ as
    \[
        Q_n := \qty{
            \frac{1}{pq} \st 0 < p < q \leq n; \ p + q > n; \ \gcd(p,q) = 1
        }
    \]
\end{definition}

\begin{definition}\label{def:pblm1_fn}
    Let $f(n)$ be the sum of all elements within $Q_n$.
\end{definition}

\begin{definition}\label{def:infimum}
    A lower bound of subset $A$ in the partially ordered set $(S,\leq)$ is defined by
    \[
        a \in S \st a \leq x \forall_{x \in A}
    \]
    A lower bound of $a$ is called an \emph{\underline{infimum}} of set $A \in (S,\leq)$,
    denoted as $a = \inf A$, is the greatest lower bound. i.e.
    \[
        \forall_{y \in S : a \leq x \forall_{x \in A}} y \leq a
    \]
\end{definition}

\begin{definition}
    The \underline{\emph{Greatest Common Divisor}} of two nonzero integers $a,b \in \Z \neq 0$, $\gcd(a,b)$,
    is defined as the largest positive integer, $d \in \Z_+$, so that $d$ is a divisor of both $a$ and $b$.
    i.e:
    \[
        \gcd(a,b) := d \in \Z_+ \st (a \divisible d) \land (b \divisible d)
                    \land (\forall_{x \in \Z_+ \st a,b \divisible x} d \geq x)
    \]
    Additionally, $a$ and $b$ are considered \emph{\underline{coprime}} if $\gcd(a,b) = 1$.
\end{definition}

\begin{assumption}
    For this problem it is assumed that $\gcd$ is only defined within $\Z_+$,
    although I believe this can also be expanded to other less-strict ordered sets in the same way.
\end{assumption}

\begin{assumption}
    It is assumed that the sum of all elements in the empty set is 0, i.e. $\sum_{i} \emptyset = 0$.
\end{assumption}

\newpage
\begin{theorem}
    \[
        \inf_{n \in \N} f(n) = 0
    \]

    \begin{proof}
        Proof by induction.

        For $n = 1$,
            $\lnot \exists_{p,q \in \Z \st 0<p<q\leq 1}$ meaning that $Q_1 = \emptyset$.

            This implies that $f(1) = \sum_{i} \emptyset = 0$ and that $f(1) \geq 0$.

        For $n = 2$,
        \[
            (p,q) \in \qty{(p,q) \st 0 < p < q \leq 2; \ p + q > n; \ \gcd(p,q) = 1} = \qty{(1,2)}
        \]
        The set $Q_2$ is then defined as
        \[
            Q_2 = \qty{\frac{1}{pq} \st (p,q) \in \qty{(1,2)}}
                = \qty{\frac{1}{(1)(2)}}
                = \qty{\frac{1}{2}}
        \]
        Therefore,
        \[
            f(2) = \sum_{i} \qty{\frac{1}{2}} = \frac{1}{2}
        \]
        It is clear that $f(2) = \frac{1}{2} \geq 0$.

        For $n = 3$,
        \[
            (p,q) \in \qty{(p,q) \st 0 < p < q \leq 3; \ p + q > n; \ \gcd(p,q) = 1}
                = \qty{(1,3),(2,3)}
        \]
        The set $Q_3$ is then defined as
        \[
            Q_3 = \qty{\frac{1}{pq} \st (p,q) \in \qty{(1,3),(2,3)}}
                = \qty{\frac{1}{(1)(3)}, \frac{1}{(2)(3)}}
                = \qty{\frac{1}{3}, \frac{1}{6}}
        \]
        Therefore,
        \[
            f(3) = \sum_{i} \qty{\frac{1}{3}, \frac{1}{6}}
                = \frac{1}{3} + \frac{1}{6}
                = \frac{2 + 1}{6}
                = \frac{3}{6}
                = \frac{1}{2}
        \]
        It is clear that $f(3) = \frac{1}{2} \geq 0$.

        For $n = 4$,
        \[
            (p,q) \in \qty{(p,q) \st 0 < p < q \leq 4; \ p + q > n; \ \gcd(p,q) = 1}
                = \qty{(1,4),(2,3),(3,4)}
        \]
        The set $Q_4$ is then defined as
        \[
            Q_4 = \qty{\frac{1}{pq} \st (p,q) \in \qty{(2,3),(3,4)}}
                = \qty{\frac{1}{(1)(4)}, \frac{1}{(2)(3)}, \frac{1}{(3)(4)}}
                = \qty{\frac{1}{4},\frac{1}{6}, \frac{1}{12}}
        \]
        Therefore,
        \[
            f(4) = \sum_{i} \qty{\frac{1}{6}, \frac{1}{12}}
                = \frac{1}{4} + \frac{1}{6} + \frac{1}{12}
                = \frac{3 + 2 + 1}{12}
                = \frac{6}{12}
                = \frac{1}{2}
        \]
        It is clear that $f(4) = \frac{1}{2} \geq 0$.

        % For $n = 5$,
        % \[
        %     (p,q) \in \qty{(p,q) \st 0 < p < q \leq 5; \ p + q > n; \ \gcd(p,q) = 1}
        %         = \qty{(1,5),(2,5),(3,4),(3,5),(4,5)}
        % \]
        % The set $Q_5$ is then defined as
        % \[
        %     Q_5 = \qty{\frac{1}{pq} \st (p,q) \in \qty{(1,5),(2,5),(3,4),(3,5),(4,5)}}
        %         = \qty{\frac{1}{(1)(5)}, \frac{1}{(2)(5)}, \frac{1}{(3)(4)}, \frac{1}{(3)(5)}, \frac{1}{(4)(5)}}
        %         = \qty{\frac{1}{5}, \frac{1}{10}, \frac{1}{12}, \frac{1}{15}, \frac{1}{20}}
        % \]
        % Therefore,
        % \[
        %     f(5) = \sum_{i} \qty{\frac{1}{5}, \frac{1}{10},
        %                         \frac{1}{12}, \frac{1}{15}, \frac{1}{20}}
        %         = \frac{1}{5} + \frac{1}{10} + \frac{1}{12} + \frac{1}{15} + \frac{1}{20}
        %         = \frac{1}{2}
        % \]
        % It is clear that $f(5) = \frac{1}{2} \geq 0$

        For an arbitrary $n \in \N$,
        \begin{align*}
            (p,q) &\in \qty{(p,q) \st 0 < p < q \leq n; \ p + q > n; \ \gcd(p,q) = 1} =\\
                &= \qty{(1,n), (2,n - \star), (3, n - \star) \dots, (n-2, n-1), (n-1, n)}
        \end{align*}
        \begin{align*}
            Q_n &= \qty{\frac{1}{pq} \st (p,q) \in \qty{(1,n), (2,n-\star), \dots, (n-2, n-1), (n-1, n)}}\\
                &= \qty{\frac{1}{(1)(n)}, \frac{1}{(2)(n-1)}, \dots, \frac{1}{(n-2)(n-1)}, \frac{1}{(n-1)(n)}}\\
                &= \qty{\frac{1}{n}, \frac{1}{2(n-\star)}, \dots, \frac{1}{(n-2)(n-1)}, \frac{1}{n(n-1)}}
        \end{align*}

        where $\star$ is dependent for on divisibility properties between $n$ and 2, 3, 4, etc.
        It is important to note that each increase of $n$ will cause every term to decrease in magnitude individually but additional elements are added that result to adding up to $\frac{1}{2}$ again.

        However, eventually this will reach a point where a lack of prime numbers in a region makes it so that the only coprime numbers satisfying the conditions are adjacent to one another, which leads to the following:
        \begin{align*}
            f(n)    &= \sum_{i} Q_n = \frac{1}{n} + \dots + \frac{1}{(\frac{n}{2}) (\frac{n}{2}+1)} + \dots + \frac{1}{n (n-1)}\\
            f(n+1)  &= \qty(\sum_{i} Q_n) \qty(\frac{n!}{(n+1)!}) + \frac{1}{(n+1)}\\
                    &= \frac{1}{n} \frac{n!}{(n+1)!} + \dots + \frac{1}{(\frac{n}{2}) (\frac{n}{2}+1)} \frac{n!}{(n+1)!} + \dots + \frac{1}{n (n-1)} \frac{n!}{(n+1)!} + \frac{1}{n+1}\\
                    &= \frac{n!}{n(n+1)n!} + \dots + \frac{n!}{\frac{n}{2}(\frac{n}{2}-1)(n+1)n!} + \dots + \frac{n!}{n (n-1) (n+1) n!} + \frac{1}{n+1}\\
                    &= \sum_{i} Q_{n+1} = \frac{1}{n+1} + \dots + \frac{1}{(\frac{n+1}{2}) (\frac{n+1}{2}+1)} + \dots + \frac{1}{n (n+1)}
        \end{align*}
        essentially every $(p,q)$ becomes $(q,q+1)$ and the new $\frac{1}{(n+1)}$ is added.

        Anyway, the point is that $\forall_{n\in\N \st n>1} f(n) \geq \frac{1}{2}$;
        however, because $f(n)$ is included, $\frac{1}{2} \leq f(n) \forall_{n \in N}$ since $Q_1 = \emptyset \implies f(1) = 0$.

        Therefore,
        \[
            \inf_n f(n) = 0
        \]

        % Therefore,
        % \begin{align*}
        %     f_{even}(n) &= \sum_{i} \qty{\frac{1}{n}, \frac{1}{2(n-1)}, \dots, \frac{1}{(n-2)(n-1)}, \frac{1}{n(n-1)}}\\
        %         &= \frac{1}{n} + \frac{1}{2(n-1)} + \dots + \frac{1}{(n-2)(n-1)} \frac{1}{n(n-1)}\\
        %         &= \frac{
        %                 (n-1)(n-2)\cdots(3)(2) + (n)(n-2)\cdots(3)(1) + \dots + (n-2)(n-3)\cdots(2)(1)
        %             }{
        %                 n(n-1)(n-2)\cdots(3)(2)(1)
        %             }\\
        %         &= \frac{
        %                 \sum_{i=1}^n \frac{n!}{(i)(n-i)}
        %             }{
        %                 n!
        %             }
        % \end{align*}

        % Something similar is true for $n \in \N \st n + 1 \divisible 2$,
        % but in reality it isn't important for the proof,
        % \begin{align*}
        %     f_{odd}(n) &= \sum_{i} \qty{\frac{1}{n}, \frac{1}{2(n)}, \dots, \frac{1}{(n-2)(n-1)}, \frac{1}{n(n-1)}}\\
        %         &= \frac{1}{n} + \frac{1}{2(n)} + \dots + \frac{1}{(n-2)(n-1)} \frac{1}{n(n-1)}\\
        %         &= \frac{
        %             \sum_{i=1}^n \frac{n!}{(n)(n-i)}
        %         }{n!}
        % \end{align*}

        % When it is known that $f(n) = \frac{1}{2}$,
        % \begin{align*}
        %     f(n)_{even} = \frac{1}{2}
        %         &= \frac{1}{n} + \frac{1}{2(n-1)} + \dots + \frac{1}{(n-2)(n-1)} \frac{1}{n(n-1)}
        % \end{align*}

        % Then this is also true for $f(n+1)$ as shown
        % (with not much algebraic detail since the answer itself remains trivial...)
        % \begin{align*}
        %     f_{odd}(n+1) &= \frac{1}{n+1} + \frac{2(n+1)} + \dots + \frac{(n-2)(n-1)} + frac{(n+1)(n + 1 - 1)}\\
        %                 &=
        % \end{align*}

        % Since it is known that the set with the least number of elements is $\emptyset$
        %     and that $f(n) = 0 \forall_{n} \st Q_n = \emptyset$, and that
    \end{proof}
\end{theorem}

% Problem 2 ----------------------------------------------
\newpage
\section{}
Let $(X,d)$ be a metric space.
Let $B_r(a)$ denote the open ball of radius $r$ centered at $a$.
i.e.
Can it happen that $B_{r_1}(a) \subset B_{r_2}(a)$ but $r_1 > r_2$?

\begin{definition}\label{def:open_ball}
    Within the metric space $(X,d)$,
    the open ball of radius $r \in X$ centered at $a \in X$,
    denoted as $B_r(a)$, is defined as:
    \[
        B_r(a) := \qty{x \in X \st d(a,x) < r}
    \]
\end{definition}

\begin{assumption}\label{ass:normed_metric}
    First it will be assumed that $(X,d)$ is a normed vector space.
    This restricts the metric and metric space into a normed space.
    This can also be denoted as $(X,\norm{\cdot})$ to distinguish between them.
    It is also assumed that $X$ is complete.
\end{assumption}

\begin{theorem}
    For  $r_1 > r_2$ then it is not possible for $B_{r_1}(a) \subset B_{r_2}(b)$ within $(X, \norm{\cdot})$:
    \begin{proof}
        Proof by contradiction.

        Let \[
            B_{r_1}(a), B_{r_2}(b) \subset X
        \]
        with $0 < r_2 < r_1$
        and $a \in B_{r_2}(b)$.

        To minimize the amount of the set existing outside of the set,
        we need to set $a = b$.
        Next, let $c$ be a point within the punctured open ball $B_{r_2}(b)$.
        i.e.\[
            c \in B_{r_2}(b) \backslash \{b\}
        \]
        $c$ can then be used to construct a point that is contained in $B_{r_2}(b)$ but not in $B_{r_1}(a)$:
        \[
            p + \frac{r_1 + r_2}{2} \frac{a c}{\norm{a c}} \in B_{r_1}(a) \backslash B_{r_2}(b)
        \]
        Meaning that there is no possible way for an open ball of greater radius (within a normed metric space).
    \end{proof}
\end{theorem}

\begin{assumption}
    The previous assumption, Assumption \ref{ass:normed_metric}, is now relax the metric so that $d$ is not restricted to be a norm (i.e. may not be linear).
\end{assumption}

\begin{theorem}
    It is possible for $B_{r_1}(a) \subset B_{r_2}(b)$ within $(X, d)$ when $r_1 > r_2$:
    \begin{proof}
        Proof by example:

        Let metric space $(X, d)$ be defined by
        \[X := {0} \cup [5, \infty)\]
        \[d(x,y) := \abs{x - y}\]

        For $r_1 = 4$, $r_2 = 3$,

        Let $B_4(0)$ be defined as
        \[
            B_4(0) := \qty{4
                x \in X \st d(0,x) < 4
            } = \{0\} \cup [2,4)
        \]

        Let $B_3(2)$ be defined as
        \[
            B_3(2) := \qty{
                x \in X \st d(2,x) < 3
            } = \{0\} \cup [2, 5)
        \]

        Clearly, $B_3(2) \subset B_4(0)$.
        Since $r_1 = 4 > r_2 = 3$, this exists as an example that satisfies the conditions.
    \end{proof}
\end{theorem}

% Problem 3 ----------------------------------------------
\newpage
\section{}
Let $M$ be the set of all bounded sequences
\[
    M = \qty{\{a_j\}_{j=1}^{\infty} \st \abs{a_j} < \infty}
\]
Define $\rho(\{a_n\},\{b_n\}) = \max_{n \in \N} \abs{a_n - b_n}$

\begin{definition}\label{def:metric}
    Function $d : X \cross X \to \R$ is considered a \underline{\emph{metric}}
    if it satisfies all of the following:
    \begin{enumerate}
        \item Non-negativity:
            \[d(a,b) \geq 0\]
        \item Symmetry:
            \[d(a,b) = d(b,a)\]
        \item Triangle Inequality:
            \[d(a,c) \leq d(a,b) + d(b,c)\]
    \end{enumerate}
\end{definition}

\subsection{Show that $(M,\rho)$ is a metric space.}

\begin{theorem}
    Let $M$ be defined as the set of all bounded sequences:\[
        M = \qty{\{a_j\}_{j=1}^{\infty} \st \abs{a_j} < \infty}
    \]
    Let the metric $\rho$ be defined on $M$ such that\[
        \rho(\{a_n\},\{b_n\}) = \max_{n\in\N} \abs{a_n - b_n}
    \]
    The metric space $(M, \rho)$ is in fact a metric space.
    \begin{proof}
        From Definition \ref{def:metric}, $\rho$ is a metric if
        $\forall_{\{a_n\},\{b_n\},\{c_n\}} \in M$
        these three conditions are all satisfied:
            (i) non-negativity,
            (ii) Symmetry, and
            (iii) Triangle Inequality.
        \begin{enumerate}
            \item Non-negativity:
            \begin{align*}
                d(a,b) &\geq 0\\
                \rho(\{a_n\},\{b_n\}) = \max_{n \in \N} \abs{a_n - b_n} &\geq 0\\
            \end{align*}
            \item Symmetry:
            \begin{align*}
                d(a,b) &= d(b,a)\\
                \rho(\{a_n\},\{b_n\}) = \max_{n \in \N} \abs{a_n - b_n}
                    &= \max_{n \in \N} \abs{b_n - a_n} = \rho(\{a_n\},\{b_n\})
            \end{align*}
            \item Triangle Inequality:
            \begin{align*}
                d(a,c) &\leq d(a,b) + d(b,c)\\
                \rho(\{a_n\},\{c_n\})
                    &\leq \rho(\{a_n\},\{b_n\}) + \rho(\{b_n\},\{c_n\})\\
                \max_{n \in \N} \abs{a_n - c_n}
                    \leq \max{n \in \N} \abs{a_n - b_n} + \abs{b_n - c_n}
                    &\leq \max_{n \in \N} \abs{a_n - b_n}
                        + \max_{n \in \N} \abs{b_n - c_n}
            \end{align*}
        \end{enumerate}
    \end{proof}
\end{theorem}

\newpage
\subsection{Show that $M$ does not contain a dense countable subset.}

% (Hint: recall the very first example of uncountable set...)

\begin{definition}\label{def:closure}
    The \underline{\emph{Closure}}, $\overline{A}$, of $A \subset X$ is defined as
    \[
        \overline{A} = A \cup \qty{
            \lim_{n\to\infty} a_n \st a_n \in A \forall_{n \in \N}
        }
    \]
\end{definition}

\begin{definition}\label{def:dense}
    A set $A \subset X$ is considered \underline{\emph{dense}} in $X$ if $\overline{A} = X$.
\end{definition}

\begin{theorem}\label{thm:cantor}
    For the power set, $\mathcal{P}(A)$,
    defined as the collections of all sets constructed from the elements of $A$,
    then the cardinality of $\mathcal{P}(A)$ will always be strictly greater then that of $A$.
    i.e.\[
        \abs{2^{A}} > \abs{A}
    \]
    \begin{itemize}
        \item This is also applicable to infinite sets with whether it is countable or not.
        i.e\[
            \abs{2^\N} = \aleph_1 > \abs{\N} = \aleph_0
        \]
        \item The theorem itself is that any mapping from $A$ to $\mathcal{P}(A)$ is not surjective which is then proven false.
        It then follows that $f : A \toI \mathcal{P}(A)$ is injective,
        which is equivalent to saying that $\abs{A} < \abs{\mathcal{P}(A)}$.
    \end{itemize}
\end{theorem}

\begin{theorem}
    $M$ does not contain any dense countable subsets.
    \begin{proof}
        Proof by contradiction inspired by Cantor's Theorem (\ref{thm:cantor}).

        Let $A_N \subset M$ be defined as
        \[
            A_N := \{\{a_j\}_{j=1}^{\infty} \st \abs{a_j} < N\}
        \]

        Similarly to Cantor's theorem, even when restricting $a_j$ from a finely sized set,
        the only mapping that exists from a countable set into $A_n$ are strictly injective.

        Next, taking $A = \lim_{N \to \infty} A_N$,
        we will prove that in order for $A$ to be dense, $A$ would no longer be countable.

        From Definition \ref{def:closure} and Definition \ref{def:dense},
        it is known that in order for $A$ to be dense within $M$,
        $\overline{A} = M$.
        Since $M$ itself is an infinite set,
        even if for sequences of a finite set of numbers,
        $A$ would become infinite and ultimately uncountable with $\abs{A} \leq \abs{M}$.
    \end{proof}
\end{theorem}

% Problem 4 ----------------------------------------------
\newpage
\section{}
Does there exist a metric space, containing a sequence of nested bounded closed sets
$F_1 \supset F_2 \supset \cdots \supset F_n \supset \cdots$
such that
\[
    \bigcap_{n \in \N} F_n = \emptyset
\]
Hint: If $d(x,y)$ is a usual Euclidean metric on $\R$,
one can shown that $\frac{d(x,y)}{1 + d(x,y)}$ is also a metric.
Such metric is often called a bounded metric...

\begin{definition}
    The set $A$ in metric space $(X,d)$ is considered \emph{\underline{open}} if
    \[
        \forall_{x \in A} \exists_{\epsilon > 0} \st \forall_{y \in X} d(x,y)<\epsilon
    \]
\end{definition}

\begin{definition}
    The set $A$ in metric space $(X,d)$ is considered \emph{\underline{closed}} if the set $A^c$ is open.
\end{definition}

\begin{definition}
    The set $A$ in metric space $(X,d)$ is called \emph{\underline{bounded}} if
    \[
        \forall_{x \in A} \exists_{R>0} \st \forall_{y\in A} d(x,y) < R
    \]
\end{definition}

\begin{theorem}
    There does exist a metric space $(X,d)$
    containing the sequence of nested bounded closed sets
    $F_1 \supset F_2 \supset \cdots \supset F_n \supset \cdots$
    such that \[
        \bigcap_{n \in \N} F_n = \emptyset
    \]
    \begin{proof}
        Let the metric space $(X,d)$ be defined with\[
            X := \R \backslash \{0\}
        \]
        and endowed with the Euclidean metric $d : \R \cross \R$ defined by:\[
            d(x,y) := \sqrt{(x-y)^2}
        \]

        Let $F_1 \subset X$ be defined for:\[
            F_1 := B_{r_1}(0) = \qty{
                x \in X \st d(0,x) \leq r_1
            }
        \]
        where $r_1$ is initialized arbitrarily large.

        For $n = 2, 3, \dots$,
        $F_n \supset \cdots \supset F_2 \subset F_1 \subset X$ is defined by:
        \[
           F_n := B_{r_n}(0) = \qty{
               x \in X \st d(0,x) \leq r_n
           }
        \]
        where $r_{n+1} = \frac{r_n}{1+r_n}$.

        Finally, the solution is very obvious that the origin is the only limit point of the intersection.\[
            \lim_{N \to \infty} \cap_{n < N} F_n = \{0\}
        \]
        However, within this particular metric space, where $X = \R \backslash \{0\}$, this limit is not within the sets themselves.
        Therefore,
        \[
            \cap_{n \in \N} F_n = 0
        \]
    \end{proof}
\end{theorem}

% Problem 5 ----------------------------------------------
\newpage
\section{}
Show that there exists a unique continuous function,
$f(x)$ on the interval $[0,1]$,
satisfying the equation
\[
    f(x) = \int_{0}^{1} \sin(x^2 + y^ 2) f(y) \dd y
\]

\begin{theorem}
    There exists a unique continuous function $f : [0,1] \to \R$
    that satisfies the following equation
    \begin{equation}\label{eq:pblm5}
        f(x) = \int_{0}^{1} \sin(x^2 + y^ 2) f(y) \dd y
    \end{equation}
    \begin{proof}
        I'll prove that the is only a single solution by essentially treating the integral statement as a set of systems of equations (but with an operator) and then demonstrate that the solution function is unique as a contradiction would occur otherwise.

        Let $T$ be a functional mapping of the $f(y)$ to $f(x)$,
        $T : \mathbb{C}([0,1]) \to \mathbb{C}([0,1])$, defined as:
        \[
            T(f(y)) := \int_{0}^{1} \sin(x^2 + y^ 2) f(y) \dd{y}
        \]

        Now we take $T(f(x)) = f(x)$ and make the claim $f(x)$ is not unique.
        This would mean that $T(g(x)) = g(x)$ is another solution.
        If there are multiple solutions, then the following would be true:
        \begin{align*}
            T(f(x)) - f(x)
                &= T(g(x)) - g(x)\\
            \int_{0}^{1} \sin(x^2 + y^2) f(y) \dd{y} - f(x)
                &= \int_{0}^{1} \sin(x^2 + y^2) g(y) \dd{y} - g(x)\\
            f(x) - g(x)
                &= \int_{0}^{1} \sin(x^2 + y^2) f(y) \dd{y}
                - \int_{0}^{1} \sin(x^2 + y^2) g(y) \dd{y}\\
            f(x) - g(x)
                &= \int_{0}^{1} \sin(x^2 + y^2) (f(y) - g(y)) \dd{y}
            \intertext{Since $\abs{\sin{x}}\leq 1 \implies \int_0^1 \sin(x) \dd{x} < 1$,}
                &< \int_{0}^{1} (f(y) - g(y)) \dd{y} \leq
            \intertext{Since we can look at the integral over the region as less then the maximum value times the width:}
                &\leq (1-0) \sup_{y \in [0,1]} (f(y) - g(y))\\
            f(x) - g(x)
                & < \sup_{y \in [0,1]} (f(y) - g(y))
        \end{align*}
        Which is not possible, leading to the claim that two solutions exist to be false.
    \end{proof}
\end{theorem}

% Problem 6 ----------------------------------------------
\newpage
\section{}
Let $V$ be a complete metric space without isolated points.
Show that $V$ is uncountable $(\abs{V} > \abs{\N})$.

\begin{definition}\label{def:complete_cauchy_limit}
    A metric space $(X,d)$ is considered \emph{\underline{Complete}}
    if every Cauchy sequence of points in $X$ has a limit within $X$.
    \begin{itemize}
        \item A sequence $x_1, x_2, \dots$ in metric space $(X,d)$
        is considered \emph{\underline{Cauchy}} if
        \[
            \forall_{r > 0} \exists_N \st \forall_{m,n > N} d(x_m,x_n) < r
        \]
        \item $x$ is the \underline{\emph{limit}} of sequence ($x_n$),
        $\lim_{n \to \infty} x_n$, if
        \[
            \forall_{\epsilon>0} \exists_{N \in \N} \st \forall_{n\geq N} \abs{x_n - x} < \epsilon
        \]
    \end{itemize}
\end{definition}

\begin{definition}\label{def:isolated_points}
    A point within metric space $(X,d)$ is considered an
    \emph{\underline{isolated point}} of set $A \subset X$
    in which no other points are within the neighborhood of $x$.
    i.e.\[
        \exists_{\epsilon>0} \st \forall_{y \in X}
            \st d(x,y) < \epsilon y \implies \not \in A
    \]
    \begin{itemize}
        \item A complete set $A$ that contains no isolated points is called
            \emph{\underline{dense-in-itself}}.
    \end{itemize}
\end{definition}

\begin{definition}\label{def:sur/in/bijective_funcs}
    A \emph{\underline{one to one correspondance}} is also known as a
    bijective function that maps $\N \to X$.
    \begin{itemize}
        \item A function $f : \N \to A$ is said to be \underline{\emph{surjective}} if\[
            \exists_{f : \N \toS A} \iff
            \exists_{f : \N \to A} \st \forall_{x \in \N} \exists f(x) \in A
        \]

        \item A function $f : \N \to A$ is said to be \underline{\emph{injective}} if\[
            \exists_{f : \N \toI A} \iff
            \exists_{f : \N \to A} \st \forall_{f(x) \in A} \exists_{x \in \N}
        \]

        \item A function $f : A \to B$ is said to be \underline{\emph{bijective}}
        if $f$ is both surjective and injective.
        i.e.\[
            \exists_{f : A \toB B} \iff
            \exists_{f : A \to B} \st
                \qty(\forall{x \in A} \exists_{f(x) \in B}) \land
                \qty(\forall{y \in B} \exists_{f^{-1}(y) \in A})
        \]
    \end{itemize}
\end{definition}

\begin{definition}\label{def:cardinalityAndCountable}
    The \emph{\underline{Cardinality}} of set $A$,
        denoted as $\abs{A}$,
        is the number of unique elements contained within $A$.
    \begin{itemize}
        \item A set $A$ is considered \emph{\underline{Countable}} if $\abs{A} \leq \abs{\N}$.
        This is also said to be true if a surjective function exists mapping $\N$ to $A$.

        \item Set $A$ and $B$ within metric space $(X,d)$ are said be of the same cardinality,
        $\abs{A}=\abs{B}$,
        if there exists a bijective mapping between $A$ and $B$, $f : A \toB B$.

        \item If $A$ is an infinite set, then $A$ is \emph{\underline{Countably Infinite}},
        $\abs{A} = \aleph_0 = \abs{\N}$,
        if there exists a one to one correspondence from $\N$ to $A$.

        \item For $A$ A set $A$ is considered \emph{\underline{uncountable}} if it is not countable.
        i.e. $\abs{A} > \abs{\N}$.
        This is also said to be true if an injective function exists mapping $\N$ to $A$,
        but that no surjective mappings exist.
    \end{itemize}
\end{definition}

\begin{theorem}
    A complete metric space, $(V,d)$, that contains no isolated point is uncountable.
    \begin{proof}
        From Definition \ref{def:complete_cauchy_limit},
        we have that all cauchy sequences in the complete metric space $(X,d)$ must have a limit in $X$.

        From Definition \ref{def:cardinalityAndCountable},
        it is known that within all countable sets there exists a one-to-one correspondence between $\N$ and the set $A$.

        For $A$ to be uncountable, an injective function mapping $\N$ to $A$, there exists, $f : \N \toI A$.

        From Definition \ref{def:sur/in/bijective_funcs}, this means that
        $\forall_{f(x) \in A} \exists_{x \in \N}$,
        however, since $\N$ is not a complete set, it is not possible for a one-to-one correspondence to exist.
        Therefore, the set is not countable and therefore uncountable.
    \end{proof}
\end{theorem}

\end{document}


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{physics}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{graphicx,wrapfig,lipsum}
\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\bea}{\begin{flalign*}}
\newcommand{\eea}{\end{flalign*}}

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Assignment\ \#3}
\newcommand{\hmwkDueDate}{Due on 23rd October, 2018}
\newcommand{\hmwkClass}{Fluid Mechanics}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{}
\newcommand{\hmwkAuthorName}{\textbf{Aditya Vijaykumar}}

%
% Title Page
%

\title{
    %\vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{\hmwkDueDate\ }\\
%    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle
\textbf{Acknowledgements} - I thank Saumav Kapoor for discussions.

%\pagebreak
\begin{homeworkProblem}[1]
	\textbf{Part (a)}\\
	The unsteady state Bernoulli equation tells us that,
	\begin{align*}
	\pdv{\phi}{t} + \dfrac{P_{atm}}{\rho} + \dfrac{v^2}{2} + gz &= constant\\
	\pdv{v}{t} + v\pdv{v}{y} + g &= 0
	\end{align*}
	where we have differentiated with $ y $ going from the first to the second line.

	From the geometry of the cone, we have,
	\begin{align*}
	r_1 &= r_0 +y \tan \alpha\\
	\pi r_1^2 &= \pi r_0^2 + \pi y^2 \tan^2 \alpha + 2\pi r_0 y \tan \alpha\\
	A_1 &= \pi r_0^2 + \pi y^2 \tan^2 \alpha + 2 \sqrt{A \pi } y \tan \alpha	\end{align*}
	From this and the continuity equation, we get,
\begin{align*}
v = \dfrac{r_0^2}{\beta^2}v_0 \qq{, } \beta^2 = r_0^2 +  y^2 \tan^2 \alpha + 2 r_0 y \tan \alpha
\end{align*}
Substituting back into earlier equation,
\begin{equation*}
\dfrac{r_0^2}{\beta^2}\pdv{v_0}{t} - \dfrac{r_0^2}{\beta^2} v_0^2 \dfrac{r_0^2}{\beta^4} (2y \tan \alpha + 2 r_0 \tan \alpha) + g = 0
\end{equation*}
The above equation holds for all $ y $ and specifically $ y=0 $. Let's put $ y=0$ and $ \beta^2 = r_0^2 $,
\begin{equation*}
	\pdv{v_0}{t} - \dfrac{2}{r_0} v_0^2 \tan \alpha + g = 0
\end{equation*}
Solving this gives,
\begin{equation*}
v_0 = \sqrt{\dfrac{gr_0}{2 \tan \alpha}} \coth\qty( \sqrt{\dfrac{2g\tan \alpha}{r_0}}t + C)
\end{equation*}
All that is left is to evaluate the constant $ C $.

We go back to the continuity equation, which says,
\begin{equation*}
\pi (y + y_0)^2 v(y,t) \tan^2 \alpha = K(t) \implies v(y,t) = \dfrac{K(t)}{\pi (y+y_0)^2  \tan^2 \alpha } \implies \phi(y,t) = -\dfrac{K(t)}{\pi (y+y_0) \tan^2 \alpha}
\end{equation*}
Writing Bernoulli between points $ y=h $ and $ y=r_0 \tan \alpha $,
\begin{align*}
	-\dfrac{K'}{\pi (h+y_0) \tan^2 \alpha} + \dfrac{K^2}{2\pi^2 \tan^4 \alpha h^4} + gh &= -\dfrac{K'}{\pi (y_0) \tan^2 \alpha} + \dfrac{K^2}{2\pi^2 \tan^4 \alpha r_0^4}
\end{align*}
Substituting $ K(t) = v_0 \pi r_0^2 \tan^2 \alpha $, we can get an expression for the constant $ C $ in terms of height $ h $.

\textbf{Part (b)}\\
We know that,
\begin{equation*}
\dv{V}{t} = Q \implies t = \int \dfrac{dV}{Q}
\end{equation*}
\begin{align*}
\therefore t_1  =  \int \dfrac{dV_1}{Q_1} &\qq{ } t_2  =  \int \dfrac{dV_2}{Q_2}\\
t_1  =  \int \dfrac{\pi h^2 dh}{A_1 \sqrt{2gh}} &\qq{ } t_2  =  \int \dfrac{\pi h^2 dh}{A_2 \sqrt{2gh}}\\
t_1 - t_2  = \qty(\dfrac{1}{A_1} - \dfrac{1}{A_2})&\int \dfrac{\pi h^2 dh}{\sqrt{2gh}} \implies \qq{tank with larger base area will drain faster}
\end{align*}
\end{homeworkProblem}

\begin{homeworkProblem}[2]
	We first write the Bernoulli equation for between the point where water leaves the tap $ (z_1=0) $ and a point distance $ h $ below $ (z_2=-h) $,
	\begin{equation*}
	\dfrac{P_0 }{\rho} + \dfrac{v_1^2}{2} = \dfrac{P_0 }{\rho} + \dfrac{v_2^2}{2} - gh  \implies \dfrac{v_2^2}{v_1^2} = 1 + \dfrac{2gh}{v_1^2}
	\end{equation*}
	The continuity equation gives,
	\begin{equation*}
	\pi r_1^2 v_1 = \pi r_2^2 v_2 \implies \dfrac{v_2}{v_1} = \dfrac{r_1^2}{r_2^2}
	\end{equation*}
	Using the above two equations, we get,
	\begin{equation*}
	\dfrac{r_1^4}{r_2^4} = 1 + \dfrac{2gh}{v_1^2} \implies \boxed{\dfrac{R_0^4}{r^4} = 1 + \dfrac{2gH}{v_0^2}}
	\end{equation*}
	where $ r $ is the cross-sectional radius at height $ H $ below the tap, and $ R_0 $ and $ v_0 $ and the cross-sectional radius and velocity of the water the moment it leaves the tap.

\end{homeworkProblem}

\begin{homeworkProblem}[3]
	We work in cylindrical coordinates. The assumption of laminar flow $ \implies u_r = u_\phi = 0 $. The assumption of axisymmetry $ \implies u_z = u_z(r, z) $ The continuity condition $ \div{\va{u}} = 0$ gives,
	\begin{equation*}
	\pdv{u_z}{z} = 0 \implies u_z = u_z(r)
	\end{equation*}
	We now proceed and write the Navier-Stokes equation in cylindrical coordinates component-wise,
	\begin{align*}
	0 &= -\dfrac{1}{\rho}\pdv{P}{r}\\
	0 &= -\dfrac{1}{\rho r}\pdv{P}{\phi}\\
	0 &= -\dfrac{1}{\rho}\pdv{P}{z} + \nu \dfrac{1}{r} \pdv{r} \qty(r \pdv{u_z}{r})
	\end{align*}
	We can see from the first two equations that $ P = P(z) $. In the third equation, since the first term on the RHS depends only on $ z $ and the second term depends only on $ r $, we say that each of the terms should be constants. We get,
	\begin{align*}
	 \dfrac{1}{r} \dv{r} \qty(r \dv{u_z}{r}) &= \dfrac{1}{\mu}\dv{P}{z} = constant\\
	 \dv{r} \qty(r \dv{u_z}{r}) &= \dfrac{r}{\mu}\dv{P}{z}\\
	 \implies r \dv{u_z}{r} &= \dfrac{r^2}{2\mu}\dv{P}{z} + A\\
	 \implies \dv{u_z}{r} &= \dfrac{r}{2\mu}\dv{P}{z} + \dfrac{A}{r}\\
	 \implies {u_z} &= \dfrac{r^2}{4\mu}\dv{P}{z} + A \ln r + B\\
	\end{align*}
	We need the flow to be well-defined at $ r=0 $. As it stands, for non-zero $ A $, the flow will not be well-defined for $ r=0 $, which is undesirable. Hence, $ A=0 $.

	If $ R $ is the radius of the pipe, and the pipe is not moving, we get $ u_z(R) = 0 $, which means,
	\begin{equation*}
	0 = \dfrac{R^2}{4\mu}\dv{P}{z} + B \implies B = - \dfrac{R^2}{4\mu}\dv{P}{z}
	\end{equation*}
	So the final answer is,
	\begin{equation*}
	u_z = \dfrac{1}{4 \mu} \dv{P}{z} (r^2 - R^2)
	\end{equation*}
\end{homeworkProblem}

\begin{homeworkProblem}[4]
	We solve the problem for a two-dimensional jet. The orthogonal directions are taken to be $ x $ and $ y $. We assume that steady state.

	The Continuity equation gives us,
	\begin{equation*}
	\pdv{u}{x} + \pdv{v}{y} = 0 \implies u\pdv{u}{x} + u\pdv{v}{y} = 0
	\end{equation*}
	The $ x $-component of the Navier-Stokes gives us,
	\begin{equation}
	u \pdv{u}{x} + v \pdv{u}{y} = \nu \pdv[2]{u}{y}
	\label{xns}
	\end{equation}

	Adding up the two equations, one has,
	\begin{align*}
		2u \pdv{u}{x} + v \pdv{u}{y} + u \pdv{v}{y}  &= \nu \pdv[2]{u}{y}\\
		\pdv{(u^2)}{x} + \pdv{(uv)}{y} &= \nu \pdv[2]{u}{y}
	\end{align*}
	Integrating both sides with respect to $ y $,
	\begin{equation*}
	\pdv{x} \int_{-\infty}^{\infty} u^2 dy + \eval{uv}_{-\infty}^{\infty} = \nu \eval{\pdv{u}{y}}_{-\infty}^\infty
	\end{equation*}
	We now would like to impose boundary conditions. The velocity is purely along the $ x $-axis at $ y = 0 $. As $ y \rightarrow \pm \infty $, both $ u \rightarrow 0  $ and $ v $ $ \rightarrow 0 $, and so do their derivatives.

	We then have,
	\begin{equation}
	\pdv{x} \int_{-\infty}^{\infty} u^2 dy = 0 \implies \int_{-\infty}^{\infty} u^2 dy = constant = M
	\label{conserv}
	\end{equation}
	We now try to guess the form of the similarity solution for this problem. Let's assume,
	\begin{equation}
	x \rightarrow \lambda^a x' \qq{ } y \rightarrow \lambda^b y' \qq{ } \psi \rightarrow \lambda^c \psi'
	\label{ansatz}
	\end{equation}
	Using the fact that $ u = \psi_y $ and $ v = -\psi_x $, one can write (\ref{xns}) as,
	\begin{equation}
	\psi_y \psi_{xy} - \psi_{x}\psi_{yy} = \nu \psi_{yyy}
	\label{psixns}
	\end{equation}
	and (\ref{conserv}) as,
	\begin{equation}
	\int_{-\infty}^{\infty} \psi_y^2 dy = M
	\label{psiconserv}
	\end{equation}
	Substituting (\ref{ansatz}) into (\ref{psixns}) and (\ref{psiconserv}), we get,
	\begin{align*}
	2c - 2b - a &= c - 3b \implies a = b + c \qq{and} \\
	2(c-b) + b &= 0 \implies b = 2c
	\end{align*}
	Solving which we get,
	\begin{equation*}
	b = \dfrac{2a}{3} \qq{ } c = \dfrac{a}{3}
	\end{equation*}
	and the final form being,
	\begin{equation*}
		x \rightarrow \lambda^a x' \qq{ } y \rightarrow \lambda^{2a/3} y' \qq{ } \psi \rightarrow \lambda^{a/3} \psi'
	\end{equation*}
	This suggests that,
	\begin{equation*}
	\dfrac{\psi }{ x^{1/3} }\sim f\qty(\dfrac{y}{x^{2/3}}) \implies \psi = A x^{1/3}f(\eta)
	\end{equation*}
	where $ \eta = \dfrac{y}{x^{2/3}}$. We note the following,
	\begin{align*}
	\psi_y &= A x^{1/3}f'(\eta) \dv{\eta}{y} \\
	&= A x^{-1/3}f'\\
	\psi_x &= \dfrac{A}{3}x^{-2/3}f(\eta) + A x^{1/3}f'(\eta)\dv{\eta}{x}\\
	&=\dfrac{A}{3}x^{-2/3}f(\eta) - \dfrac{2A}{3} x^{-2/3}f'(\eta)\eta\\
	&= \dfrac{Ax^{-2/3}}{3}(-2 \eta f'+f)\\
	\psi_{xy} &= \dfrac{Ax^{-4/3}}{3}(-2 \eta f'' - f')\\
	\psi_{yy} &=  A x^{-1}f''\\
	\psi_{yyy} &=  A x^{-5/3}f'''
	\end{align*}
	Putting all this into (\ref{psixns}), we get,
	\begin{equation*}
	-f'(-2 \eta f''+f') - (-2 \eta f'+f)f'' = \dfrac{3\nu}{A} f''' \implies \dfrac{3\nu}{A} f''' + f'^2 + f''f = 0
	\end{equation*}
	If we set $ A =  \nu $ (we can always do that since it is an arbitrary constant), we get our final answer,
	\begin{equation*}
	3 f''' + f'^2 + f''f = 0
	\end{equation*}
\end{homeworkProblem}

\end{document}


\hypertarget{program-verification}{%
\section{Program Verification}\label{program-verification}}

\begin{itemize}
\tightlist
\item
  What are the basic ideas of verification?

  \begin{itemize}
  \tightlist
  \item
    the problem of erroneous software; correctness; knowing correctness;
    specification and implementation
  \end{itemize}
\item
  Basic theory of verifying imperative programs
\item
  An in principle understanding of verification technology
\item
  at the end, students should be in a good starting position for using
  actual verification tools like Dafny
\item
  besides that, knowing these points increases one's repertoire of
  possibilities to think about software
\end{itemize}

\hypertarget{software-qualities}{%
\subsection{Software Qualities}\label{software-qualities}}

\begin{itemize}
\tightlist
\item
  Reliability: correctness, robustness

  \begin{itemize}
  \tightlist
  \item
    efficiency, usability etc. irrelevant as long as software is not
    reliable
  \end{itemize}
\item
  Dependability: knowing that software is reliable

  \begin{itemize}
  \tightlist
  \item
    reliability itself is not enough --- we must know that software is
    reliable
  \end{itemize}
\end{itemize}

\hypertarget{iml}{%
\subsection{IML}\label{iml}}

\begin{itemize}
\tightlist
\item
  IML is a simple imperative programming language augmented with
  specification constructs
\item
  under development for this course to demonstrate the basic principles
  of program verification
\item
  its only data types are integers and booleans
\item
  IML: Imperative Mini Language
\end{itemize}

\begin{lstlisting}
specification
requires a >= 0
modifies r
ensures r*r <= a && a < (r+1)*(r+1)
\end{lstlisting}

\begin{itemize}
\tightlist
\item
  the requires clause declares a precondition
\item
  the modifies clause declares a framecondition

  \begin{itemize}
  \tightlist
  \item
    this is a list of variables that are allowed to be changed, but the
    central idea is that all other variables remain constant
  \end{itemize}
\item
  the ensures clause declares a postcondition
\end{itemize}

This IML statements declare actually followin code:

\begin{lstlisting}
int f(int a)
{
    int t, s, i;
    t= 1; s= 1; i= 0;
    while (s <= a) {
        t= t + 2;
        s= s + t;
        i= i + 1;
    }
    return i;
}
\end{lstlisting}

\hypertarget{example}{%
\subsubsection{Example}\label{example}}

We skipped somehow the most of the grammar in IML, but we took a look in
the following example (not in detail).

\begin{lstlisting}
specification
    requires a > 0 && b > 0
    modifies x
    ensures x = gcd(a, b)
implementation
    x := a;
    y := b;
    while x != y
        invar gcd(x, y) = gcd(a, b) && x > 0 && y > 0
    do
        if x > y then
            x := x - y
        else
            y := y - x
        end
    end
\end{lstlisting}

\begin{itemize}
\tightlist
\item
  gcd(a, b) denotes the greatest common divisor of a and b
\item
  we use gcd in the postcondition to specify that our program computes a
  gcd
\item
  we use gcd in the while loop (after invar) for verification purposes
\item
  the meaning of invar in the while loop will be carefully discussed
  later
\item
  Note: the red phrases are assertions; those containing gcd could not
  occur as boolean expressions in if or while (see grammar!)
\end{itemize}

\clearpage
\hypertarget{specification-vs.implementation}{%
\subsubsection{Specification
vs.~Implementation}\label{specification-vs.implementation}}

\begin{itemize}
\tightlist
\item
  the specification describes what the function does without explaining
  how to do it
\item
  the implementation describes how to compute the function without
  explaining what the result will be
\end{itemize}

When we need both specification and implementation, then simply let us
put both of them together to form the program.

Specification AND implementation in Dafny:

\begin{lstlisting}
method NatSquareRootA(a:int) returns (r:int)
    requires a >= 0;
    ensures r*r <= a < (r+1)*(r+1);
{
    var d:int;
    var s:int;
    d := 1; // oDd
    s := 1; // Square
    r := 0; // Root
    while (s <= a)
        invariant d == 2*r + 1;
        invariant s == (r+1)*(r+1);
        invariant r*r <= a;
    {
        d := d + 2;
        s := s + d;
        r := r + 1;
    }
}
\end{lstlisting}

\hypertarget{dafny}{%
\subsection{Dafny}\label{dafny}}

Dafny is a specification and implementation language to proving the
correctness of an implementation against a specification.

Since very special knowledge is needed for developing an implementation
from a specification, it is not reasonable to assume that it could be
possible to construct a compiler that compiles a specification into
executable code.

\hypertarget{validation-vs-verification}{%
\subsection{Validation vs
Verification}\label{validation-vs-verification}}

\textbf{Validation}: Does the specification fulfill the requirements?\\
\textbf{Verification}: Does the implementation fulfill the
specification?

\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{figures/validationverification.png}
\caption{Validation and Verification}
\end{figure}

Focus on verification:

\begin{itemize}
\tightlist
\item
  Specification and implementation

  \begin{itemize}
  \tightlist
  \item
    two descriptions of the same problem, and that with different points
    of view
  \item
    redundancy
  \end{itemize}
\item
  How to Know Consistency?

  \begin{itemize}
  \tightlist
  \item
    Testing
  \item
    Proving
  \item
    Combination of both
  \end{itemize}
\end{itemize}

\hypertarget{testing}{%
\subsubsection{Testing}\label{testing}}

\begin{itemize}
\tightlist
\item
  program will be executed on chosen input
\item
  is output consistent with specification?

  \begin{itemize}
  \tightlist
  \item
    yes: no (nearly no) knowledge gained
  \item
    no: now we know more: that the program contains an error
  \end{itemize}
\end{itemize}

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]
\textbf{Dijkstra's famous statement} \\
"The number of different inputs, i.e. the number of different computations for which the assertions claim to hold is so fantastically high that demonstration of correctness by sampling is completely out of the question. Program testing can be used to show the presence of bugs, but never to show their absence!"
\end{tcolorbox}

In other words: A successful industrial acceptance test does not mean
that a software product is free of errors; it just means that the
customer has to pay

\hypertarget{proving}{%
\subsubsection{Proving}\label{proving}}

\begin{itemize}
\tightlist
\item
  program will not be executed
\item
  rather we try to find a mathematical proof
\item
  do we find a proof?

  \begin{itemize}
  \tightlist
  \item
    yes: now we know that the program is correct
  \item
    no: we know that the program might contain errors, or a good idea
    for the proof is (still) missing
  \end{itemize}
\end{itemize}

\hypertarget{testing-and-proving}{%
\subsubsection{Testing and Proving}\label{testing-and-proving}}

\begin{itemize}
\tightlist
\item
  Testing: good for finding bugs
\item
  Proving: good for showing that there are no bugs
\item
  good practical method:

  \begin{itemize}
  \tightlist
  \item
    first: test your program to find as many errors as possible
  \item
    then: try to prove your program correct
  \end{itemize}
\end{itemize}

\clearpage
\hypertarget{state}{%
\subsection{State}\label{state}}

\begin{itemize}
\tightlist
\item
  the distinguishing feature of any imperative programming language is
  the explicit manipulation of state
\item
  the state of an imperative program can be modelled as a function that
  maps the variables (VAR) of a program to their current contents (VAL):

  \begin{itemize}
  \tightlist
  \item
    STATES = VAR -\textgreater{} VAL
  \item
    $\sigma$1, $\sigma$2, $\sigma$3, $\sigma$4 : STATES
  \end{itemize}
\end{itemize}

\begin{lstlisting}
$\sigma$1(x) = 17, $\sigma$1(y) = 5
x := x - y;
$\sigma$2(x) = 17 - 5 = 12, $\sigma$2(y) = 5
y := x + y;
$\sigma$3(x) = 12, $\sigma$3(y) = 12 + 5 = 17
x := y - x
$\sigma$4(x) = 17 - 12 = 5, $\sigma$4(y) = 17
\end{lstlisting}

\hypertarget{boolean-expressions}{%
\subsection{Boolean Expressions}\label{boolean-expressions}}

\begin{itemize}
\tightlist
\item
  given a boolean expression and a state

  \begin{itemize}
  \tightlist
  \item
    boolean expression either true or false
  \end{itemize}
\item
  condition in if or while command

  \begin{itemize}
  \tightlist
  \item
    condition will be evaluated; yields either true or false
  \end{itemize}
\item
  condition as assert command

  \begin{itemize}
  \tightlist
  \item
    should always yield true; if it does not, the program is in error
  \end{itemize}
\end{itemize}

\hypertarget{assertions}{%
\subsection{Assertions}\label{assertions}}

\begin{itemize}
\tightlist
\item
  in programming languages like Java, the assert commands contain
  boolean expressions that can be evaluated at run time
\item
  in verification languages like IML or Dafny, the assert commands
  contain assertions
\item
  an assertion describes a set of states: the set of all states that
  satisfy the assertion

  \begin{itemize}
  \tightlist
  \item
    the assertion `x \textgreater{} 5' describes the set of all states
    with $\sigma$(x) \textgreater{} 5, for example
  \item
    $\sigma$1 with $\sigma$1(x) = 6 and $\sigma$1(y) = 25, or
  \item
    $\sigma$2 with $\sigma$2(x) = 17 and $\sigma$2(y) = 35
  \item
    the assertion `true' describes the set of all states that satisfy
    true, that is, the full set of all possible states
  \end{itemize}
\end{itemize}

\hypertarget{implication}{%
\subsection{Implication}\label{implication}}

\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{figures/implication.png}
\caption{Implication}
\end{figure}

\begin{itemize}
\tightlist
\item
  ``If I win, I'll eat my hat.''
\item
  is true

  \begin{itemize}
  \tightlist
  \item
    if I do not win (independent of what I will do with my hat) --- ex
    falso quodlibet
  \item
    if I win and I eat my hat
  \end{itemize}
\item
  is false

  \begin{itemize}
  \tightlist
  \item
    if I win but I do not eat my hat
  \end{itemize}
\end{itemize}

\begin{figure}[H]
\centering
\includegraphics[width=0.7\textwidth]{figures/implication2.png}
\caption{Implication 2}
\end{figure}

\begin{itemize}
\tightlist
\item
  implication has nothing to do with causal relations; just the truth
  table matters
\item
  if A is false, the implication will always be true.
\end{itemize}

\clearpage
\hypertarget{weaker-and-stronger-conditions}{%
\subsubsection{Weaker and Stronger
Conditions}\label{weaker-and-stronger-conditions}}

\begin{itemize}
\tightlist
\item
  examples:

  \begin{itemize}
  \tightlist
  \item
    x = 5 $\land$ y = 7 -\textgreater{} x = 5
  \item
    x = 5 -\textgreater{} x = 5 $\lor$ y = 7
  \end{itemize}
\item
  P -\textgreater{} Q

  \begin{itemize}
  \tightlist
  \item
    P more restrictive than Q
  \item
    set of states given by P is subset of set of states given by Q
  \item
    P stronger than Q
  \item
    Q weaker than P
  \end{itemize}
\item
  boundary cases:

  \begin{itemize}
  \tightlist
  \item
    What is the strongest condition? --\textgreater{} False
  \item
    What is the weakest condition? --\textgreater{} True
  \end{itemize}
\end{itemize}

\hypertarget{validity-versus-truth}{%
\subsubsection{Validity Versus Truth}\label{validity-versus-truth}}

\begin{itemize}
\tightlist
\item
  A boolean formula B (for example an assertion or a Hoare triple) is
  valid if it is true in all states, written $\models$ B.

  \begin{itemize}
  \tightlist
  \item
    x + 5 = 5 + x is true in all states
  \item
    thus x + 5 = 5 + x is valid: $\models$ x + 5 = 5 + x
  \end{itemize}
\end{itemize}

\clearpage
\hypertarget{hoare-triples}{%
\subsection{Hoare Triples}\label{hoare-triples}}

A Hoare triple consists of

\begin{itemize}
\tightlist
\item
  an assertion P, called the \textbf{precondition} of the Hoare triple
\item
  a command C
\item
  an assertion Q, called the \textbf{postcondition} of the Hoare triple
\end{itemize}

\textit{Note: P and Q are the precondition and postcondition of the Hoare
triple, not precondition and postcondition of the command}

\begin{lstlisting}
{ x = 5 } x := x + 1 { x = 17 }
{ x > 5 } x := x + 1 { x > 6 }
{ j = 0 } while i = 0 do skip endwhile { k = 0 }
\end{lstlisting}

\begin{itemize}
\tightlist
\item
  a Hoare triple itself is a boolean formula, which can be true in some
  state and false in others
\item
  we call the state in which execution of C begins the \textbf{prestate}
  of that execution, and the resulting state its \textbf{poststate}, the
  latter provided that execution terminates
\end{itemize}

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]
((prestate satisfies P $\wedge$ execution of C terminates) $\Rightarrow$ poststate satisfies Q)
\end{tcolorbox}

\begin{itemize}
\tightlist
\item
  This means, if the prestate is wrong, the full Hoare tripple is true
  (since it's an implication)
\item
  The prestate also includes the termination of the program c. If the
  program doesn't terminate, everything is ok
\end{itemize}

\begin{figure}[H]
\centering
\includegraphics[width=0.6\textwidth]{figures/hoaretriple.png}
\caption{Hoare Triple example}
\end{figure}

\begin{itemize}
\tightlist
\item
  given the following Hoare triple:

  \begin{itemize}
  \tightlist
  \item
    \{ j = 0 \} while i = 0 do skip endwhile \{ k = 0 \}
  \end{itemize}
\item
  The example above describes all 8 kinds of prestates (i = 0 implies 2
  states each).
\item
  The example shows, that the hoare triple would be false in one
  prestate and thus the hoarse triple itself is not valid.
\end{itemize}

\hypertarget{conditional-or-partial-correctness}{%
\subsubsection{Conditional or Partial
Correctness}\label{conditional-or-partial-correctness}}

\begin{itemize}
\tightlist
\item
  A Hoare triple \{P\} C \{Q\} is called \textbf{valid}, written $\models$ \{P\}
  C \{Q\} if it is true in all prestates.
\item
  A Hoare triple is valid, If execution of command C begins in any state
  that satisfies the precondition P and execution terminates, then the
  resulting state satisfies the postcondition Q.
\item
  Note that a valid Hoare triple does not provide any information
  concerning the resulting state if execution begins in any state that
  does not satisfy the precondition.
\item
  We are only interested in valid Hoare triples.
\end{itemize}

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]
Examples: \\
– $\nvDash$ { x = 5 } x := x + 1 { x = 17 } (this is not valid, since the postcondition could not be met) \\
– $\models$ { x > 5 } x := x + 1 { x > 6 } \\
– $\nvDash$ { j = 0 } while i = 0 do skip endwhile { k = 0 }
\end{tcolorbox}

\hypertarget{total-vs.partial-correctness}{%
\subsubsection{Total vs.~Partial
Correctness}\label{total-vs.partial-correctness}}

\begin{itemize}
\tightlist
\item
  If the precondition is true, the execution terminates properly and the
  postcondition is true, the Hoare triple is called totally correct.
\item
  If you don't know if the execution terminates properly, but if it
  terminates the result is true, the Hoare triple is called partially
  correct.
\end{itemize}

\hypertarget{specification-of-imperative-programs}{%
\subsection{Specification of Imperative
Programs}\label{specification-of-imperative-programs}}

A specification for imperative programs should provide the following
information:

\begin{itemize}
\tightlist
\item
  a precondition P
\item
  a list x of variables that may be changed

  \begin{itemize}
  \tightlist
  \item
    with the important understanding that all other variables must not
    be changed
  \end{itemize}
\item
  a postcondition Q
\end{itemize}

We denote such a specification by \{P\} x:=? \{Q\}

\hypertarget{specification-for-integer-square-root}{%
\subsubsection{Specification for Integer Square
Root}\label{specification-for-integer-square-root}}

\begin{itemize}
\tightlist
\item
  English spec

  \begin{itemize}
  \tightlist
  \item
    Find an integer approximation to the square root of integer a.
  \end{itemize}
\item
  add precision

  \begin{itemize}
  \tightlist
  \item
    a $\geqslant$ 0
  \item
    store result in variable r
  \item
    choose largest integer r such that $r^2$ $\leqslant$ a
  \end{itemize}
\item
  formal spec

  \begin{itemize}
  \tightlist
  \item $\{0 \leqslant a\} r:=? \{r^2 \leqslant a < (r + 1)^2\}$
  \end{itemize}
\end{itemize}

It is important to list all the variables that are allowed to be changed
(r := ?). If we would not define that, we could change a to 0 to meet
the conditions.

\hypertarget{rigid-variables}{%
\subsubsection{Rigid Variables}\label{rigid-variables}}

Rigid variables can be introduced to connect the pre- and the
postconditions with variables that only occur in assertions and not in
the program.

\{ x = X \} x:=? \{ x = X + 6 \}

this means: for all values X, if x = X in the initial state and
execution terminates, then x = X + 6 in the final state.

\clearpage


\documentclass{article}

\usepackage{fullpage}
\usepackage{textcomp}
\usepackage{amsmath}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\cfoot{\sc Page \thepage\ of \pageref{end}}

\begin{document}

{\large \noindent{}University of Toronto at Scarborough\\
\textbf{CSC A67/MAT A67 - Discrete Mathematics, Fall 2015}}

\section*{\huge Exercise \#7: Proofs}

{\large Due: November 20, 2015 at 11:59 p.m.\\
This exercise is worth 3\% of your final grade.}\\[1em]
\textbf{Warning:} Your electronic submission on MarkUs affirms that this exercise is your own work and no
one else's, and is in accordance with the University of Toronto Code of Behaviour on Academic Matters,
the Code of Student Conduct, and the guidelines for avoiding plagiarism in CSC A67/MAT A67.\\[1ex]
This exercise is due by 11:59 p.m. November 20. Late exercises will not be accepted.\\[1ex]
\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\labelenumii}{(\alph{enumii})}
\begin{enumerate}
\item The\marginpar{[5]} \textit{greatest common divisor} of two positive integers $a$ and $b$ is the largest positive integer that divides both $a$ and $b$ (written $\gcd(a,b)$). For example, $\gcd(4,6)=2$ and $\gcd(5,6)=1$.
	\begin{enumerate}
	\item Prove that $\gcd(a,b) = \gcd(a,b-a).$
	\item Let $r=b\bmod a$. Using part \textbf{(a)}, prove that $\gcd(a,b) = \gcd(a,r)$.
	\end{enumerate}
\item Prove\marginpar{[4]} that $\sqrt[3]{5}$ is irrational.
\item Prove\marginpar{[4]} the following statement by contraposition:\\[1ex]
Let $x$ be an integer. If $x^2+x+1$ is even, then $x$ is odd.
\item Prove\marginpar{[4]} the following statement by contradiction:\\[1ex]
Let $x$ and $y$ be integers. If $3x+5y=153$, then at least one of $x$ and $y$ is odd.
\item An\marginpar{[4]} integer is called ``sane" if $3\,|\,(n^2+2n)$. (That is, if $(n^2+2n)\bmod 3=0$.)
	\begin{enumerate}
	\item Prove or disprove that all odd integers are sane.
	\item Prove or disprove that, if $3\,|\,n$, then $n$ is sane.
	\end{enumerate}
\end{enumerate}
\hrulefill\\
\noindent[Total: 21 marks]\label{end}

\end{document}


\documentclass[12pt]{article}
\author{David Alves}

\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{dirtytalk}
\usepackage[a4paper, total={6.5in, 8.5in}]{geometry}
\usepackage{forest}
\usepackage{skak}
\usepackage{tikz}
\usepackage{titling}

\title{Math 142 Problem Set 4}
\author{David Alves}
\date{2016-09-20}

\begin{document}
\pagenumbering{gobble}

\begin{center}
\Large \thetitle \\
\large \theauthor \\
\thedate
\end{center}

\subsection*{Sources}

    \begin{itemize}
    \item Notes from lecture and my own memory from Math 42 for solving the problems
    \item \textit{Combinatorics Through Guided Discovery} for formal definition of quotient principle
    \item http://tex.stackexchange.com and https://www.sharelatex.com for help with \LaTeX
    \end{itemize}

\section{Counting Equivalence Relations}
\subsection*{Problem Statement}
What is the number of equivalence relations on $[5]$?
\subsection*{Solution}
There are 52 equivalence relations on $[5]$.
\begin{proof}
From the previous homework, we know that the number of equivalence relations on $S \rightarrow S$ is equal to the number of partitions on $S$. Therefore we can count partitions of $[5]$ in order to get the number of equivalence relations on $[5]$. Below is a systematic enumeration of the partitions of $[5]$. Nodes in the tree consist of partitions of a subset, with leaf nodes consisting of partitions of the full set. A node's children are formed by adding the next element to each of the existing partitions and a new partition. The first level of the tree adds element 1, the second level adds element 2, etc.
\end{proof}
\scalebox{0.65}{
\begin{forest}
  for tree={
    grow'=0,
    child anchor=west,
    parent anchor=east,
    anchor=west,
    calign=center,
    inner ysep=0.0pt,
    fit=band,
    before computing xy={l=135pt},
  }
    [$\{\{1\}\}$
        [$\{\{1\text{,}2\}\}$
            [$\{\{1\text{,}2\text{,}3\}\}$
                [$\{\{1\text{,}2\text{,}3\text{,}4\}\}$
                    [$\{\{1\text{,}2\text{,}3\text{,}4\text{,}5\}\}$]
                    [$\{\{1\text{,}2\text{,}3\text{,}4\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\text{,}2\text{,}3\}\text{,}\{4\}\}$
                    [$\{\{1\text{,}2\text{,}3\text{,}5\}\text{,}\{4\}\}$]
                    [$\{\{1\text{,}2\text{,}3\}\text{,}\{4\text{,}5\}\}$]
                    [$\{\{1\text{,}2\text{,}3\}\text{,}\{4\}\text{,}\{5\}\}$]
                ]
            ]
            [$\{\{1\text{,}2\}\text{,}\{3\}\}$
                [$\{\{1\text{,}2\text{,}4\}\text{,}\{3\}\}$
                    [$\{\{1\text{,}2\text{,}4\text{,}5\}\text{,}\{3\}\}$]
                    [$\{\{1\text{,}2\text{,}4\}\text{,}\{3\text{,}5\}\}$]
                    [$\{\{1\text{,}2\text{,}4\}\text{,}\{3\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\text{,}2\}\text{,}\{3\text{,}4\}\}$
                    [$\{\{1\text{,}2\text{,}5\}\text{,}\{3\text{,}4\}\}$]
                    [$\{\{1\text{,}2\}\text{,}\{3\text{,}4\text{,}5\}\}$]
                    [$\{\{1\text{,}2\}\text{,}\{3\text{,}4\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\text{,}2\}\text{,}\{3\}\text{,}\{4\}\}$
                    [$\{\{1\text{,}2\text{,}5\}\text{,}\{3\}\text{,}\{4\}\}$]
                    [$\{\{1\text{,}2\}\text{,}\{3\text{,}5\}\text{,}\{4\}\}$]
                    [$\{\{1\text{,}2\}\text{,}\{3\}\text{,}\{4\text{,}5\}\}$]
                    [$\{\{1\text{,}2\}\text{,}\{3\}\text{,}\{4\}\text{,}\{5\}\}$]
                ]
            ]
        ]
        [$\{\{1\}\text{,}\{2\}\}$
            [$\{\{1\text{,}3\}\text{,}\{2\}\}$
                [$\{\{1\text{,}3\text{,}4\}\text{,}\{2\}\}$
                    [$\{\{1\text{,}3\text{,}4\text{,}5\}\text{,}\{2\}\}$]
                    [$\{\{1\text{,}3\text{,}4\}\text{,}\{2\text{,}5\}\}$]
                    [$\{\{1\text{,}3\text{,}4\}\text{,}\{2\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\text{,}3\}\text{,}\{2\text{,}4\}\}$
                    [$\{\{1\text{,}3\text{,}5\}\text{,}\{2\text{,}4\}\}$]
                    [$\{\{1\text{,}3\}\text{,}\{2\text{,}4\text{,}5\}\}$]
                    [$\{\{1\text{,}3\}\text{,}\{2\text{,}4\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\text{,}3\}\text{,}\{2\}\text{,}\{4\}\}$
                    [$\{\{1\text{,}3\text{,}5\}\text{,}\{2\}\text{,}\{4\}\}$]
                    [$\{\{1\text{,}3\}\text{,}\{2\text{,}5\}\text{,}\{4\}\}$]
                    [$\{\{1\text{,}3\}\text{,}\{2\}\text{,}\{4\text{,}5\}\}$]
                    [$\{\{1\text{,}3\}\text{,}\{2\}\text{,}\{4\}\text{,}\{5\}\}$]
                ]
            ]
            [$\{\{1\}\text{,}\{2\text{,}3\}\}$
                [$\{\{1\text{,}4\}\text{,}\{2\text{,}3\}\}$
                    [$\{\{1\text{,}4\text{,}5\}\text{,}\{2\text{,}3\}\}$]
                    [$\{\{1\text{,}4\}\text{,}\{2\text{,}3\text{,}5\}\}$]
                    [$\{\{1\text{,}4\}\text{,}\{2\text{,}3\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\}\text{,}\{2\text{,}3\text{,}4\}\}$
                    [$\{\{1\text{,}5\}\text{,}\{2\text{,}3\text{,}4\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}3\text{,}4\text{,}5\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}3\text{,}4\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\}\text{,}\{2\text{,}3\}\text{,}\{4\}\}$
                    [$\{\{1\text{,}5\}\text{,}\{2\text{,}3\}\text{,}\{4\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}3\text{,}5\}\text{,}\{4\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}3\}\text{,}\{4\text{,}5\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}3\}\text{,}\{4\}\text{,}\{5\}\}$]
                ]
            ]
            [$\{\{1\}\text{,}\{2\}\text{,}\{3\}\}$
                [$\{\{1\text{,}4\}\text{,}\{2\}\text{,}\{3\}\}$
                    [$\{\{1\text{,}4\text{,}5\}\text{,}\{2\}\text{,}\{3\}\}$]
                    [$\{\{1\text{,}4\}\text{,}\{2\text{,}5\}\text{,}\{3\}\}$]
                    [$\{\{1\text{,}4\}\text{,}\{2\}\text{,}\{3\text{,}5\}\}$]
                    [$\{\{1\text{,}4\}\text{,}\{2\}\text{,}\{3\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\}\text{,}\{2\text{,}4\}\text{,}\{3\}\}$
                    [$\{\{1\text{,}5\}\text{,}\{2\text{,}4\}\text{,}\{3\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}4\text{,}5\}\text{,}\{3\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}4\}\text{,}\{3\text{,}5\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}4\}\text{,}\{3\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\}\text{,}\{2\}\text{,}\{3\text{,}4\}\}$
                    [$\{\{1\text{,}5\}\text{,}\{2\}\text{,}\{3\text{,}4\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}5\}\text{,}\{3\text{,}4\}\}$]
                    [$\{\{1\}\text{,}\{2\}\text{,}\{3\text{,}4\text{,}5\}\}$]
                    [$\{\{1\}\text{,}\{2\}\text{,}\{3\text{,}4\}\text{,}\{5\}\}$]
                ]
                [$\{\{1\}\text{,}\{2\}\text{,}\{3\}\text{,}\{4\}\}$
                    [$\{\{1\text{,}5\}\text{,}\{2\}\text{,}\{3\}\text{,}\{4\}\}$]
                    [$\{\{1\}\text{,}\{2\text{,}5\}\text{,}\{3\}\text{,}\{4\}\}$]
                    [$\{\{1\}\text{,}\{2\}\text{,}\{3\text{,}5\}\text{,}\{4\}\}$]
                    [$\{\{1\}\text{,}\{2\}\text{,}\{3\}\text{,}\{4\text{,}5\}\}$]
                    [$\{\{1\}\text{,}\{2\}\text{,}\{3\}\text{,}\{4\}\text{,}\{5\}\}$]
                ]
            ]
        ]
    ]
\end{forest}
}

\section{Graph Counting}
\subsection*{Problem Statement}
Count the number of graphs on $[n]$ vertices. Count the number of relations from $[n]$ to $[m]$. Comment on similarities between the two (if you found any).

\subsection*{Solution}

An edge in an undirected graph of $[n]$ vertices is a set of two elements (since order doesn't matter on an undirected graph). There are $n$ ways to choose the first element and $n-1$ ways to choose the second element for an edge. We then divide by 2 due to the quotient principle because the order of the two elements in our set does not matter. Thus there are $\frac{n (n-1)}{2}$ possible edges. A graph on $[n]$ consists of a subset of edges from among all possible edges on $[n]$. Each edge can either be present or not present in the graph, so by the product principle there are $2^{\frac{n (n-1)}{2}}$ graphs on $[n]$.\\

A relation on $[n] \rightarrow [m]$ is a set of lists $(a,b) \mid a \in n \text{ and } b \in m$. There are $nm$ such lists by the product principle. Each list is either present or not present in a given set, so there are $2^{nm}$ possible relations on $[n] \rightarrow [m]$.\\

A graph on $[n]$ is a relation on $[n] \rightarrow [n]$ with the additional restriction that 1) none of the lists can contain the same element twice and 2) $(b, a)$ is present in the set if and only if $(a, b)$ is present in the set. The first restriction forbids loops while the second restriction makes the graph undirected.

\section{Balloon Game}
\subsection*{Problem Statement}
Consider the following game: Alice and Bob start with a shared pile of $n \geq 1$ of water balloons, and Alice goes first. On each turn, if you start with no balloons, you lose. If you have at least 1 balloon, you must throw 1, 2, or 3 balloons at your opponent. When does Alice have a winning strategy? (i.e. a strategy that guarantees she will eventually win regardless of what Bob does). Prove the strategy works by strong induction.
\subsection*{Solution}

Alice has a winning strategy for all $n$ not divisible by 4.

\begin{proof}
We prove this by strong induction on the following statement: $p(n)=$ \say{Assuming optimal play by both players, if there are $n$ balloons remaining then the current player will lose if $n$ is divisible by 4, otherwise they will win.}

We are given that the current player will lose if there are $n=0$ balloons remaining, so $p(0)$ is true because 0 is divisible by 4. For $n=$ 1, 2 and 3, the current player can throw all the remaining balloons which forces the other player to lose, so $p(n)$ is true for $n=$ 1, 2, and 3. For $n \geq 4$, if $n$ is divisible by 4 then the current player can throw $k=$ 1, 2, or 3 balloons, but in all of those cases the other player will have $n-k$ balloons remaining where $n-k$ is not divisible by 4, thus the other player will win because $p(n-k)$ has already been proven to be a win if $n-k$ is not divisible by 4. If $n \geq 4$ is not divisible by 4, then $n = 4a + b$ where $a$ and $b$ are positive integers and $b \in \{1,2,3\}$. In that case the current player can throw $b$ balloons to win since they will leave the other player with $n-b$ balloons, we have already shown that $p(n-b)$ is true, and $n-b$ is divisible by four which means it is a loss for the other player.
\end{proof}

\section{Quotient Principle}
\subsection*{Problem Statement}
Explicitly use the quotient principle to find that the binomial coefficient $\binom{n}{k}$ is $\frac{n!}{k!(n-k)!}$ by counting the number of ways to get \emph{lists} of $k$ elements from $[n]$. Don't be sketchy.
\subsection*{Solution}

\begin{proof}
Let $S$ be the set of $k$-length lists that can be formed from items in $[n]$ without duplicate items in any one list. There are $n$ choices for the first element in a $k$-length list, $n-1$ choices for the second element, etc. down to $n -k + 1$ choices for the last element. This gives a total of $\frac{n!}{(n-k)!}$ $k$ such lists in $S$. We now partition $S$ such that each partition consists of orderings of a different set of $k$ elements. Consider the lists in a single partition. There are $k$ choices for which element comes first, $k-1$ choices for which element comes second, etc, giving a total of $k!$ orderings by the product principle. Therefore each partition of $S$ contains $k!$ lists. Therefore since we have partitioned a set of size $\frac{n!}{(n-k)!}$ into blocks of size $k!$, there are $\frac{n!}{k!(n-k)!}$ such blocks according to the quotient principle. Each partition is a subset of $k$ elements from $S$. Thus $\binom{n}{k} = \frac{n!}{k!(n-k)!}$.
\end{proof}

\section{Counting Flags}
\subsection*{Problem Statement}
Count the number of ways to put 5 distinguishable flags on 3 distinguishable poles. On each pole, the only thing that matters is the order of the flags (top to bottom) on each pole. For example, one configuration is to have flags 1, 5, 2 on pole 1 (in that order), no flags on pole 2, and flags 4, 3 on pole 3. Explore for general numbers of flags and poles.
\subsection*{Solution}

There are 2520 ways to place five distinguishable flags onto three distinguishable poles such that all flags are on a pole and the order of flags on a pole matters. More generally, there are $\frac{(n+k-1)!}{(k-1)!}$ ways to place $n$ flags onto $k$ poles.

\begin{proof}
Let $f_1, f_2, \ldots, f_n$ denote the $n$ flags, and let $p_1, p_2, \ldots, p_k$ denote the $k$ poles. A pole is equivalent to a list of flags since the order of flags on a pole matters. For example $(f_1, f_2)$ is distinct from $(f_2, f_1)$. There is a bijection between the $k$ lists and a single list containing all flags and $k-1$ separators. For example with $k=3$ poles and $n=5$ flags, the arrangement $p_1 = (f_1, f_5, f_2), p_2 = (), p_3 = (f_4, f_3)$ is equivalent to the list $(f_1, f_5, f_2, \circ, \circ, f_4, f_3)$ where $\circ$ is a separator indicating the end of the current pole and the start of a new pole. If these separators were distinguishable, the number of arrangements would be $(n+k-1)!$. Since the separators are not distinguishable, we use the quotient principle and divide by $(k-1)!$ orderings of the separators, giving a total count of
\[
\frac{(n+k-1)!}{(k-1)!}
\]

\end{proof}

\section {Time Spent}

I spent about 8 hours on this problem set. For a lot of that time I was stuck on the counting flags problem until we went over a similar problem in class which gave me the idea for the separators. The rest of the problems were pretty straightforward.

\end{document}