% !TEX root = main.tex

%-------------------------------------------------
\section{Elementary probability}\label{ss:elementary}

What is the probability that a random event $A$ occurs? One answer is that this is a number between $0$ and $1$ that indicates how likely $A$ is to occur. Putting aside the question of how we might find such a number, this is not a convincing definition because we must now explain what we mean by ``how likely''. It turns out that probability is difficult to define precisely.

Suppose for the moment however that probabilities have been assigned to the individual outcomes of a random experiment. This can be represented by a \emph{probability mass function},
\[
\begin{array}{cccl}
p:	& \Omega	& \longrightarrow	& [0,1] \\
	& \omega 	& \mapsto			& p(\omega).
\end{array}
\]
Because we want to \emph{quantify} how likely $A$ is to occur, it is reasonable to require that $p(\omega)\geq 0$ for all $\omega\in\Omega$. If the sample space is a countable set, it is also reasonable to define the probability of an event $A$ to be equal the sum of the probabilities of the outcomes it contains:
\begin{equation}\label{eq:prob_event}
P(A) = \sum_{\omega\in A} p(\omega).\tag{*}
\end{equation}
This is a \emph{probability distribution function}, which assigns probabilities to \emph{subsets} of the sample space.

\bigskip
Intuitively, probability should somehow reflect a sense of \emph{proportion}, between how likely $A$ is to occur and how likely $A$ is not to occur.
\bit
\it The ratio $P(A)/P(A^c)$ is called the \emph{odds on} $A$ occurring.
\it The ratio $P(A^c)/P(A)$ is called the \emph{odds against} $A$ occuring.
\eit
Odds suffer by the fact that they can take arbitrarily large values. A better definition is obtained by expressing how likely $A$ is to occur as a proportion of how likely \emph{any} event is to occur, and make the latter equal to $1$:
\[
\sum_{\omega\in\Omega} p(\omega) = 1.
\]
%The probability $P(A)$ can then be viewed as a proportion of this total ammount.

\begin{exercise}\label{exe:elementary_properties}
Show that probability distribution functions as defined in \eqref{eq:prob_event} have the following properties, where $A$ and $B$ are subsets of the sample space:
\ben
\it $P(\emptyset)=0$ and $P(\Omega)=1$.
\it Complementarity: $P(A^c) = 1 - P(A)$.
\it Monotonicity: if $A\subseteq B$ then $P(A)\leq P(B)$.
\it Additivity: if $A$ and $B$ are disjoint then $P(A\cup B)=P(A)+P(B)$.
\it Addition formula: $P(A\cup B)=P(A)+P(B)-P(A\cap B)$.
\een
\end{exercise}

%-----------------------------
\subsection{Conditional probability}

Suppose we know that event $B$ occurs. Then event $A$ occurs if and only if $A\cap B$ occurs, and the probability that $A$ occurs should now represent how likely $A\cap B$ is to occur as a proportion of how likely $B$ was to occur in the first place. Thus we define the \emph{conditional probability of $A$ given $B$} to be
\[
P(A|B) = \frac{P(A\cap B)}{P(B)}.
\]
provided that $P(B)>0$.

To analyse random events it is often useful to break then into disjoint components and analyse each component separately.
\begin{definition}
A family of sets $\{A_1,A_2,\ldots\,A_n\}$ is called a \emph{partition} of set $B$ if
\ben
\it $B \subseteq \bigcup_{i=1}^{n} A_i$ and
\it $A_i\cap A_j = \emptyset$ for all $i\neq j$.
\een
\end{definition}

% partition theorem
\begin{theorem}[Partition Theorem]\label{thm:partition}
If $\{A_1,A_2,\ldots,A_n\}$ is a partition of $B$ then
$
P(B) = \sum_{i=1}^{n} P(B|A_i)P(A_i).
$
\begin{proof}
Because the $A_i$ are disjoint and $B$ is contained in $\subseteq\cup_{i=1}^{n}A_i$, we can represent $B$ as a disjoint union,
\[
B = (B\cap A_1)\cup (B\cap A_2)\cup \ldots = \bigcup_{i=1}^{\infty}(B\cap A_i)
\]
By the additivity property (see Exercise~\ref{exe:elementary_properties})
\begin{align*}
P(B)
	= P\left(\bigcup_{i=1}^{\infty}(B\cap A_i)\right)
	= \sum_{i=1}^{\infty}P(B\cap A_i)
	= \sum_{i=1}^{\infty}P(B|A_i)P(A_i),
\end{align*}
as required.
\end{proof}
\end{theorem}

If we perform a random experiment and observe that $B$ occurs, how does this change what we know about event $A_i$? This is answered by Bayes' theorem.

