\chapter{Semisimple algebras}
In what follows, \textbf{assume the field $k$ is algebraically closed}.

Fix an algebra $A$ and suppose
you want to study its representations.
We have a ``direct sum'' operation already.
So, much like we pay special attention to prime numbers,
we're motivated to study irreducible representations
and then build all the representations of $A$ from there.

Unfortunately, we have seen (\Cref{exer:irred_not_indecomp})
that there exists a representation which is not irreducible,
and yet cannot be broken down as a direct sum (indecomposable).
This is \emph{weird and bad}, so we want to give a name
to representations which are more well-behaved.
We say that a representation is \vocab{completely reducible}
if it doesn't exhibit this bad behavior.

Even better, we say a finite-dimensional algebra $A$
is \vocab{semisimple} if all its finite-dimensional
representations are completely reducible.
So when we study finite-dimensional representations of
semisimple algebras $A$,
we just have to figure out what the irreps are,
and then piecing them together will give all
the representations of $A$.

In fact, semisimple algebras $A$ have even nicer properties.
The culminating point of the chapter is when we prove that
$A$ is semisimple if and only if $A \cong \bigoplus_i \Mat(V_i)$,
where the $V_i$ are the irreps of $A$
(yes, there are only finitely many!).

\section{Schur's lemma continued}
\prototype{For $V$ irreducible,
	$\Homrep(V^{\oplus 2}, V^{\oplus 2}) \cong k^{\oplus 4}$.}
\begin{definition}
	For an algebra $A$ and representations $V$ and $W$,
	we let $\Homrep(V,W)$ be the set of intertwining operators between them.
	(It is also a $k$-algebra.)
\end{definition}

By Schur's lemma (since $k$ is algebraically closed,
which again, we are taking as a standing assumption),
we already know that if $V$ and $W$ are irreps, then
\[
	\Homrep(V,W) \cong
	\begin{cases}
		k & \text{if $V \cong W$} \\
		0 & \text{if $V \not\cong W$}.
	\end{cases}
\]
Can we say anything more?
For example, it also tells us that
\[ \Homrep(V, V^{\oplus 2}) = k^{\oplus 2}. \]
The possible maps are $v \mapsto (c_1v_1, c_2v_2)$ for some choice of $c_1, c_2 \in k$.

More generally, suppose $V$ is an irrep and consider
$\Homrep(V^{\oplus m}, V^{\oplus n})$.
Intertwining operators are determined completely
$T : V^{\oplus m} \to V^{\oplus n}$ by the $mn$ choices of compositions
\begin{diagram}
	V & \rInj & V^{\oplus m} & \rTo^T & V^{\oplus n} & \rSurj & V
\end{diagram}
where the first arrow is inclusion to the $i$th component of $V^{\oplus m}$
(for $1 \le i \le m$) and the second arrow is inclusion to the $j$th
component of $V^{\oplus n}$ (for $1 \le j \le n$).
However, by Schur's lemma on each of these compositions,
we know they must be constant.

