\Lecture{Jayalal Sarma}{Sept 29, 2020}{08}{PIE and three applications}{Sumanth Naik}{$\alpha$}{JS}

%\section{Introduction}
The journey so far has been that we have been doing counting by bijections and established certain ideas regarding double counting and the bijections behind the scenes. Then we came to Principle of Inclusion-Exclusion(PIE) as a consequence of a bijection argument. In this lecture, we will look at another proof (an algebraic proof) for PIE and then 3 interesting applications of PIE.

\section{Principle of Inclusion Exclusion (PIE) - An Algebraic Proof} \label{sec:Principle of Inclusion - Exclusion(PIE)}
If there are $n$ subsets of a ground set $X$; $A_1$, $A_2$, $A_3, \ldots A_n$ $\subseteq$ $X$, then PIE helps us to estimate the size of the set of union of all $n$ subsets of the ground set. Mathematically, PIE states that,
\begin{align*}
\left|\bigcup_{i=1}^{n} A_i\right| &= \sum_{1 \le i \le n} | A_i|
\hspace{0.1cm}- \sum_{1 \le i < j \le n} \left| A_i \cap A_j \right| \\
&\hspace{0.5cm}+ \sum_{1 \le i < j < k \le n} | A_i \cap A_j \cap A_k| \hspace{0.2cm}.\hspace{0.1cm}.\hspace{0.1cm}.\hspace{0.1cm}.\hspace{0.1cm}.\\
\left|\bigcup_{i=1}^{n} A_i\right| &= \sum_{\emptyset \neq I \subseteq [n]} (-1)^{|I| +1} \left|\bigcap_{i \in I} A_i \right|\\
&=\sum_{\emptyset \neq I \subseteq [n]} (-1)^{|I| +1} \left|A_I\right|
\end{align*}
where $[n] = \{1,2,3, \ldots, n\} $ (short-hand notation for $1$ to $n$ elements) and $A_I = \bigcap_{i \in I} A_i$.\\
\\
Note that the intuition behind understanding the formula in the second step from first is that, $ \emptyset \neq I \subseteq [n]$ captures all the combinations of $1,2,3, \ldots ,n$ sized sets from $n$ sized set of numbers, i.e., $1 \le i \le n$ (set of combinations of 1 sized set from n sized set), $1 \le i < j \le n$ (set of combinations of 2 sized set from n sized set) and so on up to set of combinations of $n$ sized set from n sized set. The alternating sign in first equation's term is captured by $(-1)^{|I| +1}$ in second equation. And finally, the intersection part of all the terms in first equation, i.e., $|A_i|, |A_i \cap A_j|,  |A_i \cap A_j \cap A_j| \ldots$ is captured in $ \bigcap_{i \in I} A_i$ of the second equation.
\begin{proof}
Define the characterestic function of the set $A_i$ as $f_i$ described as : $f_i:X\longrightarrow\{0,1\}$, where the images are defined as $$\forall x \in X,\hspace{0.3cm} f_i(x) =
  \begin{cases}
    1&\mbox{if } x \in A_i \\
    0& \textrm{otherwise }
  \end{cases}
$$

By definition, $(1-f_i(x))$ is the characteristic function for the compliment of $A_i$ (i.e. $X\setminus A_i$ or $\overline A_i$). In other words, when you subtract the characteristic function of a set from $1$, the difference is the characteristic function of the compliment of the same set. It is also to be noted that $f_i(x)f_j(x)$ is the characteristic function of $A_i\cap A_j$. In other words; when you multiply the characteristic functions of two sets with each other, the product is the characteristic function of the intersection of the two sets.
\begin{align}
\intertext{Consider a function defined as,} F(x) &= \prod_{i=1}^{n}(1-f_i(x))\nonumber \\
&= (1-f_1(x))(1-f_2(x)) \ldots (1-f_n(x))\nonumber  \\
&= \sum_{I\subseteq[n]}(-1)^{|I|}\left(\prod_{i \in I} f_i(x)\right) \label{eq:F_def_in_PIE}
\end{align}
Note that the $F(x)$ represents the characteristic function of intersection of compliments (compliment of each $f_i$), hence by De-Morgan's Law, its mathematical equivalent is,
\[
\overline{\left(\bigcup_{i=1}^{n} A_i\right)} = X \setminus \bigcup	_{i=1}^{n}A_i
\]
To get the size of the set in the $RHS$ of previous equation (it has all the elements which are not present in any of the $n$ subsets of $X$), we just need to count the number of $x$'s in $X$ for which $F(x)$ is 1 (as $F(x)$ will be 1 for any $x$ only if every $f_i(x)$ is 0, i.e., $\forall i,x \notin A_i$). Hence:
\begin{equation}
\label{eq:sigma_F_1}
|X \setminus \bigcup_{i=1}^{n}A_i| = \sum_{x \in X} F(x)
\end{equation}

Also from (\ref{eq:F_def_in_PIE}),
\begin{align}
\sum_{x \in X} F(x)&= \sum_{x} \sum_{I \subseteq [n]} (-1)^{|I|} \left(\prod_{i \in I} f_i(x)\right)\nonumber \\
&= \sum_{I \subseteq [n]} (-1)^{|I|} \left(\sum_{x} \left(\prod_{i \in I} f_i(x)\right)\right)\nonumber \\
&=\sum_{I \subseteq [n]} (-1)^{|I|} \left|\bigcap_{i \in I}A_i\right|\label{eq:sigma_F_2}
\end{align}
The last step is because $(\prod_{i \in I} f_i(x))$ is the characteristic function of intersection of $n$ subsets, i.e., $\bigcap_{i \in I}A_i$. And its summation over $x$, $(\sum_{x} (\prod_{i \in I} f_i(x)))$ will give us the size of the intersection, $\left|\bigcap_{i \in I}A_i\right|$. Also, note that the convention when $I=\emptyset$ is,
%\begin{equation}
$\left|\bigcap_{i \in I}A_i\right| = |X|$.
which can be reasoned as when $I$ is empty, $\left(\prod_{i \in I} f_i(x)\right)$ is $1$ for any $x$. And its summation over $x$, $\sum_{x} \left(\prod_{i \in I} f_i(x)\right)$ gives $|X|$.
\begin{align*}
\intertext{By (\ref{eq:sigma_F_1}) and (\ref{eq:sigma_F_2}),}
\left|X \setminus \bigcup_{i=1}^{n}A_i\right| &= \sum_{I \subseteq [n]} (-1)^{|I|} \left|\bigcap_{i \in I}A_i\right|\\
|X | - \left| \bigcup_{i=1}^{n}A_i\right| &= \sum_{I \subseteq [n]} (-1)^{|I|} \left|\bigcap_{i \in I}A_i \right|\\
\left| \bigcup_{i=1}^{n}A_i \right| &= |X| - \sum_{I \subseteq [n]} (-1)^{|I|} \left|\bigcap_{i \in I}A_i\right|\\
&=\sum_{\emptyset \neq I \subseteq [n]} (-1)^{|I|+1} \left|\bigcap_{i \in I}A_i \right| \\
\end{align*}
This completes the algebraic proof for PIE.
\end{proof}

\section{Applications of PIE} \label{sec:Applications of PIE - lec1}

We now see three different applications of PIE which exposes some interesting features of the tool.

\subsection{Counting the number of derangements on $n$ elements.} \label{subsec:derangements application}
Consider a scenario where, $n$ people go to a theatre to watch a movie, they keep their hats outside with the gatekeeper. On return, in a rush, the gatekeeper panicked and gave back the hats randomly.\\
\textbf{Question:} What is the chance that nobody got their own hat for a very large $n$?\\
\textbf{Answer (surprisingly high)}: roughly 36\% ! (more precisely, the probability is $1/e = 0.3678$).

Formally, if we view the rearrangement as a permutation on $n$ elements, the property that we are looking for can be expressed mathematically as follows : A permutation $\sigma \in S_n$ is said to be a derangement if $\forall i \in [n], \sigma(i) \ne i$.
Now we prove the following theorem.

\begin{theorem}
Number of derangements on $n$ elements is $$\left(\sum_{k=0}^{n} \frac{(-1)^k}{k!}\right)n!$$
\end{theorem}

Before we proceed, let us demonstrate why this implies our surprising answer. We know that the total number of ways for the $n$ people to pick $n$ hats is $n!$ (factorial of $n$) and hence the chance of derangement is $\left(\sum_{k=0}^{n} \frac{(-1)^k}{k!}\right)$. As $n\rightarrow\infty$, $\left(\sum_{k=0}^{n} \frac{(-1)^k}{k!}\right) \rightarrow 1/e \thicksim 0.3678$.). We now proceed with the proof of the above theorem, which is a nice application of PIE.

\begin{proof}
Let $S_n$ be the set of permutations on $n$ elements. $\sigma \in S_n$ is a permutation function on $n$  elements ($\sigma : [n] \rightarrow [n]$). $\forall_{i=1}^{n},~ \sigma(i)$ is defined as the person to whom $i^{\text{th}}$ person's hat was given. If $\sigma(i) = i$, then it means that the $i^{\text{th}}$ person got the correct hat - in terms of formal language of permutations, this is called a \textit{fix-point} of the permutation. What we are looking for is to count the number of fix-point-free permutations in $S_n$.

The strategy is to count the number of non-derangements and subtract from $n!$.
Mathematically, non-derangement is captured as $\exists i,\hspace{0.2cm} \sigma(i) = i$. Now we set up the application of PIE in this context, by defining the $A_i$s first. Define $A_i$ as,
$$\forall i \in \{1,2,...n\},\hspace{0.2cm} A_i = \{\sigma \in S_n\hspace{0.1cm} |\hspace{0.1cm} \sigma(i) = i\}$$
So, $A_i$ represents the set of $n$ elements whose $i^{\text{th}}$ element is fixed to $i$, other elements can be any non repeating value of $1$ to $n$ (except $i$ as it is taken).

The set that we want to estimate the size of - the set of non-derangement can be represented as $\bigcup_{i=1}^{n} A_i$.
Hence, we are interested in finding the number of non-derangements $|\bigcup_{i=1}^{n} A_i|$.

We want to apply PIE - which is about intersection of these $A_i$. Can $A_i$ and $A_j$ really intersect? Indeed, they can, and we can even estimate the size of the intersection: indeed, for a permutation to be in the intersection it has to be fixing the element $i$ and $j$ and it has the freedom to choose any permutation for the remaining values. Hence,
$$|A_i \cap A_j| = (n-2)!$$

Now we generalize this estimate to arbitrary size intersections since they appear in the RHS of PIE. For a shorthand notation, define, $A_I = \bigcap_{i \in I} A_i$. Now, from the statement of $PIE$, we need to estimate sizes of $\left| A_I \right|$ for different $I \subseteq [n]$. Observe that,
\begin{align}
|A_I| &= (n-|I|)! \label{eq:size_of_A_I_derangement_problem}
\end{align}
Indeed, in $A_I$, $\forall i \in I$, $\sigma(i)$ is fixed to $i$ by definition. For the remaining $n-|I|$ values, $\sigma$ can take any arbitrary permutation of the same $n-|I|$ values, hence $(n-|I|)!$ gives the number of possibilities.\\

Using PIE and using the idea of fixing size of $I$ and sum over each size in next step,
\begin{align}
|\bigcup_{i=1}^{n} A_i| &= \sum_{\emptyset \neq I \subseteq [n]} (-1)^{|I|+1} |A_I|\nonumber \\
&= \sum_{k=1}^{n} (-1)^{k+1} \left(\sum_{I\subseteq [n],|I|=k} |A_I|\right)\nonumber \\
&= \sum_{k=1}^{n} (-1)^{k+1} \left(\sum_{I\subseteq [n],|I|=k} (n-k)!\right)\nonumber \tag{By (\ref{eq:size_of_A_I_derangement_problem})}\\
&= \sum_{k=1}^{n} (-1)^{k+1} (n-k)! {n \choose k}\nonumber \\
&= \sum_{k=1}^{n} (-1)^{k+1} \frac{n!} {k!}\nonumber \\
&=  \left(\sum_{k=1}^{n}  \frac{(-1)^{k+1}} {k!}\right)n! \label{eq:non_derangements}
\end{align}
Now, to get number of derangements, subtract (\ref{eq:non_derangements}) from $n!$, which is
\begin{align*}
n! - \left(\sum_{k=1}^{n}  \frac{(-1)^{k+1}} {k!}\right)n! &= \left(\sum_{k=0}^{n} \frac{(-1)^k}{k!}\right)n!
\end{align*}
\end{proof}