\begin{theorem}[Bayes' Theorem]\label{thm:bayes}
If $\{A_1,A_2,\ldots,A_n\}$ is a partition of $B$ and $P(B)>0$, then
$
P(A_i|B) = \displaystyle\frac{P(B|A_i)P(A_i)}{\sum_j P(B|A_j)P(A_j)}.
$
\begin{proof}
Set intersection is commutative so
\[
P(A|B) = \frac{P(A\cap B)}{P(B)} = \frac{P(B\cap A)}{P(B)} = \frac{P(B|A)P(A)}{P(B)}.
\]
Hence,
\[
P(A_i|B)
	= \frac{P(B|A_i)P(A_i)}{P(B)}
	= \frac{P(B|A_i)P(A_i)}{\sum_{j=1}^{\infty} P(B|A_j)P(A_j)}
\]
where the last equality follows by the partition theorem, as required.
\end{proof}
\end{theorem}

% elementary example
\begin{example}
One in every $100$ people has a certain disease. People having the disease test positively with probability 0.92; people not having the disease test negatively with probability 0.97. If a person tests positively for the disease, what is the probability that the person actually has the disease?
\begin{solution}
Let $A$ be the event that the person has the disease. Let $B$ be the event that
the person tests positively:
\[
P(A)=0.01,\ P(A^c)=0.99,\ P(B|A)=0.92 \text{ and } P(B|A^c)=0.03
\]
The set $\{A,A^c\}$ is a partition of $B$, so by the partition theorem,
\[
P(B)
	= P(B|A)P(A)+P(B|A^c)P(A^c)
	= (0.92\times 0.01)+(0.03\times 0.99)
	= 0.029403.
\]
By Bayes' theorem,
\[
P(A|B)
	= \frac{P(B|A)P(A)}{P(B)}
	= \frac{0.92\times 0.01}{0.029403}
	= 0.3129 \text{ approx.}
\]
Approximately one third of positive tests are ``true positives'', the remainder are ``false positives''.
\end{solution}
\end{example}

\begin{exercise}
\begin{questions}
\question % Bertrand
\textbf{Bertrand's box paradox}. Suppose we have a box containing two gold coins, a box containing two silver coins, and a box containing one gold coin and one silver coin. A box is chosen at random, and a coin is chosen at random from the box. If the chosen coin is a gold coin, what is the probability that the box contains another gold coin?
\begin{answer}
Let $A$ be the event that a gold coin is chosen. By Bayes theorem (with the obvious notation),
\begin{align*}
P(GG|A)
	& = \frac{P(A|GG)P(GG)}{P(A|GG)P(GG)+P(A|SS)P(SS)+P(A|GS)P(GS)} \\
	& = \frac{1\times 1/3}{(1\times 1/3)+(0\times 1/3)+(1/2\times 1/3)}
	= \frac{2}{3}.
\end{align*}
This is related to the famous \emph{Monty Hall problem}.
\end{answer}
\question % Galton
\textbf{Galton's paradox}. Three fair coins are tossed independently. Given that at least two are alike, the probability that they are all alike is $1/2$. Do you agree?
\begin{answer}
No. For any outcome at least two coins will be alike, so this provides no additional information. In fact,
\[
P(\text{All are alike} | \text{Two are alike}) = P(\text{All are alike}) = 1/4.
\]
\end{answer}
\end{questions}
\end{exercise}

%-----------------------------
\subsection{Independence}

If the probability that event $A$ occurs is not affected by whether or not event $B$ occurs (and vice versa), we say that $A$ and $B$ are \emph{independent}.

% definition: independence
\begin{definition}
Two events $A$ and $B$ are said to be \emph{independent} if $P(A|B)=P(A)$ or equivalently
\[
P(A\cap B) = P(A)P(B).
\]
\end{definition}

\begin{example}
A fair die is rolled once. Let $A$ be the event that the outcome is even, and let $B$ be the event that the outcome is divisible by $3$. Are $A$ and $B$ independent?
\begin{solution}
\[
P(A) = P(\{2,4,6\}) = 1/2;\quad
P(B) = P(\{3,6\}) = 1/3;\quad
P(A\cap B) = P(\{6\}) = 1/6.
\]
Thus $A$ and $B$ are independent because $P(A\cap B) = P(A)P(B)$.
\end{solution}
\end{example}

%-----------------------------
%\subsubsection{Pairwise and total independence}
The notion of independence can be extended to three or more events.

\begin{definition}
A family of events $\{A_1,A_2,\ldots\}$ is said to be
\ben
\it \emph{pairwise independent} if $P(A_i\cap A_j)=P(A_i)P(A_j)$ for all $i\neq j$.
\it \emph{totally independent} if for every finite sub-family
$\{B_1,B_2,\ldots,B_m\}\subset \{A_1,A_2,\ldots\}$,
\[
P(B_1\cap B_2\cap \ldots \cap B_m) = P(B_1)P(B_2)\cdots P(B_m).
\]
\een
\end{definition}
Note that total independence implies pairwise independence, but not vice versa.

\begin{example}
Let $\Omega=\{1,2,3,4\}$ where each outcome is equally likely, and consider the events $A=\{1,2\}$, $B=\{1,3\}$ and $C=\{1,4\}$. Show that $\{A,B,C\}$ is pairwise independent but not totally independent.
\begin{solution}
\bit
\it
$A$ and $B$ are independent: $P(A)=P(B)=1/2$ and $P(A\cap B)=1/4$ so $P(A\cap B) = P(A)P(B)$.
\it
Similary $A$ and $C$ are independent, and $B$ and $C$ are indpendent, so the set $\{A,B,C\}$ is pairwise independent.
\it
In contrast, $P(A\cap B\cap C) = 1/4$ but $P(A)P(B)P(C)=1/8$, so the set $\{A,B,C\}$ is not totally independent.
\eit
\end{solution}
\end{example}

\begin{exercise}
\begin{questions}
\question % (1)
Let $A$ and $B$ be two events with $P(A)=0.2$, $P(B)=0.5$ and $P(A\cap B)=0.1$. Compute the conditional probability $P(A|B)$ and decide whether or not $A$ and $B$ are independent.
\begin{answer}
\bit
\it $P(A|B)   = P(A\cap B)/P(B) = 0.1/0.5 = 0.25$.
\it $P(A|B)=P(A)$ so $A$ and $B$ are independent.
\eit
\end{answer}

\question % (2)
Show that if $A$ and $B$ are independent then $A$ and $B^c$ are also independent.
\begin{answer}
\begin{align*}
P(A\cap B^c)
	& = P(A) - P(A\cap B) \\
	& = P(A) - P(A)P(B) \quad\text{by independence,} \\
	& = P(A)(1-P(B)) \\
	& = P(A)P(B^c).
\end{align*}
\end{answer}

\question % de Mere
\textbf{de M\'{e}r\'{e}'s paradox}. Solve de M\'{e}r\'{e}'s paradox by computing the probability that at least one six appears in 4 rolls of a single fair die, and the probability that at least one double-six appears in 24 rolls of two fair dice.
\begin{answer}
Assuming that the rolls are independent:
\begin{align*}
P(\text{at least one six in 4 rolls of a single die)}
	& = 1- P(\text{no sixes obtained in 4 rolls}) \\
	& = 1 - (5/6)^4 \quad\text{(by independence)} \\
	& = 0.5177 \\
P(\text{at least one double six in 24 rolls of two dice})
	& = 1- P(\text{no double-sixes in 24 rolls}) \\
	& = 1 - (35/36)^{24} \quad\text{(by independence)} \\
	& = 0.4914
\end{align*}
\end{answer}

\question % independence
Two fair dice are rolled independently. Let $A$ be the event that the first die shows $3$, $B$ that the second die shows $4$ and and $C$ that the total shown on the two dice is $7$.
\begin{parts}
\part
Define a sample space for the experiment and identify the subsets corresponding to events $A$, $B$ and $C$.
\begin{answer}
\begin{itemize}
\item[] $\Omega = \{(i,j):1\leq i,j\leq 6\}$
\item[] $A = \{(3,j):1\leq j\leq 6\}$
\item[] $B = \{(i,4):1\leq i\leq 6\}$
\item[] $C = \{(i,j):1\leq i,j\leq 6\mbox{ and }i+j=7\}$
\end{itemize}
Note that because each outcome is equally likely, $P(A)=P(B)=P(C)=1/6$.
\end{answer}
\part
Show that $\{A,B,C\}$ is pairwise independent but not (totally) independent.
\begin{answer}
To show that the set $\{A,B,C\}$ is pairwise independent, we need to show that any two events chosen from the set are independent of each other.
\bit
\it For $A$ and $B$, their intersection $A\cap B$ is the event $\{(3,4)\}$, consisting of the single outcome $(3,4)$. This means that $P(A\cap B)=1/36$ and hence $P(A\cap B) = P(A)P(B)$.
\it Similarly, $A\cap C=\{(3,4)\}$ so $P(A\cap C)=P(A)P(C)$, and $B\cap C=\{(3,4)\}$ so $P(B\cap C)=P(B)P(C)$.  Hence, the set $\{A,B,C\}$ is pairwise independent.
\it However, the intersection of all three events is also $\{(3,4)\}$ so $P(A\cap B\cap C)=1/36$. Hence $P(A\cap B\cap C) \neq P(A)P(B)P(C)$ so the set $\{A,B,C\}$ is not totally independent.
\eit
\end{answer}
\end{parts}

\question % bayes theorem (GS 1.8.15)
A random number $N$ of dice are rolled independently. Suppose that $P(N=k) = 2^{-k}$ for $k\in\{1,2,\ldots\}$ (and zero otherwise). Let $S$ be the sum of the scores shown on the dice. Show that
\begin{parts}
\part $P(N=2|S=4)=432/2197$,
\begin{answer}
The event $S=4$ can only occur when
\bit
\it $N=1$ and the die shows $4$ (which occurs with probability $1/6$),
\it $N=2$ and the dice show $(1,3)$, $(2,2)$ or $(3,1)$ (which occurs with probability $3/36$),
\it $N=3$ and the dice show $(1,1,2)$, $(1,2,1)$ or $(2,1,1)$ (which occurs with probability $3/216$),
\it $N=4$ and all four dice show $1$ (which occurs with probability $1/1296$).
\eit
By Bayes' theorem,
\begin{align*}
P(N=2|S=4)
	& = \frac{P(S=4|N=2)P(N=2)}{\sum_{k=1}^{\infty} P(S=4|N=k)P(N=k)} \\
	& = \frac{3/36\times 1/4}{(1/6\times 1/2) + (3/36\times 1/4) + (3/216\times 1/8) + (1/1296\times 1/16)} \\
	& = \frac{432}{1728 + 432 + 36 + 1}
	  = \frac{432}{2197}.
\end{align*}
\end{answer}

\part $P(S=4|N\text{ is even})=433/6912$,
\begin{answer}
Using the formula for a geometric series with first term $1/4$ and common raio $1/4$, we have
\[
P(\text{$N$ even}) = \frac{1}{4} + \frac{1}{16} + \frac{1}{64} + \ldots = \frac{1}{3}.
\]
If $N$ is even, then $S=4$ only if
\bit
\it $N=2$ and the dice show $(1,3)$, $(2,2)$ or $(3,1)$ (which occurs with probability $3/36$),
\it $N=4$ and all four dice show $1$ (which occurs with probability $1/1296$).
\eit
Hence,
\begin{align*}
P(S=4|\text{$N$ even})
	& = \frac{P(\text{$S=4$ and $N$ even})}{P(\text{$N$ even})} \\
	& = \frac{P(S=4|N=2)P(N=2) + P(S=4|N=4)P(N=4)}{P(\text{$N$ even})} \\
	& = \frac{(3/36\times 1/4) + (1/1296\times 1/16)}{1/3}
	= \frac{433}{6912}.
\end{align*}
\end{answer}

\part $P(N=2|$S=4\text{ and the first die shows $1$}) = 144/169,
\begin{answer}
Let $D$ be the score on the first die. If $D=1$, then $S=4$ only if
\bit
\it $N=2$ and the other die shows $3$ (which occurs with probability 1/6),
\it $N=3$ and the other two dice show $(1,2)$ or $(2,1)$ (which occurs with probability 2/36), or
\it $N=4$ and the other three dice all show $1$ (which occurs with probability 1/216).
\eit
Hence,
\begin{align*}
P(N=2|S=2,D=1)
	& = \frac{P(N=2,S=4,D=1)}{P(S=4,D=1)} \\
	& = \frac{1/6\times 1/4}{(1/6\times 1/4) +(2/36\times 1/8) + (1/216\times 1/16)}
	= \frac{144}{169}.
\end{align*}
\end{answer}

\part $P(\text{Largest number is $m$}) = m/(12-m)$ for every $m\in\{1,2,3,4,5,6\}$.
\begin{answer}
Let $M$ be the maximum number shown on the dice. For $m\in\{1,2,3,4,5,6\}$, the probability that $m$ is the maximum number shown on a single die is $m/6$. Assuming that the dice are independent, the probability that $m$ is the maximum number shown on $k$ dice is $(m/6)^k$. Hence,
\begin{align*}
P(M\leq m)
	& = \sum_{k=1}^{\infty}P(M\leq m|N=k)P(N=k) \\
	& = \sum_{k=1}^{\infty}\left(\frac{m}{6}\right)^k\frac{1}{2^k}
	= \sum_{k=1}^{\infty}\left(\frac{m}{12}\right)^k
	= \frac{m}{12-m},
\end{align*}
where we have used the formula for a geometric series whose first term and common ratio are both equal to $m/12$.
\end{answer}
\end{parts}

\end{questions}
\end{exercise}


the following is new in july 2001:

\subsubsection{$greduce$\_$orders$: Reduction with several term orders}
The shortest polynomial with different polynomial term orders is computed
with the operator $greduce$\_$orders$:

\begin{description}
\ttindex{$greduce$\_$orders$}
\item[{\it greduce\_orders}]($exp$, \{$exp1$, $exp2$, \ldots , $expm$\}
[,\{$v_1$,$v_2$ \ldots $v_n$\}]);

where {\it exp} is an expression and $\{exp1, exp2,\ldots , expm\}$ is
a list of any number of expressions or equations. The list of variables
$v_1,v_2 \ldots v_n$ may be omitted; if set, the variables must be a list.
\end{description}

The expression {\it exp} is reduced by {\it greduce} with the orders
in the shared variable {\it gorders}, which must be a list of term
orders (if set). By default it is set to

\begin{center}
$\{revgradlex,gradlex,lex\}$
\end{center}

The shortest polynomial is the result.
The order with the shortest polynomial is set to the shared variable
{\it gorder}. A Groebner basis of the system \{$exp1$, $exp2$, \ldots ,
$expm$\} is computed for each element of $orders$.
With the default setting {\it gorder} in most cases will be set
to {\it revgradlex}.
If the variable set is given, these variables are taken; otherwise all
variables of the system \{$exp1$, $exp2$, \ldots , $expm$\} are
extracted.

The Groebner basis computations can take some time; if interrupted, the
intermediate result of the reduction is set to the shared variable
$greduce$\_$result$, if one is done already. However, this is not
nesessarily the minimal form.

If the variable {\it gorders} should be set to orders with a parameter,
the term oder has to be replaced by a list; the first element is the
term oder selected, followed by its parameter(s), e.g.

\begin{center}
$orders:=\{\{gradlexgradlex,2\},\{lexgradlex,2\}\}$
\end{center}


\subsubsection{Repeated Quadratic Factors}
\noindent
If a quadratic factor that can't be broken into linear factors is repeated, then we can write
\begin{equation*}
	Q(x) = R(x)(ax^2+bx+c)^k\text{, }b^2-4ac < 0\text{, }k \geq 0\text{, and }R(x)\text{ is not divisible by }(ax^2+bx+c)^k
\end{equation*}
Now we have to do a combination of what we did for repeated linear factors and quadratic factors. We say
\begin{equation*}
	\frac{P(x)}{R(x)(ax^2+bx+c)^k}=\left(\text{Decomposition of }R(x)\right)+\frac{A_1x+B_1}{ax^2+bx+c}+\ldots+\frac{A_kx+B_k}{(ax^2+bx+c)^k}
\end{equation*}
and then solve for the coefficients in the numerator.

\ifodd\includeBackgroundReviewExamples\input{./backgroundReview/algebraPreCalc/repeatedQuadraticFactors_example.tex}\fi


\providecommand{\main}{../..}
\documentclass[\main/thesis.tex]{subfiles}
\begin{document}

\section{The Maximum Numeral}\label{maximum}

A number is said to be the \textit{maximum} if it is greater than or equal
to all the other numbers.

\begin{lstlisting}
Maximum : ∀ {b d o} → (xs : Numeral b d o) → Set
Maximum {b} {d} {o} xs = (ys : Numeral b d o) → ⟦ xs ⟧ ≥ ⟦ ys ⟧
\end{lstlisting}

If a numeral is a maximum
\footnote{More precisely, ``If a \text{value} of a numeral is a maximum ...''},
then its least significant digit (LSD) must be the greatest.

\begin{lstlisting}
Maximum⇒Greatest-LSD : ∀ {b} {d} {o}
    → (xs : Numeral b d o)
    → Maximum xs
    → Greatest (lsd xs)
\end{lstlisting}

\subsection{Properties of each Category}

\paragraph{NullBase}

\begin{center}
    \begin{adjustbox}{max width=\textwidth}
        \begin{tikzpicture}
            % the frame
            \path[clip] (-1, -1) rectangle (11, 2);
            % the spine
            \draw[ultra thick] (0,0) -- (1,0);
            \draw[ultra thick] (9,0) -- (10,0);
            % the body

            \foreach \i in {1,...,7} {
                \draw[ultra thick, fill=white] ({\i+0.05}, -0.2) rectangle ({\i+0.95}, +0.2);
            };
            \draw[ultra thick, fill=black] ({8.05}, -0.2) rectangle ({8.95}, +0.2);

            % labels
            \draw[->, ultra thick] (1.5,1) -- (1.5,0.5)
                node at (1.5, 1.3) {$o$};
            \draw[->, ultra thick] (8.5,1) -- (8.5,0.5)
                node at (8.5, 1.3) {$o+d$};
        \end{tikzpicture}
    \end{adjustbox}
\end{center}

It is obvious that systems of {\lstinline|NullBase|} have maximum.
If a numeral's LSD happens to be the greatest,
then the numeral must be the maximum.

\begin{lstlisting}
Maximum-NullBase-Greatest : ∀ {d} {o}
    → (xs : Numeral 0 (suc d) o)
    → Greatest (lsd xs)
    → Maximum xs
\end{lstlisting}

With this lemma, we can tell whether a numeral is a maximum by looking at its
LSD. In case that the LSD is not the greatest, we could disprove the proposition
by contraposition.

\begin{lstlisting}
    Maximum-NullBase : ∀ {d} {o}
        → (xs : Numeral 0 (suc d) o)
        → Dec (Maximum xs)
    Maximum-NullBase xs with Greatest? (lsd xs)
    Maximum-NullBase xs | yes greatest =
        yes (Maximum-NullBase-Greatest xs greatest)
    Maximum-NullBase | no ¬greatest =
        no (contraposition (Maximum⇒Greatest-LSD xs) ¬greatest)
\end{lstlisting}

\paragraph{AllZeros}

\begin{center}
    \begin{adjustbox}{max width=\textwidth}
        \begin{tikzpicture}
            % the frame
            \path[clip] (0, -1) rectangle (4, 2);
            % the spine
            \draw[ultra thick] (2,0) -- (4,0);
            % the body
            \draw[ultra thick, fill=black] ({1.1}, -0.4) rectangle ({2.9}, +0.4);

            % labels
            \draw[->, ultra thick] (2,1.5) -- (2,0.8)
                node at (2, 1.8) {$0$};
        \end{tikzpicture}
    \end{adjustbox}
\end{center}

\textit{All} numerals of systems of {\lstinline|AllZeros|} are maxima since they
are all mapped to $ 0 $.

\begin{lstlisting}
Maximum-AllZeros : ∀ {b}
    → (xs : Numeral b 1 0)
    → Maximum xs
Maximum-AllZeros xs ys = reflexive (
    begin
        ⟦ ys ⟧
    ≡⟨ toℕ-AllZeros ys ⟩
        zero
    ≡⟨ sym (toℕ-AllZeros xs) ⟩
        ⟦ xs ⟧
    ∎)
\end{lstlisting}

\paragraph{Proper}

On the contrary, there are no maxima in the systems of {\lstinline|Proper|}.
In fact, that is the reason why they are categorized as \textit{proper} in the
first place. The theorem below is proven by contradicting two propositions:

\begin{itemize}
    \item Given {\lstinline|claim : Maximum xs|}, we claim that {\lstinline|xs|}
        is greater than or equal to {\lstinline|greatest-digit d ∷ xs|},
        a numeral we composed by prefixing it with the greatest digit.
    \item On the other hand, we prove that {\lstinline|xs|} is less than
        {\lstinline|greatest-digit d ∷ xs|}.
\end{itemize}

\begin{lstlisting}
Maximum-Proper : ∀ {b d o}
    → (xs : Numeral (suc b) (suc d) o)
    → (proper : 2 ≤ suc (d + o))
    → ¬ (Maximum xs)
Maximum-Proper {b} {d} {o} xs proper claim = contradiction p ¬p
    where
        p : ⟦ xs ⟧ ≥ ⟦ greatest-digit d ∷ xs ⟧
        p = claim (greatest-digit d ∷ xs)
        ¬p : ⟦ xs ⟧ ≱ ⟦ greatest-digit d ∷ xs ⟧
        ¬p = <⇒≱ (
            start
                suc ⟦ xs ⟧
            ≈⟨ cong suc (sym (*-right-identity ⟦ xs ⟧)) ⟩
                suc (⟦ xs ⟧ * 1)
            ≤⟨ s≤s (n*-mono ⟦ xs ⟧ (s≤s z≤n)) ⟩
                suc (⟦ xs ⟧ * suc b)
            ≤⟨ +n-mono (⟦ xs ⟧ * suc b) (≤-pred proper) ⟩
                d + o + ⟦ xs ⟧ * suc b
            ≈⟨ cong
                (λ w → w + ⟦ xs ⟧ * suc b)
                (sym (greatest-digit-toℕ (Fin.fromℕ d)
                (greatest-digit-is-the-Greatest d)))
            ⟩
                ⟦ greatest-digit d ∷ xs ⟧
            □)
\end{lstlisting}

\subsection{Determine the Maximum}

We can \textit{decide} whether a numeral is a maximum by applying them to
lemmata of each category.

\begin{lstlisting}
Maximum? : ∀ {b d o}
    → (xs : Numeral b d o)
    → Dec (Maximum xs)
Maximum? {b} {d} {o} xs with numView b d o
Maximum? xs | NullBase d o = Maximum-NullBase xs
Maximum? xs | NoDigits b o = no (NoDigits-explode xs)
Maximum? xs | AllZeros b   = yes (Maximum-AllZeros xs)
Maximum? xs | Proper b d o proper = no (Maximum-Proper xs proper)
\end{lstlisting}

\paragraph{Summary}

\begin{center}
    \begin{adjustbox}{max width=\textwidth}
    \begin{tabular}{ | l | c | c | c | c | }
    \textbf{Properties} & \textbf{NullBase} & \textbf{NoDigits} & \textbf{AllZeros} & \textbf{Proper} \\
    \hline
    has an maximum & yes & no & yes & no \\
    \end{tabular}
    \end{adjustbox}
\end{center}

\end{document}


\documentclass{article}
\usepackage{lisp-on-tex}
\lispinterp{%
  (\define \sq (\lambda (\n) (\* \n \n)))
  (\define \fact (\lambda (\n) (\lispif (\= \n :0) :1 (\* \n (\fact (\- \n :1))))))
  }
\newcommand\sq[1]{\lispinterp{(\texprint (\sq :#1))}}
\newcommand\fact[1]{\lispinterp{(\texprint (\fact :#1))}}

\begin{document}
\section{Factorials and Squares}
  \begin{center}
  \begin{tabular}{r||rr}\hline\hline
    $n$ & $n!$ & $n^2$ \\
    \hline
     1 & \fact{1} & \sq{1} \\
     2 & \fact{2} & \sq{2} \\
     3 & \fact{3} & \sq{3} \\
     4 & \fact{4} & \sq{4} \\
     5 & \fact{5} & \sq{5} \\
     6 & \fact{6} & \sq{6} \\
     7 & \fact{7} & \sq{7} \\
     8 & \fact{8} & \sq{8} \\
     9 & \fact{9} & \sq{9} \\
    10 & \fact{10} & \sq{10} \\
    11 & \fact{11} & \sq{11} \\
    \hline
  \end{tabular}
  \end{center}
\end{document}


%\vspace{-5pt}
\section{Methods}
\label{sec:methods}

\noindent
In this model, we simply take the set of $K+W$ positional and key tokens, and
the set of $K+W+1$ output tokens, and fit a model similar to word
vectors~\cite{ref:mikolov:wvec}. The details of the model are described below.

We first assign a $D$ dimensional vector to each one of $K+W$ different key
tokens and positional tokens. We denote such token-vectors by $v_i$, where $1
\leq i \leq K+W$. Next, given a fixed size window of tokens $[t_1, t_2, \ldots,
t_W]$, we compute a score for each possible output $j$, $s_j$ as a function of
the token-vectors of the tokens in the window, i.e.,
\[
s_j = f_j\left(v_{t_1}, v_{t_2}, \ldots v_{t_W}\right)
\]
The final loss function for this particular example is given by
\[
L = \log\left(\frac{e^{s_{t_o}}}{\sum_j{e^{s_j}}}\right)
\]
where $t_o$ is the output token. This is the cross-entropy loss
between softmax based probabilities for each output and the actual observed
output. According to the actual form of the function $f_j$, we get different
models. A few of these models are described below.

For each model, we use {\sc AdaGrad} optimizer to minimize the total loss
function with respect to the parameters of that model. {\sc AdaGrad} was chosen
because it gave the best performance in our case among other alternatives such
as vanilla SGD and momentum based SGD.

\subsection{Fixed Window Weight Model}
In the spirit of continuous bag-of-word (CBOW) model~\cite{ref:mikolov:wvec}, in
this model we assume that a token at position $i$ has a ``weight'' of $w_i$, and
combine the token-vectors of the window according to these weights. The final
score is assumed to be a linear function of this weighted token-vectors. Thus,
the overall model is
\begin{align}
u &= \sum_{i=1}^{W}{w_i v_{t_i}}\\
s_j &= p_j^Tu\\
L &= \log\left(\frac{e^{s_{t_o}}}{\sum_j{e^{s_j}}}\right)
\end{align}
The parameters in this model are the weights $w_i$, the word vectors $v_i$, and
the ``prediction'' vectors $p_j$. The gradients of the loss w.r.t. the
parameters are obtained by backpropagation, the details of which are omitted
here for space.

\subsection{Matrix Vector Model}
In this case, we do not introduce any averaging as in the case of CBOW, but
instead simply concatenate the token-vectors to create a larger vector which is
then used to create the scores. Formally, the model is
\begin{align}
u &= [v_{t_1}; v_{t_2}; v_{t_3}; \ldots; v_{t_W}]\\
s_j &= p_j^Tu\\
L &= \log\left(\frac{e^{s_{t_o}}}{\sum_j{e^{s_j}}}\right)
\end{align}
Note that since here $u$ is $DW$ dimensional instead of being $D$ dimensional as
in the case of Fixed Window Weight Model. Thus, the prediction vectors $p_j$ are
much higher dimensional as well, which means this model has a higher number
of parameters as compared to Fixed Window Weight Model.

\subsection{Feed-Forward Neural Network Model}
\label{sec:nnlm}
This case differs from the Matrix Vector Model by addition of one or more
non-linear transformations between the concatenated token-vectors and the final
scores. We denote a specific instance of this model by NL-$k$, where $k$ is the
number of non-linearity layers it contains. Thus, for example, NL-$0$ is
equivalent to the Matrix-Vector model described above, while for NL-$3$ the
probabilities are obtained as:
\begin{align}
u &= [v_{t_1}; v_{t_2}; v_{t_3}; \ldots; v_{t_W}]\\
z_1 &= \text{relu}(Q_1u)\\
z_2 &= \text{relu}(Q_2z_1)\\
z_3 &= \text{relu}(Q_3z_2)\\
s_j &= p_j^Tz_3\\
L &= \log\left(\frac{e^{s_{t_o}}}{\sum_j{e^{s_j}}}\right)
\end{align}
Here $\text{relu}(.)$ is the rectified linear unit, i.e., $\text{relu}(x) = x$
if $x \geq 0$, and $0$ otherwise. In this work, we specifically experimented
with NL-$0$, NL-$1$, NL-$2$, and NL-$3$.

\subsection{Feed-Forward Model with Soft Attention}
\label{sec:annlm}
Motivated by the recent successes of attention based models, we explore an
attention mechanism for our problem as well. We experiment with a
``soft''-attention model, i.e., a weight $a_i$ between 0 and 1 is assigned to
each position $i$. The attentions are assumed to be the result of a sigmoid
function on a linear combination of the concatenated word-vectors. Subsequently,
the word vector for the $i^{th}$ token is weighted by $a_i$, and the
aforementioned NL-$k$ model is applied on the concatenation of these weighted
word vectors instead. Thus, for example, an attention based NL-$3$ model takes
the form of:
\begin{align}
u &= [v_{t_1}; v_{t_2}; v_{t_3}; \ldots; v_{t_W}]\\
a &= \sigma(Au)\\
z &= [a_1v_{t_1}; a_2v_{t_2}; a_3v_{t_3}; \ldots; a_Wv_{t_W}]\\
s_j &= \text{NL-}3(z ; Q_1, Q_2, Q_3, p_j)\\
L &= \log\left(\frac{e^{s_{t_o}}}{\sum_j{e^{s_j}}}\right)
\end{align}
Here NL-$3(x ; Q_1, Q_2, Q_3, p_j)$ is the function going from $u$ to $s_j$ in
the case of a NL-$3$ model, described in Section~\ref{sec:nnlm}.

\subsection{GRU based Recurrent Model}
\label{sec:rnnlm}
Recurrent neural network models based on cells like LSTM~\cite{ref:lstm} and
GRU~\cite{ref:gru} have recently been shown to achieve state-of-the-art
performance in language models. Inspired by these results, we also attempted to
use a GRU based recurrent model for our prediction task. Specifically, our model
was the following:
\begin{align}
[g_1; g_2; g_3; \ldots; g_{W}] &= \text{GRU}([v_{t_1}; v_{t_2}; v_{t_3}; \ldots;
v_{t_W}])\\
s_j &= p_j^T[g]\\
L &= \log\left(\frac{e^{s_{t_o}}}{\sum_j{e^{s_j}}}\right)
\end{align}
Here, $g_i$ is the output of the $i^{th}$ GRU cell, and we have a dense layer
after that to get the scores for each output token. As we did not achieve
competitive performance with this model as compared to NL-$1$, we did not
experiment further with deeper GRU models.


\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb,amsfonts,stmaryrd}
\usepackage{enumitem}
\usepackage{tabu}
\usepackage{fixltx2e}
\usepackage{xcolor}
\usepackage{mathtools}
\usepackage{tcolorbox}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}

\DeclarePairedDelimiter\abs{\lvert}{\rvert}%

\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
%If you want to title your bold things something different just make another thing exactly like this but replace "problem" with the name of the thing you want, like theorem or lemma or whatever

\newenvironment{nscenter}
 {\parskip=0pt\par\nopagebreak\centering}
 {\par\noindent\ignorespacesafterend}

\def\SPSB#1#2{\rlap{\textsuperscript{\textcolor{black}{#1}}}\SB{#2}}

\begin{document}
 %Good resources for looking up how to do stuff:
%Binary operators: http://www.access2science.com/latex/Binary.html
%General help: http://en.wikibooks.org/wiki/LaTeX/Mathematics

\begin{center}
\textbf{INTRO TO ABSTRACT ALGEBRA} \\
Jacob Shiohira, FALL 2017 \\
MATH 310 $|$ University of Nebraska-Lincoln
\end{center}

\section*{Chapter 1}
% TODO: Add a mention about sets and set builder notation that will come up

\begin{center}
\textbf{Section 1.1: The Division Algorithm} \\
\end{center}

\noindent
\textbf{WELL-ORDERING AXIOM} Every nonempty subset of the set of non-negative integers contains a smallest element. \\

\noindent
\textbf{THEOREM 1.1} Let $a,b$ be integers with $b>0$. Then there exist unique integers $q$ an $r$ such that

\begin{align*}
a=bq+r \text{     and     } 0 \leq r < b.
\end{align*}

\noindent
Notice that the restrictions on $b$ and $r$. If these did not exist, we could find multiple $q,r \in \Z$ that would satisfy the Division Algorithm.

\begin{center}
\textbf{Section 1.2: Divisibility} \\
\end{center}

\noindent
\textbf{DEFINITION}: Let $a$ and $b$ be integers with $b \neq 0$. We say that $b$ \textbf{divides} $a$ (or that $b$ is a divisor of $a$, or that $b$ is a factor of $a$) if $a=bc$ for some integer $c$. In symbols, "$b$ divides $a$" is written $b|a$ and "b does not divide a" is written $b \not | a$. \\

\noindent
\textbf{Remarks:}
\begin{enumerate}
\item Every nonzero integer $b$ divides $0$ because $0=0b$. For every integer $a$, we have  $1$ divides $a$ because $a=1\cdot a$.
\item If $b$ divides $a$, then $a=bc$ for some $c$. Hence, $-a=b(-c)$, so that $b|(-a)$. An analogous argument shows that every divisor of $-a$ is also a divisor of $a$. Therefore,
\begin{center}
$a$ and $-a$ have the same divisors.
\end{center}

\item Suppose $a \neq 0$ and $b|a$. Then, $a=bc$, so that $\abs{a}=\abs{b}\abs{c}$. Consequently, $0 \leq \abs{b} \leq \abs{a}$. This last inequality is equivalent to $-\abs{a} \leq b \leq \abs{a}$. Therefore,
\begin{center}
\begin{enumerate}[label=(\alph*)]
\item every divisor of the nonzero integer $a$ is less than or equal to $\abs{a}$;
\item a nonzero integer has only finitely many divisors.
\end{enumerate}
\end{center}
\item If $a$ and $b$ are integers, then lcm$(a,b)$gcd$(a,b)=\abs{ab}$.
\end{enumerate}

\noindent
\textbf{DEFINITION}: Let $a$ and $b$ be integers, $ab \neq 0$. The \textbf{greatest common denominator} (gcd) of $a$ and $b$ is the largest integer $d$ that divides both $a$ and $b$. In other words, $d$ is the gcd of $a$ and $b$ provided that
\begin{enumerate}
\item $d|a$ and $d|b$;
\item if $c|a$ and $c|b$, then $c \leq d$.
\end{enumerate}
\noindent
The greatest common divisor of $a$ and $b$ is usually denoted $(a,b)$.\\

\noindent
\textbf{THEOREM 1.2} Let $a$ and $b$ be integers, $ab \neq 0$, and let $d$ be their greatest common divisor. Then there exist (not necessarily unique) integers $u$ and $v$ such that $d=au+bv$. \\
\noindent
\textbf{Remarks:}
\begin{enumerate}
\item Every integer that can be written in the form $au+bv$ for some $u, v \in \Z$, is a multiple of the gcd$(a,b)$.
\item Every common divisor of $a$ and $b$ also divides gcd$(a,b)$.
\end{enumerate}

% \noindent
% We are then able to find a smallest group sent in and or information

\noindent
\textbf{COROLLARY 1.3} Let $a$ and $b$ be integers, both not $0$, and let $d$ be a positive integer. Then $d$ is the greatest common divisor of $a$ and $b$ if and only if $d$ satisfies these conditions:
\begin{enumerate}
\item $d|a$ and $d|b$;
\item if $c|d$ and $c|b$, then $c|d$.
\end{enumerate}

\noindent
Note that the 'if and only if' part of the statement requires two steps. \\

\noindent
\textbf{THEOREM 1.4} If $a|bc$ and $(a,b)=1$, then $a|c$. \\

\begin{center}
\textbf{Section 1.3: Primes and Unique Factorization}
\end{center}

\noindent
Every nonzero integer $n$ has except $\pm 1$ has at least four distinct divisors, namely, $1,-1,n,-n$. Integers that have \textit{only} these divisors play a crucial role. \\

\noindent
\textbf{DEFINITION}: An integer $p$ is said to be \textbf{prime} if $p \neq 0, \pm1$ and the only divisors of $p$ are $\pm 1$ and $\pm p$. \\

\noindent
\textbf{Remarks:}
\begin{enumerate}[label=(\alph*)]
\item $p$ is prime if and only if $-p$ is prime.
\item If $p$ and $q$ are prime and $p|q$, then $p= \pm q$.
\item If $p=rt$, then either $r=\pm 1$ or $t=\pm 1$.
\item Integers $a$ and $b$ are \textit{relatively prime} if gcd$(a,b)=1$.
\end{enumerate}

\noindent
\textbf{THEOREM 1.5} Let $p$ be an integer with $p \neq 0, \pm1$. Then $p$ is prime if and only if $p$ has this property:
\begin{center}
whenever $p|bc$, then $p|b$ or $p|c$.
\end{center}

\noindent
\textbf{Remarks:}
\begin{enumerate}[label=(\alph*)]
\item This theorem is especially useful when proving that if $p|b^2$ for any prime $p$ and some integer $b$, then $p|b$ or $p|b$
\end{enumerate}

\noindent
\textbf{COROLLARY 1.6} If $p$ is prime and $p|a_1a_2 \cdot \cdot \cdot a_n$, then $p$ divides at least on eof the $a_i$. \\

\noindent
\textbf{THEOREM 1.7} Every integer $n$ except $0, \pm 1$ is a product of primes. \\

\noindent
\textbf{THEOREM 1.8} Every integer $n$ except $0, \pm 1$ is a product of primes. This prime factorization is unique in the following sense: If
\begin{align*}
n=p_1p_1 \cdot \cdot \cdot p_r \text{     and     } n=q_1q_1 \cdot \cdot \cdot q_s
\end{align*}
with each $p_i, q_j$ prime, then $r=s$ (that is, the number of factors is the same) and after reordering and relabeling the $q's$,
\begin{align*}
p_1=\pm q_1, \text{     }, p_2=\pm q_2, \text{     }, p_3=\pm q_3, \text{     }, ..., p_r=\pm q_r.
\end{align*}

\noindent
\textbf{COROLLARY 1.9} Every integer $n>1$ can be written in one and only one way in the form $n=p_1p_2p_3 \cdot \cdot \cdot p_r$ where $p_i$ are positive primes such that $p_1 \leq p_2 \leq p_3 \leq \cdot \cdot \cdot p_r$. \\

\noindent
\textbf{THEOREM 1.10} Let $n>1$. If $n$ has no positive prime factor less than or equal to $\sqrt{n}$, then $n$ is prime. \\

\begin{center}
\textbf{Helpful Proofs}
\end{center}

\noindent
\textbf{Euclidean Algorithm} Find $(4631, 42371)$. \\

\noindent
By the Euclidean Algorithm, we have

\begin{align*}
42371 & = 9 \cdot 4361 + 3122 \\
4361 & = 1 \cdot 3122 + 1239 \\
3122 & = 2 \cdot 1239 + 644 \\
1239 & = 1 \cdot 644 + 595 \\
644 & = 1 \cdot 595 + 49 \\
595 & = 12 \cdot 49 + 7 \\
49 & = 7 \cdot 7 + 0 \\
\end{align*}

\noindent
therefore $(4361, 42371)=7$.\\

\noindent
\textbf{Famous Induction Proof} If $n$ is a positive integer, then
\begin{center}
$1+2+ \cdot \cdot \cdot + n = \frac{n(n+1)}{2}$.
\end{center}

\begin{tcolorbox}
To verify that a proposition $P(n)$ holds for all natural numbers $n$, the \textbf{Principle of Mathematical Induction} consists of successfully carrying out the following two steps:

\begin{itemize}
\item \textbf{Base Case}: Prove that $P(0)$ is true.
\item \textbf{Induction Step}: Assume that $P(n)$ is true for any arbitrary $n$, then prove that $P(n+1)$ is true.
\end{itemize}
\end{tcolorbox}

\vspace{.2cm}
\noindent
We will proceed by induction that, for all $n \in \Z_+$,
\begin{align*}
\sum_{n=1}^{n} i = \frac{n(n+1)}{2}.
\end{align*}

\noindent
\textbf{Base Case} When $n=1$, the LHS is the sum of the first $1$ integer, which is simply $1$. The RHS is $1(1+1)/2=1$. Both sides are equal, and the inductive hypothesis holds for the base case. \\

\noindent
\textbf{Inductive Case} Let $m$ and $k$ be integers such that $m \geq 1$ and $1 \leq k \leq m$. Suppose that $P(k)$ holds. We then want to prove that $P(k+1)$ holds
\begin{align*}
\sum_{i=1}^{k+1} i & = \frac{(k+1)(k+2)}{2} \\
& = [1+2+ \cdot \cdot \cdot + k] + (k+1)
\end{align*}

\noindent
Well, by the summation,
\begin{align*}
\sum_{i=1}^{k+1} i & = 1+2+ \cdot \cdot \cdot + k + (k+1) \\
& = [1+2+ \cdot \cdot \cdot + k] + (k+1)
\end{align*}

\noindent
By the induction hypothesis,
\begin{align*}
\sum_{i=1}^{k+1} i & =  \sum_{i=1}^{k} i  + (k+1) \\
& = \frac{k(k+1)}{2}  + (k+1) \\
& =  \frac{k^2+k)}{2} +  \frac{2(k+1)}{2}\\
& =  \frac{k^2+k)}{2} +  \frac{2k+2)}{2}\\
& =  \frac{k^2+3k+2)}{2} \\
& =  \frac{(k+1)(k+2)}{2}
\end{align*}

\noindent
Thus, $P(k+1)$ holds, and the proof of the induction step is complete. We may now conclude that, by the principle of mathematical induction, $P(n)$ holds true for all $n \in \Z_+$. \\

\noindent
\textbf{Infinitude of Primes} Suppose that there are actually a finite number of primes such that $p_1<p_2<...<p_r$. Then, let $N=p_1p_2 \cdot \cdot \cdot p_r$. By the Fundamental Theorem of Arithmetic, $N+1$ also has a unique prime factorization. $N-1$ is either prime or composite. If $N-1$ is prime, then we have found another prime and contradict our original assumption. If $N-1$ is composite, it is a product of primes such that it has a prime $p_i$ in common with $N$. So, $p_i$ divides $N-(N-1)=1$, which is a contradiction. There is no prime $q$ such that $q|1$ because that would imply that $q \leq 1$, but by definition, $q>1$. Thus, there are an infinite number of primes. \qedsymbol

\section*{Chapter 2}
% TODO: Add a mention about sets and set builder notation that will come up

\begin{center}
\textbf{Section 2.1: Congruence and Congruence Classes} \\
\end{center}

\noindent
\textbf{Definition} Let $a,b,n$ be integers with $n>0$. Then $a$ is congruent $b$ modulo $n$, written "$a \equiv b (\text{mod}n)$", provided $n$ divides $a-b$. \\

\noindent
\textbf{Theorem 2.1} Let $n$ be a positive integer. for all $a,b,c \in \Z$,
\begin{enumerate}
\item $a \equiv a (\text{mod}n)$;
\item If $a \equiv b (\text{mod}n)$, then $b \equiv a (\text{mod}n)$;
\item If $a \equiv b (\text{mod}n)$ and $b \equiv c (\text{mod}n)$, then $a \equiv c (\text{mod}n)$.
\end{enumerate}

\noindent
\textbf{Theorem 2.2} If $a \equiv b (\text{mod}n)$ and $b \equiv c (\text{mod}n)$,
\begin{enumerate}
\item $a + c \equiv b + d(\text{mod}n)$
\item $ac \equiv bd (\text{mod}n)$
\end{enumerate}

\noindent
\textbf{Definition} Let $a$ an $n$ be integers $n>0$. The congruence class of a modulo $n$ (denoted by [$a$]) is the set of all those integers that are congruent to a modulo $n$, that is,
\begin{center}
[$a$]$=\{b|b \in \Z \text{  and  } b \equiv a(\text{mod}n)\}$.
\end{center}

\noindent
\textbf{Theorem 2.3} $a \equiv c (\text{mod}n)$ if and only if [$a$]$=$[$c$]. \\

\noindent
\textbf{Corollary 2.4} Two congruence classes modulo $n$ are either disjoint or identical. \\

\noindent
\textbf{Corollary 2.5} Let $n>1$ be an integer and consider congruence modulo $n$.
\begin{enumerate}
\item If $a$ is any integer and $r$ is the remainder when $a$ is divided by $n$, then [$a$]$=$[$r$].
\item There are exactly $n$ distinct congruence classes, namely, [$0$], [$1$], [$2$], $\cdot \cdot \cdot$, [$n-1$].
\end{enumerate}

\noindent
\textbf{Definition} The set of all congruence classes modulo $n$ is denoted $\Z_n$ (which is read "$\Z$ mod $n$). \\

\noindent
\textbf{Theorem 2.6} If [$a$]$=$[$b$] and [$c$]$=$[$d$] in $\Z_n$, then \\
\begin{center}
[$a+c$]$=$[$b+d$] and [$ac$]$=$[$bd$].
\end{center}

\noindent
\textbf{Definition} Addition and multiplication in $\Z_n$ are defined by \\
\begin{center}
[$a$]$\oplus$[$r$]$=$[$a+c$] and [$a$]$\varodot$[$c$]$=$[$ac$].
\end{center}

\noindent
\textbf{Theorem 2.7} For any classes [$a$], [$b$], [$c$] in $\Z_n$,
\begin{enumerate}
\item If [$a$] $\in \Z_n$ and [$b$] $\in Z_n$, then [$a$]$\oplus$[$b$]$\in \Z_n$. \\
\item [$a$]$\oplus$([$b$]$\oplus$[$c$])$=$([$b$]$\oplus$[$a$])$\oplus$[$c$]. \\
\item [$a$]$\oplus$([$0$]$=$[$0$]$\oplus$[$a$]. \\
\item [$a$]$\oplus$([$0$]$=$[$a$]$=$[$0$]$\oplus$[$a$]. \\
\item For each $[$a$]$ in $\Z_n$, the equation [$a$]$\oplus X=$[$0$] has a solution in $\Z_n$. \\
\item If [$a$] $\in \Z_n$ and [$b$]$\in \Z_n$, then [$a$]$\varodot$[$b$]$\in \Z_n$. \\
\item [$a$] $\varodot$([$b$]$\varodot$[$c$])$=$([$a$]$\varodot$[$b$])$\varodot$[$c$]. \\
\item  [$a$] $\varodot$[$b$]$=$[$b$]$\varodot$[$a$]. \\
\item [$a$] $\varodot$[$1$]$=$[$a$]$=$[$1$]$\varodot$[$a$].
\end{enumerate}

\noindent
\textbf{Theorem 2.8} If $p>1$ is an integer, then the following conditions are equivalent:
\begin{enumerate}
\item $p$ is prime
\item For any $a \neq 0 \in \Z_p$, the equation $ax=1$ has a solution in $\Z_p$.
\item Whenever $bc=0$ in $\Z_p$, then $b=0$ or $c=0$.
\end{enumerate}

\noindent
\textbf{Theorem 2.9} Let $a$ an $n$ be integers with $n>1$. Then
\begin{center}
The equation $[a]x=[1]$ has a solution in $\Z_n$ if and only if $(a,n)=1$ in $\Z$.
\end{center}

\noindent
\textbf{Theorem 2.10}
Let $a$ and $n$ be integers with $n>1$. Then
\begin{center}
$[a]$ is a unit with $\Z_n$ if and only if $(a,n)=1$ in $\Z$.
\end{center}
\end{document}


% ----------------------------------------------------------------------
\section{Elasticity with Infinitesimal Strain and Prescribed Slip on Faults}

For each fault, which is an internal interface, we add a boundary
condition to the elasticity equation prescribing the jump in the
displacement field across the fault,
\begin{gather}
  \label{eqn:bc:prescribed_slip}
  \vec{u}^+(\vec{x},t) - \vec{u}^-(\vec{x},t) - \vec{d}(\vec{x},t) = \vec{0} \text{ on }\Gamma_f,
\end{gather}
where $\vec{u}^+$ is the displacement vector on the ``positive'' side
of the fault, $\vec{u}^-$ is the displacement vector on the
``negative'' side of the fault, $\vec{d}$ is the slip vector on the
fault, and $\vec{n}$ is the fault normal which points from the
negative side of the fault to the positive side of the fault. Note
that as an alternative to prescribing the jump in displacement across
the fault, we can also prescribe the jump in velocity or acceleration
across the fault in terms of slip rate or slip acceleration,
respectively.

Using a domain decomposition approach for constraining the fault slip
yields additional Neumann-like boundary conditions on the fault
surface,
\begin{gather}
  \tensor{\sigma} \cdot \vec{n} = -\vec{\lambda}(\vec{x},t) \text{ on }\Gamma_{f^+}, \\
  \tensor{\sigma} \cdot \vec{n} = +\vec{\lambda}(\vec{x},t) \text{ on }\Gamma_{f^-},
\end{gather}
where $\vec{\lambda}$ is the vector of Lagrange multipliers
corresponding to the tractions applied to the fault surface to
generate the prescribed slip.

\begin{table}[htbp]
  \caption{Mathematical notation for elasticity equation with
    infinitesimal strain and prescribed slip on faults.}
  \label{tab:notation:elasticity:prescribed:slip}
  \begin{tabular}{lcp{3in}}
    \toprule
    {\bf Category} & {\bf Symbol} & {\bf Description} \\
    \midrule
    Unknowns & $\vec{u}$ & Displacement field \\
    & $\vec{v}$ & Velocity field \\
    & $\vec{\lambda}$ & Lagrange multiplier field \\
    Derived quantities & $\tensor{\sigma}$ & Cauchy stress tensor \\
                   & $\tensor{\epsilon}$ & Cauchy strain tensor \\
    Common constitutive parameters & $\rho$ & Density \\
  & $\mu$ & Shear modulus \\
  & $K$ & Bulk modulus \\
Source terms & $\vec{f}$ & Body force per unit volume, for example $\rho \vec{g}$ \\
    & $\vec{d}$ & Slip vector field on the fault corresponding to a
      jump in the displacement field across the fault \\
    \bottomrule
  \end{tabular}
\end{table}

\subsection{Quasistatic}

As in the case of elasticity without faults, we first consider the
quasistatic case in which we neglect the inertial term
($\rho \frac{\partial \vec{v}}{\partial t} \approx \vec{0}$). We place
all of the terms in the elasticity equation on the LHS, consistent
with implicit time stepping. Our solution vector consists of both
displacements and Lagrange multipliers, and the strong form for the
system of equations is
\begin{gather}
  % Solution
  \vec{s}^T = \left( \vec{u} \quad \vec{\lambda} \right)^T \\
  % Elasticity
  \vec{f}(\vec{x},t) + \tensor{\nabla} \cdot \tensor{\sigma}(\vec{u}) = \vec{0} \text{ in }\Omega, \\
  % Neumann
  \tensor{\sigma} \cdot \vec{n} = \vec{\tau}(\vec{x},t) \text{ on }\Gamma_\tau, \\
  % Dirichlet
  \vec{u} = \vec{u}_0(\vec{x},t) \text{ on }\Gamma_u, \\
  % Prescribed slip
  \vec{u}^+(\vec{x},t) - \vec{u}^-(\vec{x},t) - \vec{d}(\vec{x},t) = \vec{0} \text{ on }\Gamma_f,  \\
  \tensor{\sigma} \cdot \vec{n} = -\vec{\lambda}(\vec{x},t) \text{ on }\Gamma_{f^+}, \text{ and}\\
  \tensor{\sigma} \cdot \vec{n} = +\vec{\lambda}(\vec{x},t) \text{ on }\Gamma_{f^-}.
\end{gather}
We create the weak form by taking the dot product with the trial
function $\trialvec[u]$ or $\trialvec[\lambda]$ and integrating over
the domain. After using the divergence theorem and incorporating the
Neumann boundary and fault interface conditions, we have
\begin{gather}
  % Elasticity
  \int_\Omega \trialvec[u] \cdot \vec{f}(\vec{x},t) + \nabla \trialvec[v] : -\tensor{\sigma}(\vec{u}) \, d\Omega
  + \int_{\Gamma_\tau} \trialvec[u] \cdot \vec{\tau}(\vec{x},t) \, d\Gamma,
  + \int_{\Gamma_{f}} \trialvec[u^+] \cdot \left(-\vec{\lambda}(\vec{x},t)\right)
  + \trialvec[u^-] \cdot \left(+\vec{\lambda}(\vec{x},t)\right)\, d\Gamma = 0\\
  % Prescribed slip
  \int_{\Gamma_{f}} \trialvec[\lambda] \cdot \left(
    -\vec{u}^+(\vec{x},t) + \vec{u}^-(\vec{x},t) + \vec{d}(\vec{x},t) \right) \, d\Gamma = 0.
\end{gather}
We have chosen the signs in the last equation so that the Jacobian
will be symmetric with respect to the Lagrange multiplier. We solve
the system of equations using implicit time stepping, making use of
residuals functions and Jacobians for the LHS.

\subsubsection{Residual Pointwise Functions}

Identifying $F(t,s,\dot{s})$ and $G(t,s)$, we have
\begin{align}
 % Fu
F^u(t,s,\dot{s}) &= \int_\Omega \trialvec[u] \cdot \eqnannotate{\vec{f}(\vec{x},t)}{\vec{f}^u_0} + \nabla \trialvec[u] : \eqnannotate{-\tensor{\sigma}(\vec{u})}{\tensor{f^u_1}} \, d\Omega
  + \int_{\Gamma_\tau} \trialvec[u] \cdot \eqnannotate{\vec{\tau}(\vec{x},t)}{\vec{f}^u_0} \, d\Gamma
  + \int_{\Gamma_{f}} \trialvec[u^+] \cdot \eqnannotate{\left(-\vec{\lambda}(\vec{x},t)\right)}{\vec{f}^u_0}
  + \trialvec[u^-] \cdot \eqnannotate{\left(+\vec{\lambda}(\vec{x},t)\right)}{\vec{f}^u_0}\, d\Gamma \\
  % Fl
  F^\lambda(t,s,\dot{s}) &= \int_{\Gamma_{f}} \trialvec[\lambda] \cdot \eqnannotate{\left(
    -\vec{u}^+(\vec{x},t) + \vec{u}^-(\vec{x},t) + \vec{d}(\vec{x},t) \right)}{\vec{f}^\lambda_0} \, d\Gamma, \\
  % Gu
  G^u(t,s) &= 0 \\
  % Gl
  G^\lambda(t,s) &= 0
\end{align}
Compared to the quasistatic elasticity case without a fault, we have
simply added additional pointwise functions associated with the
fault. Our fault implementation does not change the formulation for
the materials or external Dirichlet or Neumann boundary conditions.

\subsubsection{Jacobian Pointwise Functions}

The LHS Jacobians are:
\begin{align}
  % J_F uu
  J_F^{uu} &= \frac{\partial F^u}{\partial u} + s_\mathit{tshift} \frac{\partial F^u}{\partial \dot{u}}
      = \int_\Omega \nabla \trialvec[u] : -\tensor{C} : \frac{1}{2}(\nabla + \nabla^T)\basisvec[u]
\, d\Omega
      = \int_\Omega \trialscalar[u]_{i,k} \, \eqnannotate{\left( -C_{ikjl} \right)}{J_{f3}^{uu}} \, \basisscalar[u]_{j,l}\, d\Omega \\
  % J_F ul
  J_F^{u\lambda} &= \frac{\partial F^u}{\partial \lambda} + s_\mathit{tshift} \frac{\partial F^u}{\partial \dot{\lambda}}
      = \int_{\Gamma_{f}} \trialscalar[u^+]_i \eqnannotate{\left(-\delta_{ij}\right)}{J^{u\lambda}_{f0}} \basisscalar[\lambda]_j
                   + \trialscalar[u^-]_i \eqnannotate{\left(+\delta_{ij}\right)}{J^{u\lambda}_{f0}} \basisscalar[\lambda]_j\, d\Gamma, \\
  % J_F lu
  J_F^{\lambda u} &= \frac{\partial F^\lambda}{\partial u} + s_\mathit{tshift} \frac{\partial F^\lambda}{\partial \dot{u}}
      = \int_{\Gamma_{f}} \trialscalar[\lambda]_i
                    \eqnannotate{\left(-\delta_{ij}\right)}{J^{\lambda u}_{f0}} \basisscalar[u^+]_j
                    + \trialscalar[\lambda]_i \eqnannotate{\left(+\delta_{ij}\right)}{J^{\lambda u}_{f0}} \basisscalar[u^-]_j \, d\Gamma, \\
  % J_F ll
  J_F^{\lambda \lambda} &= \tensor{0}
\end{align}
This LHS Jacobian has the structure
\begin{equation}
  J_F = \left( \begin{array} {cc} J_F^{uu} & J_F^{u\lambda} \\ J_F^{\lambda u} & 0 \end{array} \right)
      = \left( \begin{array} {cc} J_F^{uu} & C^T \\ C & 0 \end{array} \right),
\end{equation}
where $C$ contains entries of $\pm 1$ for degrees of
freedom on the two sides of the fault. The Schur complement of $J$
with respect to $J_F^{uu}$ is $-C\left(J_F^{uu}\right)^{-1}C^T$.

\subsection{Dynamic}

The equation prescribing fault slip is independent of the Lagrange
multiplier, so we do not have a system of equations that we can put in
the form $\dot{s} = G^*(t,s)$. Instead, we have a
differential-algebraic set of equations (DAEs), which we solve using
an implicit-explicit (IMEX) time integration scheme. As in the case of
dynamic elasticity without faults, we introduce the velocity
($\vec{v}$) as an unknown to turn the elasticity equation into two
first order equations. The strong form for our system of equations is:
\begin{gather}
  % Solution
  \vec{s}^T = \left( \vec{u} \quad \vec{v} \quad \vec{\lambda} \right)^T \\
  % Displacement-velocity
  \frac{\partial \vec{u}}{\partial t} = \vec{v}, \\
  % Elasticity
  \rho(\vec{x}) \frac{\partial \vec{v}}{\partial t} =
  \vec{f}(\vec{x},t) + \nabla \cdot \tensor{\sigma}(\vec{u}), \\
  % Neumann BC
  \tensor{\sigma} \cdot \vec{n} = \vec{\tau} \text{ on } \Gamma_\tau. \\
  % Dirichlet BC
  \vec{u} = \vec{u}_0 \text{ on } \Gamma_u, \\
  % Presribed slip
  \vec{u}^+(\vec{x},t) - \vec{u}^-(\vec{x},t) - \vec{d}(\vec{x},t) = \vec{0} \text{ on }\Gamma_f,  \\
  \tensor{\sigma} \cdot \vec{n} = -\vec{\lambda}(\vec{x},t) \text{ on }\Gamma_{f^+}, \text{ and}\\
  \tensor{\sigma} \cdot \vec{n} = +\vec{\lambda}(\vec{x},t) \text{ on }\Gamma_{f^-}.
\end{gather}
The differentiation index is 2 because we must take the second time
derivative of the prescribed slip equation to match the order of the
time derivative in the elasticity equation,
\begin{gather}
  \frac{\partial \vec{v}^+}{\partial t} - \frac{\partial \vec{v}^-}{\partial t} -
  \frac{\partial^2 \vec{d}(\vec{x},t)}{\partial t^2} = \vec{0}.
\end{gather}
We generate the weak form in the usual way,
\begin{gather}
  % Displacement-velocity
  \int_{\Omega} \trialvec[u] \cdot \frac{\partial \vec{u}}{\partial t} \, d\Omega =
  \int_{\Omega} \trialvec[u] \cdot \vec{v} \, d\Omega, \\
  % Elasticity
  \begin{multlined}
  \int_{\Omega} \trialvec[v] \cdot \rho(\vec{x}) \frac{\partial \vec{v}}{\partial t} \, d\Omega
  = \int_\Omega \trialvec[v] \cdot \vec{f}(\vec{x},t) + \nabla \trialvec[v] : -\tensor{\sigma}(\vec{u}) \, d\Omega
  + \int_{\Gamma_\tau} \trialvec[v] \cdot \vec{\tau}(\vec{x},t) \, d\Gamma \\
  + \int_{\Gamma_{f}} \trialvec[v^+] \cdot \left(-\vec{\lambda}(\vec{x},t)\right)
  + \trialvec[v^-] \cdot \left(+\vec{\lambda}(\vec{x},t)\right)\, d\Gamma,
  \end{multlined}\\
  % Prescribed slip
  \int_{\Gamma_f} \trialvec[\lambda] \cdot \left(
    \frac{\partial \vec{v}^+}{\partial t} - \frac{\partial \vec{v}^-}{\partial t} -
    \frac{\partial^2 \vec{d}(\vec{x},t)}{\partial t^2} \right) \, d\Gamma = 0.
\end{gather}

For compatibility with PETSc TS IMEX implementations, we need
$\dot{\vec{s}}$ on the LHS for the explicit part (displacement-velocity and
elasticity equations) and we need $\vec{\lambda}$ in the equation for
the implicit part (prescribed slip equation). We first focus on the
explicit part and create a lumped LHS Jacobian matrix, $M$, so that we
have
\begin{gather}
  % Displacement-velocity
  \label{eqn:displacement:velocity:prescribed:slip:weak:form}
  \frac{\partial \vec{u}}{\partial t} = M_u^{-1} \int_{\Omega} \trialvec[u] \cdot \vec{v} \, d\Omega, \\
  % Elasticity
  \label{eqn:elasticity:prescribed:slip:dynamic:weak:form}
  \begin{multlined}
  \frac{\partial \vec{v}}{\partial t}
  = M_v^{-1} \int_\Omega \trialvec[v] \cdot \vec{f}(\vec{x},t) + \nabla \trialvec[v] : -\tensor{\sigma}(\vec{u}) \, d\Omega
  + M_v^{-1} \int_{\Gamma_\tau} \trialvec[v] \cdot \vec{\tau}(\vec{x},t) \, d\Gamma \\
  + M_{v^+}^{-1} \int_{\Gamma_{f}} \trialvec[v^+] \cdot \left(-\vec{\lambda}(\vec{x},t)\right) \, d\Gamma
  + M_{v^-}^{-1} \int_{\Gamma_{f}}\trialvec[v^-] \cdot \left(+\vec{\lambda}(\vec{x},t)\right) \, d\Gamma,
\end{multlined}\\
% Mu
M_u = \mathit{Lump}\left( \int_\Omega \trialscalar[u]_i \delta_{ij} \basisscalar[u]_j \, d\Omega \right), \\
% Mv
M_v = \mathit{Lump}\left( \int_\Omega \trialscalar[v]_i \rho(\vec{x}) \delta_{ij} \basisscalar[v]_j \, d\Omega \right).
\end{gather}
Now, focusing on the implicit part we want to introduce
$\vec{\lambda}$ into the prescribed slip equation. We solve the
elasticity equation for $\frac{\partial \vec{v}}{\partial t}$, create
the weak form, and substitute into the prescribed slip
equation. Solving the elasticity equation for
$\frac{\partial \vec{v}}{\partial t}$, we have
\begin{equation}
  \frac{\partial \vec{v}}{\partial t} = \frac{1}{\rho(x)} \vec{f}(\vec{x},t) + \frac{1}{\rho(x)} \left(\nabla \cdot \tensor{\sigma}(\vec{u}) \right),
\end{equation}
and the corresponding weak form is
\begin{equation}
  \label{eqn:prescribed:slip:DAE:weak:form}
  \int_{\Omega} \trialvec[v] \cdot \frac{\partial \vec{v}}{\partial t} \, d\Omega
  = \int_\Omega \trialvec[v] \cdot \frac{1}{\rho(x)} \vec{f}(\vec{x},t) + \trialvec[v] \cdot \frac{1}{\rho(x)} \left(\nabla \cdot \tensor{\sigma}(\vec{u}) \right) \, d\Omega,
\end{equation}
We apply the divergence theorem,
\begin{equation}
  \int_{\Omega} \nabla \cdot \vec{F} \, d\Omega = \int_\Gamma \vec{F} \cdot \vec{n} \, d\Gamma,
\end{equation}
with $\vec{F} = \trialvec[v] \cdot \frac{1}{\rho(x)} \left(\nabla \cdot \tensor{\sigma}(\vec{u})\right)$ to get
\begin{equation}
  \int_\Omega \trialvec[v] \cdot \frac{1}{\rho(x)} \left(\nabla \cdot \tensor{\sigma}(\vec{u}) \right) \, d\Omega
  = \int_\Gamma \trialvec[v] \cdot \left( \frac{1}{\rho(x)} \tensor{\sigma}(\vec{u}) \cdot \vec{n} \right) \, d\Gamma
  + \int_\Omega \nabla\trialvec[v] : \left(-\frac{1}{\rho(\vec{x})} \tensor{\sigma}(\vec{u}) \right)
  + \trialvec[v] \cdot \left(-\frac{\nabla \rho(\vec{x})}{\rho^2} \cdot \tensor{\sigma}(\vec{u}) \right) \, d\Omega.
\end{equation}
Restricting the trial function to $v^+$ and $v^-$ while recognizing that there is no overlap between the external Neumann boundary conditions $\Gamma_\tau$ and the fault interfaces $\Gamma_f$, yields
\begin{gather}
  \int_\Omega \trialvec[v^+] \cdot \frac{1}{\rho(x)} \left(\nabla \cdot \tensor{\sigma}(\vec{u}) \right) \, d\Omega
  = \int_{\Gamma_f} \trialvec[v^+] \cdot \left(-\frac{1}{\rho(x)} \vec{\lambda} \right) \, d\Gamma
  + \int_\Omega \nabla\trialvec[v^+] : \left(-\frac{1}{\rho(\vec{x})} \tensor{\sigma}(\vec{u}) \right)
  + \trialvec[v^+] \cdot \, \left(-\frac{\nabla \rho(\vec{x})}{\rho^2} \cdot \tensor{\sigma}(\vec{u}) \right) \, d\Omega, \\
  \int_\Omega \trialvec[v^-] \cdot \frac{1}{\rho(x)} \left(\nabla \cdot \tensor{\sigma}(\vec{u}) \right) \, d\Omega
  = \int_{\Gamma_f} \trialvec[v^-] \cdot \left(+\frac{1}{\rho(x)} \vec{\lambda} \right) \, d\Gamma
  + \int_\Omega \nabla\trialvec[v^-] : \left(-\frac{1}{\rho(\vec{x})} \tensor{\sigma}(\vec{u}) \right)
  + \trialvec[v^-] \cdot \, \left(-\frac{\nabla \rho(\vec{x})}{\rho^2} \cdot \tensor{\sigma}(\vec{u}) \right) \, d\Omega. \end{gather}
Picking $\trialvec[v]=\trialvec[\lambda]$ and substituting into equation~\vref{eqn:prescribed:slip:DAE:weak:form} gives
\begin{multline}
  \int_{\Gamma_f} \trialvec[\lambda] \cdot \left(
    \frac{\partial \vec{v}^+}{\partial t} - \frac{\partial \vec{v}^-}{\partial t} -
    \frac{\partial^2 \vec{d}(\vec{x},t)}{\partial t^2} \right) \, d\Gamma = \\
  \int_\Omega \trialvec[v^+] \cdot \left( \frac{1}{\rho(\vec{x})} \vec{f}(\vec{x}, t)
    -\frac{\nabla \rho(\vec{x})}{\rho^2(\vec{x})} \cdot \tensor{\sigma}(\vec{u}) \right)
  + \nabla \trialvec[v^+] : \left(-\frac{1}{\rho(\vec{x})} \tensor{\sigma}(\vec{u}) \right) \, d\Omega
  + \int_{\Gamma_f} \trialvec[v^+] \cdot \left(-\frac{1}{\rho(\vec{x})} \vec{\lambda} \right) \, d\Gamma \\
  - \int_\Omega \trialvec[v^-] \cdot \left( \frac{1}{\rho(\vec{x})} \vec{f}(\vec{x}, t)
  -\frac{\nabla \rho(\vec{x})}{\rho^2(\vec{x})} \cdot \tensor{\sigma}(\vec{u}) \right)
  + \nabla \trialvec[v^-] : \left(-\frac{1}{\rho(\vec{x})} \tensor{\sigma}(\vec{u}) \right) \, d\Omega
  + \int_{\Gamma_f} \trialvec[v^-] \cdot \left(-\frac{1}{\rho(\vec{x})} \vec{\lambda} \right) \, d\Gamma \\
  - \int_{\Gamma_f} \trialvec[\lambda] \cdot \frac{\partial^2 \vec{d}(\vec{x}, t)}{\partial t^2} \, d\Gamma.
\end{multline}
We rewrite the integrals over the domain involving the degrees of
freedom adjacent to the fault as integrals over the positive and
negative sides of the fault. These are implemented as integrals over
the faces of cells adjacent to the fault; they involve quantities,
such as density, that are defined only within the domain cells. After
collecting and rearranging terms, we have
\begin{multline}
  \label{eqn:elasticity:prescribed:slip:dynamic:DAE:weak:form}
  \int_{\Gamma_{f^+}} \trialvec[\lambda] \cdot \frac{1}{\rho(\vec{x})} \left(
    \vec{\lambda} - \vec{f}(\vec{x},t) + \frac{\nabla\rho(\vec{x})}{\rho(\vec{x})} \cdot \tensor{\sigma}(\vec{u}) \right)
  + \nabla \trialvec[\lambda] : \left(+\frac{1}{\rho(\vec{x})} \tensor{\sigma}(\vec{u}) \right) \, d\Gamma \\
  + \int_{\Gamma_{f^-}} \trialvec[\lambda] \cdot \frac{1}{\rho(\vec{x})} \left(
    \vec{\lambda} + \vec{f}(\vec{x},t) - \frac{\nabla\rho(\vec{x})}{\rho(\vec{x})} \cdot \tensor{\sigma}(\vec{u}) \right)
  + \nabla \trialvec[\lambda] : \left(-\frac{1}{\rho(\vec{x})} \tensor{\sigma}(\vec{u}) \right)  \, d\Gamma \\
  + \int_{\Gamma_f} \trialvec[\lambda] \cdot \frac{\partial^2 \vec{d}(\vec{x}, t)}{\partial t^2} \, d\Gamma
  = 0.
\end{multline}

\subsection{Residual Pointwise Functions}

Combining the explicit parts of the weak form in equations~\ref{eqn:displacement:velocity:prescribed:slip:weak:form} and \ref{eqn:elasticity:prescribed:slip:dynamic:weak:form} with the implicit part of the weak form in equation~\ref{eqn:elasticity:prescribed:slip:dynamic:DAE:weak:form} and identifying $F(t,s,\dot{s})$ and $G(t,s)$, we have
\begin{gather}
  % Fu
  F^u(t,s,\dot{s}) = \frac{\partial \vec{u}}{\partial t} \\
  % Fv
  F^v(t,s,\dot{s}) = \frac{\partial \vec{v}}{\partial t} \\
  % Fl
  \begin{multlined}
    F^\lambda(t,s,\dot{s}) =   \int_{\Gamma_{f^+}} \trialvec[\lambda] \cdot \eqnannotate{\frac{1}{\rho(\vec{x})} \left(
    \vec{\lambda} - \vec{f}(\vec{x},t) + \frac{\nabla\rho(\vec{x})}{\rho(\vec{x})} \cdot \tensor{\sigma}(\vec{u}) \right)}{f^\lambda_0}
  + \nabla \trialvec[\lambda] : \eqnannotate{\left(+\frac{1}{\rho(\vec{x})} \tensor{\sigma}(\vec{u})\right)}{f^\lambda_1} \, d\Gamma \\
  + \int_{\Gamma_{f^-}} \trialvec[\lambda] \cdot \eqnannotate{\frac{1}{\rho(\vec{x})} \left(
    \vec{\lambda} + \vec{f}(\vec{x},t) - \frac{\nabla\rho(\vec{x})}{\rho(\vec{x})} \cdot \tensor{\sigma}(\vec{u}) \right)}{f^\lambda_0}
  + \nabla \trialvec[\lambda] : \eqnannotate{\left(-\frac{1}{\rho(\vec{x})} \tensor{\sigma}(\vec{u}) \right)}{f^\lambda_1}  \, d\Gamma \\
  + \int_{\Gamma_f} \trialvec[\lambda] \cdot \eqnannotate{\frac{\partial^2 \vec{d}(\vec{x}, t)}{\partial t^2}}{f^\lambda_0} \, d\Gamma
  \end{multlined}\\
  % Gu
  G^u(t,s) = \int_\Omega \trialvec[u] \cdot \eqnannotate{\vec{v}}{\vec{g}^u_0} \, d\Omega, \\
  % Gv
  G^v(t,s) =  \int_\Omega \trialvec[v] \cdot \eqnannotate{\vec{f}(\vec{x},t)}{\vec{g}^v_0} + \nabla \trialvec[v] : \eqnannotate{-\tensor{\sigma}(\vec{u})}{\tensor{g^v_1}} \, d\Omega
  + \int_{\Gamma_\tau} \trialvec[v] \cdot \eqnannotate{\vec{\tau}(\vec{x},t)}{\vec{g}^v_0} \, d\Gamma,
  + \int_{\Gamma_{f}} \trialvec[v^+] \cdot \eqnannotate{\left(-\vec{\lambda}(\vec{x},t)\right)}{\vec{g}^v_0}
             + \trialvec[v^-] \cdot \eqnannotate{\left(+\vec{\lambda}(\vec{x},t)\right)}{\vec{g}^v_0} \, d\Gamma, \\
  % Gl
  G^l(t,s) = 0
\end{gather}

\subsection{Jacobian Pointwise Functions}

For the explicit part we have pointwise functions for computing the
lumped LHS Jacobian. These are exactly the same pointwise functions as
in the dynamic case without a fault,
\begin{align}
  % J_F uu
  J_F^{uu} &= \frac{\partial F^u}{\partial u} + s_\mathit{tshift} \frac{\partial F^u}{\partial \dot{u}} =
             \int_\Omega \trialscalar[u]_i \eqnannotate{s_\mathit{tshift} \delta_{ij}}{J^{uu}_{f0}} \basisscalar[u]_j  \, d\Omega, \\
  % J_F vv
  J_F^{vv} &= \frac{\partial F^v}{\partial v} + s_\mathit{tshift} \frac{\partial F^v}{\partial \dot{v}} =
             \int_\Omega \trialscalar[v]_i \eqnannotate{\rho(\vec{x}) s_\mathit{tshift} \delta_{ij}}{J ^{vv}_{f0}} \basisscalar[v]_j \, d\Omega
\end{align}
For the implicit part, we have pointwise functions for the LHS Jacobians associated with the prescribed slip,
\begin{gather}
  \begin{multlined}
  % J_F lu
  J_F^{\lambda u} = \frac{\partial F^\lambda}{\partial u} + s_\mathit{tshift} \frac{\partial F^\lambda}{\partial \dot{u}} = \\
                    \int_{\Gamma_{f^+}} \trialscalar[\lambda]_i \eqnannotate{\frac{\rho_{,j}(\vec{x})}{\rho^2(\vec{x})} C_{ikjl} \basisscalar[u]_{j,l}}{J^{\lambda u}_{fX}}
                    + \trialscalar[\lambda]_{i,k} \eqnannotate{+\frac{1}{\rho(\vec{x})} C_{ikjl} \basisscalar[u]_{k,l}}{J^{\lambda u}_{f3}} \, d\Gamma \\
                    +\int_{\Gamma_{f^-}} \trialscalar[\lambda]_i \eqnannotate{-\frac{\rho_{,j}(\vec{x})}{\rho^2(\vec{x})} C_{ikjl} \basisscalar[u]_{j,l}}{J^{\lambda u}_{fX}}
                    + \trialscalar[\lambda]_{i,k} \eqnannotate{-\frac{1}{\rho(\vec{x})} C_{ikjl} \basisscalar[u]_{k,l}}{J^{\lambda u}_{f3}} \, d\Gamma
                  \end{multlined} \\
  % J_F ll
  J_F^{\lambda \lambda} = \frac{\partial F^\lambda}{\partial \lambda} + s_\mathit{tshift} \frac{\partial F^\lambda}{\partial \dot{\lambda}} =
             \int_{\Gamma_{f^+}} \trialscalar[\lambda]_i \eqnannotate{\frac{1}{\rho(\vec{x})} \delta_{ij}}{J^{\lambda\lambda}_{f0}} \basisscalar[\lambda]_j \, d\Gamma
            + \int_{\Gamma_{f^-}} \trialscalar[\lambda]_i \eqnannotate{\frac{1}{\rho(\vec{x})} \delta_{ij}}{J^{\lambda\lambda}_{f0}} \basisscalar[\lambda]_j \, d\Gamma
\end{gather}

% End of file


\section{A Bayesian Model for Massive Competitions}
\label{sec:bayes_model}
% The method is best-suited for competitions in which the most pertinent information is round rankings. Note that, in the programming contest setting, this means we discard specific information about player scores, which are difficult to model and depend heavily on the specifics of the problem set. This method would be ill-suited to model, for instance, track races, where a runner's absolute time is more informative than relative rankings. On the other hand, it may be very well-suited to obstacle-course races, if each round consists of novel obstacles that make the absolute times hard to interpret.

We now describe the setting formally, denoting random variables by capital letters. A series of competitive \textbf{rounds}, indexed by $t=1,2,3,\ldots$, take place sequentially in time. Each round has a set of participating \textbf{players} $\cP_t$, which may in general overlap between rounds. A player's \textbf{skill} is likely to change with time, so we represent the skill of player $i$ at time $t$ by a real random variable $S_{i,t}$.

In round $t$, each player $i\in \cP_t$ competes at some \textbf{performance} level $P_{i,t}$, typically close to their current skill $S_{i,t}$. The deviations $\{P_{i,t}-S_{i,t}\}_{i\in\cP_t}$ are assumed to be i.i.d. and independent of $\{S_{i,t}\}_{i\in\cP_t}$.

Performances are not observed directly; instead, a ranking gives the relative order among all performances $\{P_{i,t}\}_{i\in\cP_t}$. In particular, ties are modelled to occur when performances are exactly equal, a zero-probability event when their distributions are continuous.\footnote{
%If $e$ contains ties, then $(E_t = e)$ has probability zero in our model.
The relevant limiting procedure is to treat performances within $\epsilon$-width buckets as ties, and letting $\epsilon\rightarrow 0$. This technicality appears in the proof of \Cref{thm:uniq-max}.} This ranking constitutes the observational \textbf{evidence} $E_t$ for our Bayesian updates. The rating system seeks to estimate the skill $S_{i,t}$ of every player at the present time $t$, given the historical round rankings $E_{\le t} := \{ E_1,\ldots,E_t \}$.

We overload the notation $\Pr$ for both probabilities and probability densities: the latter interpretation applies to zero-probability events, such as in $\Pr(S_{i,t} = s)$. We also use colons as shorthand for collections of variables differing only in a subscript: for instance, $P_{:,t}:=\{P_{i,t}\}_{i\in\cP_t}$. The joint distribution described by our Bayesian model factorizes as follows:
\begin{align}
    &\Pr(S_{:,:}, P_{:,:}, E_:) \label{eq:model}
    \\&= \prod_i \Pr(S_{i,0})
    \prod_{i,t} \Pr(S_{i,t}\mid S_{i,t-1})
    \prod_{i,t} \Pr(P_{i,t}\mid S_{i,t})
    \prod_t \Pr(E_t\mid P_{:,t}), \nonumber
\end{align}
\vspace{-1.5em}
\begin{align*}
    \text{where } \Pr(S_{i,0}) &\text{ is the initial skill prior,}
    \\\Pr(S_{i,t}\mid S_{i,t-1}) &\text{ is the skill evolution model (\Cref{sec:skill-drift}),}
    \\\Pr(P_{i,t}\mid S_{i,t}) &\text{ is the performance model, and}
    \\\Pr(E_t\mid P_{:,t}) &\text{ is the evidence model.}
\end{align*}
For the first three factors, we will specify log-concave distributions (see \Cref{def:log-concave}). The evidence model, on the other hand, is a deterministic indicator. It equals one when $E_t$ is consistent with the relative ordering among $\{P_{i,t}\}_{i\in\cP_t}$, and zero otherwise.

Finally, our model assumes that the number of participants $|\cP_t|$ is large. %(in practice, in the tens to thousands).
The main idea behind our algorithm is that, in sufficiently massive competitions, from the evidence $E_t$ we can infer very precise estimates for $\{P_{i,t}\}_{i\in\cP_t}$. Hence, we can treat these performances as if they were observed directly.
%\begin{theorem}
%Consider a round $t$ with player $i$ having performance $P_{i,t}$, and a set of participants $\cP_t$ drawn from the same distribution as player $i$. Suppose are prior believe on $P_{i,t}$ is continuous and has positive density at its true value. Then with probability 1, in the limit $|\cP_t|\rightarrow \infty$, the posterior belief on $P_{i, t}$ conditioned on $E_t$ concentrates around its true value. Furthermore,
%\[\lim_{|\cP_t|\rightarrow\infty} \Pr(S_{i,t}=s \mid P_{i,<t},\,E_t) = \Pr(S_{i,t} = s \mid P_{i, \leq t}). \]
%\end{theorem}
%\begin{proof}

That is, suppose we have the skill prior at round $t$:
\begin{equation}
\label{eq:pi-s}
\pi_{i,t}(s) := \Pr(S_{i,t} = s \mid P_{i,<t}).
\end{equation}

Now, we observe $E_t$. By \Cref{eq:model}, it is conditionally independent of $S_{i,t}$, given $P_{i,\le t}$. By the law of total probability,
\begin{align*}
&\Pr(S_{i,t}=s \mid P_{i,<t},\,E_t)
\\&= \int \Pr(S_{i,t}=s \mid P_{i,<t},\,P_{i,t}=p) \Pr(P_{i,t}=p \mid P_{i,<t},\,E_t) \, \mathrm{d}p
\\&\rightarrow \Pr(S_{i,t}=s \mid P_{i,\le t}) \quad\text{almost surely as }|\mathcal P_t|\rightarrow\infty.
\end{align*}
The integral is intractable in general, since the performance posterior $\Pr(P_{i,t}=p \mid P_{i,<t},\,E_t)$ depends not only on player $i$, but also on our belief regarding the skills of all $j\in\cP_t$. However, in the limit of infinite participants, Doob's consistency theorem~\cite{F63} implies that it concentrates at the true value $P_{i,t}$. Since our posteriors are continuous, the convergence holds for all $s$ simultaneously.
%\end{proof}

Indeed, we don't even need the full evidence $E_t$. Let $E^L_{i,t} = \{j\in\cP:P_{j,t}>P_{i,t}\}$ be the set of players against whom $i$ lost, and $E^W_{i,t} = \{j\in\cP:P_{j,t}<P_{i,t}\}$ be the set of players against whom $i$ won. That is, we only see who wins, draws, and loses against $i$. $P_{i,t}$ remains identifiable using only $(E^L_{i,t}, E^W_{i,t})$, which will be more convenient for our purposes.

Passing to the limit in which $P_{i,\le t}$ is identified serves to justify several common simplifications made by total-order rating systems. Firstly, since $P_{i,\le t}$ is a sufficient statistic for predicting $S_{i,t}$, it may be said that $(E^L_{i,\le t}, E^W_{i,\le t})$ are ``almost sufficient'' for $S_{i,t}$: any additional information, such as from domain-specific scoring systems, becomes redundant for the purposes of skill estimation. Secondly, conditioned on $P_{:,\le t}$, the posterior skills $S_{:,t}$ are independent of one another. As a result, there are no inter-player correlations to model, and a player's posterior is unaffected by rounds in which they are not a participant. Finally, if we've truly identified $P_{i,t}$, then rounds later than $t$ should not prompt revisions in our estimate for $P_{i,t}$. This obviates the need for expensive whole-history update procedures~\cite{DHMG07,WHR}, for the purposes of present skill estimation.\footnote{As opposed to \emph{historical} skill estimation, which is concerned with $P(S_{i,t} \mid P_{i,\le t'})$ for $t'>t$. Whole-history methods can take advantage of future information.}

Finally, a word on the rate of convergence. Suppose we want our estimate to be within $\epsilon$ of $P_{i,t}$, with probability at least $1-\delta$. By asymptotic normality of the posterior~\cite{F63}, it suffices to have $O(\frac 1{\epsilon^2}\log \frac 1\delta)$ participants.

When the initial prior, performance model, and evolution model are all Gaussian, treating $P_{i,t}$ as certain is the \emph{only} simplifying approximation we will make; that is, in the limit $|\cP_t|\rightarrow\infty$, our method performs \emph{exact} inference on \Cref{eq:model}. In the following sections, we focus some attention on generalizing the performance model to non-Gaussian log-concave families, parametrized by location and scale. We will use the logistic distribution as a running example and see that it induces robustness; however, our framework is agnostic to the specific distributions used.%For non-Gaussian performance models, we will make a few additional approximations, but we resist the temptation to approximate the posteriors by something compact.

The prior \textbf{rating} $\mu^\pi_{i,t}$ and posterior rating $\mu_{i,t}$ of player $i$ at round $t$ should be statistics that summarize the player's prior and posterior skill distribution, respectively. We'll use the mode: thus, $\mu_{i,t}$ is the maximum a posteriori (MAP) estimate, obtained by setting $s$ to maximize the posterior $\Pr(S_{i,t}=s \mid P_{i,\le t})$. By Bayes' rule,
\begin{align}
\label{eq:new-obj}
\mu_{i,t}^\pi &:= \argmax_{s} \pi_{i,t}(s), \nonumber
\\\mu_{i,t} &:= \argmax_{s} \pi_{i,t}(s) \Pr(P_{i,t} \mid S_{i,t}=s).
\end{align}

This objective suggests a two-phase algorithm to update each player $i\in\cP_t$ in response to the results of round $t$. In phase one, we estimate $P_{i,t}$ from $(E^L_{i,t}, E^W_{i,t})$. By Doob's consistency theorem, our estimate is extremely precise when $|\cP_t|$ is large, so we assume it to be exact. In phase two, we update our posterior for $S_{i,t}$ and the rating $\mu_{i,t}$ according to \Cref{eq:new-obj}.


\subsection{Position space representation}

First we define the time integral of the Lagrangian of the classical oscillator given in Eq.~(\ref{eq:5}), over a period $T=2\pi/\omega$ as
\begin{equation} \label{eq:b1}
  \Delta_{\varepsilon} = \frac{1}{T} \int_0^T L(\zeta,\dot{\zeta},t') dt'.
\end{equation}
Additionally, performing this integral, we can obtain a more simplified result
\begin{equation} \label{eq:b2}
  \Delta_{\varepsilon} = \frac{e^2E^2}{4m_e(\omega_0^2 - \omega^2)}.
\end{equation}
Next, we define another parameter
\begin{equation} \label{eq:b3}
  \xi =
  \int_0^t \; L(\zeta,\dot{\zeta},t') dt' -
  \Delta_{\varepsilon} t,
\end{equation}
and after simplifying, we can identify
\begin{equation} \label{eq:b4}
  \xi =
  \frac{e^2E^2\qty(3\omega^2 - \omega_0^2)}{8m_e\omega(\omega_0^2 - \omega^2)^2} \sin(2\omega t),
\end{equation}
which is a periodic function in time. Using these parameters, we can factorize the wave function given in Eq.~(\ref{eq:2}) as linearly time-dependent part and periodic time-dependent part as follows
\begin{equation} \label{eq:b5}
  \begin{aligned}
    \psi_{\alpha}&(x,y,t) \\
    & =
    \exp(\frac{i}{\hbar} \left(-\epsilon_nt + \Delta_{\varepsilon} t \right) )
    \frac{1}{\sqrt{L_x}} \chi_n\bm{\left(}y - y_0 - \zeta(t)\bm{\right)}
    \\
    & \quad\times
    \exp \left(
       \frac{i}{\hbar}
       \left\{
       p_x x +
       \frac{eE(y-y_0)}{\omega}\cos(\omega t)  \right. \right. \\
    & \left. \left. \qquad\qquad\qquad\qquad
    + m_e\dot{\zeta}(t) \left[ y-y_0 -\zeta(t) \right]
    + \xi \right\}
     \right).
  \end{aligned}
\end{equation}
This leads to separate the linear time-dependent phase component as the quasienergies
\begin{equation} \label{eq:b6}
  \varepsilon_{n} =
  \hbar \omega_0\qty(n + \frac{1}{2}) - \Delta_{\varepsilon},
\end{equation}
while rest of the components as time-periodic Floquet modes
\begin{equation} \label{eq:b7}
  \begin{aligned}
    \phi_{n,m}(x,y,t) =  &
    \frac{1}{\sqrt{L_x}} \chi_n\bm{\left(}y - y_0 - \zeta(t)\bm{\right)} \\
    & \times
    \exp \left(
       \frac{i}{\hbar}
       \left\{
       p_x x +
       \frac{eE(y-y_0)}{\omega}\cos(\omega t)  \right. \right. \\
    & \left. \left. \qquad\qquad\quad
    + m_e\dot{\zeta}(t) \left[ y-y_0 -\zeta(t) \right]
    + \xi \right\}
     \right).
  \end{aligned}
\end{equation}

\subsection{Momentum space representation}

We perform continuous Fourier transform over the considering confined space $A=L_xL_y$ on the Floquet modes given in Eq.~(\ref{eq:7}) to realize the Floquet modes in momentum space
\begin{equation} \label{eq:b8}
  \begin{aligned}
    \phi_{n,m}&(k_x,k_y,t) \\
    & =
    \exp(\frac{-i\gamma(t)}{\hbar}y_0)
    \exp(\frac{-i}{\hbar}\left[m_e \dot{\zeta}(t) \zeta(t) - \xi \right]) \\
    & \quad\times
    \int_{-L_y/2}^{L_y/2} \exp(-i \left[k_y - \gamma(t) \right]y)
      \chi_n \bm{\left(}y - \mu(t)\bm{\right)} dy \\
    & \quad\times
    \frac{1}{\sqrt{L_x}} \int_{-L_x/2}^{L_x/2}
     \exp(-ik_x x)\exp( \flatfrac{i p_x }{\hbar}x ) dx.
  \end{aligned}
\end{equation}
Here we used new two parameters
\begin{equation} \label{eq:b9}
  \mu(t) = \frac{eE\sin(\omega t)}{m_e(\omega_0^2 - \omega^2)} + y_0,
\end{equation}
and
\begin{equation} \label{eq:b10}
  \gamma(t) =
  \frac{eE\omega_0^2\cos(\omega t)}{\hbar\omega(\omega_0^2 - \omega^2)}.
\end{equation}
Subsequently, using the Fourier transform identity \cite{bruus04}
\begin{equation} \label{eq:b11}
  \int_{-L_x/2}^{L_x/2}
  \exp( -ik_x x + \flatfrac{i p_x x}{\hbar}) dx =
  L_x \delta_{k_x,\flatfrac{p_x}{\hbar}},
\end{equation}
we can derive
\begin{equation} \label{eq:b12}
  \begin{aligned}
    \phi_{n,m}(k_x,k_y,t)  =
    \Phi_{n,m}&(k_y,t)
    \delta_{k_x,\flatfrac{p_x}{\hbar}}
    \exp(\frac{-i}{\hbar} \gamma(t)y_0) \\
    & \times
    \exp(\frac{-i}{\hbar}
    \left[ m_e \dot{\zeta}(t) \zeta(t) - \xi \right]),
  \end{aligned}
\end{equation}
where we can define $\Phi_{n,m}(k_y,t)$ as
\begin{equation} \label{eq:b13}
  \begin{aligned}
    &\Phi_{n,m}(k_y,t) \\
    & \quad=
    \sqrt{L_x}
    \int_{-L_y/2}^{L_y/2}
    \chi_n \bm{\left(}y - \mu(t)\bm{\right)}
    \exp \bm{\left(}-i\left[k_y - \gamma(t) \right]y\bm{\right)} dy.
  \end{aligned}
\end{equation}
Substituting ${k'_y} = k_y -\gamma(t)$ with $y' = y -\mu(t)$, and assuming that the size of the considered 2DEG sample in $y$-direction is considerably large ($L_y \rightarrow \infty$), we can obtain
\begin{equation} \label{eq:b14}
  \Phi_{n,m}({k'_y} ,t) =
  {\sqrt{L_x}} e^{-i {k'_y}\mu}
  \int_{-\infty}^{\infty} \chi_{n}(y') \exp(-i{k'_y} y') dy'.
\end{equation}
Moreover, we can identify that the above integral represents the Fourier transform of $\chi_n$ functions. In addition, using the symmetric conditions of the Fourier transform for Gauss-Hermite functions $\theta_n(x)$ \cite{celeghini21}
\begin{equation} \label{eq:b15}
  \mathcal{FT}[\theta_n(\kappa x),x,k] = \frac{i^n}{|\kappa|}\theta_n(k/\kappa),
\end{equation}
we can simply the Eq.~(\ref{eq:b14}) as
\begin{equation} \label{eq:b16}
  \Phi_{n,m}({k'_y} ,t) =
  \sqrt{L_x} e^{-i {k'_y}\mu} \widetilde{\chi}_n(k'_y),
\end{equation}
with
\begin{equation} \label{eq:b17}
  \widetilde{\chi}_{n}(k) =
  \frac{i^n}{\sqrt{2^{n} n! \sqrt{\pi}}}
  \left(\frac{1}{\kappa} \right)^{1/2}
  e^{-\flatfrac{k^2}{(2 \kappa^2)}}
  \mathcal{H}_n (\flatfrac{k}{\kappa}).
\end{equation}
Finally, substitute Eq.~(\ref{eq:b16}) back into Eq.~(\ref{eq:b12}) and this leads to
\begin{equation} \label{eq:b18}
  \begin{aligned}
    \phi_{n,m}(k_x,k_y,t)  = &
    {\sqrt{L_x}} \widetilde{\chi}_n \bm{\left(} k_y - b\cos(\omega t)\bm{\right)} \\
    & \times
    \exp \left(
      i\xi -ik_y  \left[d\sin(\omega t) + \frac{\hbar k_x}{eB} \right]
    \right),
  \end{aligned}
\end{equation}
where
\begin{equation} \label{eq:b19}
  b =
  \frac{eE\omega_0^2}{\hbar\omega(\omega_0^2 - \omega^2)},
\end{equation}
and
\begin{equation} \label{eq:b20}
  d =
 \frac{eE}{m_e(\omega_0^2 - \omega^2)}.
\end{equation}
It is necessary to notice that $k_x$ is quantized with $k_x = \flatfrac{2\pi m}{L_x} ~,~ m \in \mathbb{Z}$.


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{September 10, 2014}
\maketitle
\section*{assignment}
\subsection*{2.2 \#16}
prove f is onto iff there exists $g:B\to A$ such that $f\circ g=f(g(x))=1_B$
\subsubsection*{proof}
Assume $f$ is onto then $\forall b\in B$ $\exists x_b\in A$ such  that $f(x_b)=b$.

For every $b\in B$ choose $x_b\in A$

define $g:B\to A, g(b)=x_b$, then $(f\circ f)(b)=f(g(b))=f(x_b)=b$

other way

prove that for every $b\in B$ there exists $x\in A$ such that $f(x)=b$

we have $b=f(g(b))$. $g(b)=x$. almost a tautology. done
\subsection*{2.2 \#18}
\subsubsection*{LOOK HERE}
Let $A$ be a

\section*{last time}
equivalence relations
\subsection*{example}
let $f:S\to T$. on $S$ we define the equivalence relation as follows: $x,y\in S$ then $x\sim_f y$ iff $f(x)=f(y)$.

two elements are related iff they have the same image. if $f$ is injective then $[f]=f$. constant function has one equivalence class.

\subsection*{proposition}
there exists a one to one (bijection) from the set of equivalence classes $S/\sim_f$ and $f(s)$. $\bar f:S/\sim_f\to f(S)$. Namelly $[x]\to f(x)$.

question? does $[x]=[y]$ imply that $f(x)=f(y)$? in this case, $[x]=[y]\Rightarrow x\sim_f y\Rightarrow f(x)=f(y)$ so f is a well defined function. (well defined is redundant, but places proper emphasis)

surjectivity of $\bar f$ is clear. what about injectivity? if $f(x)=f(y)\to x\sim_f y\to [x]=[y]$
\section*{1.4 integers modulo n}
$n>1,n\in\mathbb{Z}$. on $\mathbb{Z}$ we define the equiv relation $\equiv$ as $a\equiv b \mod n$ if and only if $n|(a-b)$.

$\mathbb{Z}_n=\mathbb{Z}/\equiv\to$ set of equiv classes. $\mathbb{Z}_n=\{[0],[1],\dots,[n-1]\}$

alternate notation is $\mathbb{Z}_n=\{\bar0,\bar1,\dots,\bar{n-1}\}$.

define operations on $\mathbb{Z}_n$ as follows:

addition: $[a]+[b]=[a+b]$

multiplication: $[a]\cdot[b]=[a\cdot b]$

$[a]=[a'],[b]=[b']\to[a+b]=[a'+b']$.

$n|(a-a'),n|(b-b')\to n|((a+b)-(a'+b'))$

similarly for multiplication.

$[a]=[a'],[b]=[b']\to[a\cdot b]=[a'\cdot b']$.

\subsection*{proposition}
these operation satisfy associative, commutative, distributive

definition:
Let $[a]_n\in\mathbb{Z}_n$. If there exists $[b]_n\in\mathbb{Z}$ such that $[b]\ne 0, [a][b]=[0]$. We say that $[a]$ is a zero-divisor in $\mathbb{Z}_n$

\subsubsection*{example}
$\mathbb{Z}_6=\{[0],[1],[2],[3],[4],[5],[6]\}$. zero divisors are $\{[0],[2],[3],[4]\}$

\subsection*{multiplicative inverse}
if $[a][b]=1$ for some $[b]\in\mathbb{Z}_n$ we say that $[a]$ is an invertible element of $\mathbb{Z}_n$ and $[b]$ is a multiplicative inverse of $[a]$.

$\mathbb{Z}_6$ invertible elements:$\{[1][5]\}$ because $[5][5]=1$ (25 mod 6 is 1)

lets take $[a]\in \mathbb{Z}$ then $[a]$ is invertible iff $\gcd(a,n)=1$.
\subsubsection*{proof}
assume $(a,n)=1$ then $a\alpha+n\beta=1$ with $\alpha,\beta\in\mathbb{Z}$.Then $[1]=[a][\alpha]+[n][\beta]$ $[n]=[0]$

assume $[a]$ is invertible. then there exists $[b]$ such that $[a][b]=1, n|(ab-1)$. $ab-1=nk, (a,n)=1$
\end{document}


% !TEX root = main.tex

%-------------------------------------------------
\section{Large samples}\label{sec:large_samples}

Intuitively we would like an estimator to improve as the sample size increases. The \emph{asymptotic} behaviour of a quantity refers to the way it behaves as another quantity tends to some limit. We now write $T_n$ to represent an estimator defined on a random sample of size $n$ and consider its behaviour as $n\to\infty$.

\begin{definition}
Let $T_n$ be an esimator of some unknown parameter $\theta\in\Theta$.
\ben
\it $T_n$ is said to be \emph{asymptotically unbiased} if %for all $\theta\in\Theta$,
$\expe(T_n)\to\theta$ as $n\to\infty$ for all $\theta\in\Theta$.
%\[
%\expe(T_n)\to \theta \quad\text{as $n\to\infty$}.
%\]
\it $T_n$ is said to be \emph{consistent} if %for all $\theta\in\Theta$,
$T_n\to\theta$ in probability as $n\to\infty$ for all $\theta\in\Theta$.
%\[
%T_n\to\theta \quad\text{in probability as $n\to\infty$.}
%\]
\it $T_n$ is said to be \emph{asymptotically normal} if the distribution of $\sqrt{n}(T_n-\theta)$ converges to a normal distribution as $n\to\infty$ for all $\theta\in\Theta$.
%\[
%\sqrt{n}(T_n-\theta)\to Z\quad\text{in distribution as $n\to\infty$, where $Z\sim N(\mu,\sigma^2)$.}
%\]
\een
\end{definition}

\begin{lemma}
If $T_n$ is an unbiased estimator of $\theta$ and $\var(T_n)\to 0$ as $n\to\infty$ then $T_n$ is a consistent estimator of $\theta$.
\end{lemma}
\begin{proof}
This follows by Chebyshev's inequality: for all $\epsilon>0$,
\[
\prob(|T_n-\expe(T_n)|> \epsilon) \leq \frac{\var(T_n)}{\epsilon^2}.
\]
Since $T_n$ is unbiased, $\expe(T_n)=\theta$ so $\prob(|T_n - \theta|>\epsilon)\to 0$ as $n\to\infty$, as required.
\end{proof}

\begin{example}
The reading on a voltmeter connected to a test circuit is a random variable $X$ that has a uniform distribution over the interval $(\theta,\theta+1)$, where $\theta$ is unknown. Let $X_1, X_2, ...,X_n$ be a random sample of observations from the voltmeter. Show that
\[
T_n = \frac{1}{n}\sum_{i=1}^n\left( X_i - \frac{1}{2}\right)
\]
is a consistent estimator for $\theta$.
\begin{solution}
First we note that $T_n$ is unbiased, because $\expe(X_i)=\theta+1/2$ so
\[
\expe(T_n) = \frac{1}{n}\sum_{i=1}^n \expe(X_i) - \frac{1}{2} = \theta.
\]
To show that $T_n$ is consistent we therefore only need to show that its variance tends to zero as $n\to\infty$:
\[
\var\left(\bar{X}- \frac{1}{2}\right)
	= \var(\bar{X})
	= \frac{\var{X}}{n}
	= \frac{1}{12n} \to 0 \quad\text{as}\quad n\to\infty.
\]
\end{solution}
\end{example}

%----------------------------------------------------------------------
\begin{exercise}
\begin{questions}
%----------------------------------------

%==========================================================================
\question
Let $X_1,X_2,\ldots,X_n$ be a random sample from the $\text{Uniform}(0,\theta)$ distribution. Show that
\[
T_n = \max\{X_1,X_2,\ldots,X_n\}
\]
is an asymptotically unbiased estimator of $\theta$.
\begin{answer}
The PDF of $T_n= \max\{X_1,X_2,\ldots,X_n\}$ is
\[
f(t;\theta)	= \frac{nt^{n-1}}{\theta^n} \quad\text{for\quad $0<t<\theta$\quad (zero otherwise).}
\]

The expected value of $T_n$ is
\[
\expe(T_n)
	= \int_{0}^{\theta }t\frac{nt^{n-1} }{\theta ^{n} }\,dv
	= \frac{n}{(n+1)\theta ^{n} } \left[ t^{n+1} \right] _{0}^{\theta }
	= \frac{n\theta }{n +1}
	= \left(1-\frac{1}{n+1}\right)\theta.
\]
The bias of $T_n$ is
\[
\bias(T_n) = \expe(T_n-\theta) = -\frac{\theta}{n+1} \to 0 \text{ as }n\to\infty.
\]
and because this holds for all $\theta>0$ it follows that $T_n$ is an asymptotically unbiased estimator for $\theta$.
\end{answer}

%==========================================================================
\question
Let $X_1,X_2,\ldots,X_n$ be a random sample from the $\text{Bernoulli}(\theta)$ distribution. Show that the sample mean
\[
\displaystyle T_n = \frac{1}{n}\sum_{i=1}^n X_i
\]
is a consistent estimator of $\theta$.

\begin{answer}
This follows by the weak law of large numbers.
\par
In more detail, because $\expe(T_n)=\theta$ and $\var(T_n) = \displaystyle\frac{\theta(1-\theta)}{n}$, it follows by Chebyshev's inequality that
\[
\prob(|T_n-\theta|>\epsilon) \leq \frac{\theta(1-\theta)}{n\epsilon^2}.
\]
Since $\theta\in[0,1]$ is bounded, we have for every $\epsilon >0$ that
\[
\prob(|T_n-\theta|>\epsilon)\rightarrow 0 \text{ as } n\rightarrow\infty.
\]
Thus $T_n\to\theta$ in probability as $n\to\infty$. This holds for all $\theta\in[0,1]$, so $T_n$ is a consistent estimator of $\theta$.
\end{answer}

%==========================================================================
\question
Let $X$ be a random variable with finite mean $\mu$ and finite variance $\sigma^2$. Let $X_1,X_2,\ldots,X_n$ be a random sample from the distribution of $X$ and consider the sample mean estimators of $\mu$ and $\sigma^2$,
\[
\Xbar_n = \frac{1}{n}\sum_{i=1}^n X_i
\quad\text{and}\quad
\hat{\sigma}^2_n = \frac{1}{n}\sum_{i=1}^n (X_i-\Xbar_n)^2.
\]
\begin{parts}
\part
Show that $\hat{\sigma}^2_n$ is an asymptotically unbiased estimator of $\sigma^2$.
\begin{answer}
As we have seen,
\[
\expe(\hat{\sigma}^2_n) = \left(\frac{n-1}{n}\right)\sigma^2
\quad\text{and}\quad
\bias(\hat{\sigma}^2_n) = -\frac{\sigma^2}{n}.
\]
Hence $\bias(\hat{\sigma}^2_n)\to 0$ as $n\to\infty$, and because this holds for all $\sigma^2>0$ we have that $\hat{\sigma}^2_n$ is an asymptotically unbiased estimator for $\sigma^2$.
\end{answer}

\part
Show that $\Xbar_n$ is a consistent and asymptotically normal estimator of $\mu$.
\begin{answer}
Because $\sigma^2$ is finite, by the law of large numbers we have $\Xbar_n\to\mu$ in probability as $n\to\infty$, and by the central limit theorem,
\[
\sqrt{n}(\Xbar_n-\mu) \to N(0,\sigma^2) \text{\quad in distribution as $n\to\infty$.}
\]
These hold for all $\mu\in\R$, so we have shown that $\Xbar_n$ is a consistent and asymptotically normal estimator for $\mu$.
\end{answer}

\part
If $\expe(X^4)<\infty$ show that $\hat{\sigma}^2_n$ is a consistent and asymptotically normal estimator of $\sigma^2$.
\begin{answer}
For $\hat{\sigma}^2_n$ we write $X_i-\bar{X}_n = (X_i-\mu) - (\Xbar_n-\mu)$, from which we obtain
\[
\hat{\sigma}^2_n
	= \frac{1}{n}\sum_{i=1}^n (X_i-\mu)^2 + (\Xbar_n-\mu)^2
\]

For the first term we have $\expe\big[(X_i-\mu)^2\big] = \sigma^2$ and $\var\big[(X_i-\mu)^2\big] = \mu_4 - \sigma^4$ where $\mu_4=\expe(X^4)$.
By hypothesis these are both finite, so by the law of large numbers applied to the random variables $(X_i-\mu)^2$,
\[
\frac{1}{n}\sum_{i=1}^n (X_i-\mu)^2 \to \sigma^2 \quad\text{in probability as $n\to\infty$.}
\]
For the second term, by Markov's inequality and the fact that $\expe(\Xbar_n)=\mu$ and $\var(\Xbar_n)=\sigma^2/n$,
\begin{align*}
\prob((\Xbar_n-\mu)^2>\epsilon)
	\leq 	\frac{\expe\big[(\Xbar_n-\mu)^2\big]}{\epsilon}
	=		\frac{\var(\Xbar_n)}{\epsilon}
	=		\frac{\sigma^2}{n\epsilon}.
\end{align*}
Hence $(\Xbar_n-\mu)^2\to 0$ in probability as $n\to\infty$, and thus we have shown that $\hat{\sigma}^2_n\to\sigma^2$ in probability as $n\to\infty$. Since this holds for every $\sigma^2>0$ we conclude that $\hat{\sigma}^2_n$ is a consistent estimator for $\sigma^2$.

To show that $\hat{\sigma}^2_n$ is asymptotically normal, let us write
\[
\sqrt{n}(\hat{\sigma}^2_n -\sigma^2)
	= \sqrt{n}\left(\frac{1}{n}\sum_{i=1}^n(X_i-\mu)^2 -\sigma^2\right) - \sqrt{n}(\Xbar_n-\mu)^2
\]
As above, we can use Markov's inequality to show that the second term converges to zero in probability as $n\to\infty$:
\begin{align*}
\prob(\sqrt{n}(\Xbar_n-\mu)^2>\epsilon)
	\leq 	\frac{\expe\big[\sqrt{n}(\Xbar_n-\mu)^2\big]}{\epsilon}
	=		\frac{\sqrt{n}\var(\Xbar_n)}{\epsilon}
	=		\frac{\sigma^2}{\sqrt{n}\epsilon}
	\to 0 \quad\text{as $n\to\infty$.}
\end{align*}

For the first term, we have $\expe\big[(X_i-\mu)^2\big]=\sigma^2$ and $\var\big[(X_i-\mu)^2\big]=\mu_4-\sigma^4$, both of which are finite, so by the central limit theorem applied to the random variables $(X_i-\mu)^2$
\[
\sqrt{n}(\hat{\sigma}^2_n -\sigma^2)
	\to N(0, \mu_4 - \sigma^4) \quad\text{in distribution as $n\to\infty$.}
\]
Because this holds for all $\sigma^2>0$ we conclude that $\hat{\sigma}^2_n$ is an asymptotically normal estimator for $\sigma^2$.
\end{answer}
\end{parts}

%----------------------------------------
\end{questions}
\end{exercise}
%----------------------------------------------------------------------


\documentclass{article}

\usepackage{color}
\usepackage{mathrsfs,amsmath}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{listings}
\usepackage{syntax}
\usepackage{pythonhighlighting}
\usepackage{fancyvrb}
\usepackage{minted}

\usepackage{graphicx}

\graphicspath{ {./assets/} }

\usepackage[margin=1.4in]{geometry}

\title{Homework \#3 | Fall 2021}
\author{Jared Dyreson\\
        California State University, Fullerton}

\DeclareRobustCommand{\bowtie}{%
  \mathrel\triangleright\joinrel\mathrel\triangleleft}

\definecolor{mygray}{rgb}{0.4,0.4,0.4}
\definecolor{mygreen}{rgb}{0,0.8,0.6}
\definecolor{myorange}{rgb}{1.0,0.4,0}

\usepackage [english]{babel}
\usepackage [autostyle, english = american]{csquotes}
\MakeOuterQuote{"}

\titlespacing*{\section}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}
\titlespacing*{\subsection}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}

\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}

\begin{document}

\maketitle
\tableofcontents

\newpage

\section{General Information}

\subsection{Contributors}

\begin{enumerate}
\item Jared Dyreson | \href{mailto:jareddyreson@csu.fullerton}{\underline{jareddyreson@csu.fullerton.edu}} | CWID: 889546529
\end{enumerate}

\subsection{Repository}

The repository for this project can be found \href{https://github.com/JaredDyreson/CS335_Project3}{\underline{here}}. Please consult the README.md file for more information regarding the execution of the program.

\newpage

\section{Algorithm 1 | Pattern Sorting}

\subsection{Pseudocode}

\begin{verbatim}

function swap(a: int, b: int):
    c: int = a
    a = b
    b = c

function pattern_sorting(container: list[int], pattern: list[int]):
    for key in pattern:
        for i in range(0, container.size()):
            for j in range(i, container.size()):
                if(key == container[i]):
                    swap(container[i], container[j])
\end{verbatim}

\subsection{Mathematical Analysis}

In this function, we need to rearrange the array based on a pattern that contains at least one element in the aforementioned array.
To begin, you need to iterate over all the keys to sort once, which will be linear time $O(n)$.
For this routine, you will need a nested for loop to check the current index to all of the neighboring indices. That inner loop takes $O(n^{2})$.
This sorting algorithm takes directly from bubble sort, where the swap takes place when we meet the criteria.
In this instance, the criteria is the left hand side of the array's index being equal to the current value in the pattern.
In terms of memory usage, the only other external data container is a single integer in the swap method. Other than that, the program uses no extra space when sorting.
We can come to the conclusion that since the outermost loop of $O(n)$ needs to run $O(n^{2})$ times per iteration, the running time complexity is $O(n^{3})$.

\newpage

\section{Algorithm 2 | Merging Arrays}

\subsection{Pseudocode}

\begin{verbatim}
function merge(input: list[list[int]]):
    heap = createHeap(int, list[int], lessThanComp) # O(n)

    # nested loops are O(log(n) * n^2)
    for row in input:
        for element in row:
            heap.insert(element)

    external: list[int] = []  # O(1)

    while heap is not empty: # O(log(n))
        external.append(heap.pop())

\end{verbatim}

\subsection{Mathematical Analysis}

In this function, we need to merge a collection of arrays into one large array and the resultant must be sorted in descending order.
To achieve this, we are going to employ a min heap and it uses a priority queue with a greater than comparator to sort them.
Here is an example of what min heap looks like; the least most element is at the top and removal of the root will have the least most element bubble to the top.

\begin{figure}[!h]
\centering
\includegraphics[width=9cm]{min_heap}
\end{figure}

First, creating a min heap will take $O(n)$ time and will use a list to store all the values in the tree.
Then, we need to iterate over the collection of arrays that contain the data we need to sort.
This takes $O(n^{2})$ time because of the way the data is stored.
If the data was stored in a contiguous data structure, this would only take $O(n)$ time but will still result in around the same amount of time as the number of elements hasn't changed.
Each insertion inside the min heap will take $O(\log(n))$ time.
Lastly, extracting the data from the heap will take $O(\log(n))$ per instance, it should be around $O(n)$ because we're completely emptying the heap.
Overall, the time complexity for this function should be $O(\log(n) * n^{2})$.

\end{document}