Thus, $\Homrep(V^{\oplus n}, V^{\oplus m})$ consist of $n \times m$ ``matrices''
of constants, and the map is provided by
\[
	\begin{bmatrix}
		c_{11} & c_{12} & \dots & c_{1(n-1)} & c_{1n} \\
		c_{21} & c_{22} & \dots & c_{2(n-1)} & c_{1n} \\
		\vdots & \vdots & \ddots & \vdots & \vdots \\
		c_{m1} & c_{m2} & \dots & c_{m(n-1)} & c_{mn}
	\end{bmatrix}
	\begin{bmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{bmatrix}
	\in V^{\oplus n}
\]
where the $c_{ij} \in k$ but $v_i \in V$; note the type mismatch!
This is \emph{not} just a linear map $V^{\oplus n_i} \to V^{\oplus m_i}$;
rather, the outputs are $m$ \emph{linear combinations} of the inputs.

More generally, we have:
\begin{theorem}
	[Schur's lemma for completely reducible representations]
	\label{thm:compred_schur}
	Let $V$ and $W$ be completely reducible representations,
	and set $V = \bigoplus V_i^{\oplus n_i}$, $W = \bigoplus V_i^{\oplus m_i}$
	for integers $n_i, m_i \ge 0$, where each $V_i$ is an irrep.
	Then
	\[ \Homrep(V, W)
		\cong \bigoplus_i \Mat_{n_i \times m_i}(k) \]
	meaning that an intertwining operator $T : V \to W$
	amounts to, for each $i$, an $n_i \times m_i$ matrix of constants
	which gives a map $V_i^{\oplus n_i} \to V_i^{\oplus m_i}$.
\end{theorem}

\begin{corollary}
	[Subrepresentations of completely reducible representations]
	\label{cor:subrep_schur}
	Let $V = \bigoplus V_i^{\oplus n_i}$ be completely reducible.
	Then any subrepresentation $W$ of $V$ is isomorphic
	to $\bigoplus V_i^{\oplus m_i}$ where $m_i \le n_i$ for each $i$,
	and the inclusion $W \injto V$ is given
	by the direct sum of inclusion $V_i^{\oplus m_i} \injto V_i^{\oplus n_i}$,
	which are $n_i \times m_i$ matrices.
\end{corollary}
\begin{proof}
	Apply Schur's lemma to the inclusion $W \injto V$.
\end{proof}

\section{Density theorem}
We are going to take advantage of the previous result to prove that
finite-dimensional algebras have finitely many irreps.

\begin{theorem}
	[Jacobson density theorem]
	Let $(V_1, \rho_1)$, \dots, $(V_r, \rho_r)$ be pairwise nonisomorphic
	finite-dimensional representations of $A$.
	Then there is a surjective map of vector spaces
	\[ \bigoplus_{i=1}^r \rho_i : A \surjto \bigoplus_{i=1}^r \Mat(V_i). \]
\end{theorem}
The right way to think about this theorem is that
\begin{moral}
	Density is the ``Chinese remainder theorem''
	for irreps of $A$.
\end{moral}
Recall that in number theory, the Chinese remainder theorem tells us
that given lots of ``unrelated'' congruences, we can find a single $N$
which simultaneously satisfies them all.
Similarly, given lots of different nonisomorphic representations of $A$,
this means that we can select a single $a \in A$ which induces any tuple
$(\rho_1(a), \dots, \rho_r(a))$ of actions we want --- a surprising result,
since even the $r=1$ case is not obvious at all!

\begin{diagram}
	&&& \rho_1(a) &= M_1 \in \Mat(V_1) \\
	&& \ruTo(3,2) & \rho_2(a) &= M_2 \in \Mat(V_2) \\
	\boxed{a \in A} && \ruTo(3,1) && \vdots \\
	& \rdTo(3,1) && \rho_r(a) &= M_r \in \Mat(V_r) \\
\end{diagram}

This also gives us the non-obvious corollary
\begin{corollary}
	[Finiteness of number of representations]
	Any finite-dimensional algebra $A$ has at most $\dim A$ irreps.
	\label{cor:finiteness}
\end{corollary}
\begin{proof}
	If $V_i$ are such irreps then
	$A \surjto \bigoplus_i V_i^{\oplus \dim V_i}$,
	hence we have the inequality $\sum (\dim V_i)^2 \le \dim A$.
\end{proof}

\begin{proof}[Proof of density theorem]
	Let $V = V_1 \oplus \dots \oplus V_r$, so $A$
	acts on $V = (V, \rho)$ by $\rho = \bigoplus_i \rho_i$.
	Thus by \Cref{prob:reg_mat}, we can instead consider $\rho$
	as an \emph{intertwining operator}
	\[ \rho : \Reg(A) \to \bigoplus_{i=1}^r \Mat(V_i)
		\cong \bigoplus_{i=1}^r V_i^{\oplus d_i}. \]
	We will use this instead as it will be easier to work with.

	First, we handle the case $r = 1$.
	Fix a basis $e_1$, \dots, $e_n$ of $V = V_1$.
	Assuming for contradiction that the map is not surjective.
	Then there is a map of representations (by $\rho$ and the isomorphism)
	$\Reg(A) \to V^{\oplus n}$ given by $a \mapsto (a \cdot e_1, \dots, a \cdot e_n)$.
	By hypothesis is not surjective:
	its image is a \emph{proper} subrepresentation of $V^{\oplus n}$.
	Assume its image is isomorphic to $V^{\oplus m}$ for $m < n$,
	so by \Cref{thm:compred_schur} there is a matrix of constants $X$ with
	\begin{diagram}
		\Reg(A) & \rTo & V^{\oplus n} & \lInj^{X \cdot -} & V^{\oplus r} \\
		a & \rMapsto & (a \cdot e_1, \dots, a \cdot e_n) && \\
		1_A & \rMapsto & (e_1, \dots, e_n) & \lMapsto & (v_1, \dots, v_m)
	\end{diagram}
	where the two arrows in the top row have the same image;
	hence the pre-image $(v_1, \dots, v_m)$ of $(e_1, \dots, e_n)$ can be found.
	But since $r < n$ we can find constants $c_1, \dots, c_n$ not all zero
	such that $X$ applied to the column vector $(c_1, \dots, c_n)$ is zero:
	\[
		\sum_{i=1}^n c_ie_i
		=
		\begin{bmatrix} c_1 & \dots & c_n \end{bmatrix}
		\begin{bmatrix} e_1 \\ \vdots \\ e_n \end{bmatrix}
		=
		\begin{bmatrix} c_1 & \dots & c_n \end{bmatrix}
		X
		\begin{bmatrix} v_1 \\ \vdots \\ v_m \end{bmatrix}
		= 0
	\]
	contradicting the fact that $e_i$ are linearly independent.
	Hence we conclude the theorem for $r=1$.

	As for $r \ge 2$, the image $\rho\im(A)$ is necessarily of the form
	$\bigoplus_i V_i^{\oplus r_i}$ (by \Cref{cor:subrep_schur})
	and by the above $r_i = \dim V_i$ for each $i$.
\end{proof}

\section{Semisimple algebras}

\begin{definition}
	A finite-dimensional algebra $A$ is a \vocab{semisimple}
	if every finite-dimensional representation of $A$ is completely reducible.
\end{definition}

\begin{theorem}
	[Semisimple algebras]
	Let $A$ be a finite-dimensional algebra.
	Then the following are equivalent:
	\begin{enumerate}[(i)]
		\ii $A \cong \bigoplus_i \Mat_{d_i}(k)$ for some $d_i$.
		\ii $A$ is semisimple.
		\ii $\Reg(A)$ is completely reducible.
	\end{enumerate}
\end{theorem}
\begin{proof}
	(i) $\implies$ (ii) follows
	from \Cref{thm:rep_1mat} and \Cref{prop:rep_direct_sum}.
	(ii) $\implies$ (iii) is tautological.

	To see (iii) $\implies$ (i), we use the following clever trick.
	Consider
	\[ \Homrep(\Reg(A), \Reg(A)). \]
	On one hand, by \Cref{prob:regA_intertwine},
	it is isomorphic to $A\op$ ($A$ with opposite multiplication),
	because the only intertwining operators $\Reg(A) \to \Reg(A)$
	are those of the form $- \cdot a$.
	On the other hand, suppose that we have set
	$ \Reg(A) = \bigoplus_i V_i^{\oplus n_i} $.
	By \Cref{thm:compred_schur}, we have
	\[ A\op \cong \Homrep(\Reg(A), \Reg(A))
		= \bigoplus_i \Mat_{n_i \times n_i}(k). \]
	But $\Mat_n(k)\op \cong \Mat_n(k)$ (just by transposing),
	so we recover the desired conclusion.
\end{proof}

In fact, if we combine the above result with
the density theorem (and \Cref{cor:finiteness}), we obtain:
\begin{theorem}
	[Sum of squares formula]
	For a finite-dimensional algebra $A$ we have
	\[ \sum_{i} \dim(V_i)^2 \le \dim A \]
	where the $V_i$ are the irreps of $A$;
	equality holds exactly when $A$ is semisimple,
	in which case
	\[ \Reg(A) \cong \bigoplus_i \Mat(V_i)
		\cong \bigoplus_I V_i^{\oplus \dim V_i}. \]
\end{theorem}
\begin{proof}
	The inequality was already mentioned in \Cref{cor:finiteness}.
	It is equality if and only if the map $\rho : A \to \bigoplus_i \Mat(V_i)$
	is an isomorphism; this means all $V_i$ are present.
\end{proof}

\begin{remark}
	[Digression]
	For any finite-dimensional $A$, the kernel of the map
	$\rho : A \to \bigoplus_i \Mat(V_i)$ is denoted $\opname{Rad}(A)$
	and is the so-called \vocab{Jacobson radical} of $A$;
	it's the set of all $a \in A$ which act by zero in all irreps of $A$.
	The usual definition of ``semisimple'' given in books is that
	this Jacobson radical is trivial.
\end{remark}

\section{Maschke's theorem}
We now prove that the representation theory of groups is as nice as possible.
\begin{theorem}
	[Maschke's theorem]
	Let $G$ be a finite group, and $k$ an algebraically closed
	field whose characteristic does not divide $|G|$.
	Then $k[G]$ is semisimple.
\end{theorem}
This tells us that when studying representations of groups,
all representations are completely reducible.
\begin{proof}
	Consider any finite-dimensional representation $(V, \rho)$ of $k[G]$.
	Given a proper subrepresentation $W \subseteq V$,
	our goal is to construct a supplementary $G$-invariant subspace $W'$
	which satisfies \[ V = W \oplus W'. \]
	This will show that indecomposable $\iff$ irreducible,
	which is enough to show $k[G]$ is semisimple.

	Let $\pi : V \to W$ be any projection of $V$ onto $W$,
	meaning $\pi(v) = v \iff v \in W$.
	We consider the \emph{averaging} map $P : V \to V$ by
	\[
		P(v) = \frac{1}{\left\lvert G \right\rvert}
		\sum_{g \in G} \rho(g\inv) \circ \pi \circ \rho(g).
	\]
	We'll use the following properties of the map:
	\begin{exercise}
		Show that the map $P$ satisfies:
		\begin{itemize}
			\ii For any $w \in W$, $P(w) = w$.
			\ii For any $v \in V$, $P(w) \in W$.
			\ii The map $P : V \to V$ is an intertwining operator.
		\end{itemize}
	\end{exercise}
	Thus $P$ is idempotent (it is the identity on its image $W$),
	so by \Cref{prob:idempotent} we have $V = \ker P \oplus \img P$,
	but both $\ker P$ and $\img P$ are subrepresentations as desired.
\end{proof}
\begin{remark}
	In the case where $k = \CC$, there is a shorter proof.
	Suppose $B : V \times V \to \CC$ is an arbitrary bilinear form.
	Then we can ``average'' it to obtain a new bilinear form
	\[ \left< v,w \right> \defeq \frac{1}{|G|} \sum_{g \in G} B(g \cdot v, g \cdot w). \]
	The averaged form $\left< -,- \right>$ is $G$-invariant,
	in the sense that $\left< v,w \right> = \left< g \cdot v, g \cdot w\right>$.
	Then, one sees that if $W \subseteq V$ is a subrepresentation,
	so is its orthogonal complement $W^\perp$.
	This implies the result.
\end{remark}

\section{Example: the representations of $\CC[S_3]$}
We compute all irreps of $\CC[S_3]$.
I'll take for granted right now there are exactly three such representations
(which will be immediate by the first theorem in the next chapter:
we'll in fact see that the number of representations of $G$
is exactly equal to the number of conjugacy classes of $G$).

Given that, if the three representations of have dimension $d_1$, $d_2$, $d_3$ ,
then we ought to have
\[ d_1^2 + d_2^2 + d_3^2 = |G| = 6. \]
From this, combined with some deep arithmetic,
we deduce that we should have $d_1 = d_2 = 1$ and $d_3 = 2$
or some permutation.

In fact, we can describe these representations explicitly.
First, we define:
\begin{definition}
	Let $G$ be a group.
	The complex \vocab{trivial group representation} of a group $G$
	is the one-dimensional representation $\Ctriv = (\CC, \rho)$
	where $g \cdot v = v$ for all $g \in G$ and $v \in \CC$
	(i.e.\ $\rho(g) = \id$ for all $g \in G$).
\end{definition}
\begin{remark}
	[Warning] The trivial representation of an \emph{algebra} $A$
	doesn't make sense for us:
	we might want to set $a \cdot v = v$ but this isn't linear in $A$.
	(You \emph{could} try to force it to work by
	deleting the condition $1_A \cdot v = v$ from our definition;
	then one can just set $a \cdot v = 0$.
	But even then $\Ctriv$ would not be the trivial representation of $k[G]$.)
\end{remark}

Then the representations are:
\begin{itemize}
	\ii The one-dimensional $\Ctriv$;
	each $\sigma \in S_3$ acts by the identity.

	\ii There is a nontrivial one-dimensional representation
	$\Csign$ where the map $S_3 \to \CC^\times$ is given
	by sending $\sigma$ to the sign of $\sigma$.
	Thus in $\Csign$ every $\sigma \in S_3$ acts as $\pm 1$.
	Of course, $\Ctriv$ and $\Csign$ are not isomorphic
	(as one-dimensional representations are never isomorphic
	unless the constants they act on coincide for all $a$,
	as we saw in \Cref{prob:one_dim}).

	\ii Finally, we have already seen the two-dimensional representation,
	but now we give it a name.
	Define $\refl_0$ to be the representation whose vector space is
	$\{ (x,y,z) \mid x+y+z = 0 \}$,
	and whose action of $S_3$ on it is permutation of coordinates.
	\begin{exercise}
		Show that $\refl_0$ is irreducible, for example by showing directly
		that no subspace is invariant under the action of $S_3$.
	\end{exercise}
	Thus $V$ is also not isomorphic to the previous two representations.
\end{itemize}
This implies that these are all the irreps of $S_3$.
Note that, if we take the representation $V$ of $S_3$ on $k^{\oplus 3}$,
we just get that $V = \refl_0 \oplus \CC_{\text{triv}}$.

\section\problemhead

\begin{problem}
	Find all the irreps of $\CC[\Zc n]$.
	\begin{hint}
		They are all one-dimensional, $n$ of them.
		What are the homomorphisms $\Zc n \to \CC^\times$?
	\end{hint}
\end{problem}

\begin{problem}
	[Maschke requires $|G|$ finite]
	Consider the representation of the group $\RR$
	on $\CC^{\oplus 2}$ under addition by a homomorphism
	\[
		\RR \to \Mat_2(\CC)
		\quad\text{by}\quad
		t \mapsto
		\begin{bmatrix} 1 & t \\ 0 & 1 \end{bmatrix}.
	\]
	Show that this representation is not irreducible,
	but it is indecomposable.
	\begin{hint}
		The span of $(1,0)$ is a subrepresentation.
	\end{hint}
\end{problem}

\begin{problem}
	Prove that all irreducible representations
	of a finite group are finite-dimensional.
	\begin{hint}
		This is actually easy.
	\end{hint}
	\begin{sol}
		Pick any $v \in V$, then the subspace
		spanned by elements $g \cdot v$ for $v \in V$
		is $G$-invariant;
		this is a finite-dimensional subspace,
		so it must equal all of $V$.
	\end{sol}
\end{problem}

\begin{problem}
	\gim
	Determine all the complex irreps of $D_{10}$.
	\begin{hint}
		There are only two one-dimensional ones
		(corresponding to the only two
		homomorphisms $D_{10} \to \CC^\times$).
		So the remaining ones are two-dimensional.
	\end{hint}
\end{problem}


This module tries to recognize syntactic symmetries in the input formula and adds symmetry breaking constraints.
The core functionality is provided by \texttt{carl} through \texttt{carl::formula::breakSymmetries()} which internally encodes the formula as a graph and uses \texttt{bliss} to find automorphisms on this graph.

\paragraph{Efficiency}
Finding automorphisms is as difficult as determining whether two graphs are isomorphic, and it is not known whether this problem can be solved in polynomial or exponential time.
In practice, current solvers like \texttt{bliss} perform very good on large graphs and we therefore assume this module to be sufficiently fast.


\subsection{Endomorphisms on real functions}

We start with our vector \(f(x)\).

\(h(x)=f(x)g(x)\)

The equivalent of the identity matrix is where \(g(x)=1\).

These are similar to endomorphisms where all off diagonal elements are \(0\).

\subsubsection{Differentiation}

\(h(x)=\dfrac{\delta }{\delta x}f(x)\)

\subsubsection{Integration}

\(h(x)=\int_{-\infty }^x f(z) dz\)


\section{Neural Networks}

% ##############################################################################
\subsection{Artificial Neural Networks}
\label{ssec:ArtificialNeuralNetworks}

Neural networks are computing systems that are inspired by, but not identical to, biological neural networks that constitute animal brains. Such systems essentially \emph{learn} to perform tasks by considering multiple samples, generally without being programmed with task-specific rules. They form a basis for deep machine learning~\cite{goodfellow2016dl}.

The goal of a neural network is to approximate some unknown function $f$. For instance, when considering a classiﬁer, the transformation $y = \func{f}{\vx}$  maps the given input $\vx$ to a category $y$. Such a network, therefore, defines a mapping and learns the value of the parameters that result in the best function approximation.

These models can be described with a directed acyclic graph denoting the sequential composition of several functions. More concretely, we might have three functions $\suprbrackets{f}{1}$, $\suprbrackets{f}{2}$ and $\suprbrackets{f}{3}$, forming a chain, $\func{f}{\vx} = \func{\suprbrackets{f}{3}}{\func{\suprbrackets{f}{2}}{\func{\suprbrackets{f}{1}}{\vx}}}$. These chain structures are the most commonly used structures in neural networks. Deep machine learning consists of multiple such layers of neurons that are trained using the \emph{backpropagation} algorithm~\cite{rumelhart1986backprop}.

% ##############################################################################
\subsection{Convolutional Neural Networks}
\label{ssec:ConvolutionalNeuralNetworks}

This type of neural network has gained popularity in the computer vision community thanks to a never-seen-before performance on image classification task~\cite{krizhevsky2012classification}. This approach processes images or other high dimensional, grid-like input and then learns the importance (weights and biases) of various aspects of the input data.

The successful ability of these networks to capture spatial properties via learned convolutional filters is the fundamental principle. Let $f$ and $g$ be functions. Then, the operation of convolution denoted by $\star$ produces a third function, as a result of the following computation (demonstrating the commutativity property, too)~\cite{goodfellow2016dl}:
\begin{equation}
    \label{eq:ConvolutionContinuous}
    \func{\rbrackets{f \star g}}{t} =
    \int_{-\infty}^{\infty}
    \func{f}{\tau}
    \func{g}{t - \tau}
    d\tau =
    \int_{-\infty}^{\infty}
    \func{f}{t -\tau}
    \func{g}{\tau}
    d\tau.
\end{equation}
In this setting, $f$ is the input, $g$ is the kernel, and the output of this operation is a feature map. During training, the aim is to learn the weights of the kernel matrix that produces a feature map based on which the model can solve the given task.

Let $I$ be a two-dimensional input image and $K$ be a two-dimensional kernel. Then, for a given position $\rbrackets{i, j}$ in the input image $I$, the discrete convolution can be written as
\begin{equation}
    \label{eq:ConvolutionDiscrete}
    \func{\rbrackets{f \star g}}{i, j} =
    \sum_{m}
    \sum_{n}
    \func{I}{m, n}
    \func{K}{i - m, j - n}.
\end{equation}
Many machine learning libraries implement the cross-correlation operation, not the convolution operation by its strict definition. This operation is the same except for the fact that the kernel is not flipped. Thus, the result of the cross-correlation is given by

\begin{equation}
    \label{eq:CrossCorrelation}
    \func{\rbrackets{f \star g}}{i, j} =
    \sum_{m}
    \sum_{n}
    \func{I}{i + m, j + n}
    \func{K}{m, n}.
\end{equation}

An indispensable outcome of \glspl{cnn} is the ability to capture hierarchical relations. Layers placed near the input of the model capture low-level features such as edges, colors, gradient orientations, and so on. On the other hand, layers placed further, deeper in the model, highlight semantic, abstract features that are specific to the task at hand.

Another prominent use case of \glspl{cnn} is \emph{transfer learning}, where a pre-trained model is adopted for a new task, utilizing the already learned features. These pre-trained models may come in various flavors, but typical ones are pre-trained for an image classification task using the \datasetname{ImageNet} dataset~\cite{deng2009imagenet}. The reasoning is that visual features such as edges and contours are vital to general object recognition tasks, hence it is not needed to learn coarse, rudimentary, low-level features from scratch all the time.


\section{Algebraic Manipulations}
\subsection{Definitions}
Sophie Germain: \[x^4 + 4y^4 = (x^2-2xy+y^2)(x^2+2xy+y^2)\] \\
$(x+y)^3 = x^3+3xy(x+y)+y^3 = x^3+3x^2y+3xy^2+y^3$. \\
$(x-y)^3 = x^3-3xy(x-y)+y^3 = x^3-3x^2y+3xy^2-y^3$. \\
$x^3 + y^3 = (x+y)(x^2-xy+y^2)$. \\
$x^3 - y^3 = (x-y)(x^2+xy+y^2)$. \\
$x^3+y^3+z^3-3xyz = (x+y+z)(x^2+y^2+z^2−xy−yz−zx)$.

\subsection{Practice Problems}
\begin{enumerate}
  \item Given that $x$ and $y$ are distinct nonzero real numbers such that $x+2/x=y+2/y$, what is $xy$?
  \\ \textbf{Solution}:
  \begin{align*}
    x - y &= 2/y - 2/x \\
    x - y &= \frac{2x - 2y}{xy} \\
    &= \frac{2(x-y)}{xy} \\
    &= \frac{2}{xy} = 1 \\
    xy &= \boxed{2}.
  \end{align*}
  \item Suppose that real number $x$ satisfies $\sqrt{49-x^2} - \sqrt{25 - x^2} = 3$. What is the value of $\sqrt{49-x^2} + \sqrt{25 - x^2}$
  \\ \textbf{Solution}:
  \begin{align*}
    &(\sqrt{49-x^2} - \sqrt{25 - x^2})(\sqrt{49-x^2} + \sqrt{25 - x^2}) \\
    &= (49-x^2) - (25 - x^2) \\
    &= 24 = 3(\sqrt{49-x^2} + \sqrt{25 - x^2})
    (\sqrt{49-x^2} + \sqrt{25 - x^2}) = \boxed{8}.
  \end{align*}
  \item What is the minimum value of the expression $x^2 + 8x + 13$ for any real $x$?
  \\ \textbf{Solution}:
  \begin{align*}
    x^2 + 8x + 13 = (x + 4)^2 - 3 \\
    \min((x + 4)^2 - 3) = \boxed{-3}.
  \end{align*}
  \item Real numbers $x$ and $y$ satisfy the equation $x^2+y^2=10x-6y-34$. What is $x+y$?
  \\ \textbf{Solution}:
  \begin{align*}
    (x^2-10x) + (y^2+6y) = -34 \\
    (x-5)^2+(y+3)^2 = 0 \\
    x = 5, y = -3 \\
    x+y = \boxed{2}.
  \end{align*}
  \item There is a positive integer $n$ such that $(n+1)!+(n+2)! = n!\cdot 440$. What is the sum of the digits of $n$?
  \\ \textbf{Solution}:
  \begin{align*}
    n!(n+1)^2(n+2) &= n!(440) \\
    (n+1)(n+3) &= 440 \\
    ((n+2)+1)((n+2)-1) &= 440 \\
    (n+2)^2-1^2 &= 440 \\
    (n+2)^2 &= 441 \\
    n + 2 &= 21 \\
    n &= \boxed{19}.
  \end{align*}
  \item For all integers $n \geq 9$, the value of $\frac{(n+2)! - (n+1)!}{n!}$ is always which of the following?
  \\ \textbf{Solution}:
  \begin{align*}
    \frac{n!((n+2)(n+1)-(n+1))}{n!} = (n+1)^2.
  \end{align*}
  The expression must always be a perfect square.
  \item Let $f(x) = x^{2}(1-x)^{2}$. What is the value of the sum
  $f \left(\frac{1}{2019} \right)-f  \left(\frac{2}{2019} \right)+f \left(\frac{3}{2019} \right)-f \left(\frac{4}{2019} \right)+\cdots + f \left(\frac{2017}{2019} \right) - f \left(\frac{2018}{2019} \right)?$
  \\ $\textbf{(A) }0\qquad\textbf{(B) }\frac{1}{2019^{4}}\qquad\textbf{(C) }\frac{2018^{2}}{2019^{4}}\qquad\textbf{(D) }\frac{2020^{2}}{2019^{4}}\qquad\textbf{(E) }1$
  \\ \textbf{Solution}:
  \begin{align*}
    \left( f \left(\frac{1}{2019} \right) - f \left(\frac{1}{2019} \right) \right) +  \left( f \left(\frac{2}{2019} \right) - f \left(\frac{2}{2019} \right) \right) + \cdots \\ + \left( f \left(\frac{1009}{2019} \right) - f \left(\frac{1009}{2019} \right) \right)
  \end{align*}
  The answer is $\boxed{\textbf{(A) }0}$.
  \item Given that $x+\frac{1}{x}=3$, find
  \begin{enumerate}
    \item $x^2+\frac{1}{x^2} = (x + \frac{1}{x})^2 = x^2 + 2 + \frac{1}{x^2} = 3^2 - 2 = \boxed{7}$.
    \item $x^3 + \frac{1}{x^3} = (x+\frac{1}{x})(x^2-1+\frac{1}{x^2}) = 3(7-1)=\boxed{18}$.
    \item $x^4 + \frac{1}{x^4} = 7^2 + 2 = 49 + 2 = \boxed{51}$.
  \end{enumerate}
  \item Real numbers $x$ and $y$ satisfy $x + y = 4$ and $x \cdot y = -2$. What is the value of\[x + \frac{x^3}{y^2} + \frac{y^3}{x^2} + y?\]
  $\textbf{(A)}\ 360\qquad\textbf{(B)}\ 400\qquad\textbf{(C)}\ 420\qquad\textbf{(D)}\ 440\qquad\textbf{(E)}\ 480$
  \\ \textbf{Solution}:
  \begin{align*}
    &\frac{x^3}{x^2}+\frac{x^3}{y^2}+\frac{y^3}{x^2}+\frac{y^3}{y^2} \\
    &= \frac{x^3+y^3}{x^3}+\frac{x^3+y^3}{y^2} \\
    &= \frac{88}{x^2} = \frac{88(x^2+y^2)}{4} = \boxed{44}.
  \end{align*}
  \item Let $r$, $s$, and $t$ be the three roots of the equation\[8x^3 + 1001x + 2008 = 0.\]Find $(r + s)^3 + (s + t)^3 + (t + r)^3$.
  \\ \textbf{Solution}:
  \begin{align*}
    (r+s)^3 + (s+t)^3 + (t+r)^3  \\ = (0-t)^3 + (0-r)^3 + (0-s)^3 = -(r^3 + s^3 + t^3) \\
    r^3 + s^3 + t^3 - 3rst = (r+s+t)(r^2 + s^2 + t^2 - rs - st - tr) = 0 \\
    r^3+s^3+t^3 = 3rst = -251, -251 \cdot -3 = \boxed{753}.
  \end{align*}
  \item Find $3x^2y^2$ is $x$ and $y$ are integers such that $y^2+3x^2y^2=30x^2+517$.
  \\ \textbf{Solution}:
  \begin{align*}
    a = x^2, b = y^2 \\
    b+3ab = 30a+517 \\
    ab + \frac{b}{3} - 10a = \frac{517}{3} \\
    (a+\frac{1}{3})(b-10) = \frac{507}{3} \\
    (3x^2 + 1)(y^2 - 10) = 507 \\
    (x, y) = (\pm 2, \pm 7)
  \end{align*}
  $3x^2y^2 = 3 \cdot 4 \cdot 49 = \boxed{588}$.
  \item What is the remainder when $s^{202} + 202$ is divided by $2^{101} + 2^{51} + 1$.
  \item Two non-zero real numbers, $a$ and $b,$ satisfy $ab = a - b$. Which of the following is a possible value of $\frac {a}{b} + \frac {b}{a} - ab$?

  \textbf{Solution}:
  \begin{align*}
    \frac{a^2 + b^2}{ab} - ab &= \frac{(a-b)^2+2ab}{ab} - ab \\
    &= \frac{(ab)^2 + 2ab}{ab} - ab \\
    &= ab + 2 - ab = \boxed{2} \\
  \end{align*}
  \item If $x + \frac{1}{x} = 4$, then what is the value of $x^8 + \frac{1}{x^8}$?

  \textbf{Solution}:
  \begin{align*}
    x^2 + \frac{1}{x^2} = 4^2 - 2 = 14 \\
    x^4 + \frac{1}{x^4} = 14^2 - 2 = 194 \\
    x^8 = \frac{1}{x^8} = 194^2 - 2 = \boxed{37624}.
  \end{align*}
  \item Let $a$ and $b$ be relatively prime positive integers with $a>b>0$ and $\dfrac{a^3-b^3}{(a-b)^3} = \dfrac{73}{3}.$ What is $a-b?$
  \\ \textbf{Solution}:
  \begin{align*}
    \frac{a^3-b^3}{(a-b)^3} &= \frac{(a-b)(a^2+ab+b^2)}{(a-b)^3} \\
    &= \frac{a^2+ab+b^2}{(a-b)^2} \\
    &= \frac{(a-b)^2 - 3ab}{(a-b)^2} \\
    &= 1+\frac{3ab}{(a-b)^2} \\
    \frac{3ab}{(a-b)^2} &= \frac{70}{3} \\
    9ab &= 70(a-b)^2 \\
    3 \sqrt{\frac{ab}{70}} &= a - b \\
    ab | 70&, 3 | a - b.
  \end{align*}
  Thus $a = 10, b = 7$ so $a - b = \boxed{3}$.
  \item If $(a - 1/a)^2 = 4$, what is the absolute value of $a^3 - 1/a^3$?

  \textbf{Solution}:
  \begin{align*}
    a - \frac{1}{a} &= 2 \\
    (a - \frac{1}{a})^3 &= a^3 - \frac{1}{a^3} - 3(x - \frac{1}{x}) \\
    2^3 &= a^3 - \frac{1}{a^3} - 6 \\
    a^3 - \frac{1}{a^3} &= \boxed{14}
  \end{align*}
\end{enumerate}


\documentclass[main.tex]{subfiles}
\begin{document}
\chapter{Set Theory}

\epigraph{Sets are wild fam.}{Justin Goodman}

\minitoc

\section{Introduction}

Sets were introduced by Georg Cantor in the late 1800s. Cantor is the grandfather of set theory and continuity. We will see continuity topics later, including Cantor's famous diagonal argument. We can define all of discrete mathematics using sets. What is a set though?

\begin{defn}[Set\index{Set}]
	An unordered collection of unique objects. We denote sets using curly braces \(\{\}\) with objects appearing in them -- e.g.\ \(\{\circ, 3, \pi, \blacktriangle\}\)
\end{defn}

Each part of this definition is important -- we do not have a set unless it satisfies the entire definition. We now examine the definition.

\begin{itemize}
	\item A set is a \textbf{collection} of stuff. Think of a set like a box. You can put things in your box, and you can take them out. Your box is special -- it can expand/contract to fit anything you like.
	\item A set is \textbf{unordered}. This simply means that any different ordering we give to a set does not change the equality property of the set -- \(\{1,2\} = \{2,1\}\)
	\item A set contains \textbf{objects}. A set can contain anything you want.
	\item A set contains \textbf{unique} objects. For any two distinct objects in a set, the objects cannot be equal. Sometimes we see books describe the sets \(\{1,1,2,3\}\) and \(\{1,2,3\}\) as equal, however we argue that the first set is not even a set!\footnote{We would classify the set \(\{1,1,2,3\}\) as a \textit{multi-set}} We recommend you ask your instructor about this distinction, and follow what they prefer.
\end{itemize}

This chapter includes an overview of set theory -- sets, operations, binary relations, and theorems.

\section{Building Sets}

Before we dive into set theory concepts, we first introduce a few ways to denote sets.

To start, you can simply denote a set by just writing each element inside some curly braces. For example, \[\{1,2,3\}\] describes the set containing 1, 2, and 3. This method is not useful when describing big sets, though. If your set has \(2^{64}\) elements, you would never be able to write them all out!

To solve this, we can use \textit{ellipses} -- \(\cdots\) -- three dots in a row. Ellipses inside a set simply mean that you take the implicit pattern described in the set already, and continue it (possibly indefinitely). For example, \[\{1,2,3,\cdots,10\} = \{1,2,3,4,5,6,7,8,9,10\}\]
Here, the pattern is described in the \(1,2,3\) part -- increase by 1. Now,

So far, the presented notations lack power. To combat this, we introduce set-builder notation. As the name implies, this is a way of building sets.

\begin{defn}[Set-builder Notation\index{Set-builder Notation}]
	A way of defining sets. Syntax: \(\{\,\mbox{element} \mid \mbox{condition(s)}\,\}\), read as, ``element \textit{such that} condition(s) is (are) satisfied.'' For example, the set of even integers (which we will learn about soon) can be written as: \(\{e \mid (\exists k \in \Z)[e = 2k]\}\)
\end{defn}

\begin{rem}
	You may also see the \(:\) character instead of the \(\mid\) character in set-builder notation. These are equivalent. \(\{e \mid (\exists k \in \Z)[e = 2k]\} = \{e : (\exists k \in \Z)[e = 2k]\}\).
\end{rem}

It is pivotal that you know how to read and create sets this way. The syntax is very flexible because the conditions can be almost anything you like. The conditions should, however, relate to the set itself (otherwise the set would be trivially pointless).

\exsol{
	Build a set that contains all square roots of even integers (for now, use the definition of even integers given previously).
}{
	\[S = \{x \mid (\exists k \in \Z)[x^2 = 2k]\}\]
}

\exsol{
	Build a set that contains everything except for the object \(\star\).
}{
	\[S = \{y : y \neq \star\}\]
}

With set-builder notation, we can describe the following set short-cut: \[[n] = \{i \in \Z \mid 0 \leq i \leq n\}\].
We do not know what \(\Z\) is just yet, but we will get there soon enough.

\begin{rem}
	Some authors denote \([3] = \{1,2,3\}\) since they do not include 0 as part of the natural numbers. More on this later. For now, just follow whatever your professor is doing.
\end{rem}

\begin{rem}
	Some authors also reserve \([x]\) to mean the floor function -- the greatest integer smaller than \(x\). As with anything in math, context is key. We will not use brackets to indicate the floor function, but you should be aware that different notation conventions exist.
\end{rem}

Finally, we can describe continuous-interval sets. You may be familiar with the real number line -- this is a continuous line because there are no ``breaks'' between any two numbers you pull from it. Given any two numbers on the real number line, we can always take the midpoint to get another real number! How do we denote these intervals? We use interval notation:
\begin{itemize}
	\item \((x,y) = \{r \in \R : x < r < y\}\)
	\item \((x,y] = \{r \in \R : x < r \leq y\}\)
	\item \([x,y) = \{r \in \R : x \leq r < y\}\)
	\item \([x,y] = \{r \in \R : x \leq r \leq y\}\)
\end{itemize}

A parenthesis means we \textit{exclude} the associated number from the continuous interval, and a bracket means we \textit{include} the associated number.

\section{Definitions}

We include a handful of definitions and notations we use in our study of set theory.

Binary relations:

\begin{defn}[Member/Element]
	An object that is part of a set. Symbol: \(\in\). Example: \(5 \in \{1,2,3,4,5\}\)
\end{defn}

\begin{defn}[Subset]
	A set of elements that are all members of another set. A subset CAN be equal to its parent set. Symbol: \(\subseteq\). Example: for sets \(S\) and \(T\), \(S \subseteq T \Leftrightarrow (\forall s \in S)[s \in T]\)
\end{defn}

\begin{defn}[Proper Subset]
	A set of elements that are all members of another set, but the subset is NOT equal to the parent set. Symbol: \(\subset\). Example: for sets \(S\) and \(T\), \(S \subset T \Leftrightarrow (\forall s \in S)[(s \in T) \land (S \neq T)]\)
\end{defn}

\begin{defn}[Superset]
	A flipped version of subset. Symbol: \(\supseteq\). Example: for sets \(S\) and \(T\), \(S \supseteq T \Leftrightarrow (\forall t \in T)[t \in S]\)
\end{defn}

\begin{defn}[Proper Superset]
	A flipped version of proper subset. Symbol: \(\supset\). Example: for sets \(S\) and \(T\), \(S \supset T \Leftrightarrow (\forall t \in T)[(t \in S) \land (S \neq T)]\)
\end{defn}

\begin{defn}[Equality]
	Two sets are equal if and only if both sets are subsets of each other. Notation: for sets \(S\) and \(T\), \(S = T \Leftrightarrow (S \subseteq T) \land (T \subseteq S)\). To prove this, you can use set-builder notation \& theorems (given later in this chapter) to show equivalence, or you can prove \((e \in S \Rightarrow e \in T) \land (e \in T \Rightarrow e \in S)\)
\end{defn}

Things:

\begin{defn}[Cardinality]
	The number of elements in a set. Notation: for a set \(S\), cardinality is denoted by \(|S|\). For example, $|\{2,3,4,5,6\}| = 5$
\end{defn}

\begin{defn}[Empty/Null Set]
	The set containing zero elements. Notation: $\emptyset$ or $\{\}$ -- these symbols are \textit{interchangable}. \textbf{Note}: \(|\emptyset| = 0\)
\end{defn}

\begin{defn}[Universal Set]
	The set of all possible sets. Notation: \(U\) is the Universal Set
\end{defn}

\begin{defn}[Power Set]
	The set of all possible subsets of a set. Notation: of a set \(S\), the power set is denoted \(\mathcal{P}(S)\). For example, \(\mathcal{P}(\{1,2,3\}) = \{\emptyset, \{1\}, \{2\}, \{3\}, \{1,2\}, \{1,3\}, \{2,3\}, \{1,2,3\}\}\). \textbf{Note}: for any set \(S\), \(|\mathcal{P}(S)| = 2^{|S|}\)
\end{defn}

\begin{defn}[Disjoint]
	Two sets are disjoint if and only if both sets have no members in common. For two sets \(S\) and \(T\), this is equivalent to \(S \cap T = \emptyset\)
\end{defn}

\begin{defn}[Partition]
	(of a set) A set of sets \(T\) where the union of every element in \(T\) equals the original set, and all elements in \(T\) are disjoint. For example, \(\{\{1,2\}, \{3\}, \{4,5,6\}\}\) is a partition of \(\{1,2,3,4,5,6\}\)
\end{defn}

Operations:

\begin{defn}[Union]
	(of two sets) A set that includes all elements from both sets (discounting duplicates, since a set must contain unique elements). Notation: for sets \(S\) and \(T\), \(S \cup T = \{e \mid (e \in S) \lor (e \in T)\}\). For example, \(\{1,2,3\} \cup \{3,4,5\} = \{1,2,3,4,5\}\)
\end{defn}

\begin{defn}[Intersection]
	(of two sets) A set that includes only elements from both sets. Notation: for sets \(S\) and \(T\), \(S \cap T = \{e \mid (e \in S) \land (e \in T)\}\). For example, \(\{1,2,3\} \cap \{3,4,5\} = \{3\}\)
\end{defn}

\begin{defn}[Subtraction]
	(of two sets) A set representing the elements of the second set taken out of the first set. \textbf{Note}: subtraction order \textit{matters} (i.e.\ subtraction is not commutative). Notation: for sets \(S\) and \(T\), \(S - T = \{e \mid (e \in S) \land (e \not\in T)\}\). You may also see set subtraction represented as \(S \setminus T\). For example, \(\{1,2,3\} \setminus \{3,4,5\} = \{1,2\}\)
\end{defn}

\begin{defn}[Compliment]
	(of a set) A set containing every element from the universal set that is NOT contained in the original set. \textbf{Note}: you can take the compliment with respect to different universes so long as you specify which one -- by default the universal set is assumed. Notation: for a set \(S\), the complement is noted as \(S^{\mathsf{c}}\), or \(S^{'}\), or \(\overline{S}\); with the universe \(U\), \(S^{'} = \{e \mid e \in (U - S)\}\)
\end{defn}

\begin{defn}[Cross Product]
	(of two sets) The set of all ordered pairings of two sets. Notation: for sets \(S\) and \(T\), \(S \times T = \{(s,t) \mid s \in S \land t \in T\}\).

	Note: you can take the cross product of multiple sets. For sets \(A_1 \cdots A_n\), the cross product \(A_1 \times A_2 \times \cdots \times A_n = \{(a_1, a_2, \cdots, a_n) \mid a_i \in A_i\}\). When \(A_1 = \cdots = A_n = A\) then we let \(A^n = A_1 \times A_2 \times \cdots \times A_n\)
\end{defn}

\section{Theorems}

We will not go into depth on the axioms of Zermelo–Fraenkel set theory. We do include a handful of nice theorems that will aid in proving statements about sets. Sometimes these are referred to as axioms, however we argue that the following statements can be derived from ZF set theory axioms and should hence be called theorems. It does not really matter though.

You are not required to memorize these theorems -- they will be given to you as a table.
\marginpar{See appendix \ref{appendix:tables}.}

\begin{thm}[Commutativity]
	For any sets \(A\) and \(B\) the union and intersection operations are commutative: \[A \cup B = B \cup A\] \[A \cap B = B \cap A\]
\end{thm}

\begin{thm}[Associativity]
	For any sets \(A\), \(B\), and \(C\) the union and intersection operations are associative: \[(A \cup B) \cup C = A \cup (B \cup C)\] \[(A \cap B) \cap C = A \cap (B \cap C)\]
\end{thm}

\begin{thm}[Distributivity]
	For any sets \(A\), \(B\), and \(C\) the union and intersection operations are distributive: \[A \cap (B \cup C) = (A \cap B) \cup (A \cap C)\] \[A \cup (B \cap C) = (A \cup B) \cap (A \cup C)\]
\end{thm}

\begin{thm}[Identity]
	For any set \(A\) and universe \(U\) the following hold: \[A \cup \emptyset = A\] \[A \cap U = A\]
\end{thm}

\begin{thm}[Inverse]
	For any set \(A\) and universe \(U\) the following hold: \[A \cup A^{\mathsf{c}} = U\] \[A \cap A^{\mathsf{c}} = \emptyset\]
\end{thm}

\begin{thm}[Double Compliment]
	For any set \(A\) the following holds: \[(A^{\mathsf{c}})^{\mathsf{c}} = A\]
\end{thm}

\begin{thm}[Idempotence]
	For any set \(A\) the following hold: \[A \cup A = A\] \[A \cap A = A\]
\end{thm}

\begin{thm}[Universal Bound (Domination)]
	For any set \(A\) and universe \(U\) the following hold: \[A \cup U = U\] \[A \cap \emptyset = \emptyset\]
\end{thm}

\begin{thm}[De Morgan's]
	For any sets \(A\) and \(B\) the following hold: \[(A \cup B)^{\mathsf{c}} = A^{\mathsf{c}} \cap B^{\mathsf{c}}\] \[(A \cap B)^{\mathsf{c}} = A^{\mathsf{c}} \cup B^{\mathsf{c}}\]
\end{thm}

\begin{thm}[Absorption]
	For any sets \(A\) and \(B\) the following hold: \[A \cup (A \cap B) = A\] \[A \cap (A \cup B) = A\]
\end{thm}

\begin{thm}[Absolute Compliment]
	For a given universe \(U\) the following hold: \[\emptyset^{\mathsf{c}} = U\] \[U^{\mathsf{c}} = \emptyset\]
\end{thm}

\begin{thm}[Set Subtraction Equality]
	\label{set-sub-eq}
	For any sets \(A\) and \(B\) the set subtraction operation satisfies the following: \[A - B = A \cap B^{\mathsf{c}}\]
	This establishes a relationship between the relative and absolute compliment
\end{thm}

The aforementioned theorems are helpful for simplifying complicated sets.

\exsol{
	Simplify the following expression: \[((A \cup B) \cap C) \cup ((A^{\mathsf{c}} \cap B^{\mathsf{c}}) \cup D^{\mathsf{c}})^{\mathsf{c}}\]
}{
	Lots of compliments is a good indication for using De Morgan's.
	\begin{align*}
	& ((A \cup B) \cap C) \cup ((A^{\mathsf{c}} \cap B^{\mathsf{c}}) \cup D^{\mathsf{c}})^{\mathsf{c}} \\
	&= ((A \cup B) \cap C) \cup ((A \cup B)^{\mathsf{c}} \cup D^{\mathsf{c}})^{\mathsf{c}} & \text{De Morgan's} \\
	&= ((A \cup B) \cap C) \cup ((A \cup B) \cap D) & \text{De Morgan's} \\
	&= (A \cup B) \cap (C \cup D) & \text{Distributivity}
	\end{align*}
}

\exsol{
	\label{ex-prove-equivalence}
Show the following equivalence: \[A \cup (B \cup (A \cap C)) = A \cup B\]
}{
	Sometimes just trying random things works out in your favor.
	\begin{align*}
	A \cup (B \cup (A \cap C)) &= A \cup ((A \cap C) \cup B) & \text{Commutativity} \\
	&= (A \cup (A \cap C)) \cup B & \text{Associativity} \\
	&= A \cup B & \text{Absorption}
	\end{align*}
}

\begin{rem}
	There is a stark similarity between set and Boolean simplification.
\end{rem}

\section{Important Sets}

We introduce some notation for a handful of important sets.

\begin{defn}[The Natural Numbers -- \(\N\)]
	The standard discrete numbers with which you count. Some math classes start the naturals at 1, however in computer science we start the naturals at 0. Just remember simply that arrays utilize 0-indexing, so we do the same. The set looks like so: \(\{0,1,2,3,4,5,\cdots\}\)
\end{defn}

In mathematics, we define the natural numbers \textit{inductively} -- we will discuss induction in a few chapters. We introduce the inductive definition here. You do not need to know this, however we think it is interesting.

\begin{prop}[Inductive Definition of \(\N\)]
	\label{ind-defn-N}
	Define a set \(S \subseteq \R\) to be \textit{inductive} if and only if the following conditions hold:
	\begin{itemize}
		\item \(0 \in S\)
		\item if \(x \in S\) then \(x + 1 \in S\)
	\end{itemize}

	\noindent Define \(\N\) as the intersection of all inductive sets.
\end{prop}

Understandably you may be confused on the notation of \(\R\) -- we will come back to this in a moment. For now, we continue to the integers.

\begin{defn}[The Integers -- \(\Z\)]
	The standard \textit{signed} discrete numbers with which you count. The integers include all of the natural numbers as well as all of their negatives\footnote{0 is neither positive nor negative, so we cannot take its negation, however we let \(0 \in \Z\)}. The set looks like so: \(\{\cdots,-3,-2,-1,0,1,2,3,\cdots\}\)
\end{defn}

The next set, which you may be familiar with, is the rationals.

\begin{defn}[The Rationals -- \(\Q\)]
	The set of numbers that can be written as a ratio (\(\Q\)uotient) of integers. \(\Q = \{x = \frac{a}{b} \mid a \in \Z \land b \in \Z^{\neq 0}\}\)
\end{defn}

Naturally we can define somewhat of an `opposite' to the rationals.

\begin{defn}[The Irrationals -- \(\R \setminus \Q\)]
	The set of real numbers that do not satisfy the rational property. A provable example is that \(\sqrt{2} \in \R \setminus \Q\)
\end{defn}

The real numbers are not the main focus in discrete mathematics, however we still provide a definition.

\begin{defn}[The Reals -- \(\R\)]
	The continuous interval \((-\infty, \infty)\). Any number that does not have the form \(a+bi\), where \(i = \sqrt{-1}\)
\end{defn}

In an analytical mathematics course, the reals and irrationals are more strongly defined. The above definitions are enough for this course.

\section{Sets to Logic}

We can use set-builder notation along with our familiar logic rules to prove things about sets. This proof technique can be used to prove the theorems we showed earlier.

\exproof{
	Prove theorem \ref{set-sub-eq}: \[A - B = A \cap B^{\mathsf{c}}\]
}{
	\begin{align*}
	A - B &= \{x \mid x \in A \land x \not\in B\}  & \text{defn of subtraction} \\
	&= \{x \mid x \in A \land x \in B^{\mathsf{c}}\} & \text{defn of compliment} \\
	&= A \cap B^{\mathsf{c}} & \text{defn of intersection}
	\end{align*}
}

\exproof{
	Prove example \ref{ex-prove-equivalence} \[A \cup (B \cup (A \cap C)) = A \cup B\]
}{
	\begin{align*}
	& A \cup (B \cup (A \cap C)) \\
	&= \{x \mid x \in A \lor (x \in B \lor (x \in A \land x \in C))\} & \text{defn of } \cup/\cap \\
	&= \{x \mid x \in A \lor ((x \in A \land x \in C) \lor x \in B)\} & \text{Commutativity (logic)} \\
	&= \{x \mid (x \in A \lor (x \in A \land x \in C)) \lor x \in B\} & \text{Associativity (logic)} \\
	&= \{x \mid x \in A \lor x \in B\} & \text{Absorption (logic)} \\
	&= A \cup B & \text{defn of } \cup
	\end{align*}
}

\section{Summary}

\begin{itemize}
	\item Sets are unordered collections of unique objects
	\item Many operations and theorems exist in set theory
	\item \(\N, \Z, \Q, \R \setminus \Q, \R\) are all important sets
\end{itemize}

\section{Practice}

\begin{enumerate}
	\item Provide an example of a valid set, and an invalid set.
	\item Build a set of natural numbers that are all multiples of 3.
	\item Explain why the cardinality of a finite set is a natural number.
	\item For two sets \(A\) and \(B\), is it necessarily the case that \(|A \cup B| = |A| + |B|\)?
	\item Explain intuitively why \(|\mathcal{P}(A)| = 2^{|A|}\).
	\item Is \(\{\Z^-, 0, \Z^+\}\) a valid partition of \(\Z\)? Explain. If it is not, change the partition to make it valid.
	\item Is \(\{\{1,3,5,7,9,\cdots\} , \{0,2,4,6,8,\cdots\}\}\) a valid partition of \(\N\)? Explain. If it is not, change the partition to make it valid.
	\item Provide a set \(T\) which is a valid partition of \(\N\) such that \(|T| = 5\).
	\item For each of the following, answer true or false:
	\begin{enumerate}
		\item \(\Z \supset \N\)
		\item \(\N \in \Z\)
		\item \(0 \in \emptyset\)
		\item \(\emptyset \in \emptyset\)
		\item \(\emptyset \subseteq \emptyset\)
		\item \(\emptyset \subset \emptyset\)
		\item \(\mathcal{P}(\emptyset) = \emptyset\)
	\end{enumerate}
	\item Simplify the expression \(A^{\mathsf{c}} \cup (B \cup A)^{\mathsf{c}}\).
	\item Prove the two Absorption theorem statements are equivalent.
\end{enumerate}

%\section{Solutions}
%
%\begin{enumerate}
%	\item Valid: \(\{1,2,3\}\). Invalid: \(1,2,3\) (this is invalid because it is missing the \(\{\}\))
%	\item Let \(S = \{x \mid (\exists k \in \N)[x = 3k]\}\)
%	\item Consider that \(\N\) contains all of the \textit{counting} numbers. By taking the cardinality, you are simply \textit{counting} the number of elements.
%	\item The only case when \(|A \cup B| = |A| + |B|\) is if \(A \cap B = \emptyset\). For example, \(|\{1,2,3\} \cup \{3,4,5\}| = |\{1,2,3,4,5\}| = 5 \neq 6 = |\{1,2,3\}| + |\{3,4,5\}|\)
%	\item Consider each subset as a binary string, where each position in the string represents an element. 1 means the element is in the subset, and 0 means the element is not in the subset. The amount of strings total is \(2^{\text{length of each string}}\). Since the length of each string is just the number of elements in \(A\), we recover that \(|\mathcal{P}(A)| = 2^{|A|}\). The intuition here is to think of each element as being in or out of a subset.
%	\item No -- each element in a partition must be a set, and 0 is not a set.
%	\item Yes -- the first set contains all odd naturals, and the second set contains all even naturals. Since there is no overlap between odds and evens, the partition is valid. We will learn about this soon.
%	\item One possibility: \(T = \{\{0,1,2\}, \{4,5\}, \{3,6,9\}, \{7,8\}, \N^{\geq 10}\}\)
%	\item
%	\begin{enumerate}
%		\item True
%		\item False
%		\item False
%		\item False
%		\item True
%		\item False
%		\item False
%	\end{enumerate}
%	\item
%	\begin{align*}
%	A^{\mathsf{c}} \cup (B \cup A)^{\mathsf{c}} &= A^{\mathsf{c}} \cup (B^{\mathsf{c}} \cap A^{\mathsf{c}}) & \text{De Morgan's} \\
%	&= A^{\mathsf{c}} \cup (A^{\mathsf{c}} \cap B^{\mathsf{c}}) & \text{Commutativity} \\
%	&= A^{\mathsf{c}} & \text{Absorption} \\
%	\end{align*}
%	\item
%	\begin{align*}
%	A \cup (A \cap B) &= (A \cup A) \cap (A \cup B) & \text{Distributivity} \\
%	&= A \cap (A \cup B) & \text{Idempotence}
%	\end{align*}
%\end{enumerate}
\end{document}


%!TEX root = ../notes.tex
\section{May 2, 2022}
\subsection{LLL Reduction}
\ul{Problem}: Given a lattice, find a good basis for the given lattice. Let's say we have
\begin{align*}
    \mathcal{B}  & = (\bvec{v}_1, \bvec{v}_2, \dots, \bvec{v}_n)    \\
    \mathcal{B}' & = (\bvec{v}_1', \bvec{v}_2', \dots, \bvec{v}_n')
\end{align*}
where $\mathcal{B}'$ is the corresponding vector space obtained from Gram-Schmidt. Note that this is \emph{not} a basis of the lattice.

We have
\[\bvec{v}_i' = \bvec{v}_i - \sum_{j < i}\mu_{ij}\bvec{v}_j'\]
where $\mu_{ij} = \frac{\bvec{v}_i\cdot \bvec{v}_j'}{\bvec{v}_i'\cdot\bvec{v}_i'}$.

What do we know about $\det\{\bvec{v}_i\}$ and $\det\{\bvec{v}_i'\}$? We note that $\det\{\bvec{v}_i\} = \det\{\bvec{v}_i'\}$. This is as our row/column operations (except scaling) don't change determinant.

\ul{Ideas}:

We want some $\bvec{v}_1, \bvec{v}_2, \dots, \bvec{v}_n$ are approximately orthogonal.

We want $\bvec{v}_1 \leq \bvec{v}_2 \leq \dots \leq \bvec{v}_n$ (approximately sorted).

\begin{definition}[LLL Reduction]
    $\mathcal{B}$ is LLL reduced if
    \begin{enumerate}
        \item \emph{We want a measure of orthogonality, so we bound $\mu_{ij}$ from Gram-Schmidt to a certain value. }

              We have that
              \[\boxed{|\mu_{ij}| = \left\lvert\frac{\bvec{v}_i\cdot \bvec{v}_j'}{\bvec{v}_i'\cdot\bvec{v}_i'}\right\rvert\leq \frac{1}{2}}\]
        \item \emph{We want our measure in a way that failure of exact orthogonality doesn't contribute.}

              We take the projection of $\bvec{v}_{i-1}$ onto
              \[\langle\bvec{v}_1, \dots, \bvec{v}_{i-2}\rangle^\perp\]
              and compare that with the length of the projection of $\bvec{v}_i$ onto
              \[\langle\bvec{v}_1, \dots, \bvec{v}_{i-1}\rangle^\perp\]
              We want
                  {\small
                      \[\frac{3}{4}\left|\left|\ \text{Projection of $\bvec{v}_{i-1}$ onto } \langle\bvec{v}_1, \dots, \bvec{v}_{i-2}\rangle^\perp\right|\right|\leq \left|\left|\ \text{Projection of $\bvec{v}_{i}$ onto } \langle\bvec{v}_1, \dots, \bvec{v}_{i-1}\rangle^\perp\right|\right|\]
                  }
              \emph{Noting that $\frac{3}{4}$ was arbitrarly chosen as a `fudge factor'.}

              So we have
              \[\frac{3}{4}||\bvec{v}_{i-1}||^2\leq ||\bvec{v}_i' + \mu_{i-1, i}\cdot\bvec{v}_{i-1}'||^2 = ||\bvec{v}_i||^2 + \mu_{i-1, i}^2\cdot||\bvec{v}_{i-1}'||\]
              so then
              \[\boxed{||\bvec{v}_i^2||\geq\left( \frac{3}{4} - \mu_{i-1, i}^2 \right)\cdot ||\bvec{v}_{i-1}'||^2}\]
    \end{enumerate}
\end{definition}

Our goal is that we want an algorithm to find an LLL basis. Additionally, once we do find an LLL basis, we want to know that it will be sufficiently orthogonal.

Code in \textsf{lll.ipynb}.


\hypertarget{functions}{%
\section{Functions}\label{functions}}

A function in morpho is defined with the \texttt{fn} keyword, followed
by the function's name, a list of parameters enclosed in parentheses,
and the body of the function in curly braces. This example computes the
square of a number:

\begin{lstlisting}
fn sqr(x) {
  return x*x
}
\end{lstlisting}

Once a function has been defined you can evaluate it like any other
morpho function.

\begin{lstlisting}
print sqr(2)
\end{lstlisting}

\hypertarget{return}{%
\section{Return}\label{return}}

The \texttt{return} keyword is used to exit from a function, optionally
passing a given value back to the caller. \texttt{return} can be used
anywhere within a function. The below example calculates the \texttt{n}
th Fibonacci number,

\begin{lstlisting}
fn fib(n) {
  if (n<2) return n
  return fib(n-1) + fib(n-2)
}
\end{lstlisting}

by returning early if \texttt{n\textless{}2}, otherwise returning the
result by recursively calling itself.


\documentclass[a4paper]{article}
\usepackage{fullpage}

\usepackage{latexsym}         % for some symbols
\usepackage{amsmath}          % for maths
\usepackage{amssymb}          % for Real number symbol
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{subfigure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Notation

\newcommand{\normal}{\mathcal{N}}
\newcommand{\thetaall}{\tilde{\Theta}}

\newcommand{\vect}[2]{\begin{bmatrix} #1 \\ #2 \end{bmatrix}}
\newcommand{\mat}[4]{\begin{bmatrix} #1 & #2\\ #3& #4 \end{bmatrix}}

\newcommand{\dotprod}[2]{\langle #1 , #2 \rangle}
\newcommand{\trace}{\mathrm{tr}}
\newcommand{\deter}{\mathrm{det}}

% end notation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title{Distance between two 2D Gaussians}
\author{Cheng Soon Ong}
\date{24 March 2017}

\begin{document}

\maketitle

\section{Motivation}

In astronomy cross identification is the task of finding the same object in the sky in two images.
The location of each pixel is known, but the challenge lies in the fact that the two images are
measured in different wavelengths.
When doing radio cross identification we need to compare two distributions, one from the optical
image and a second from the radio image.
We assume here that each empirical distribution is well approximated by a single two dimensional
Gaussian.
The first step to cross identification is then to compute the distance between the two Gaussians.

\section{General abstract setup}

One way to measure the difference between two distributions is by using the Kullback-Leibler (KL)
divergence. This is asymmetric, and one often looks at the average of the KL divergence in
both directions. This section selects the relevant results
from~\cite{nielsen09clumnd,nielsen11staefd}.

Let $\normal(\mu, S)$ denote the $d$ dimensional normal distribution with mean $\mu$ and covariance
matrix $S$. We rewrite this Gaussian in its canonical decomposition in terms of its natural
parameters. The sufficient statistics are stacked onto a tuple containing a $d$ dimensional vector
and a $d\times d$ matrix
\[
  \tilde{x} = (x, -\frac{1}{2}xx^\top)
\]
associated with the natural parameters
\begin{equation}
  \label{eq:nat-param}
  \thetaall = (\theta, \Theta) = \left(S^{-1}\mu, \frac{1}{2} S^{-1}\right)
\end{equation}
The KL divergence between two Gaussian distributions
\[
N_p = \normal(\mu_p, S_p)\qquad\mbox{and}\qquad N_q = \normal(\mu_q, S_q)
\]
is given by the Bregman divergence with generator $F$
\begin{align}
  KL(N_p||N_q) &= D_F(\thetaall_q || \thetaall_p)\\
  &= F(\thetaall_q) - F(\thetaall_p) - \dotprod{(\thetaall_q - \thetaall_p)}{\nabla F(\thetaall_p)}
  \label{eq:bregman-div}
\end{align}
The function $F$ turns out to be the log normaliser specifying the exponential family
(of the Gaussian)
\begin{equation}
  \label{eq:log-normaliser}
  F(\thetaall) = \frac{1}{4}\trace(\Theta^{-1} \theta\theta^\top)
    -\frac{1}{2} \log \deter \Theta + \frac{d}{2}\log 2\pi.
\end{equation}
The gradient of $F$ is given by
\begin{equation}
  \label{eq:grad-log-normaliser}
  \nabla F(\thetaall) = \left(
  \frac{1}{2} \Theta^{-1}\theta
  ,
  -\frac{1}{2} \Theta^{-1} - \frac{1}{4} (\Theta^{-1}\theta)(\Theta^{-1}\theta)^\top
  \right).
\end{equation}
The inner product in \eqref{eq:bregman-div} is the sum of the inner products of the
vectors and matrices,
\[
  \dotprod{\thetaall_p}{\thetaall_q} = \dotprod{\theta_p}{\theta_q} + \dotprod{\Theta_p}{\Theta_q}
\]
where the matrix inner product is $\dotprod{\Theta_p}{\Theta_q} = \trace(\Theta_p\Theta_q^\top)$.

\section{Two dimensional Gaussian}

We explicitly show each element of the vector and matrix for a 2 dimensional Gaussian
mean $\mu$ and variance $S$,
\[
  \normal\left( \vect{\mu_1}{\mu_2}, \mat{s_{11}}{s_{12}}{s_{21}}{s_{22}}\right).
\]
The determinant and inverse of $S$ is given by
\begin{equation}
  \label{eq:det-S}
  a := \deter S = |s_{11} s_{22} - s_{21} s_{22}|
\end{equation}
and
\begin{equation}
  \label{eq:inv-S}
  S^{-1} = \frac{1}{a}\mat{s_{22}}{-s_{12}}{-s_{21}}{s_{11}}
\end{equation}
respectively.
We can then explicitly compute the parameters for the KL divergence in the previous section.
Starting from the right most term in \eqref{eq:bregman-div},
since $d=2$ the constant is $\log 2\pi$.
Recall the relationship between determinants and inverses:
\[
  \deter S^{-1} = \frac{1}{\deter S}
\]
Because we are only considering a two dimensional problem, constants are squared in the determinant,
i.e. $\deter(c S) = c^2 \deter S$.
By the definition of $\Theta$, we have
\begin{align*}
  \frac{1}{2} \log \deter \Theta &= \frac{1}{2} \log \deter (\frac{1}{2} S^{-1}) \\
  &= \frac{1}{2} \log \frac{1}{4} \frac{1}{\deter S}\\
  &= \frac{1}{2} \log \frac{1}{4a}
\end{align*}
where the last line substitutes \eqref{eq:det-S}.
By the definition of $\theta$,
\begin{equation}
  \label{eq:theta}
  \theta = S^{-1}m = \frac{1}{a}\vect{s_{22}\mu_1 - s_{12}\mu_2}{s_{11}\mu_2 - s_{21}\mu_1}.
\end{equation}

We also require
\begin{align}
  \Theta^{-1}\theta &= 2SS^{-1}m = 2m\nonumber\\
  &=\vect{2\mu_1}{2\mu_2}\label{eq:2mean},
\end{align}
which allows us to compute terms in the gradient. By multiplying
\eqref{eq:2mean} and \eqref{eq:theta} we have
\begin{align*}
  \Theta^{-1}\theta\theta^\top &= \frac{1}{a}\vect{2\mu_1}{2\mu_2}
  \vect{s_{22}\mu_1 - s_{12}\mu_2}{s_{11}\mu_2 - s_{21}\mu_1}^\top\\
  &=\frac{2}{a}\mat{\mu_1(s_{22}\mu_1 - s_{12}\mu_2)}{\mu_1(s_{11}\mu_2 - s_{21}\mu_1)}{\mu_2(s_{22}\mu_1 - s_{12}\mu_2)}{\mu_2(s_{11}\mu_2 - s_{21}\mu_1)},
\end{align*}
allowing us to calculate the first term of the log normaliser
\[
  \frac{1}{4}\trace(\Theta^{-1} \theta\theta^\top)= \frac{1}{2a}
  \left(\mu_1(s_{22}\mu_1 - s_{12}\mu_2) + \mu_2(s_{11}\mu_2 - s_{21}\mu_1)\right).
\]
Substituting into \eqref{eq:log-normaliser}, we have
\begin{equation}
  \label{eq:gauss-log-normaliser}
  F(\thetaall) = \frac{1}{2a}
  \left(\mu_1(s_{22}\mu_1 - s_{12}\mu_2) + \mu_2(s_{11}\mu_2 - s_{21}\mu_1)\right)
  - \frac{1}{2} \log \frac{1}{4a} + \log 2\pi.
\end{equation}
Substituting into \eqref{eq:grad-log-normaliser}, we have
\begin{equation}
  \label{eq:gauss-grad-log-normaliser-vec}
  \frac{1}{2}\Theta^{-1}\theta = \mu
\end{equation}
and
\begin{equation}
  \label{eq:gauss-grad-log-normaliser-mat}
  -\frac{1}{2} \Theta^{-1} - \frac{1}{4} (\Theta^{-1}\theta)(\Theta^{-1}\theta)^\top
  =
  - S - \mu\mu^\top.
\end{equation}
It is likely that \eqref{eq:gauss-log-normaliser} and \eqref{eq:gauss-grad-log-normaliser-mat}
are true in general for all Gaussians (not just 2D Gaussians).

\bibliographystyle{alpha}
\bibliography{gaussian}
\end{document}


\chapter{Geometric Parameters}

\section{Wing Basic Geometric Parameters}

\begin{figure}
  \centering
  \includegraphics[width=120mm]{eps/wing_geometric_parameters.eps}
  \caption{Wing basic geometric parameters}
\end{figure}

Aspect ratio is given by the following formula: \cite{Raymer1992}
\begin{equation}
  A = \frac{b^2}{S}
\end{equation}

Taper ratio is given by the following formula. \cite{Raymer1992}
\begin{equation}
  \lambda = \frac{c_t}{c_r}
\end{equation}

\section{Mean Aerodynamic Chord}

\begin{figure}
  \centering
  \includegraphics[width=120mm]{eps/wing_mean_aerodynamic_chord.eps}
  \caption{Mean aerodynamic chord}
\end{figure}

For tapper wing mean aerodynamic chord can be calculated using following formula: \cite{Corke2003, Galinski2016}
\begin{equation}
  \hat c = \frac{2}{3} c_r \frac{1+\lambda+\lambda^2}{1+\lambda}
\end{equation}

For more complex shapes mean aerodynamic chord is given as follows: \cite{Paturski02}
\begin{equation}
  \hat c =
  \left(
    \int_{-\frac{b}{2}}^{\frac{b}{2}} \left( c \left( y \right) \right)^2 dy
  \right)
  \div
  \left(
    \int_{-\frac{b}{2}}^{\frac{b}{2}} \left( c \left( y \right) \right) dy
  \right)
\end{equation}

\section{Wing Aerodynamic Center}

\begin{figure}
  \centering
  \includegraphics[width=120mm]{eps/wing_aerodynamic_center.eps}
  \caption{Wing aerodynamic center}
\end{figure}

Position of wing aerodynamic center ${\vec r}_{AC}$ is at 25\% of the mean aerodynamic chord and its lateral coordinate is given by the following formula. \cite{Raymer1992, Corke2003, Galinski2016, Torenbeek1982}
\begin{equation}
  y_{AC} =
  \frac{ b \left( 1 + 2 \lambda \right) }{ 6 \left( 1 + \lambda \right) }
\end{equation}