\subsection{Euler's $\Phi$ function.} \label{subsec:euler's function application}
\begin{theorem}
Let $n \in N$, $\Phi (n)$ = number of numbers $\leq n$, which are relatively prime to $n$. If $$n=\prod_{i=1}^{k}p_i^{\alpha_i}$$ where $p_i$ are distinct primes and $\forall i,~ \alpha_i \geq 1$, then $$\Phi(n) = n \left(\prod_{i=1}^{k}\left(1-\frac{1}{p_i}\right) \right)$$
\end{theorem}
\begin{proof}
Let $X=\{1,2,3,...,n\}$. Then,
\[
\forall 1 \leq i \leq k, A_i = \{m\in X ~|~p_i \textrm{ divides } m\}
\]
Thus, $A_i$ represents the set of multiples of $p_i$ less than $n$.
Number of numbers which are not relatively prime to $n$ is given by (as every number in any of $A_i$ will have $p_i$ as common factor) - is given by exactly the set : $\bigcup_{i=1}^{k} A_i$.  Thus we have the ground set for application for PIE. We need to be able to estimate the sizes of the intersections. More precisely:
\begin{align}
\Phi (n) &= n - |\bigcup_{i=1}^{k}A_i| \tag{apply PIE}
\nonumber \\
&=n- \sum_{I \subseteq [k], I \neq \emptyset} (-1)^{|I|+1}|A_I| \label{eq:mobius_with_PIE}
\end{align}
where
%\begin{align}
To esteimate $|A_I|$. We claim that $|A_I| = |\bigcap_{i \in I}A_i| = \frac{n}{\prod_{i \in I}p_i}$. This can be reasoned as follows : in $\bigcap_{i \in I}A_i$, there will be those numbers which are multiples of all the $p_i$'s. The same set can be obtained by including the product of every $p_i$, i.e., $\prod_{i \in I}p_i$, and all the numbers less than $n$ which are multiples of that product. The number of such numbers can be captured by $\frac{n}{\prod_{i \in I}p_i}$.\\
By Equation~\ref{eq:mobius_with_PIE} and using the convention of $\prod_{i \in I}p_i$ is 1 when $I=\emptyset$,
\begin{align*}
\Phi (n) &= n - \sum_{I \subseteq [k], I \neq \emptyset} (-1)^{|I|+1}\frac{n}{\left(\prod_{i \in I}p_i\right)}\\
&= \sum_{I \subseteq [k]} (-1)^{|I|}\frac{n}{(\prod_{i \in I}p_i)}\\
&= n\sum_{I \subseteq [k]} (-1)^{|I|}\frac{1}{\left(\prod_{i \in I}p_i\right()}\\
&=n\left(\prod_{i=1}^{k}\left(1-\frac{1}{p_i}\right)\right)
\end{align*}
Note that the last step is done similar to  (\ref{eq:F_def_in_PIE}) in PIE (section \ref{sec:Principle of Inclusion - Exclusion(PIE)}) derivation : $f_i$ there is equivalent to $\frac{1}{p_i}$ here. This completes the proof for the theorem.
\end{proof}
\vspace{.5cm}
\noindent
\begin{corollary}$\Phi$ is multiplicative when numbers are co-primes. i.e., if $n_1, n_2$ are co-primes, then $\Phi(n_1 n_2) = \Phi(n_1) \Phi(n_2)$.
\end{corollary}
\begin{proof}
Let $A$ be the set of prime factors of $n_1n_2$. Since $n_1n_2$ is the product of two numbers $n_1$ and $n_2$, any prime $p \in A$ should divide at least one of $n_1$ and $n_2$. If $n_1$ and $n_2$ are co-primes, then the do not have any common prime factor. Therefore, any prime $p \in A$ should divide exactly one of $n_1$ and $n_2$. So, we can partition the set $A$ into two sets $X$ and $Y$ where $X$ is the set of prime factors of $n_1$ and $Y$ is that of $n_2$.
\begin{align*}
    \Phi(n_1n_2) &= n_1 n_2  (\prod_{p \in A}(1-\frac{1}{p}))\\
    &= n_1 (\prod_{p\in X}(1-\frac{1}{p})). n_2 (\prod_{p\in Y}(1-\frac{1}{p}))\\
    &= \Phi(n_1) \Phi(n_2)
\end{align*}
Thus, if $n_1$, $n_2$ are co-primes, then $\Phi(n_1 n_2) = \Phi(n_1) \Phi(n_2)$. \end{proof}

\subsection{Probability that two natural numbers are co-primes} \label{subsec:co-primes application}
For two randomly chosen natural numbers, what is the probability that they do not have a common factor (other than 1)?\\
Answer: $\sim60\% $
\begin{proof}
Fix $n$; $S = \{(a,b) | a,b \in [n]\}$.\\
Consider two definitions, the good set $G$ (represents set of pairs whose elements have $gcd = 1$) and the bad set $B$ (represents set of pairs whose elements have $gcd > 1$),
\[
G = \{(a,b)| \text{ no } d > 1 \text{ exist such that }d  \hspace{0.1cm}divides \hspace{0.1cm} a \text{ and } d  \hspace{0.1cm}divides \hspace{0.1cm} b\}
\]
\[
B = \{(a,b)| \exists d > 1 \text{ such that }d \hspace{0.1cm}divides \hspace{0.1cm} a \text{ and } d \hspace{0.1cm}divides \hspace{0.1cm} b\}
\]
We want the upper bound of $|B|$ in terms of $n^2$.\\
Define $X$ which has all the permutations of pairs possible as, $$X = \{(a,b)|a,b \in [n]\}$$
And for prime $p \le n$, define $A_p$ as a set which contains pairs whose elements both have $p$ as a prime factor and the pair belongs to $X$. $$A_p = \{(a,b)|p \hspace{0.1cm}divides \hspace{0.1cm}a,p \hspace{0.1cm}divides \hspace{0.1cm}b, p \hspace{0.1cm}is\hspace{0.1cm}prime ,(a,b)\in X\}$$
Clearly, $$B = \bigcup_{p \le n} A_p$$
By PIE,
\begin{align}
|B| = \sum_{I \subseteq Q, I \neq \emptyset} (-1)^{|I|+1} |A_I| ~~\text{where,} ~~Q = \{p|p \le n, prime\}\label{eq:PIE_usage_application_3}
\end{align}
Now, the aim is to estimate $|A_I|$ (as stated in PIE), we can write,
\begin{align}
|A_I| =|\bigcap_{p_i \in I} A_{p_i}|\label{eq:size_of_A_I_mobius}
\end{align}
Here, $\bigcap_{p_i \in I} A_{p_i}$ denotes the set of pairs whose elements are both divisible by product of numbers (which are primes) in $I$. Note that the product need not be a prime. We can not write the resulting set ($\bigcap_{p_i \in I} A_{p_i}$) in terms of $A_p$ as $p$ is prime in the definition. So, lets create a new definition.\\
Let's define $A_d$, which denotes the set of pairs whose elements both have $d$ as a factor and the pairs belongs to $X$ (note that this definition is different from $A_p$ as there $p$ should be a prime, here $d$ can be any number), $$A_d = \{(a,b)|d \hspace{0.1cm}divides \hspace{0.1cm} a, d \hspace{0.1cm}divides \hspace{0.1cm} b, (a,b) \in X\}$$
Rewriting (\ref{eq:size_of_A_I_mobius}) using the definition of $A_d$,
\begin{align}
|A_I| =|A_d| \label{eq:size_of_A_I_equals_size_of_A_d}
~~where, \hspace{0.3cm}d = \prod_{p_i \in I}p_i
\end{align}
Estimating $|A_d|$ separately, from definition, $a$ can be any mutiple of $d$ which is less than or equal to $n$, similarly $b$ too can be any mutiple of $d$ which is less than or equal to $n$. Hence,
\begin{align}
|A_d| &=\lfloor \frac{n}{d} \rfloor \lfloor \frac{n}{d} \rfloor\nonumber\\
&=(\lfloor \frac{n}{d} \rfloor)^2 \label{eq:size_of_A_d}
\end{align}
From (\ref{eq:PIE_usage_application_3}), splitting the summation by number of primes taking part,
\begin{align}
|B| &=\sum_{k \geq 1} (\sum_{I \subseteq Q, I \neq \emptyset,|I| = k} (-1)^{|I|+1} |A_I|) \nonumber \tag{Apply (\ref{eq:size_of_A_I_equals_size_of_A_d}) and (\ref{eq:size_of_A_d}) }\\
&=  \sum_{k \geq 1}(\sum_{d \le n,\substack{d\text{ is a product } \\ \text{of } k \text{ distinct}\\ \text{primes from }Q} }(-1)^{k+1}(\lfloor \frac{n}{d} \rfloor)^2)  \label{eq:bad_set}
\end{align}
Note that the value of $k$ is used only to determine the sign of the terms in $|B|$. Usage of Mobius function gives a clever way to reduce the equation of $|B|$ to a single summation from double summation.\\
Mobius function $\mu(d)$ is given by
\[
  \mu(d) =
  \begin{cases}
    0 &\mbox{if } p^2 \hspace{0.1cm} \text{divides} \hspace{0.1cm} d, \hspace{0.1cm} p  \hspace{0.1cm} \text{is prime}\\
    1 &\mbox{if } d = 1\\
    (-1)^k &\mbox{if } d \text{ is a product of }k \text{ distinct primes}
  \end{cases}
\]
Using $\mu(d)$ in (\ref{eq:bad_set}),
$$|B| = \sum_{2 \le d \le n}(-\mu(d) ((\lfloor \frac{n}{d} \rfloor)^2))$$
Now estimating $|G|$; since all of $S$ can be either in $G$ or $B$ but not both and size of $S$ is $n^2$,
\begin{align}
|G| &= n^2 - |B|\nonumber \\
&= n^2 + \sum_{2 \le d \le n}\mu(d) ((\lfloor \frac{n}{d} \rfloor)^2)\nonumber \\
&= \sum_{1 \le d \le n}\mu(d) ((\lfloor \frac{n}{d} \rfloor)^2) \label{eq:good_set_1}
\end{align}
Last step uses the fact that $\mu(1) = 1$ in the Mobius function.\\
 Furthermore for any $x$,
\begin{align*}
(\lfloor x \rfloor )^2 - x^2 &= (x-\{x\})^2 - x^2\\
&= x^2 - 2\{x\}x + \{x\}^2 -x^2\\
&= -2x\{x\} + \{x\}^2\\
&= O(x)
\end{align*}
Using this fact in (\ref{eq:good_set_1}),
\begin{align}
|G| &= \sum_{1 \le d \le n}\mu(d) (\frac{n^2}{d^2} + O(\frac{n}{d}))\nonumber \\
&= n^2 \sum_{1 \le d \le n}\frac{\mu(d)}{d^2} +  O(n \sum_{1 \le d \le n}(\frac{\mu(d)}{d})) \label{eq:good_set_2}
\end{align}
Estimating the second term in (\ref{eq:good_set_2}):
\begin{align}
n \sum_{1 \le d \le n}(\frac{\mu(d)}{d}) &\le n (\sum_{1 \le d \le n}\frac{1}{d})\nonumber \\
&\le n \log{n} \label{eq:term_2_in_good_set}
\end{align}
Last step is derived by the asymptotic estimate of the sequence of Harmonic series. \\ \\
Estimating the first term in (\ref{eq:good_set_2}):\\
Using Euler's series, the following approximation can be done.
\begin{align}
M = \sum_{d=1}^{\infty} \frac{\mu(d)}{d^2} \sim \frac{6}{\pi^2} \label{eq:approx_M}
\end{align} \\
It can also be proven that
\begin{align}
|M-\sum_{1 \le d \le n} \frac{\mu(d)}{d^2}| \le \frac{1}{n}\label{eq:term_1_in_good_set}
\end{align}
Using (\ref{eq:good_set_2}), (\ref{eq:term_2_in_good_set}), (\ref{eq:approx_M}) and (\ref{eq:term_1_in_good_set}),
\begin{align*}
|G| &= n^2 (\frac{6}{\pi^2} + \frac{1}{n})+ O(n \log{n})\\
|G| &= n^2 \frac{6}{\pi^2} + O(n \log{n})\\
\frac{|G|}{n^2}&=\frac{6}{\pi^2} + O(1)
\end{align*}
Thus, as $n\rightarrow \infty$, the probability that two randomly chosen numbers do not have a common factor converges to $\frac{6}{\pi^2}$ $\sim$ $60\%$.
\end{proof}

\Lecture{Jayalal Sarma}{Sept 29, 2020}{09}{Surjections and Stirling numbers}{Raghul}{$\alpha$}{JS}

\section{Introduction}
In this lecture, we will look at another application of Principle of Inclusion-Exclusion(PIE) - counting number of surjections. Later, we will look at a concept related to that application - Stirling numbers of the second kind.

\section{Applications of PIE} \label{sec:Applications of PIE - lec2}
\subsection{Number of surjections from $[m]$ to $[n]$} \label{subsec:surjections application}
Consider $f : [m] \rightarrow [n]$. The total number of functions is $n^m$ - each element in $[m]$ has $n$ choices for its image. The number of injections is ${n \choose m}m!$ - the $m$ different images required can be chosen from $[n]$ in ${n \choose m}$ ways and then these images can assigned their pre-images from $[m]$ in $m!$ ways. The number of surjections is not that obvious and can be derived using PIE.\\
\begin{theorem}
The number of surjections from $[m]$ to $[n]$ is given by
$$\sum_{k=0}^{n} (-1)^k (n-k)^m {n \choose k}$$
\end{theorem}
\begin{proof}
Let $X$ be the set of all functions from $[m]$ to $[n]$. We know that
\begin{align}
    |X| = n^m \label{eq:surjection:size(X)}
\end{align}
Let us define $A_i$ ($\subseteq X$) for all $i\in[n]$ as follows.
$$A_i = \{f : [m] \rightarrow [n] ~|~ \forall j \in [m],~ f(j) \neq i\} $$
In other words, $A_i$ is the set of functions in which the element $i$ in $[n]$  does not have a pre-image and hence any element in $A_i$ is a non-surjection. The union of all the $A_i$'s will be the set of all non-surjections.\\
Clearly, $|A_i| = (n-1)^m$ : since each element in $[m]$ has only $n-1$ choices for its image. Similarly, $\forall i < j, ~|A_i\cap A_j| = (n-2)^m$ and so on. Thus, for any $I \subseteq [n]$,
\begin{align}
|A_I| = |\bigcap_{i \in I} A_i| = (n-|I|)^m \label{eq:surjection:size(A_I)}
\end{align}
Using PIE to find the number of non-surjections,
\begin{align}
|\bigcup_{i=1}^{n} A_i| &= \sum_{\emptyset \neq I \subseteq [n]} (-1)^{|I| +1} |A_I|\nonumber\\
&= \sum_{k=1}^{n} (-1)^{k+1} \sum_{I \subseteq [n], |I| = k} |A_I|\nonumber\\
&= \sum_{k=1}^{n} (-1)^{k+1} \sum_{I \subseteq [n], |I| = k} (n-k)^m \nonumber\tag{By \ref{eq:surjection:size(A_I)}}\\
&= \sum_{k=1}^{n} (-1)^{k+1} (n-k)^m {n \choose k} \label{eq:surjection:size(unionA_i)}
\end{align}
Therefore, the number of surjections is given by
\begin{align*}
|X \setminus \bigcup_{i=1}^{n} A_i| &= |X| - |\bigcup_{i=1}^{n} A_i|\\
&= n^m - \sum_{k=1}^{n} (-1)^{k+1} (n-k)^m {n \choose k} \tag{using \ref{eq:surjection:size(X)} and \ref{eq:surjection:size(unionA_i)}}\\
&= (-1)^0 (n-0)^m {n \choose 0}+ \sum_{k=1}^{n} (-1)^{k} (n-k)^m {n \choose k}\\
&= \sum_{k=0}^{n} (-1)^{k} (n-k)^m {n \choose k}
\end{align*}
This completes the proof.
\end{proof}
\noindent\\
\section{Stirling numbers of the second kind}
Let us now look at another way of counting the number of surjections - in terms of Stirling numbers of the second kind. The number of ways of partitioning $[n]$ into $k$ non-empty parts, where neither the order of the parts nor the order of elements within a part matter, is denoted by ${n \brace k}$ and is a Stirling number of the second kind. \\
For example; ${4 \brace 1} = 1$ because [1,2,3,4] is the only way of partitioning, ${4 \brace 2} = 7$ because $[1,2,3|4]$, $[1,2,4|3]$, $[1,3,4|2]$, $[2,3,4|1]$, $[1,2|3,4]$, $[1,3|2,4]$ and $[1,4|2,3]$ are the ways of partitioning, ${4 \brace 3} = 6$ because $[1,2|3|4]$, $[1,3|2|4]$, $[1,4|2|3]$, $[1|2,3|4]$, $[1|2,4|3]$ and $[1|2|3,4]$ are the ways of partitioning and ${4 \brace 4}$ = 1 because $[1|2|3|4]$ is the only way of partitioning.\\ \\
Let us now count the number of surjections from $[m]$ to $[n]$ in terms of Stirling numbers of the second kind. We know that in a surjection, every element in the co-domain $[n]$ has at least one pre-image. So, we could partition the domain $[m]$ into $n$ non-empty parts such that all the elements within a part have the same image in the co-domain. (For example; for $f : [5] \rightarrow {0,1,2}$, $f(x) = x ~mod~3 $, the partition of the domain is $[1,4|2,5|3]$.) Such a partition could be done in ${m \brace n}$ ways and then each of these parts can be assigned to one element in $[n]$ in $n!$ ways. Thus the number of surjections from $[m]$ to $[n]$ in terms of Stirling numbers of the second kind is ${m \brace n}n!$. \\ \\
We have counted the number of surjections in 2 different ways (using PIE and in terms of ${m \brace n}$). These two values should be equal and equating them would give us an expression for ${m \brace n}$ as follows.
\begin{align*}
    {m \brace n}n! &= \sum_{k=0}^{n} (-1)^{k} (n-k)^m {n \choose k}\\
    {m \brace n} &= {\frac{1}{n!}}\sum_{k=0}^{n} (-1)^{k} (n-k)^m {n \choose k}
\end{align*}
It is to be noted that by convention, ${0 \brace 0} = 1$ and $\forall n>0, {n \brace 0} = {0 \brace n} = 0$. \\
\begin{theorem} For any $n,k \in \N$;
$${n \brace k} = {n-1 \brace k-1} + k {n-1 \brace k}$$
\end{theorem}
\begin{proof}
We shall use double counting to prove this theorem. Let us count the number of ways of partitioning $[n]$ into $k$ non-empty parts.\\ Clearly, the L.H.S. of the equation is the number of ways of partitioning $[n]$ into $k$ non-empty parts. \\
Consider the element $n$ in $[n]$; in a partition, this element can either be in a part of size $1$ or a part of size $\geq 2$. The number of partitions in which $n$ is in a part of size $1$ is ${n-1 \brace k-1}$ : $n$ is the only element in a part and then the remaining $n-1$ elements are to be partitioned into $k-1$ non-empty parts. The number of partitions in which $n$ is in a part of size $\geq 2$ is $k {n-1 \brace k}$ : the remaining $n-1$ elements are to be partitioned into $k$ non-empty parts and then $n$ is added to one of those parts in $k$ ways. Thus, the total number of partitions is ${n-1 \brace k-1} + k {n-1 \brace k}$, which is the R.H.S. of the equation.\\
These two methods have counted the same value and hence should be equal.
\end{proof}
\noindent
The equation stated in the theorem above is actually a very important property of Stirling numbers of the second kind. It is often used to connect any function or a set of numbers with the Stirling numbers of the second kind. \\
\section{Instances of Stirling numbers of the second kind}
Following are some of the instances where Stirling numbers of second kind appear.
\subsection{$n^{th}$ derivative of $e^{e^x}$}
The $n^{\text{th}}$ derivative of the function $f(x) = e^{e^x}$ is given by
    $$f^{(n)}(x) = f(x) \sum_{k=0}^{\infty}{n \brace k} e^{kx}$$
\subsection{Falling factorials of $x$}
We know that polynomials in one variable $x$ (like $4x^2+3x+2$, $10x^3+9x$, etc.) can be expressed as a linear combination of the powers of $x$ i.e. $x^0,x^1,x^2,\ldots$. Thus, the powers of $x$ are said to form a basis for such polynomials. \\
    The falling factorials of $x$ form another basis for polynomials in one variable $x$. The falling factorials are given by
    \begin{align*}
        (x)_0 &= 1 &
        (x)_1 &= x\\
        (x)_2 &= x(x-1) &
        for~ any~k > 0,~ (x)_k &= x(x-1)(x-2)\ldots(x-k+1)
    \end{align*}
    One can easily prove that the falling factorials form a basis for polynomials if it can be proved that $\forall n$, $x^n$ is a linear combination of falling factorials (for any polynomial, write the polynomial as a linear combination of $x^n$'s and then replace $x^n$'s with the corresponding linear combinations of $(x)_n$'s).
\begin{theorem}Powers of $x$ can be written as the linear combination of falling factorials of $x$ using the following equation.
    $$\forall n, x^n \equiv \sum_{k=0}^n {n \brace k} (x)_k$$
\end{theorem}
    \begin{proof} (Note: This proof was done during the discussion session - not in the lecture video.)\\
    Let the polynomial on the L.H.S. be $P(x)$ and that on the R.H.S. be $Q(x)$. In order to prove that $P(x) \equiv Q(x)$, it is sufficient to prove that $P(x) = Q(x)$ for sufficiently large number of distinct values of $x$. The reasoning for the same is as follows.\\
    One can clearly see that the degree of both $P(x)$ and $Q(x)$ is $n$. So, the maximum degree of the polynomial $R(x) = P(x) - Q(x)$ is also $n$. This implies that the maximum number of roots for the equation $R(x)=0$ is $n$. Therefore, if one can prove that $R(x)=0$ for at least $n+1$ distinct values of $x$, then it must be the case that $R(x) \equiv 0$ and hence $P(x) \equiv Q(x)$.\\
    So, all we have to do now is to prove that $P(x) = Q(x)$ for at least $n+1$ distinct $x$'s where $n$ is the degree of the polynomial $P(x)$. Let us use double counting to prove this.\\
    \noindent\\
    Let $x$ be any natural number. Let us count the number of different strings of length $n$ over \{$1,2,3\ldots x$\} in two different ways.
    \begin{enumerate}
        \item Each character in the string can be chosen in $x$ ways and there are $n$ characters in total. Therefore the count is $x^n$ ($=P(x)$).
        \item Let there be $k$ distinct characters in our string. Clearly, $0 \leq k \leq n$ and different values of $k$ would lead to different strings. So, we have to do summation over the value of $k$. Now, let us partition the $n$ available spaces into $k$ non-empty parts - so that spaces within the same part will get the same character and spaces in different parts get different characters. This partitioning can be done in ${n \brace k}$ ways. There are $k$ parts now and we have to assign one character each to these parts from \{$1,2,3\ldots x$\}. The character for the first part can be chosen in $x$ ways, for the second part it is $(x-1)$ ways, for the third part it is $(x-2)$ ways and so on until $(x-k+1)$ ways for the $k^{\text{th}}$ part. Therefore, the count here is given by
        \begin{align*}
            \sum_{k=0}^{n}{n \brace k} x(x-1)(x-2)\ldots(x-k+1) = \sum_{k=0}^{n}{n \brace k} (x)_k = Q(x)
        \end{align*}
    \end{enumerate}
    These two methods count the same number and hence they should be equal. Therefore, $\forall x \in \N, ~ P(x)=Q(x)$, irrespective of the value of $n$. This means that for any $n$, we have proven that $P(x)=Q(x)$ for an infinite number of values of $x$. Hence, $\forall n,~P(x)\equiv Q(x)$.
    \end{proof}
\section{Other interesting types of numbers}
\subsection{Bell numbers ($B_n$) }
    The number of ways of partitioning $[n]$ into non-empty parts is given by the Bell number $B_n$. It can clearly be seen that
    $$B_n = \sum_{k=0}^{n} {n \brace k}$$
    \begin{figure}[h]
        \centering
         \includegraphics[scale = 0.7]{images/Stirling1.png}
        \caption{Permutations on 4 elements with 2 cycles }
        \label{Fig:StirlingI}
    \end{figure}
\subsection{Stirling numbers of the first kind (${n \brack k}$)} The number of ways of permuting $n$ elements such that the permutations have $k$ cycles is given by the Stirling number of the first kind ${n \brack k}$. Figure \ref{Fig:StirlingI} shows all possible ways of permuting 4 elements with 2 cycles (${4 \brack 2} = 11$). From the definition of ${n \brack k}$, it can clearly be seen that $$n! = \sum_{k=0}^{n} {n \brack k}$$

\Lecture{Jayalal Sarma}{Sept 29, 2020}{10}{Tutte’s Matrix Tree Theorem and counting arborescences}{Raghul}{$\alpha$}{JS}
\section{Introduction}
In this lecture, we will be looking at another application of the Principle of Inclusion-Exclusion(PIE) - Matrix Tree Theorem. We will understand the theorem and then we will cover all the bases required to prove the theorem. The proof of the theorem will be completed in the next lecture.

\section{Kirchoff’s Matrix Tree Theorem} \label{sec:kirchoff's application}
The original theorem for undirected graphs was stated by Kirchoff in the 19th century and the generalised verion for directed graphs was stated by Tutte in the 20th century. This theorem is a classical bridge between combinatorial and algebraic quantities. Let us define few important terms before we jump into the theorems and proofs.\\
\begin{definition}\textbf{Laplacian Matrix for undirected graphs:}
For any undirected graph $G(V,E)$ with $n$ vertices, let us define a $n$x$n$ matrix $L(G)$ called the \textit{Laplacian matrix} of $G$ as follows.
\[
  L(G)_{ij} =
  \begin{cases}
    deg(v_i) &\mbox{if }~ i = j\\
    -1 &\mbox{if }~ i \neq j ~\text{and}~(v_i,v_j)\in E\\
    0 &\mbox{otherwise}
  \end{cases}
\]
\end{definition}
\noindent
It can also be noted that for a graph $G(V,E)$ without any self edges (i.e. $\forall i, ~ (v_i,v_i) \notin E$), the Laplacian matrix can also be defined as $L(G) = D - A$ where $D$ is a diagonal matrix with $D_{ii} = ~deg(v_i)$ and $A$ is the adjacency matrix of $G$.
\begin{theorem} Matrix Tree Theorem for undirected graphs by Kirchoff:\\
For any undirected graph $G(V,E)$, the number of different spanning trees rooted at $v_i$ contained in $G$ is given by $det(L_G[i])$ where $L_G[i]$ refers to the matrix obtained by removing the $i^{\text{th}}$ row and the $i^{\text{th}}$ column from $L(G)$ (for any $i \in [n]$).
\end{theorem}
\noindent
Note that the theorem has connected a combinatorial quantity to an algebraic one. It should also be noted that $det(L_G[i])$ is the same for every value of $i$ (since the number of undirected spanning trees does not change with the root $v_i$). The usual proof of this theorem is done using induction on the number of vertices. Instead we will use PIE to prove the generalised version and this theorem will follow as a consequence. Before doing the proof, let us cover few other concepts required for the proof.
\section{Determinant of a Matrix}\label{sec:determinant of a matrix}
From high school mathematics; we all know that for a 2x2 matrix $A$ and a 3x3 matrix $B$, the determinants are given by
\begin{align*}
  det(A) &= a_{11}a_{22}-a_{12}a_{21}\\
  det(B) &= b_{11}b_{22}b_{33}-b_{11}b_{23}b_{32}-b_{12}b_{21}b_{33}+b_{12}b_{23}b_{31}+b_{13}b_{21}b_{32}-b_{13}b_{22}b_{31}
\end{align*}
It is to be noticed that in the determinant expression of a $n$x$n$ matrix, the subscripts in each term match with one of the $n!$ possible permutations on $[n]$ and there are $n!$ terms in the expression. For example; the first term in the expression for $|A|$ represents the permutation $[1\rightarrow1; ~2\rightarrow2]$ and the other term represents $[1\rightarrow2; ~2\rightarrow1]$. Similarly, the second term in the expression for $|B|$ represents $[1\rightarrow1; ~2\rightarrow3;~3\rightarrow2]$ while the fifth term represents $[1\rightarrow3; ~2\rightarrow1;~3\rightarrow2]$.\\
Thus, each term in determinant expression of a $n$x$n$ matrix represents one of the permutations of $[n]$ and all the permutations are represented exactly once. In other words, given a permutation $\sigma$ on $[n]$, the term $\prod_{i=1}^{n} a_{i\sigma(i)}$ appears exactly once in the expression of the determinant of a $n$x$n$ matrix $A$.\\
Given any permutation $\sigma$ on $[n]$, we can represent it in the point representation as a $n$-tuple as $(\sigma(1),\sigma(2),\sigma(3)\ldots \sigma(n))$. We can define the number of inversions of $\sigma$ ($Inv(\sigma)$) as follows.
$$Inv(\sigma) = |\{(i,j)~|~i<j~\text{and}~\sigma(i)>\sigma(j)\}|$$
For example; for the permutation $\sigma_1 = (1,3,2)$, $Inv(\sigma_1) = 1$ (since (2,3) is the only such $(i,j)$ pair); for $\sigma_2 = (3,1,2)$, $Inv(\sigma_2) = 2$ (since (1,2) and (1,3) are the $(i,j)$ pairs) and for $\sigma_3 = (3,2,1)$, $Inv(\sigma_3) = 3$ (since (1,2), (2,3) and (1,3) are the $(i,j)$ pairs). \\
It can be noticed that the sign of a term representing the permutation $\sigma$ in the determinant expression is given by
$$Sign(\sigma) = (-1)^{Inv(\sigma)}$$
From the inferences done above, one can logically guess the determinant expression for a $n$x$n$ matrix $A$ in terms of
$Sign(\sigma)$ and $\prod_{i=1}^{n} a_{i\sigma(i)}$. However, until proven mathematically, this remains nothing more than a logical guess. So, let us state this as a theorem and prove it.
\begin{theorem}
For any $n \in \N$, the determinant of the $n^{\text{th}}$ order square matrix $A$ is given by
$$det(A) = \sum_{\sigma \in S_n} Sign(\sigma)  \prod_{i=1}^{n} a_{i\sigma(i)}$$
where $S_n$ is the set of all permutations on $[n]$.
\end{theorem}
\begin{proof}
We know that the determinant of any matrix $A$ follows the following four properties.
\begin{enumerate}
    \item If all the elements in a row of $A$ are 0, then $det(A)=0$
    \item If two rows of $A$ are identical, then $det(A)=0$
    \item If a row of $A$ is a multiple of another row, then $det(A)=0$
    \item Adding the multiple of a row of $A$ to another row, does not change the value of $det(A)$
\end{enumerate}
Though not done as part of the lecture, it can be proven that there is only one expression in terms of $a_{ij}$'s that satisfies all the four properties. Therefore, it is sufficient to prove that the expression given in the theorem satisfies all the four properties stated above to prove the whole theorem. \\
Let us now prove the first property : Let all the elements in row $k$ be 0 i.e. $\forall_{j\in[n]}~ a_{kj} = 0$. It can clearly be seen that each term in the determinant expression stated in the theorem has some $a_{k\sigma(k)}$ in it. So each term will be 0 and hence $det(A)=0$. \\
Proving that the expression stated in the theorem satisfies the other three properties is left as an exercise for the students.
\end{proof}

\section{Applications of PIE} \label{sec:Applications of PIE - lec3}
\subsection{Tutte’s Matrix Tree Theorem} \label{subsec:tutte's application}
 Now, let us continue our journey towards stating and proving Tutte's Matrix Tree Theorem. Firstly, let us define Spanning Arborescences - the directed graphs equivalent for spanning trees and Laplacian matrix for directed graphs.
\begin{definition}\textbf{Spanning Arborescences:} An \textit{Arborescence} is a directed graph in which a vertex $u$ is called the root and for every other vertex $v$ in the graph, there is exactly one directed path from $u$ to $v$. In simpler terms, an arborescence is an directed tree in which all the edges are directed away from the root. A \textit{Spanning Arborescence} $S(V,E)$ of a directed graph $G(V',E')$ is an arborescence such that $V=V'$ and $E\subseteq E'$.
\end{definition}
\noindent\\
\begin{definition}\textbf{Laplacian matrix for directed graphs:} For any directed graph $G(V,E)$ with $n$ vertices, let us define a $n$x$n$ matrix $L(G)$ called the \textit{Laplacian matrix} of $G$ as follows.
\[
  L(G)_{ij} =
  \begin{cases}
    indeg(v_i) &\mbox{if }~ i = j\\
    -1 &\mbox{if }~ i \neq j ~\text{and}~(v_i,v_j)\in E\\
    0 &\mbox{otherwise}
  \end{cases}
\]
\end{definition}
\begin{theorem} Tutte's Matrix Tree Theorem for directed graphs\\
For any directed graph $G(V,E)$, the number of different spanning arborescences rooted at $v_i$ contained in $G$ is given by $det(L_G[i])$ where $L_G[i]$ refers to the matrix obtained by removing the $i^{\text{th}}$ row and the $i^{\text{th}}$ column from $L(G)$ (for any $i \in [n]$).
\end{theorem}
\noindent
Note that since spanning arborescences are directed, the number of spanning arborecences depend on the chosen root. Hence, unlike the undirected case, $det(L_G[i])$ here depends on the value of $i$. Without loss of generality, we can choose $i = n$ for our proof. Therefore, all we should prove is the number of spanning arborescences rooted at $v_n$ for the directed graph $G$ is given by
\begin{align}
    det(L_G[n]) = \sum_{\sigma \in S_{n-1}}~
    Sign(\sigma)~\prod_{i=1}^{n-1}l_{i\sigma(i)}
    \label{eq:to_prove:Tutte}
\end{align}
The R.H.S. of the equation is the determinant expression for the $(n-1)$x$(n-1)$ matrix $(L_G[n])$.\\Now let us define another type of directed graphs called Spregs to help with our proof process.\\
\noindent\\
\begin{definition}\textbf{Spregs:} Single prdecessor graphs or \textit{Spregs} with distinguished vertex $v$ of a directed graph $G(V,E)$ is a subgraph $T(V,E')$, $E' \subseteq E$, such that each vertex in $T$ except the vertex $v$ has exactly one predecessor and the vertex $v$ has no predecessors. In other words; in the spreg T, $indeg(v) = 0$ and for every $u \neq v$, $indeg(u)=1$.\\
\end{definition}
\begin{figure}[h]
    \centering
    \includegraphics[scale = 0.5]{images/Spreg1.png}
    \caption{Both spreg and arborescence}
    \label{Fig:Spreg1}
\end{figure}
\begin{figure}[h]
    \centering
    \includegraphics[scale = 0.6]{images/Spreg2.png}
    \caption{Spreg but not arborescence}
    \label{Fig:Spreg2}
\end{figure}
\noindent\\
It is important to distinguish between spregs and spanning arborescences : spregs may contain disconnected components and cycles in them. On the other hand, spanning arborescences are directed spanning trees and hence are single connected components and do not have cycles in them. The directed graph in figure \ref{Fig:Spreg1} is a spreg with distinguished vertex $A$ and an arborescence rooted at $A$. On the other hand, the graph in figure \ref{Fig:Spreg2} is a spreg with distinguished vertex $A$ but not an arborescence. Now let us consider the following lemma and prove it.
\noindent\\
\begin{lemma} If $T(V,E)$ is a spanning arborescence rooted at $v$, then $T$ is a spreg with distinguished vertex $v$.
\end{lemma}
\begin{proof}
Let $T(V,E)$ is a spanning arborescence rooted at $v$. We know from the definition that for every other vertex $u$ in $T$, there is a unique directed path from $v$ to $u$. The underlying undirected graph of $T$ is a tree and does not have any cycles and hence there should not be any cycles (directed/undirected) in $T$.\\
Let us now assume that $indeg(v) \neq 0$. This means that there exists a vertex $u$ in $T$ such that the edge $e = (u,v)\in E$. We know that there is a unique path in $T$ from $v$ to $u$ - let that path be $P$. Now the path $P+e$ is a directed cycle in $T$. A contradiction. Therefore, $indeg(v) = 0$.\\
Let us now assume that for some $u \neq v$ in $T$, $indeg(u) = 0$. This implies that T is not a spanning arborescence.  A contradiction. Therefore, $indeg(u) > 0$. \\
Let us now assume that for some $u \neq v$ in $T$, $indeg(u) \geq 2$. This implies $\exists u_1 \neq u_2$ such that $e_1 = (u_1,u) \in E$ and $e_2 = (u_2,u) \in E$. We know that there exists a unique path $P_1$ from $v$ to $u_1$ and another path $P_2$ from $v$ to $u_2$. Since $u_1 \neq u_2$, $P_1 \neq P_2$. Now, $P_1+e_1$ and $P_2+e_2$ are two distinct paths from $v$ to $u$. A contradiction. Therefore, $indeg(u) = 1$.\\
Therefore,  $indeg(v) = 0$ and for every other vertex $u$, $indeg(u) = 1$. In other words, $T$ is a spreg with distinguished vertex $v$.
\end{proof}
\noindent It is important to note that the converse of the above stated lemma is not true because spregs may contain discconnected components and cycles in them. Now, we will look at another lemma.
\noindent\\
\begin{lemma} If $T(V,E)$ is a spreg with distinguished vertex $v$, then the spreg consists of an arborescence rooted at $v$ and zero or more weakly connected components (the underlying undirected component is connected). Each of these weakly connected components have exactly one directed cycle in them.
\end{lemma}
\begin{proof}
The proof of this lemma is left as an exercise for the students to complete.
\end{proof}
\noindent Thus; (a spreg  with distinguished vertex $v$) = (an arborescence rooted at $v$) + $k$ (weakly connected components with one directed cycle each); where $k \geq 0$. \\
\noindent\\
For proving Tutte's theorem; the idea to count the number of arborescences rooted at $v_n$ is that we would count the number of spregs with distinguished vertex $v_n$ and then remove the number of spregs that are not arborescences - the terms in such a expression would exactly match with that of the R.H.S. of \ref{eq:to_prove:Tutte}.\\
\noindent\\
In the R.H.S. of \ref{eq:to_prove:Tutte}, consider the term for $\sigma =$ identity permutation i.e. $\forall i,~ \sigma(i)=i$. Clearly, $Sign(\sigma)=1$ since $Inv(\sigma)=0$. The term would be $+ \prod_{i=1}^{n-1}l_{ii}$. This is exactly equal to the total number of spregs with distinguished vertex $v_n$ - the reasoning is as follows.\\
Since $v_n$ is the distinguished vertex, ignore all the edges whose end vertex is $v_n$. For every other vertex $u$, choose exactly one of the edges whose end vertex is $u$ ($\prod_{i=1}^{n-1}indeg(v_i)$ ways). Clearly, such a subgraph is a spreg - by definition of spregs. Therefore, the number of distinct spregs is $\prod_{i=1}^{n-1}indeg(v_i) = \prod_{i=1}^{n-1}l_{ii}$ (by the definition of Laplacian matrix). \\
\noindent\\
We have counted all the spregs; now, spregs with cycles have to be removed from the count. This part of the proof involves PIE and will be done in the next lecture.


The Integrated Information Theory (IIT) has is proposed as a mathematical way to understand consciousness.
It revolves around analyzing the phenomenology of a system, that is, how a system experiences the environment.
IIT 3.0 mostly does this by finding the maximally irreducible conceptual structures formed by a causal structure interacting with the environment.
The theory tries to assume properties of consciousness (axioms), and from there, it postulates the properties that must be necessary for a physical substrate hosting the system.
The causal structure, also called a cause-effect structure (CES), is analyzed to find conceptual structures that measure how well a system integrates information.
A more substantial amount of integrated information results in a higher amount of possible states in the system.
Integrated information is when there is no way to cut the CES without losing information.
The CES is an unfolding of a model of the neural substrate in the sense that the model is cut in every possible way (imagine cutting a network of nodes).
The CES maps to the properties of experience, and the CES can be quantified by $\Phi$ \cite{oizumi_phenomenology_2014}.

Although IIT might seem overly abstract, the first tangible result was published as a study on the question "Why does space feel the way it does?".
Here a model of the Visual Cortex 1 and 2 (V1 and V2) was cut into a CES, using the knowledge of the grid cells that are proven to be essential for localization \cite{haun_why_2019}.

\paragraph{A summary of corollaries} of IIT, based on the article by Oizumi et. al \cite{oizumi_phenomenology_2014}:
An intelligent system will usually consist of a main \textbf{complex}, and smaller supporting complexes.
This central complex will be the most conscious part of the system, like the part of our brain that we could not function without, while the supporting complexes could be compared to smaller parts of the brain, like, for example, the visual cortex.
Intelligent systems will not be modular, that is, if the system produces less functionality than their components, and they have to produce functionality that is more than a higher order of the combined components.
Inactive systems can be conscious in the way that a system may have significant parts that are ready to be activated or that are passively affecting the state of the system.
A system can perform very complex functions but still not be conscious.
In particular, feed-forward networks would not be conscious.
An example if this is a microprocessor implementing a neural network that, in some cases, can recognize thousands of different objects faster than a human can recognize one object.
IIT states that it is not only the functionality of a system that determines how conscious it is but also how the function performs internally.
A network that can recognize objects based on internal states and previous experiences is more conscious compared to a feed-forward neural network, which only recognizes the object based on the external input it gets.
Networks that are not necessarily feed-forward only, but simulated on a physical substrate that implements functionality based on numerical approximation, would not be termed conscious in IIT 3.0 \cite{marshall_integrated_2016}.
A final corollary that summarises the ones above says that an intelligent system can develop concepts based on other concepts within itself without the need for external stimuli.
These internal concepts would more often be connected to a large number of other concepts and not contribute to specific details.

\paragraph{In this project} I hope to utilize IIT as a way to analyze the perception of automated agents, evolved as SNN \vref{sect:snn} animats \vref{sect:agent} on BrainScaleS \vref{sect:bss}.
As the complexity and states of the animats are known, the animats can be analyzed.
Analyzing the animats in regards to IIT will only be attempted if time permits.


\par
\section{Prototypes and descriptions of {\tt MT} methods}
\label{section:MT:proto}
\par
This section contains brief descriptions including prototypes
of all methods found in the {\tt MT} source directory.
\par
\subsection{Matrix-matrix multiply methods}
\label{subsection:MT:proto:mvm}
\par
There are five methods to multiply a vector times a dense matrix.
The first three methods, called {\tt InpMtx\_MT\_nonsym\_mmm*()},
are straightforward,
$y := y + \alpha A x$, where $A$ is nonsymmetric, and $\alpha$ is
real (if $A$ is real) and complex (if $A$ is complex).
The fourth method, {\tt InpMtx\_MT\_sym\_mmm()},
is used when the matrix is real symmetric or complex symmetric,
though it is not necessary that only the lower or upper
triangular entries are stored.
(If one fills the {\tt InpMtx} object with only the entries in
the lower triangle of $A$, and then permute the matrix $PAP^T$,
the entries will not generally be found in only the lower or upper
triangle. However, the code is still correct.)
The last method,
{\tt InpMtx\_MT\_herm\_mmm()}, is used when the matrix is
complex hermitian.
\par
%=======================================================================
\begin{enumerate}
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void InpMtx_MT_nonsym_mmm ( InpMtx *A, DenseMtx *Y, double alpha[], DenseMtx *X,
                            int nthread, int msglvl, int msgFile ) ;
void InpMtx_MT_sym_mmm ( InpMtx *A, DenseMtx *Y, double alpha[], DenseMtx *X,
                            int nthread, int msglvl, int msgFile ) ;
void InpMtx_MT_herm_mmm ( InpMtx *A, DenseMtx *Y, double alpha[], DenseMtx *X,
                            int nthread, int msglvl, int msgFile ) ;
\end{verbatim}
\index{InpMtx_MT_nonsym_mmm@{\tt InpMtx\_MT\_nonsym\_mmm()}}
\index{InpMtx_MT_sym_mmm@{\tt InpMtx\_MT\_sym\_mmm()}}
\index{InpMtx_MT_herm_mmm@{\tt InpMtx\_MT\_herm\_mmm()}}
These methods compute the matrix-vector product $y := y + \alpha A x$,
where $y$ is found in the {\tt Y DenseMtx} object,
$\alpha$ is real or complex in {\tt alpha[]},
$A$ is found in the {\tt A Inpmtx} object, and
$x$ is found in the {\tt X DenseMtx} object.
If any of the input objects are {\tt NULL}, an error message is
printed and the program exits.
{\tt A}, {\tt X} and {\tt Y} must all be real or all be complex.
When {\tt A} is real, then $\alpha$ = {\tt alpha[0]}.
When {\tt A} is complex, then $\alpha$ =
{\tt alpha[0]} + i* {\tt alpha[1]}.
This means that one cannot call the methods with a constant as the
third parameter, e.g.,
{\tt InpMtx\_MT\_nonsym\_mmm(A, Y, 3.22, X, nthread, msglvl, msgFile)},
for this may result in a segmentation violation.
The values of $\alpha$ must be loaded into an array of length 1 or 2.
The number of threads is specified by the {\tt nthread} parameter;
if, {\tt nthread} is {\tt 1}, the serial method is called.
The {\tt msglvl} and {\tt msgFile} parameters are used for
diagnostics during the creation of the threads' individual data
structures.
\par \noindent {\it Error checking:}
If {\tt A}, {\tt Y} or {\tt X} are {\tt NULL},
or if {\tt coordType} is not {\tt INPMTX\_BY\_ROWS},
{\tt INPMTX\_BY\_COLUMNS} or {\tt INPMTX\_BY\_CHEVRONS},
or if {\tt storageMode} is not one of {\tt INPMTX\_RAW\_DATA},
{\tt INPMTX\_SORTED} or {\tt INPMTX\_BY\_VECTORS},
or if {\tt inputMode} is not {\tt SPOOLES\_REAL} or
{\tt SPOOLES\_COMPLEX},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void InpMtx_MT_nonsym_mmm_T ( InpMtx *A, DenseMtx *Y, double alpha[], DenseMtx *X,
                            int nthread, int msglvl, int msgFile ) ;
\end{verbatim}
\index{InpMtx_MT_nonsym_mmm_T@{\tt InpMtx\_MT\_nonsym\_mm\_Tm()}}
This method computes the matrix-vector product $y := y + \alpha A^T x$,
where $y$ is found in the {\tt Y DenseMtx} object,
$\alpha$ is real or complex in {\tt alpha[]},
$A$ is found in the {\tt A Inpmtx} object, and
$x$ is found in the {\tt X DenseMtx} object.
If any of the input objects are {\tt NULL}, an error message is
printed and the program exits.
{\tt A}, {\tt X} and {\tt Y} must all be real or all be complex.
When {\tt A} is real, then $\alpha$ = {\tt alpha[0]}.
When {\tt A} is complex, then $\alpha$ =
{\tt alpha[0]} + i* {\tt alpha[1]}.
This means that one cannot call the methods with a constant as the
third parameter, e.g.,
{\tt InpMtx\_MT\_nonsym\_mmm(A, Y, 3.22, X, nthread, msglvl, msgFile)},
for this may result in a segmentation violation.
The values of $\alpha$ must be loaded into an array of length 1 or 2.
The number of threads is specified by the {\tt nthread} parameter;
if, {\tt nthread} is {\tt 1}, the serial method is called.
The {\tt msglvl} and {\tt msgFile} parameters are used for
diagnostics during the creation of the threads' individual data
structures.
\par \noindent {\it Error checking:}
If {\tt A}, {\tt Y} or {\tt X} are {\tt NULL},
or if {\tt coordType} is not {\tt INPMTX\_BY\_ROWS},
{\tt INPMTX\_BY\_COLUMNS} or {\tt INPMTX\_BY\_CHEVRONS},
or if {\tt storageMode} is not one of {\tt INPMTX\_RAW\_DATA},
{\tt INPMTX\_SORTED} or {\tt INPMTX\_BY\_VECTORS},
or if {\tt inputMode} is not {\tt SPOOLES\_REAL} or
{\tt SPOOLES\_COMPLEX},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void InpMtx_MT_nonsym_mmm_H ( InpMtx *A, DenseMtx *Y, double alpha[], DenseMtx *X,
                            int nthread, int msglvl, int msgFile ) ;
\end{verbatim}
\index{InpMtx_MT_nonsym_mmm_H@{\tt InpMtx\_MT\_nonsym\_mmm\_H()}}
This method computes the matrix-vector product $y := y + \alpha A^H x$,
where $y$ is found in the {\tt Y DenseMtx} object,
$\alpha$ is complex in {\tt alpha[]},
$A$ is found in the {\tt A Inpmtx} object, and
$x$ is found in the {\tt X DenseMtx} object.
If any of the input objects are {\tt NULL}, an error message is
printed and the program exits.
{\tt A}, {\tt X} and {\tt Y} must all be complex.
The number of threads is specified by the {\tt nthread} parameter;
if, {\tt nthread} is {\tt 1}, the serial method is called.
The {\tt msglvl} and {\tt msgFile} parameters are used for
diagnostics during the creation of the threads' individual data
structures.
\par \noindent {\it Error checking:}
If {\tt A}, {\tt Y} or {\tt X} are {\tt NULL},
or if {\tt coordType} is not {\tt INPMTX\_BY\_ROWS},
{\tt INPMTX\_BY\_COLUMNS} or {\tt INPMTX\_BY\_CHEVRONS},
or if {\tt storageMode} is not one of {\tt INPMTX\_RAW\_DATA},
{\tt INPMTX\_SORTED} or {\tt INPMTX\_BY\_VECTORS},
or if {\tt inputMode} is not {\tt SPOOLES\_COMPLEX},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\end{enumerate}
\par
\subsection{Multithreaded Factorization methods}
\label{subsection:FrontMtx:proto:factorMT}
\par
%=======================================================================
\begin{enumerate}
%-----------------------------------------------------------------------
\item
\begin{verbatim}
Chv * FrontMtx_MT_factorInpMtx ( FrontMtx *frontmtx, InpMtx *inpmtx,
             double tau, double droptol, ChvManager *chvmanager,
             IV *ownersIV, int lookahead, double cpus[], int stats[],
             int msglvl, FILE *msgFile ) ;
Chv * FrontMtx_MT_factorPencil ( FrontMtx *frontmtx, Pencil *pencil,
             double tau, double droptol, ChvManager *chvmanager,
             IV *ownersIV, int lookahead, double cpus[], int stats[],
             int msglvl, FILE *msgFile ) ;
\end{verbatim}
\index{FrontMtx_MT_factorInpMtx@{\tt FrontMtx\_MT\_factorInpMtx()}}
\index{FrontMtx_MT_factorPencil@{\tt FrontMtx\_MT\_factorPencil()}}
These two methods compute a multithreaded factorization for a matrix
$A$ (stored in {\tt inpmtx}) or a matrix pencil
$A + \sigma B$ (stored in {\tt pencil}).
The {\tt tau} parameter is used when pivoting is enabled, each
entry in $U$ and $L$ (when nonsymmetric) will have magnitude less
than or equal to {\tt tau}.
The {\tt droptol} parameter is used when the fronts are stored in
a sparse format, each entry in $U$ and $L$ (when nonsymmetric)
will have magnitude greater than or equal to {\tt droptol}.
The map from fronts to owning processes is found in {\tt ownersIV}.
The {\tt lookahead} parameter governs the
``upward--looking'' nature of the computations.
Choosing {\tt lookahead = 0} is usually the most conservative with
respect to working storage, while positive values increase the
working storage and sometimes decrease the factorization time.
On return, the {\tt cpus[]} vector is filled with the following
information.
\begin{itemize}
\item
{\tt cpus[0]} --- time spent managing working storage.
\item
{\tt cpus[1]} --- time spent initializing the fronts
                  and loading the original entries.
\item
{\tt cpus[2]} --- time spent accumulating updates from descendents.
\item
{\tt cpus[3]} --- time spent inserting aggregate fronts.
\item
{\tt cpus[4]} --- time spent removing and assembling aggregate fronts.
\item
{\tt cpus[5]} --- time spent assembling postponed data.
\item
{\tt cpus[6]} --- time spent to factor the fronts.
\item
{\tt cpus[7]} --- time spent to extract postponed data.
\item
{\tt cpus[8]} --- time spent to store the factor entries.
\item
{\tt cpus[9]} --- miscellaneous time.
\end{itemize}
On return, the {\tt stats[]} vector is filled with the following
information.
\begin{itemize}
\item
{\tt stats[0]} --- number of pivots.
\item
{\tt stats[1]} --- number of pivot tests.
\item
{\tt stats[2]} --- number of delayed rows and columns.
\item
{\tt stats[3]} --- number of entries in $D$.
\item
{\tt stats[4]} --- number of entries in $L$.
\item
{\tt stats[5]} --- number of entries in $U$.
\item
{\tt stats[6]} --- number of locks of the {\tt FrontMtx} object.
\item
{\tt stats[7]} --- number of locks of aggregate list.
\item
{\tt stats[8]} --- number of locks of postponed list.
\end{itemize}
\par \noindent {\it Error checking:}
If {\tt frontmtx}, {\tt inpmtxA}, {\tt cpus} or {\tt stats}
is {\tt NULL},
or if {\tt msglvl > 0} and {\tt msgFile} is {\tt NULL},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\end{enumerate}
\par
\subsection{Multithreaded $QR$ Factorization method}
\label{subsection:FrontMtx:proto:factorQR_MT}
\par
%=======================================================================
\begin{enumerate}
%-----------------------------------------------------------------------
\item
\begin{verbatim}
void FrontMtx_MT_QR_factor ( FrontMtx *frontmtx, InpMtx *mtxA,
                             ChvManager *chvmanager, IV *ownersIV, double cpus[],
                             double *pfacops,  int msglvl, FILE *msgFile ) ;
\end{verbatim}
\index{FrontMtx_MT_QR_factor@{\tt FrontMtx\_MT\_QR\_factor()}}
This method computes the
$(U^T+I)D(I+U)$ factorization of $A^TA$ if $A$ is real
or
$(U^H+I)D(I+U)$ factorization of $A^HA$ if $A$ is complex.
The {\tt chvmanager} object manages the working storage.
The map from fronts to threads is found in {\tt ownersIV}.
On return, the {\tt cpus[]} vector is filled as follows.
\begin{itemize}
\item
{\tt cpus[0]} -- time to set up the factorization.
\item
{\tt cpus[1]} -- time to set up the fronts.
\item
{\tt cpus[2]} -- time to factor the matrices.
\item
{\tt cpus[3]} -- time to scale and store the factor entries.
\item
{\tt cpus[4]} -- time to store the update entries
\item
{\tt cpus[5]} -- miscellaneous time
\item
{\tt cpus[6]} -- total time
\end{itemize}
On return, {\tt *pfacops} contains the number of floating point
operations done by the factorization.
\par \noindent {\it Error checking:}
If {\tt frontmtx}, {\tt frontJ} or {\tt chvmanager} is {\tt NULL},
or if {\tt msglvl > 0} and {\tt msgFile} is {\tt NULL},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\end{enumerate}
\par
\subsection{Multithreaded Solve method}
\label{subsection:FrontMtx:proto:solve-multithreaded}
\par
\begin{enumerate}
%=======================================================================
\item
\begin{verbatim}
void FrontMtx_MT_solve ( FrontMtx *frontmtx, DenseMtx *mtxX, DenseMtx *mtxB,
                         SubMtxManager *mtxmanager, SolveMap *solvemap,
                         double cpus[], int msglvl, FILE *msgFile ) ;
\end{verbatim}
\index{FrontMtx_MT_solve@{\tt FrontMtx\_MT\_solve()}}
This method is used to solve one of three linear systems of equations
using a multithreaded solve
---
$(U^T + I)D(I + U) X = B$,
$(U^H + I)D(I + U) X = B$ or
$(L + I)D(I + U) X = B$.
Entries of $B$ are {\it read} from {\tt mtxB} and
entries of $X$ are written to {\tt mtxX}.
Therefore, {\tt mtxX} and {\tt mtxB} can be the same object.
(Note, this does not hold true for an MPI factorization with pivoting.)
The submatrix manager object manages the working storage.
The {\tt solvemap} object contains the map from submatrices to
threads.
The map from fronts to processes that own them is given in the {\tt
ownersIV} object.
On return the {\tt cpus[]} vector is filled with the following.
The {\tt stats[]} vector is not currently used.
\begin{itemize}
\item
{\tt cpus[0]} --- set up the solves
\item
{\tt cpus[1]} --- fetch right hand side and store solution
\item
{\tt cpus[2]} --- forward solve
\item
{\tt cpus[3]} --- diagonal solve
\item
{\tt cpus[4]} --- backward solve
\item
{\tt cpus[5]} --- total time in the method.
\end{itemize}
\par \noindent {\it Error checking:}
If {\tt frontmtx}, {\tt rhsmtx}, {\tt mtxmanager},
{\tt solvemap}, {\tt cpus} or {\tt stats} is {\tt NULL},
or if {\tt msglvl} > 0 and {\tt msgFile} is {\tt NULL},
an error message is printed and the program exits.
%-----------------------------------------------------------------------
\end{enumerate}
\par
\subsection{Multithreaded $QR$ Solve method}
\label{subsection:FrontMtx:proto:QRsolve-MT}
\par
\begin{enumerate}
%=======================================================================
\item
\begin{verbatim}
void FrontMtx_MT_QR_solve ( FrontMtx *frontmtx, InpMtx *mtxA, DenseMtx *mtxX,
              DenseMtx *mtxB, SubMtxManager *mtxmanager, SolveMap *solvemap,
              double cpus[], int msglvl, FILE *msgFile ) ;
\end{verbatim}
\index{FrontMtx_MT_QR_solve@{\tt FrontMtx\_MT\_QR\_solve()}}
This method is used to minimize $\|B - AX\|_F$, where
$A$ is stored in {\tt mtxA},
$B$ is stored in {\tt mtxB},
and $X$ will be stored in {\tt mtxX}.
The {\tt frontmtx} object contains a
$(U^T+I)D(I+U)$ factorization of $A^TA$ if $A$ is real
or
$(U^H+I)D(I+U)$ factorization of $A^HA$ if $A$ is complex.
We solve the seminormal equations
$(U^T+I)D(I+U)X = A^TB$ or $(U^H+I)D(I+U)X = A^HB$
for $X$.
On return the {\tt cpus[]} vector is filled with the following.
\begin{itemize}
\item
{\tt cpus[0]} --- set up the solves
\item
{\tt cpus[1]} --- fetch right hand side and store solution
\item
{\tt cpus[2]} --- forward solve
\item
{\tt cpus[3]} --- diagonal solve
\item
{\tt cpus[4]} --- backward solve
\item
{\tt cpus[5]} --- total time in the solve method.
\item
{\tt cpus[6]} --- time to compute $A^TB$ or $A^HB$.
\item
{\tt cpus[7]} --- total time.
\end{itemize}
Only the solve is presently done in parallel.
\par \noindent {\it Error checking:}
If {\tt frontmtx}, {\tt mtxA}, {\tt mtxX}, {\tt mtxB}, {\tt mtxmanager},
{\tt solvemap} or {\tt cpus} is {\tt NULL},
or if {\tt msglvl} > 0 and {\tt msgFile} is {\tt NULL},
an error message is printed and the program exits.
%=======================================================================
\end{enumerate}


% !TeX root = ../main.tex

\section{Introduction}
The idea of the recursive nearest neighbors method came up in the process of studying
recommender systems in the framework of this thesis. The method that will be presented is an
effort to overcome the limitations of neighborhood-based approach. That is, to provide more
rating predictions than the conventional K-Nearest Neighbors method, which fails when it
cannot connect users or items directly due to sparseness constraints.

\begin{table}[H]
\centering
\begin{tabular}{ |c|c|c|c|c|c|c| }
\hline
\diagbox{$User$}{$Item$} & \textbf{$Item_1$} & \textbf{$Item_2$} & \textbf{$Item_3$} & \textbf{$Item_4$}  & \textbf{$Item_5$} & \textbf{$Item_6$} \\
\hline
\textbf{$User_1$} & 5 & 2 & 3 & \textbf{?} & 1 & 5 \\
\hline
\textbf{$User_2$} & 1 & 2 & 4 & \textbf{?} & 2 & 2 \\
\hline
\textbf{$User_3$} & 4  & 3 & 5 & \textbf{?} & 4 & 3 \\
\hline
\textbf{$User_4$} & 5 & 2 & 3 &  \textbf{?} & \textbf{?} & \textbf{?} \\
\hline
\textbf{$User_5$} & \textbf{?} & \textbf{?}  & \textbf{?} & 4 & 1 & 1 \\
\hline
\textbf{$User_6$} & \textbf{?} & \textbf{?} & \textbf{?}  & 3 & 5 & 2 \\
\hline
\textbf{$User_7$} & \textbf{?} & \textbf{?} & \textbf{?}  & 5 & 1 & 2 \\
\hline
\textbf{$User_8$} & \textbf{?} & \textbf{?} & \textbf{?}  & 5 & 4 & 4 \\
\hline
\end{tabular}
\caption{Modified Ratings Matrix}
\label{table:Modified Ratings Matrix}
\end{table}

The above table is a modification/extension of \autoref{table:Ratings Matrix}. If KNN was applied to
this rating matrix with $\mathcal{K}=4$(all users do not have 4 available NN, instead
they use the largest amount of NN available to them before 4) using user cosine similarity,
it would produce the rating predictions in the table below.

\begin{table}[H]
\centering
\begin{tabular}{ |c|c|c|c|c|c|c| }
\hline
\diagbox{$User$}{$Item$} & \textbf{$Item_1$} & \textbf{$Item_2$} & \textbf{$Item_3$} & \textbf{$Item_4$}  & \textbf{$Item_5$} & \textbf{$Item_6$} \\
\hline
\textbf{$User_1$} & 5 & 2 & 3 & {\color{red}4.3} & 1 & 5 \\
\hline
\textbf{$User_2$} & 1 & 2 & 4 & {\color{red}4.15} & 2 & 2 \\
\hline
\textbf{$User_3$} & 4  & 3 & 5 & {\color{red}4.12} & 4 & 3 \\
\hline
\textbf{$User_4$} & 5 & 2 & 3 &  {\color{green}\textbf{?}} & {\color{red}2.35} & {\color{red}3.42} \\
\hline
\textbf{$User_5$} & {\color{red}3.35} & {\color{red}2.35}  & {\color{red}4.02} & 4 & 1 & 1 \\
\hline
\textbf{$User_6$} & {\color{red}3.21} & {\color{red}2.4} & {\color{red}4.15}  & 3 & 5 & 2 \\
\hline
\textbf{$User_7$} & {\color{red}3.46} & {\color{red}2.32} & {\color{red}3.94}  & 5 & 1 & 2 \\
\hline
\textbf{$User_8$} & {\color{red}3.36} & {\color{red}2.35} & {\color{red}4.03}  & 5 & 4 & 4 \\
\hline
\end{tabular}
\caption{Modified Ratings Matrix After KNN}
\label{table:Modified Ratings Matrix after KNN}
\end{table}
\justify
It seems that KNN was unable to predict how $User_4$ would rate $Item_4$.\\
The connections from user cosine similarity that could be formed were the following:
\begin{align*}
	&cos(User_1,User_2) = 0.7659 &cos(User_1,User_3) = 0.8660 & &cos(User_1,User_4) = 0.7705\\
	&cos(User_1,User_5) = 0.1767 &cos(User_1,User_6) = 0.3041 & &cos(User_1,User_7) = 0.2510\\
	&cos(User_1,User_8) = 0.3973 &cos(User_2,User_3) = 0.9434 & &cos(User_2,User_4) = 0.6325\\
	&cos(User_2,User_5) = 0.1750 &cos(User_2,User_6) = 0.4217 & &cos(User_2,User_7) = 0.2034\\
	&cos(User_2,User_8) = 0.3935 &cos(User_3,User_4) = 0.7680 & &cos(User_3,User_5) = 0.1905\\
	&cos(User_3,User_6) = 0.4870 &cos(User_3,User_7) = 0.2108 & &cos(User_3,User_8) = 0.4282\\
	&cos(User_5,User_6) = 0.7264 &cos(User_5,User_7) = 0.9897 & &cos(User_5,User_8) = 0.8741\\
	&cos(User_6,User_7) = 0.7108 &cos(User_6,User_8) = 0.9239 & &cos(User_7,User_8) = 0.8947\\
\end{align*}
\vfill
\justify
The following figure is a graphical representation of the user connections.
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{chapter_3/user_connections.eps}
\caption{User Connections}
\label{figure:user_connections}
\end{figure}

It seems that from users who have rated $Item_4$, it is possible to create a connection to $User_4$, but in
order to do that they must use the intermediate connections they have in common. Graph-based
methods are known to utilize these connections efficiently to produce link similarities that
surpass the direct connection between users or items \citep{Ricci,Aggarwal}.
\section{Methodology}
The Recursive K-Nearest Neighbors algorithm utilizes the intermediate connections that two users
have in common in order to find a path to predict ratings that the conventional KNN could not find.
The concept of this algorithm, is to use the rating predictions produced by KNN, in order
to consider the users that have not rated the target item, as neighbors. As presented in
\autoref{figure:user_connections_with_KNN} below,
the KNN rating predictions related to $Item_4$ for $User_1$, $User_2$ and $User_3$ have been
added to the figure to indicate them as real rating values that these users gave to $Item_4$.
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{chapter_3/user_connections_with_KNN.eps}
\caption{User Connections as \autoref{figure:user_connections} with KNN predictions from \autoref{table:Modified Ratings Matrix after KNN}}
\label{figure:user_connections_with_KNN}
\end{figure}
Then, as new similarities can be formed for $User_4$ with $User_1$, $User_2$ and $User_3$ for $Item_4$, the weighted sum formula used in KNN can be
again used to compute the rating prediction of $User_4$ to $Item_4$ as shown in \autoref{figure:RKNN_prediction}.\\
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{chapter_3/RKNN_prediction.eps}
\caption{Recursive KNN Rating Prediction}
\label{figure:RKNN_prediction}
\end{figure}
The Recursive K-Nearest Neighbors methodology for predicting how $User_A$ would rate $Item_B$,
(with the assumption that, given a similarity metric, KNN would not be able to predict this rating)
consists of the following steps:
\begin{itemize}\label{RKNN}
	\item[] \textbf{Step 1:} Select users that are connected with $User_A$, and name it $Group_A$.
	\item[] \textbf{Step 2:} Out of $Group_A$, choose those users that have connections with
	users who have rated $Item_B$, and name it $Group_B$.
	\item[] \textbf{Step 3:}  Order $Group_B$ by descending similarity with $User_A$.
	\item[] \textbf{Step 4:}  Choose how many neighbors from $Group_B$ will contribute in the
	rating prediction by selecting the top $\mathcal{K}$ out of all the available
	neighbors in this group, and name it $Group_C$.
	\item[] \textbf{Step 5:} For each neighbor in $Group_C$, predict how this neighbor would
	rate $Item_B$ using the KNN algorithm. For convenience, we name the number of recursive
	neighbors each neighbor in $Group_C$ uses as, $\mathcal{M}$-Nearest Neighbors.
	\item[] \textbf{Step 6:} Use the rating predictions applied on $Group_C$ to perform
	the KNN algorithm on $User_A$ for $Item_B$.
\end{itemize}

Now that the steps for performing the Recursive K-Nearest Neighbors algorithm have been
introduced let us look at a general case as in the figure below:\\
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{chapter_3/Recursive_Nearest_Neighbors.eps}
\caption{Recursive Nearest Neighbors Algorithm}
\label{figure:recursive_algorithm}
\end{figure}
Interpretation of the figure:
\begin{enumerate}
	\item After the selection of the top $\mathcal{K}$ relevant Neighbors.
	(\textbf{Steps 1,2,3,4})
	\item For each Neighbor, name it $Neighbor_i$, out of $\mathcal{K}$'s choose $\mathcal{M}$
	Neighbors to apply KNN on $Neighbor_i$. (\textbf{Step 5})
	\item Use the rating predictions applied on $\mathcal{K}$'s to predict the requested
	User-Item rating.\\ (\textbf{Step 6})
\end{enumerate}


\chapter{Nonlinear filtering}
\label{ch:RNN}

The SWR detectors discussed up to this point -- both the band-pass and the GEVec-based filters -- calculate their output as a linear combination of input samples. This chapter explores whether a nonlinear method to calculate the output signal can improve SWR detection performance.

\input{RNNs}
\input{GRU-eqs}
\input{Optimize}
\input{Results}


\documentclass[t]{beamer}
\usetheme{Copenhagen}
\setbeamertemplate{headline}{} % remove toc from headers
\beamertemplatenavigationsymbolsempty

\usepackage{amsmath, tikz, bm, pgfplots, tcolorbox}
\pgfplotsset{compat = 1.16}

\title{Quadratic Formula}
\author{}
\date{}

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Objectives}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

\begin{frame}
\maketitle
\end{frame}

\section{Solve quadratic equations using the quadratic formula}

\begin{frame}{The Quadratic Formula}
The \alert{quadratic formula} can be used to solve \underline{any} quadratic equation that is equal to 0.	\newline\\	\pause

\begin{center}
For $ax^2 + bx + c = 0$
\end{center}

\begin{tcolorbox}[colback=red!10!white, colframe=red!60!black, title=Quadratic Formula]
\[x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}\]
\end{tcolorbox}
\end{frame}

\begin{frame}{Example 1}
Solve each of the following using the quadratic formula. Exact answers only.	\newline\\
(a) \quad $3x^2 + 8x - 28 = 0$		\pause
\[ a = 3 \quad b = 8 \quad c = -28 \]
\begin{align*}
\onslide<3->{x &= \frac{-8 \pm \sqrt{8^2-4(3)(-28)}}{2(3)}} \\[10pt]
\onslide<4->{x &= \frac{-8 \pm \sqrt{400}}{6}} \\[10pt]
\onslide<5->{x &= \frac{-8 \pm 20}{6}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
\[x = \frac{-8 \pm 20}{6} \]
\begin{align*}
\onslide<2->{x &= \frac{-8+20}{6} & x &= \frac{-8-20}{6}} \\[10pt]
\onslide<3->{x &= 2 & x &= -\frac{14}{3}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
(b) \quad $5x^2 + 9x - 5 = 0$ \pause
\[ a = 5 \quad b = 9 \quad c = -5 \]
\begin{align*}
\onslide<3->{x &= \frac{-9 \pm \sqrt{9^2-4(5)(-5)}}{2(5)}} \\[10pt]
\onslide<4->{x &= \frac{-9 \pm \sqrt{181}}{10}}
\end{align*}
\onslide<5->{\[x = \frac{-9 + \sqrt{181}}{10} \quad x = \frac{-9 - \sqrt{181}}{10}\]}
\end{frame}

\begin{frame}{Example 1}
(c) \quad $6x^2 - 6x - 15 = -10$ \pause
\[ 6x^2 - 6x - 5 = 0 \]	\pause
\[a = 6 \quad b = -6 \quad c = -5 \]
\begin{align*}
\onslide<4->{x &= \frac{6 \pm \sqrt{6^2-4(6)(-5)}}{2(6)}} \\[10pt]
\onslide<5->{x &= \frac{6 \pm \sqrt{156}}{12}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
\[x = \frac{6 \pm \sqrt{156}}{12} \]
\begin{align*}
\onslide<2->{x &= \frac{6 \pm 2\sqrt{39}}{12}} \\[10pt]
\onslide<3->{x &= \frac{2\left(3\pm \sqrt{39}\right)}{12}} \\[10pt]
\onslide<4->{x &= \frac{3 \pm \sqrt{39}}{6}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
(d) \quad $7x^2 + 20x - 8 = -3x^2 - 1 + 10x$	\pause
\[ 10x^2 + 10x - 7 \]	\pause
\[a = 10 \quad b = 10 \quad c = -7\]
\begin{align*}
\onslide<4->{x &= \frac{-10 \pm \sqrt{10^2-4(10)(-7)}}{2(10)}} \\[10pt]
\onslide<5->{x &= \frac{-10 \pm \sqrt{380}}{20}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
\[x = \frac{-10 \pm \sqrt{380}}{20} \]
\begin{align*}
\onslide<2->{x &= \frac{-10 \pm 2\sqrt{95}}{20}} \\[10pt]
\onslide<3->{x &= \frac{2\left(-5\pm \sqrt{95}\right)}{20}} \\[10pt]
\onslide<4->{x &= \frac{-5 \pm \sqrt{95}}{10}}
\end{align*}
\end{frame}

\section{Use the discriminant to determine the types of solutions to a quadratic equation}

\begin{frame}{The Discriminant}
The expression {\color{blue}$b^2-4ac$} in the square root is called the \alert{discriminant}. It can tell us about the solutions to a quadratic equation:	\newline\\	\pause

\begin{itemize}
	\item \textbf{Discriminant is negative:} No real values of $x$ make the original equation true. \newline\\ \pause
	\item \textbf{Discriminant is 0:} There is one value of $x$ (called a \emph{double root}). \newline\\ \pause
	\item \textbf{Discriminant is positive:} There are 2 unique answers for $x$.
\end{itemize}
\end{frame}

\begin{frame}{The Discriminant}
In addition, if $\sqrt{b^2 - 4ac}$ equals a \alert{rational number}, then the quadratic equation is factorable over the integers (only use integers in your factoring).
\end{frame}

\end{document}


Standard stereo recording practice typically considered the damping of sound with distance to not be a consideration in the effect of a stereo recording array. However, there are cases where the damping of sound between microphones may be a non-trivial consideration. This effect is typically more pronounced in the flanking microphones when used, however may be a consideration for wider-set main arrays as well.

Confounding this are issues with accurately modelling the emission and propagation of sound. As previously mentioned, the goal is not a physical model, but a practically useable abstraction. To this end, a model that includes a perceptually accurate representation of the significant effect of the phenomena is sufficient, even if the detail is lacking.

To represent an abstraction of the propagation of sound and its damping with distance, three different damping compensation arrangements have been implemented. To abstract the actual propagation of sound with respect to an real source's statistical directivity pattern and facing, an additional parameter can be introduced that affects the amount of damping with distance. Accompanying this, a Boolean parameter, $\gamma$ is introduced to allow the user to enable or disable the $\Delta{l}$ calculation.

This gives the expansion of $m(S)$ to:

\begin{equation}
m(S) = \left(\begin{cases}
\Delta{v} \cdot \Delta{l} & \; \text{if} \; \gamma = 1 \\
\Delta{v} &\; \text{if} \; \gamma = 0
\end{cases}\right)
+ \Delta{t}
\end{equation}

Noting that $\Delta{v}$ and $\Delta{l}$ should be in the form of amplitude scalars, rather than decibel amounts\footnote{Decibels amounts would need to be summed rather than multiplied.}

\subsection {Sound Damping Formula}

If there are two points in a free-field space, each a distance of $r$ from a sound source, and if we know the sound pressure level in decibels, $l$, at one of the points: then the sound pressure level at the other distance can be calculated as:

\begin{equation}
l_2 = l_1 - \left|20 \cdot \log_{10}\frac{r_1}{r_2}\right|
\end{equation}

Substituting the positions of the virtual microphone and sound source into the formula, and assuming that the microphone's signal is measured at a unit distance of one, the level at a virtual microphone can be found as:

\begin{equation}
l_m = l_S - \left|20 \cdot \log_{10}\frac{1}{d_{\vec{v}}}\right|
\end{equation}

From this, the damping amount at the microphone's distance from the sound source is simply:

\begin{equation}
\Delta{l}_m = 20 \cdot\log_{10}(d_{\vec{v}})
\end{equation}

As previously discussed, the actual damping amount displayed by a sound source in practice also depends on the directivity of the source and the acoustic environment. The most expedient method for reducing the amount of damping with distance, is to reduce the value of the multiplier for the $\log$ function in the calculation. This can be done by replacing the multiplier with a user-adjustable parameter, $\sigma$ from the multiplier, where $\sigma \in [0,20]$. To simplify the user-experience, this implementation uses $\sigma \in \{5, 10, 20\}$ which corresponds with a 1.5dB, 3dB, and 6dB amount of damping per doubling of distance.

\begin{equation}\label{distancedamping}
\Delta{l}_m = \sigma\cdot\log_{10}(d_{\vec{v}})
\end{equation}

Finally, this can be converted to an amplitude scalar value following the usual conversion\footnote{See (\ref{dbscalarconvert})}:

\begin{equation}
\Delta{l}_m= -10^{\frac{\Delta{l}_m}{20}}
\end{equation}

\subsection{Implementing $\Delta{l}$ Correction}

For aesthetic/artistic reasons, a direct modeling of the propagation of sound is likely to be undesirable. Additionally, it may even defeat the purpose in the near-capture of the real sound source. To this end there are two processing considerations made in the model: the actual distance-damping that is compensated for and the specific virtual microphones to which the $\Delta{l}$ correction is applied.

\subsubsection{Correction Amount}

It is unnecessary to apply the full amount of $\Delta{l}$ to the virtual microphones. The damping due to the distance between the source and the nearest microphone serves no artistic purpose in modelling, and will only cause the mixing engineer to have to (re)adjust the aesthetic balance of the recorded track. Thus, the compensation only needs to be applied for the distance differences between the microphones.

This can be done simply by finding the smallest value for $l$ in the set of virtual microphones, and subtracting that number from every other microphone. If $j \in M \;|\; \Delta{l}_j \leq \Delta{l}_i, \forall i \in M$, then the distance-damping formula (\ref{distancedamping}) is redefined as the intermediate value $\Delta{l}_m$, and the function $\Delta{l}(m)$ becoming:

\begin{equation}
\Delta{l}(m) = \Delta{l}_m - \Delta{l}_j
\end{equation}

\subsubsection{Microphone relationships}

Depending on the musical context, it may or may not be desirable to consider the damping effect on the full microphone array. Three different arrangements are considered by breaking the microphone array into two parts: $M = W \cup U \;|\; W = \left\{m_c, m_{mL}, m_{mR}\right\}, U = \left\{m_{fL}, m_{fR}\right\}$. These four options are (1) damping applied to $M$, (2) damping applied to $W$ and $F$ independently, and (3) damping only applied to $F$. To facilitate this, the user-settable parameter can be defined so that $\gamma \in \{0, 1, 2, 3\}$, and $\Delta{l}_j$ is taken from the same subset as $\Delta{l}_m$:

\begin{equation}
\Delta{l}(m) = \begin{cases}
\text{for}\; \gamma = 0:\Delta{l}_m \\
\text{for}\; \gamma = 1:\Delta{l}_m - \Delta{l}_j\\
\text{for}\; \gamma = 2:\begin{cases}
\Delta{l}_m - \Delta{i}_j \; &\text{if}\; m\land{}j\in{}W\\
\Delta{l}_m - \Delta{i}_j \; &\text{if}\; m\land{}j\in{}U
\end{cases}\\
\text{for}\; \gamma = 3:\begin{cases}
\Delta{l}_m \; &\text{if}\;\Delta{l}_m\in{}W\\
\Delta{l}_m - \Delta{l}_j \; &\text{if}\;m\in{}U \;|\; j\in{}U
\end{cases}
\end{cases}
\end{equation}


\section{Superconductivity}
\label{s:superconductivity}

We consider two approaches to realizing a superconducting state.
First, we assume a proximity induced state obtained by
layering a TMD on an $s$-wave superconductor.
Second, we study an intrinsic correlated phase arising
from density-density interactions.

We use $d^ν_{τ {\s}} \ofK$ as the annihilation operator
for tight-binding $d$-orbital states,
and $c^n_{τ {\s}} \ofK$ for the eigenstates of the non-interacting Hamiltonian,
$λ_{\vK}$ for the energy dispersion for Bogoliubov quasiparticles,
and $Δ_{\vK}$ for the superconducting gap function.

\subsection{Induced State}

A proximity $s$-wave superconductor will inject Cooper pairs
according to
\begin{equation}
  H^V
  = ∑_{\vK, ν, τ} \cc{B}_ν
    d^ν_{-τ ↓} \ofMK d^ν_{τ ↑} \ofK + \frac{ε}{2} + \hc
\end{equation}
The coupling constants $B_ν$ and the overall constant $ε$
depend on the material interface %
\footnote{%
  Note that all sums over $\vK$ are restricted to $\left| \vK \right|$
  less than some cutoff that restricts the momentum to a single valley.
}.
Using the abbreviated notation
$c_{\vK α} = c^-_{τ {\s}} \ofK$,
with $α =\ ↑↓$ for $τ = {\s} = ±$,
projecting onto the upper valence bands yields,
\begin{multline}
  \label{eq:induced}
  P_{τ = {\s}}^{n = -} \left( H^0 + H^V - μ N \right)
  = ∑_{\vK, α} ξ_{\vK} c_{\vK α}^† c_{\vK α} \\
  - \sumK \left( \cc{Δ}_{\vK} c_{-\vK ↓} c_{\vK ↑}
  + Δ_{\vK} c_{\vK ↑}^† c_{-\vK ↓}^† \right)
  + ε,
\end{multline}
where $ξ_{\vK} = E_{+ ↑}^- \of{\abs{\vK}} - μ$ and
the effective BCS gap function is
\begin{equation}
  Δ_{\vK}
  = \frac{1}{2} \left( B_+ + B_- \right)
  + \frac{1}{2} \left( B_+ - B_- \right)
    \cos{θ_{\vK}},
\end{equation}
with $θ_{\vK} = θ_{+↑}^- \of{\abs{\vK}}$.
This form is identical to the standard BCS Hamiltonian with
an effective spin index $α$.
However, the spin state of the Cooper pair is an equal superposition
of the singlet and the $m = 0$ component of spin triplet.
The corresponding quasiparticle eigenstates are
$γ_{\vK α}
= α \cos{β_{\vK}} c_{\vK α} + \sin{β_{\vK}} c_{-\vK, -α}^†$,
with energies
$λ_{\vK} = ± \sqrt{ξ_{\vK}^2 + Δ_{\vK}^2}$,
where $\cos{2 β_{\vK}} = ξ_{\vK} / λ_{\vK}$.
Note that if $B_+ = B_-$,
then $Δ_{\vK}$ is a constant and independent of $\vK$.
Even when $B_+$ and $B_-$ are different,
the constant term dominates.
Before exploring the nature of this state,
we analyze the case of intrinsic superconductivity,
and show that the same state is energetically preferred.

\subsection{Intrinsic Phase}

For a local attractive density-density interaction
(e.g.\ one mediated by phonons), the potential is
$V ⋍ \frac{1}{2} ∑_{\vR, \vR'} v_{\vR \vR'}
\normalorder{n_{\vR} n_{\vR'}}$,
with $v_{\vR \vR'} = v_0 δ_{\vR \vR'}$
and $n_{\vR}$ the total Wannier electron density at lattice vector $\vR$.
Projecting onto states near the chemical potential gives
\begin{multline}
  \label{eq:channels}
  P_{τ = {\s}}^{n = -} \left( H^V \right)
  = \sumKK v \of{\vK' - \vK} \\
  × \left(
    A_{\vK \vK'}^2 c_{\vK' ↑}^† c_{-\vK' ↑}^† c_{-\vK ↑} c_{\vK ↑}
  + A_{\vK' \vK}^2 c_{\vK' ↓}^† c_{-\vK' ↓}^† c_{-\vK ↓} c_{\vK ↓}
    \right. \\ + \left.
      2 \abs{A_{\vK \vK'}}^2
      c_{\vK' ↑}^† c_{-\vK' ↓}^† c_{-\vK ↓} c_{\vK ↑}
    \vphantom{2 \abs{V_{\vK \vK'}}^2} \right),
\end{multline}
where
\begin{equation}
  A_{\vK \vK'}
  = e^{i \left( ϕ_{\vK'} - ϕ_{\vK} \right)}
    \sin{\frac{θ_{\vK'}}{2}} \sin{\frac{θ_{\vK}}{2}}
  + \cos{\frac{θ_{\vK'}}{2}} \cos{\frac{θ_{\vK}}{2}}.
\end{equation}
The first two terms in \cref{eq:channels} lead to intravalley pairing,
and the third to intervalley pairing.
We analyze the possible states within mean field theory.
The BCS order parameter is
\begin{equation}
  χ
  = v_0 \sumK \cc{g}_{\vK} \ev{c_{-\vK α'} c_{\vK α}},
\end{equation}
where the form of $g_{\vK}$ depends on the particular pairing channel.
The resulting Hamiltonian has the same form as the BCS Hamiltonian in
\cref{eq:induced}
but with an effective $Δ_{\vK} = g_{\vK} · χ$.
The intravalley pairing has three symmetry channels,
with the couplings given by
$2 g_{\vK} = 1 +  \cos{θ_{\vK}}$,
$\sqrt{2} e^{- i ϕ_{\vK}} g_{\vK} = \sin{θ_{\vK}}$
and $2 e^{- 2 i ϕ_{\vK}} g_{\vK} = 1 - \cos{θ_{\vK}}$.
For these channels, since
$\ev{c_{-\vK α} c_{\vK α}} = - \ev{c_{\vK α} c_{-\vK α}}$,
relabeling $\vK → -\vK$ in the sum gives $χ = 0$ %
\footnote{%
  For odd parity interactions, where $v \ofMK = -v \ofK$, the
  intravalley pairing is not excluded by symmetry.
  Specifically, repeating the calculation with this assumption,
  the intervalley terms fully cancel, and one obtains \cref{eq:channels}
  without the intervalley term on the third line.
}.
The intervalley pairing also has three symmetry channels:
$g_{\vK} = \sqrt{2}$,
$g_{\vK} = \sqrt{2} \cos{θ_{\vK}}$,
and $g_{\vK} = \sqrt{2} \sin{θ_{\vK}} \vc{\hat{k}}$.
Of the three,
the constant valued channel is dominant %
\footnote{%
  For example, using the values for \ce{WSe2},
  $\sin^2 {θ_{\vK}} = 0.44$ and $\cos^2 {θ_{\vK}} = 0.56$
  at the chemical potential.
}.
This is to be expected, as the local density-density interaction
leads to the largest pairing for electrons of opposite spins.
Since the intravalley processes have the same spin,
they are disfavored as compared to the intervalley pairing.

The key features of the intrinsic superconducting state
are identical to the proximally induced case when density-density
interactions dominate.
We restrict further analysis to that case,
and turn to the question of pair-breaking phenomena
induced either by optical or magnetic fields.


%!TEX root = ../notes.tex
\section{April 27, 2022}
\subsection{GGH Cryptosystem: Public-Key Cryptosystem}
\recall last time we talked about GGH digital signatures.

We're going to use similar ideas to construct a public-key cryptosystem. As before, we'll have the same public/private key setup as last time.

\ul{Alice}: will choose a random basis $\{\bvec{v}_i\}$ which will be her private key, which is a \emph{sufficiently good} basis. Alice will then compute $\{\bvec{w}_i\}$ which is a bad basis (by multiplying by some $U\in\mathsf{SL}_n(\ZZ)$) which is her public key.

\ul{Bob}: will encrypt message $\{m_i\}$ by computing
\[\bvec{c} = \sum m_i \bvec{w}_i + \bvec{r}\]
where $\bvec{r}$ is a randomly generated short vector.

\ul{Alice}: Find the closest lattice point to $\bvec{c}$ using Babai's algorithm, and express it in the public basis $\{\bvec{w}_i\}$.

Code in \textsf{lattices.ipynb}.

\subsection{Lattice Reduction}
\emph{Warm-up}: Gaussian Lattice Reduction.

We'll see how to find the shortest vector in a 2-dimensional lattice.

With Gram-Schmidt, we made an orthgonal basis.
\begin{center}
    \begin{tikzpicture}
        \draw[->, thick](0,0) node[left]{$O$} -- node[above]{$\bvec{v}_2$} (4, 1);
        \draw[->, thick](0,0) -- node[below]{$\bvec{v}_1$} (3, 0);
        \draw[->, densely dotted](4,1) -- node[above]{$\mu\cdot \bvec{v}_1$} (0,1);
        \draw[->, thick, red](0,0) -- node[left, red]{$\bvec{v}_2'$} (0,1);
    \end{tikzpicture}
\end{center}

Using Gram-Schmidt, we have $\bvec{v}_2' = \bvec{v}_2 - \mu\cdot \bvec{v}_1$ where $\mu = \frac{\bvec{v}_1\cdot \bvec{v}_2}{\bvec{v}_1\cdot \bvec{v}_1}$.

With lattice reduction, we round $\mu$ to subtract by an integer multiple of $\bvec{v}_2$ instead.

\begin{center}
    \begin{tikzpicture}
        \draw[->, thick](0,0) node[left]{$O$} -- node[above]{$\bvec{v}_2$} (4, 1);
        \draw[->, thick](0,0) -- node[below]{$\bvec{v}_1$} (3, 0);
        \draw[->, densely dotted](4,1) -- node[above]{$1\cdot \bvec{v}_1$} (1,1);
        \draw[->, thick, red](0,0) -- node[above left, red]{$\bvec{v}_2'$} (1,1);
    \end{tikzpicture}
\end{center}

Lattice reduction gives us
\[\bvec{v}_2' = \bvec{v}_2 - \lfloor\mu\rceil\cdot \bvec{v}_1\]

We do this again and again.

Code in \textsf{lattices.ipynb}.

We should prove that this gives us a reasonable basis when this algorithm finishes.
\begin{proposition}
    This algorithm terminates.
\end{proposition}
\begin{proof}
    Integer vectors $||\bvec{v}_1||$ and $||\bvec{v}_2||$ always decrease, and there are only \emph{finitely many} lattice vectors that strictly decrease.
\end{proof}

\begin{proposition}
    When this algorithm terminates, $\bvec{v}_1$ is the shortest vector in the lattice.
\end{proposition}
\begin{proof}
    At the end, we know that $||\bvec{v}_2||\geq ||\bvec{v}_1||$ and that
    \[-\frac{1}{2}\leq \mu = \frac{\bvec{v}_1\cdot \bvec{v}_2}{\bvec{v}_1\cdot \bvec{v}_1} \leq \frac{1}{2}.\]
    Any vector $\bvec{w} = a_1\bvec{v}_1 + a_2\bvec{v}_2$. So
    \begin{align*}
        ||\bvec{w}||^2 & = a_1^2\cdot ||\bvec{v}_1||^2 + 2a_1a_2(\bvec{v}_1\cdot \bvec{v}_2) + a_2^2||\bvec{v}_2||^2 \\
                       & \geq a_1^2\cdot ||\bvec{v}_1||^2 + a_1a_2||\bvec{v}_1||^2 + a_2^2||\bvec{v}_2||^2           \\
                       & = (a_1^2 + a_1a_2 + a_2^2)||\bvec{v}_1||^2
    \end{align*}
    And $a_1^2 + a_1a_2 + a_2^2 = \frac{3}{4}(a_1 - a_2)^2 + \frac{1}{4}(a_1 + a_2)^2 > 0$. \textsc{otoh} $a_1, a_2\in\ZZ$ so $a_1^2 + a_1a_2 + a_2^2\geq 1$.

    So any $||\bvec{w}||^2 \geq ||\bvec{v}_1||^2$.
\end{proof}