\newpage
\section{Database}
\subsection{Pandora database}
The Pandora database contains a set of 7724 paintings from 12 movements. Thus, each movements contains
between 200 and 1000 paintings.\\
\begin{tabularx}{8cm}{|X|c|}
	\hline
	\textbf{Art movement} & \textbf{No. of paintings}\\
	\hline
	Old Greek pottery & 350\\
	\hline
	Iconoclasm & 665\\
	\hline
	High Renaissance & 812\\
	\hline
	Baroque & 960\\
	\hline
	Rococo & 844\\
	\hline
	Romanticism & 874\\
	\hline
	Impressionism & 984\\
	\hline
	Realism & 307\\
	\hline
	Cubism & 920\\
	\hline
	Abstract-expressionism & 340\\
	\hline
	Fauvism & 426\\
	\hline
	Surrealism & 242\\
	\hline
\end{tabularx}

\subsection{Wikipainting database}

Initially, the databased described by the csv file contains 101086 paintings from 130 artistic styles. 105 styles are minor styles (e.g they contains less than 1000 paintings). We chose to focus only on the 25 styles containing more than 1000 paintings, thereby reducing the dataset size to 82460. But moreover, the download urls of the csv file are not updated, so 327 images couldn't be downloaded, reducing the size of the database to 82133. You will found below the 25 styles remaining and their distribution :\\

\begin{tabularx}{14cm}{|X|c|c|}
	\hline
	\textbf{Art movement} & \textbf{Supposed no. of paintings} & \textbf{Real no. of paintings}\\
	\hline
	Art Informel & 1007 & 969 \\
	\hline
	Magic Realism & 1011 & 1011\\
	\hline
	Abstract Art & 1012 & 1006\\
	\hline
	Pop Art & 1129 & 1129\\
	\hline
	Ukiyo-e & 1178 & 1178\\
	\hline
	Mannerism (Late Renaissance) & 1194 & 1192\\
	\hline
	Color Field Painting  & 1267 & 1258\\
	\hline
	Minimalism & 1267 & 1267\\
	\hline
	High Renaissance & 1277 & 1275 \\
	\hline
	Early Renaissance & 1335 & 1330\\
	\hline
	Cubism & 1694 & 1686\\
	\hline
	Rococo & 1928 & 1928\\
	\hline
	Abstract Expressionism & 2091 & 2091\\
	\hline
	Naïve Art (Primitivism) & 2167 & 2026\\
	\hline
	Northern Renaissance & 2419 & 2405\\
	\hline
	Neoclassicism & 2702 & 2700\\
	\hline
	Baroque & 4000 & 3992\\
	\hline
	Symbolism & 4076 & 4063\\
	\hline
	Art Nouveau (Modern) & 4163 & 4163\\
	\hline
	Surrealism & 4804 & 4799\\
	\hline
	Expressionism & 5876 & 5844\\
	\hline
	Post-Impressionism & 6009 & 5998\\
	\hline
	Romanticism & 6582 & 6569\\
	\hline
	Realism & 10101 & 10090\\
	\hline
	Impressionism & 12170 & 12164\\
	\hline
	Total & 82460 & \textbf{82133}\\
	\hline
\end{tabularx}

\begin{figure}
	\includegraphics[scale = 0.3]{images/wp_distrib.png}
\end{figure}

After val train and test splitting :
train = 66 574
test = 8 226
val = 7408

\subsection{Other database ?}


%!TEX root = ../CombinatoricsNotes.tex

\section{Tur\'an type problems} % (fold)
\label{sec:turian_type_problems}

The general problem we've been considering is to find $\max |\F|$ given that $\F\subset \P([n])$ has certain properties. For example, Sperner systems, and intersecting $r$-graphs. In these problems, we are forbidding certain sub set systems\sidenote{In a Sperner system, there is no 2 element sub system $\{A,B\}$ with $A\subset B$. In an intersecting $r$-graph, there is no two element sub system $\{A,B\}$ with $A\cap B= \emptyset$.}. Here, we will focus on $r$-graphs.

We will say $\F$ and $\H$ are \defn{isomorphic} set systems if there exists a bijective map $\phi: \bigcup_{F\in \F} F \to \bigcup_{H\in \H}H$ such that $F\in \F$ if and only if $\phi(F)\in \H$.
Now, let forbidden subconfigurations $F_1,\dotsc,F_k$ be given $r$-graphs\sidenote{Recall: Set systems with elements which are in $[n]^{(r)}$.}. Define the \defn{Tur\'an number}
\[
\ex (n; F_1,\dotsc,F_k)
\]
to be the maximum $|\F|$ such that $\F$ does not contain a subgraph isomorphic to any of $F_1,F_2,\dotsc,F_k$.

\begin{remark}
We will increasingly refer to $F\in \F$ as edges.
\end{remark}

\begin{example}
If $M_2$ consists of two disjoint edges of size $r$, then \erdos-Ko-Rado says that $\ex(n;M_2) = {n-1\choose r-1}$ for $n\geq 2r$.\marginnote{Not having a subgraph isomorphic to $M_2$ means there must not be two disjoint subsets in $\F$, i.e., $\F$ is intersecting.}
\end{example}
Let
\[
\pi(n;F_1,\dotsc,F_k) := \frac{\ex(n;F_1,\dotsc,F_k)}{{n\choose r}}
\]
be the ratio of the largest valid size of $\F$ to the size of $[n]^{(r)}$.
We define the \defn{Tur\'an density} of $F_1,\dotsc,F_k$ to be
\[
\pi(F_1,\dotsc,F_k) := \lim_{n\to\infty} \pi(n; F_1,\dotsc,F_k) \in [0,1].
\]

\begin{example}
\[
\pi(M_2) = \lim_{n\to\infty} \frac{{n-1\choose r-1}}{{n\choose r}}=0,
\]
using \erdos-Ko-Rado. \marginnote{If you select two $r$-tuples of elments in an $n$ element set for very large $n$, you almost surely get disjoint tuples.}
\end{example}
\begin{theorem}[\cite{Katona_Nemetz_Simonovits}]
If $r\leq n_0\leq n$, then
\[
\pi(n_0; F_1,\dotsc,F_k) \geq \pi(n; F_1,\dotsc,F_k).
\]\label{thm:pi_decreasing}
\end{theorem}
\begin{remark}
Then $\pi(n;F_1,\dotsc,F_k)$ decreases for $n\geq r$ and is bounded below by zero,  so $\pi(F_1,\dotsc,F_k)$ exists.
\end{remark}
\begin{proof}
Let $\F\subset[n]^{(r)}$ be such that $|\F| = \ex(n; F_1,\dotsc,F_k)$ and $\F$ contains no subgraphs isomorphic to any of $F_1,\dotsc, F_k$. Let $H_1,H_2,\dotsc,H_N$ be the restrictions\sidenote{Note that for $X\subset [n]$, we define the restriction of $\F$ as $\F\restriction X := \{A\in \F: A\subset X\}$.} of $\F$ to all possible $n_0$ element subsets of $[n]$, where $N = {n\choose n_0}$.
 It suffices to show that
% \begin{align}	\label{eq:pi_avg}
\[
\pi(n; F_1,\dotsc,F_k) = \frac{|\F|}{{n\choose r}} \leq \frac{1}{{n\choose n_0}} \sum_{i=1}^N \frac{|H_i|}{{n_0\choose r}}
\]
% \end{align}
since $\frac{|H_i|}{{n_0\choose r}} \leq \pi(n_0; F_1,\dotsc,F_k)$. \marginnote{This estimate is the only actual inequality in the proof.}

We are left to estimate $\sum_{i=1}^N|H_i|$.
Given an edge in $F\in\F$, how many $H_i$'s does it appear in? Each $H_i$ whose base set\sidenote{Meaning the $n_0$-element set $X$ such that $H_i = \F\restriction X$.} includes $F$, so we need to choose $n_0-r$ more elements for the base set from the $n-r$ remaining possible elements, i.e.  ${n-r \choose n_0-r}$.
Then,
\[
\frac{1}{{n\choose n_0}}\sum_{i=1}^N \frac{|H_i|}{{n_0\choose r}} = |\F| \frac{{n-r\choose n_0 -r}}{{n\choose n_0}{n_0\choose r}}\quad \boxed{=}\quad \frac{|\F|}{{n\choose r}}.
\]
To show the boxed equality and finish the proof, we need
\begin{equation}	\label{eq:binomial_identity_boxes}
{n\choose r}{n-r \choose n_0 -r} = {n\choose n_0}{n_0 \choose r}.
\end{equation}

\lect{2}{3}
% \marginnote[0\baselineskip]{Lecture 9: Wednesday, February 3, 2016}
This is an identity which we can combinatorially reason as follows. The RHS means we first choose $n_0$ elements out of $n$, then choose $r$ out of those $n_0$. The LHS means we choose $r$ elements from $n$ then $n_0-r$ elements from the remaining $n-r$. This is depicted in \cref{fig:binomial_identity_boxes}.

\begin{marginfigure}[0\baselineskip]
\begin{center}
\begin{tikzpicture}

\begin{scope}
\node (rect) at (0,0)[draw,thick,minimum width=2.3cm, minimum height = 2.1cm, label=above:$n$]{};
% \node  at(.1,-.2)[draw,thick,minimum width=1.6cm, minimum height = 1cm, label=above:$n_0$]{};
% \node  at(.3,-.3)[draw,thick,minimum width=.7cm, minimum height = .2cm, label=above:$r$]{};
\end{scope}

\node[yshift=-1.7cm] at (0,0) {$\downarrow$};

\begin{scope}[yshift=-3.5cm]
\node (rect) at (0,0)[draw,thick,minimum width=2.3cm, minimum height = 2.1cm, label=above:$n$]{};
% \node  at(.1,-.2)[draw,thick,minimum width=1.6cm, minimum height = 1cm, label=above:$n_0$]{};
\node  at(.3,-.3)[draw,thick,minimum width=.7cm, minimum height = .2cm, label=above:$r$]{};
\end{scope}
\node[yshift=-5.2cm] at (0,0) {$\downarrow$};

\begin{scope}[yshift=-7cm]
\node (rect) at (0,0)[draw,thick,minimum width=2.3cm, minimum height = 2.1cm, label=above:$n$]{};
\node  at(.1,-.2)[draw,thick,minimum width=1.6cm, minimum height = 1cm, label=above:$n_0$]{};
\node  at(.3,-.3)[draw,thick,minimum width=.7cm, minimum height = .2cm, label=above:$r$]{};
\end{scope}
\end{tikzpicture}\hfill
\begin{tikzpicture}
\begin{scope}
\node (rect) at (0,0)[draw,thick,minimum width=2.3cm, minimum height = 2.1cm, label=above:$n$]{};
% \node  at(.1,-.2)[draw,thick,minimum width=1.6cm, minimum height = 1cm, label=above:$n_0$]{};
% \node  at(.3,-.3)[draw,thick,minimum width=.7cm, minimum height = .2cm, label=above:$r$]{};
\end{scope}

\node[yshift=-1.7cm] at (0,0) {$\downarrow$};

\begin{scope}[yshift=-3.5cm]
\node (rect) at (0,0)[draw,thick,minimum width=2.3cm, minimum height = 2.1cm, label=above:$n$]{};
\node  at(.1,-.2)[draw,thick,minimum width=1.6cm, minimum height = 1cm, label=above:$n_0$]{};
% \node  at(.3,-.3)[draw,thick,minimum width=.7cm, minimum height = .2cm, label=above:$r$]{};
\end{scope}
\node[yshift=-5.2cm] at (0,0) {$\downarrow$};

\begin{scope}[yshift=-7cm]
\node (rect) at (0,0)[draw,thick,minimum width=2.3cm, minimum height = 2.1cm, label=above:$n$]{};
\node  at(.1,-.2)[draw,thick,minimum width=1.6cm, minimum height = 1cm, label=above:$n_0$]{};
\node  at(.3,-.3)[draw,thick,minimum width=.7cm, minimum height = .2cm, label=above:$r$]{};
\end{scope}
\end{tikzpicture}
\end{center}
\caption{(above) \emph{Left:} an illustration of the LHS of \cref{eq:binomial_identity_boxes} and \emph{right:} the RHS of \cref{eq:binomial_identity_boxes}. } \label{fig:binomial_identity_boxes}
\end{marginfigure}
\end{proof}

Let $H$ be a graph ($2$-graph). Then $\ex(n,H)=\max |\edges (G)|$, where the maximum is taken over graphs $G$ with $|V(G)| = n$ such that $H$ is not a subgraph of $G$.

We may consider
\[
\pi(n;H) := \frac{\ex(n,H)}{{n\choose 2}}, \qquad \pi(H):= \lim_{n\to \infty}\pi(n,H).
\]
By \cref{thm:pi_decreasing}, $\pi(n,H)$ decreases for $n\geq 2$ (and fixed $H$), so $\pi(H)$ exists. Let $K_n$ be the complete graph on $n$ verticies: $K_n = [n]^{(2)}$. Since $K_2$ is just a single edge, $\ex(n; K_2)=0$.

Consider
$P_3 =$\scalebox{1}{\begin{tikzpicture}[color=DarkBlue]
\def\n{3}
\def\radius{.6}
\def\rotation{-30}

\def\deg{360/\n}
\pgfmathsetmacro\nminusone{\n-1}

\foreach \x in {1,...,\n}
{
	\pgfmathsetmacro\myangle{\x*\deg+\rotation};
	\filldraw (\myangle:\radius cm) circle (0.4pt) node(a\x){};
}

\foreach \y in {1,...,\n}
{

	\foreach \z in {1,...,\y}
	{
		\ifthenelse{\z < \nminusone}
		{
		\pgfmathsetmacro\myangley{\y*\deg+\rotation}
		\pgfmathsetmacro\myanglez{\z*\deg+\rotation}
		\draw (\myangley:\radius cm) -- (\myanglez:\radius cm);
		}{}

	}
}
\end{tikzpicture}}. Then $\ex(n,P_3) = \floor{n/2}$, and $\pi(P_3)=0$.

Consider $K_3 =$\scalebox{1}{\begin{tikzpicture}[color=DarkBlue]
\def\n{3}
\def\radius{.6}
\def\rotation{-30}

\def\deg{360/\n}
\pgfmathsetmacro\nminusone{\n-1}

\foreach \x in {1,...,\n}
{
	\pgfmathsetmacro\myangle{\x*\deg+\rotation};
	\filldraw (\myangle:\radius cm) circle (0.4pt) node(a\x){};
}

\foreach \y in {1,...,\n}
{

	\foreach \z in {1,...,\y}
	{
		\ifthenelse{\z < \n}
		{
		\pgfmathsetmacro\myangley{\y*\deg+\rotation}
		\pgfmathsetmacro\myanglez{\z*\deg+\rotation}
		\draw (\myangley:\radius cm) -- (\myanglez:\radius cm);
		}{}

	}
}
\end{tikzpicture}}.
Let us bound $\pi(K_3)$. Consider $n$ even, and the complete bipartite graph on $n$ verticies, shown in \cref{fig:bipartite}.

\begin{figure}
\begin{center}
\begin{tikzpicture}[color=black]

\node (rect) at (0,0)[draw,thick,minimum width=3cm, minimum height = 1cm, rounded corners=3pt]{};

\node (rect2) at (0,1.5)[draw,thick,minimum width=3cm, minimum height = 1cm, rounded corners=3pt]{};

\pgfmathsetseed{3}
% \def\z{rand}
\foreach \x in {1,...,5}
{
\filldraw (rand*1.4,rand*.4) circle (0.4pt) node(a\x){};
\filldraw (rand*1.4,1.5+rand*.4) circle (0.4pt) node(b\x){};

}

\foreach \x in {1,...,5}
{
% \ifthenelse{\x > 1}{\draw[dashed] (a\x) -- (u)}{};
\foreach \y in {1,...,\x}
{
\draw (a\x) -- (b\y);
}
}

\end{tikzpicture}
\end{center}
\caption[][1cm]{(left) The complete bipartite graph on $n$ verticies. We divide the graph into independent sets of size $n/2$, then connect each vertex in the upper set to each vertex in the lower set. This produces $(n/2)^2$ edges and no triangles. \label{fig:bipartite}}
\end{figure}

 Then $\pi(n,K_3) \geq \frac{n^2/4}{{n\choose 2}} \to \frac{1}{2}$. On the other hand, $P_3$ achieves
 \[
 \pi(3,K_3) = \frac{\ex(3,K_3)}{3} = \frac{2}{3},
 \]
 so by \cref{thm:pi_decreasing},  $\pi(K_3)\leq \frac{2}{3}$.
Thus, we have
\[
\frac{1}{2}\leq \pi(K_3)\leq \frac{2}{3}.
\]

How do we make a graph with many edges that does not contain any complete subgraphs on $t$ verticies?

We look at $t$ groups of size $\frac{n}{t}$. Then join two verticies if they lie in different groups, but not join them if they lie in the same group.

\begin{figure}
\begin{center}
\begin{tikzpicture}
\begin{scope}
% \node[left] at (0,0) {$\circlearrowleft$};

\foreach \y in {1,...,6}
{
\foreach \z in {1,...,\y}
{
\pgfmathsetmacro\myangley{-1*\y*60+90}
\pgfmathsetmacro\myanglez{-1*\z*60+90}
\draw (\myangley:3cm) -- (\myanglez:3cm);
\draw[xshift=4pt,yshift=-1pt] (\myangley:3cm) -- (\myanglez:3cm);
\draw[xshift=8pt,yshift=2pt] (\myangley:3cm) -- (\myanglez:3cm);
}
}
 % do a few by hand
 \pgfmathsetmacro\myangley{-1*3*60+90}
 \pgfmathsetmacro\myanglez{-1*5*60+90}
% \draw (\myangley:3cm) -- (\myanglez:2.9cm);

\foreach \x in {1,...,6}
{
 \pgfmathsetmacro\myangle{-1*\x*60+90}

\ifthenelse{\x > 1}{
\filldraw[white] (\myangle:3cm) circle (20pt);
\draw[black] (\myangle:3cm) circle (20pt) node{$\frac{n}{t}$
};
}{
\filldraw[white] (\myangle:3cm) circle (10pt);
\draw (\myangle:3cm) node[auto]{$\ldots$};
};

}

%  \pgfmathsetmacro\myangle{-1*60+90}
% \draw (\myangle:3cm) node[auto]{$\ldots$};

\end{scope}
\end{tikzpicture}
\end{center}
\caption{The Tur\'an graph on $n$ verticies, in the case that $n$ is divisible by $t$. We partition the graph into $t$ independent subsets of size $\frac{n}{t}$. Then we connect each vertex in each independent subset $A$ to all the verticies in $V(G)\setminus A$.  \label{fig:turan_graph}}
\end{figure}
% Connect each circle to every other circle, several times.

The \defn{Tur\'an graph} $T_t(n)=T$ is a graph with $|V(T)|=n$ such that $V(T)$ is  partitioned into $A_1,\dotsc,A_{t}$ and $v\in A_i$ is adjacent to $u\in A_j$ iff $i\neq j$, and the sizes obey $||A_i| - |A_j|| \leq 1$ for all $i,j$.

Then
\[
\pi(K_t) \geq \lim_{n\to\infty} \frac{|\edges (T_{t-1}(n))|}{{n\choose 2}} = \lim_{n\to\infty} \frac{{n\choose 2} - (t-1){\frac{n}{t-1} \choose 2}}{{n\choose 2}}= 1 - \frac{1}{t-1} = \frac{t-2}{t-1}
\]

\begin{theorem}[\cite{turan1941extremal}] \label{thm:turan}
For every $t\geq 2$, $\pi(K_t) = \frac{t-2}{t-1}$. Moreover,
\[
\ex(n,K_t)\leq \frac{t-2}{t-1} \frac{n^2}{2}.
\]
\end{theorem}
\begin{proof}[Proof by induction on $n$.]
Note that when $n$ is divisible by $t-1$,
\[
\ex(n,K_t)\geq |\edges (T_{t-1}(n))| = \frac{t-2}{t-1}\frac{n^2}{2}
\]
and equality is acheived.
Base case: for $n < t-1$, then the maximal number of edges (without restriction) is ${n\choose 2}  = \frac{n-1}{n}\frac{n^2}{2}\leq \frac{t-2}{t-1}\frac{n^2}{2}$.

Induction step. Let $n\geq t-1$. We may assume that $K_{t-1}$ is a subgraph of our graph $G$ (where $G$ is a graph on verticies with no $K_t$ subgraph and $|\mathcal{G}| = \ex(n,K_t)$.

Let $U=\{v_1,v_2,\dotsc,v_{t-1}\}$ be the set of verticies of this $K_{t-1}$ subgraph. Then
\[
 |\edges (G) | = \frac{(t-1)(t-2)}{2} + | \edges (U,V(G)\setminus U)| + |\edges (G\setminus U)|.
 \]
 This is the number of edges within $U$, plus the number of edges with exactly one end in $U$, plus the number of edges not connected to $U$, respectively. See \cref{fig:U_VG-U} for a depiction of this partition.

 % \missingfigure{partition of $G$ into $U$ and $V(G)\setminus U$. $U$ is a complete graph. Put a point $u$ in the latter.}
\begin{marginfigure}
\begin{center}
\begin{tikzpicture}
\node (rect) at (0,0)[draw,thick,minimum width=1cm, minimum height = 2cm, rounded corners=3pt,label=above:$U\cong K_{t-1}$]{};

\node (rect2) at (2,0)[draw,thick,minimum width=1cm, minimum height = 2cm, rounded corners=3pt,label=above:$V(G)\setminus U$]{};

\pgfmathsetseed{3}
% \def\z{rand}
\foreach \x in {1,...,5}
{
\filldraw[black] (rand*.5,rand*1) circle (0.4pt) node(a\x){};
}
% \draw (a1) -- (a2);

\filldraw[black] (2,.5) circle (0.4pt) node[right](u){$u$};

\foreach \x in {1,...,5}
{
\ifthenelse{\x > 1}{\draw[dashed] (a\x) -- (u)}{};
\foreach \y in {1,...,\x}
{
\draw (a\x) -- (a\y);
}
}

% \filldraw at (rect2)[draw, fill=black,circle(.4pt),above,label=above:$u$]{};

\end{tikzpicture}
\end{center}
\caption{ Illustation of the partition of $G$ into $V(G)\setminus U \ni u$ and $U$. If $u$ were adjacent to more than $t-2$ notes in $U$, then $U\cup \{u\} \cong K_t$. \label{fig:U_VG-U}}
\end{marginfigure}

 For every $u\in V(G)\setminus U$, the vertex $u$ is adjacent to $\leq t-2$ verticies in $U$ (otherwise $U\cup\{u\}\cong K_t$). So
 \[
 \edges (U,V(G)-U)| \leq (t-2) |V(G)-U| = (t-2)(n-t-1).
 \]

 Moreover,
 \[
 |\edges (G\setminus U)|  \leq \frac{t-2}{t-1}\frac{(n-t+1)^2}{2},
 \]
 by the induction hypothesis. Putting it all together,
 \begin{align*}
 |\edges (G)| &\leq \frac{(t-1)(t-2)}{2} + (t-2)(n-t+1) + \frac{t-2}{t-1}\frac{(n-t+1)^2}{2}\\
 &= \frac{t-2}{2(t-1)} \left( (t-1)^2 + 2(t-1) (n-t+1) + (n-t+1)^2 \right)\\
 &= \frac{t-2}{2(t-1)} n^2.\qedhere
 \end{align*}
\end{proof}
\lect{2}{8}
% \marginnote{Lecture 10: Monday, February 8, 2016.}
We'll provide another proof of Tur\'an's theorem, but first let us introduce some notation. Let
\[
d(G) = \frac{2|\edges (G)|}{n^2}
\]
be the \defn{density}[density of graph] of $G$; this is the probability that choosing two verticies uniformly at random (with repetition) from $V(G)$ gives an edge. The density $\lambda$ is called the \defn{Lagrangian} of $G$.

Suppose $V(G) = [n]$. Let
\[
\lambda(G) := \max_{\substack{x_i\geq 0,\\ \sum_{i=1}^n x_i=1}} \sum_{(i,j) \in \edges (G)} x_i x_j.
\]
Then $2\lambda(G)$ is the maximum probability of selecting an edge by independently sampling two verticies taken over all probability distributions on the vertex set. In particular, $2\lambda(G) \geq d(G)$, for every $G$.

\begin{example}
\[
\lambda(K_2) = \max_{\substack{x_1,x_2\geq 0 \\ x_1+x_2=1}} x_1 x_2 =\max_{x_1\geq 0} x_1(1-x_1) = \frac{1}{4},
\]
achieved when $x_1=x_2=\frac{1}{2}$.

\[
\lambda(P_3) = \max_{\substack{x_1,x_2,x_3\geq 0\\ x_1+x_2+x_3}} x_1x_2 + x_2x_3 = \max_{\substack{x_1,x_2,x_3\geq 0\\ x_1+x_2+x_3}} x_2(x_1+x_3)
\]
is still a product of two things which sum to one. So we need $x_2=\frac{1}{2}$ and $x_1+x_3=\frac{1}{2}$. We could take $x_1=x_3=\frac{1}{4}$.
\end{example}

\begin{lemma}
$\lambda(K_t) = \frac{t-1}{2 t}$.
\end{lemma}
\begin{proof}
The uniform distribution on $|V(K_t)|$ acheives $\frac{t-1}{2t}$, so it is enough to show
\[
\sum_{\substack{1\leq i<j \leq t,\\ x_i\geq 0,\\ \sum_{i=1}^n x_i=1.}} x_i x_j \leq \frac{t-1}{2t}.
\]
But
\[
\sum_{\substack{1\leq i<j \leq t,\\ x_i\geq 0,\\ \sum_{i=1}^n x_i=1.}} 2x_i x_j  = (x_1+x_2+\dotsm + x_t)^2 - \sum_{i=1}^t x_i^2 = 1- \sum_{i=1}^t x_i^2 \quad\boxed{\leq} \quad 1 - \frac{1}{t}
\]
where we need to show the boxed inequality.
Equivalently, we need $\sum_{i=1}^t x_i^2 \geq \frac{1}{t}$ for all $x_i$ as above. But this follows from Jensen's inequality (with the uniform distribution): if $f$ is convex, then
\[
\frac{\sum_{i=1}^n f(x_i)}{n} \geq f \left( \frac{x_1+\dotsm + x_n}{n}\right)
\]
for all $x_1,\dotsc,x_n$.

Here, we take $f(x)=x^2$, to obtain
\[
\frac{\sum_{i=1}^n x_i^2}{t}\geq \left(\frac{x_1+\dotsm + x_t}{t}\right)^2 = \left( \frac{1}{t} \right)^2. \qedhere
\]
\end{proof}

\begin{theorem} \label{thm:lambda_G}
If $G$ has no $K_t$ subgraph, then $\lambda(G) \leq \lambda(K_{t-1}) = \frac{t-2}{2(t-1)}$.
\end{theorem}
\begin{proof}
Let $p_G(\bar x) = \sum_{\{i,j\}\in \edges (G)} x_i x_j$. Then
\[
\lambda(G) = \max_{\substack{x_i\geq 0 \\ \sum_i x_i =1}} p_G(\bar x).
\]
Choose maximal $\bar x$ so that $p_G(\bar x) = \lambda(G)$, and $\#\{i: x_i \neq 0\}$ is minimal.
We may assume that in fact $x_i>0$ for all $i$, by throwing away verticies with zero weights.
\begin{claim}
$G$ is complete.
\end{claim}
\begin{remark}
This means the probability distribution was concentrated on a complete subgraph.
\end{remark}
\begin{subproof}[Proof of claim]
Suppose $G$ is not complete. Then there exists $i,j\in V(G)$ non-adjacent. We have
\begin{align*}
p_G(\bar x) &= x_i \overbrace{\sum_{\substack{k: \\ \{k,i\} \in \mathcal{G}(G)}} x_k}^{C_i} + x_j \overbrace{ \sum_{\substack{k: \\ \{k,j\} \in \mathcal{G}(G)}} x_k}^{C_j} + \overbrace{\sum_{\substack{\{k,\ell\} \in \edges (G):\\ k,\ell \in V(G)\setminus \{i,j\} }} x_k x_\ell}^{b}.
\end{align*}
Assume wlog that $C_j\geq C_i$. Let $\bar x'$ be obtained by setting $x'_i=0$ and $x'+j = x_i + x_j$, and the other $x'_k = x_k$ (for $k\neq j$ and $k\neq i$). Then $p_G(\bar x') = (x_i+x_j) C_j + b \geq x_i C_i + x_j C_j + b = p_G(\bar x)$.

This is a contradiction: $\bar x'$ has more zero values than $\bar x$, but still acheives $\lambda(G)$. But we choose $\bar x$ to have the minimal number of non-zero values.
 % But since $\bar x$ is maximal, we must have $C_i = C_j$.
\end{subproof}
Then $G$ is complete, and so must be of size $t-1$.
\end{proof}

\begin{remark}
 \Cref{thm:lambda_G} proves \cref{thm:turan}.
\end{remark}
\begin{proof}
\[
\frac{|\edges (G)|}{n^2}=p_G(\frac{1}{n}, \dotsc, \frac{1}{n}) \leq\lambda(G) \leq \frac{t-2}{2(t-1)}.\qedhere
\]
\end{proof}
\lect{2}{10}
% \marginnote{Lecture 11: Wednesday, February 10, 2016.}

Let $K_{1,t}$ be the graph \scalebox{.5}{\begin{tikzpicture}[color=DarkBlue]
\node (rect) at (0,0)[draw,thick,minimum width=1cm, minimum height = 2cm, rounded corners=3pt,label=above:{$t$ vertices}]{};

% \node (rect2) at (2,0)[draw,thick,minimum width=1cm, minimum height = 2cm, rounded corners=3pt,label=above:$V(G)\setminus U$]{};

\pgfmathsetseed{3}
% \def\z{rand}
\foreach \x in {1,...,5}
{
\filldraw[black] (rand*.5,rand*1) circle (0.8pt) node(a\x){};
}
% \draw (a1) -- (a2);

\filldraw[black] (-2,.5) circle (1.2pt) node[left](u){};

\foreach \x in {1,...,5}
{
\draw (a\x) -- (u);
}

% \filldraw at (rect2)[draw, fill=black,circle(.4pt),above,label=above:$u$]{};

\end{tikzpicture}}.
Then $\pi(K_{1,t})= 0$, as follows:
We may bound
\[
\ex(n,K_{1,t}) \leq \frac{(t-1)n}{2}
\]
because every vertex has degree $\leq t-1$ if there is no $K_{t,1}$ subgraph.

Let $K_{2,2}$ be the graph
\scalebox{.7}{\begin{tikzpicture}[color=DarkBlue]
\filldraw[black] (0,0) circle (1.2pt) node(a1){};

\filldraw[black] (0,1) circle (1.2pt) node(a2){};

\filldraw[black] (1,0) circle (1.2pt) node(a3){};
\filldraw[black] (1,1) circle (1.2pt) node(a4){};
\draw (a3) -- (a4);

\draw (a1) -- (a2);

\draw (a2) -- (a3);

\draw (a1) -- (a4);

% \foreach \x in {1,...,4}
% {
% \foreach \y in {1,...,2}
% {
% \draw (a\x) -- (a\y);
% }
% }

\end{tikzpicture}}.
If $G$ has no $K_{2,t}$ then it has $\leq (t-1){n\choose 2}$ paths $P_3$ as subgraphs, but if $G$ has $\epsilon {n\choose 2}$ edges, we ``expect'' $\geq \epsilon^2 {n\choose 3}$ paths $P_3$, so if $\epsilon>0$ for large $n$, we get a contradiction.
Thus, $\pi(K_{2,t})=0$.

\begin{theorem}
$\pi(K_{t,t})=0$ for every $t>1$.
\end{theorem}
\begin{remark}
This implies $\pi(H)=0$ for every bipartite graph $H$.
\end{remark}
\begin{proof}
We need to show that for every $\epsilon>0$ there exists $n_0$ such that if $G$ has no $K_{t,t}$ subgraph, and $n\geq n_0$ verticies, then $|\edges (G)|\leq \epsilon{n\choose 2}$.

Suppose that $|\edges (G)|\geq \epsilon {n\choose 2}$.

\begin{figure}
\begin{center}
\begin{tikzpicture}[color=black]

\node (rect) at (0,0)[draw,thick,minimum width=3cm, minimum height = 1cm, rounded corners=3pt, label=left:$t$]{};

\node (rect2) at (0,1.5)[draw,thick,minimum width=3cm, minimum height = 1cm, rounded corners=3pt,label=left:$t$]{};

\pgfmathsetseed{4}
% \def\z{rand}
\foreach \x in {1,...,5}
{
\filldraw (rand*1.4,rand*.3) circle (0.4pt) node(a\x){};
\filldraw (rand*1.4,1.5+rand*.3) circle (0.4pt) node(b\x){};

}

\foreach \x in {1,...,5}
{
% \ifthenelse{\x > 1}{\draw[dashed] (a\x) -- (u)}{};
\foreach \y in {1,...,\x}
{
\draw (a\x) -- (b\y);
}
}

\end{tikzpicture}
\end{center}
\caption[][0cm]{Left. The bipartite graph on $n$ verticies. We divide the graph into independent sets of size $n/2$, then connect each vertex in the upper set to each vertex in the lower set. This produces $(n/2)^2$ edges and no triangles. \label{fig:bipartite2}}
\end{figure}

Set
\[
f(G) = \sum_{\{v_1,v_2,\dotsc,v_t\}\subset V(G)^{(t)}} | N(v_1)\cap N(v_2)\dotsm \cap N(v_t)| \leq (t-1){n\choose t}
\]
where $N(v)$ is the set of neighbors of $v$ in $G$: that is, $N(v) = \{u\in V(G): \{u,v\} \in \edges (G) \}$.

We are counting subgraphs of the form
\begin{tikzpicture}[color=black]

\node (rect) at (0,0)[draw,thick,minimum width=3cm, minimum height = 1cm, rounded corners=3pt, label=left:$t$]{};
\filldraw (0,1.5) circle (0.4pt) node[above](u){$u$};

% \node (rect2) at (0,1.5)[draw,thick,minimum width=3cm, minimum height = 1cm, rounded corners=3pt,label=left:$t$]{};

\pgfmathsetseed{3}
% \def\z{rand}
\foreach \x in {1,...,6}
{
\ifthenelse{\x>5}{
\filldraw (rand*1.4,rand*.3) circle (0.4pt) node(a\x){$v_t$};

}{
\ifthenelse{\x<3}{

\filldraw (rand*1.4,rand*.3) circle (0.4pt) node(a\x){$v_\x$}; }{
	\filldraw (rand*1.4,rand*.3) circle (0.4pt) node(a\x){};
};

};
% \filldraw (rand*1.4,1.5+rand*.3) circle (0.4pt) node(b\x){};

}

\foreach \x in {1,...,6}
{
% \ifthenelse{\x > 1}{\draw[dashed] (a\x) -- (u)}{};
\foreach \y in {1,...,\x}
{
\draw (a\x) -- (u);
}
}

\end{tikzpicture}.

First, note
\[
{m\choose t} \geq \frac{m^t}{t!} - cm^{t-1}
\]
for some constant $c$ depending on $t$ only.

Then,
\begin{align*}
f(G) &= \sum_{u\in V(G)} {\deg (u) \choose t} \geq \sum_{u\in V(G)} \left( \frac{\deg^t(u)}{t!}- c \deg^{t-1}(u) \right)\\
\intertext{where we've used Jensen's for $t$th powers. Then,}
&\geq \frac{n}{t!} \left( \sum_{u\in V(G)} \frac{\deg(u)}{n} \right)^t - cn^t\\
&\geq \frac{n}{t!} \left( \frac{2 \epsilon {n\choose 2}}{n} \right)^t - cn^t\\
\intertext{Using $2 \epsilon {n\choose 2} \geq \frac{\epsilon}{2}n^2$}
&\geq \frac{n}{t!}\left( \frac{\epsilon}{2}n \right)^t - cn^t\\
& \boxed{>} (t-1) {n \choose t}
\end{align*}
where the boxed inquality yields a contradiction, and holds for large enough $t$.
\end{proof}

If $H$ is not bipartite, is it possible $\pi(H)=0$? No, there exist large ``dense'' graphs with no $H$ subgraph.
For every non-bipartite graph, the Tur\'an density is at least 1/2, for the same reason as $K_3$: it cannot be embedded in a large complete bipartite graph, so these graphs\sidenote[][-2cm]{which have density 1/2} witness this.

Let us consider graphs which are not subgaphs of the Tur\'an graph $T_{3}(n)$ (depicted in \cref{fig:T3}):
If $H$ is not a subgraph of $T_3(n)$ for any $n$, then $\pi(H)\geq \frac{2}{3}$. Let us generalize.
\begin{marginfigure}[-2cm]
\begin{center}
\begin{tikzpicture}[scale=.5]
\begin{scope}
% \node[left] at (0,0) {$\circlearrowleft$};

\foreach \y in {1,...,3}
{
\foreach \z in {1,...,\y}
{
\pgfmathsetmacro\myangley{-1*\y*120+90}
\pgfmathsetmacro\myanglez{-1*\z*120+90}
\draw (\myangley:3cm) -- (\myanglez:3cm);
\draw[xshift=4pt,yshift=-1pt] (\myangley:3cm) -- (\myanglez:3cm);
\draw[xshift=8pt,yshift=2pt] (\myangley:3cm) -- (\myanglez:3cm);
}
}
 % do a few by hand
 \pgfmathsetmacro\myangley{-1*3*120+90}
 \pgfmathsetmacro\myanglez{-1*5*120+90}
% \draw (\myangley:3cm) -- (\myanglez:2.9cm);

\foreach \x in {1,...,6}
{
 \pgfmathsetmacro\myangle{-1*\x*120+90}

\ifthenelse{\x > 1}{
\filldraw[white] (\myangle:3cm) circle (20pt);
\draw[black] (\myangle:3cm) circle (20pt) node{$\frac{n}{3}$
};
}{
\filldraw[white] (\myangle:3cm) circle (10pt);
\draw (\myangle:3cm) node[auto]{$\ldots$};
};

}

%  \pgfmathsetmacro\myangle{-1*60+90}
% \draw (\myangle:3cm) node[auto]{$\ldots$};

\end{scope}
\end{tikzpicture}
\end{center}
\caption{The Tur\'an graph $T_3(n)$.} \label{fig:T3}
\end{marginfigure}

% \begin{definition}%[$k$-coloring, $\chi(G)$]
 We say $c\!\!: V(G) \to [k]$ is a \defn{$k$-coloring} if $c(u)\neq c(v)$ for every $\{u,v\}\in \edges (G)$.

We write $\chi(G)$ for the minimum $k$ such that $G$ admits a $k$-coloring. With this definition in hand, we may formulate the following result.
% \end{definition}
\begin{lemma} \label{lem:min_Tur\'an_density_2graphs}
If $H$ contains an edge,
\[
\pi(H)\geq \frac{\chi(H)-2}{\chi(H)-1}.
\]
\end{lemma}

\begin{proof}
Let $k = \chi(H)-1$. As $H$ is not $k$-colorable, $H$ is not a subgraph of any Tur\'an graph $T_k(n)$ and so $\pi(H)\geq \lim_{n\to\infty} \frac{|\edges (T_k(n))|}{{n\choose 2}} = \frac{k-1}{k}$.
\end{proof}

\begin{lemma} \label{lem:subgraph_with_min_vertex_degree}
For every $r$, $n_0$, and $\epsilon$, there exists $N$ such that if $G$ is an $r$-graph with $|V(G)| = n\geq N$ and $|\edges (G)|\geq d {n\choose r}$, then $G$ contains a subgraph (sub $r$-graph) $G'$ such that
\[
|V(G')| =n' \geq n_0
\]
and every vertex $v\in V(G')$ belongs to at least $(d - \epsilon) {n' \choose r-1}$ edges.
\end{lemma}
\marginnote{So we can  restrict to a (large) subgraph to obtain a minimal bound on vertex degree, at the cost of $\epsilon$ density. }
\begin{proof}
Suppose not. Then there exists a vertex $v_1\in V(G)$ such that $v_1$ belongs to at most $(d - \epsilon) {n \choose r-1}$ edges. Delete this vertex to obtain a graph $G_1$ which in turn has a vertex $v_2$ in at most $(d- \epsilon){n-1 \choose r-1}$ edges. Delete this vertex to obtain $G_2$, and continue in the same manner.

We eventually arrive at a graph $G_{n-n_0}$ on $n_0$ verticies. Then
\begin{fullwidth}
\begin{align*}
d {n \choose r} &\leq |G| \\
&\leq (d -\epsilon){n\choose r-1} + (d- \epsilon) {n-1 \choose r-1} + \dotsm + (d- \epsilon){n_0+1 \choose r-1} + \underbrace{|G_{n-n-0}|}_{\leq {n_0\choose r}}.
\end{align*}
It remains to show that for $n$ large enough (in terms of $n_0,r,\epsilon$)
\[
d {n \choose r} > (d- \epsilon) \left[{n\choose r-1} +  {n-1 \choose r-1} + \dotsm + {n_0+1 \choose r-1}  \right] + {n_0 \choose r}.
\]
But, repeating the Pascal's triangle inequality,
\[
{n\choose r} = {n-1 \choose r-1} + {n-2\choose r-1} + {n-3 \choose r-1} + \dotsm + {r-1 \choose r-1}.
\]
So,
\[
d {n\choose r} = (d - \epsilon) \left( {n-1 \choose r-1} + {n-2\choose r-1} + {n-3 \choose r-1} + \dotsm + {r-1 \choose r-1} \right) + \epsilon {n\choose r}.
\]
\end{fullwidth}

This eliminates most terms; we are left with
\[
\epsilon {n\choose r} \overset{?}{>} (d- \epsilon) {n\choose r-1} + {n_0 \choose r}.
\]
But the polynomial in $n$ on the left has degree $r$, and on the right, degree $r-1$, so for $n\geq N$ with $N$ large enough, we have strict inequality.

\end{proof}

\begin{theorem}[\cite{erdos-stone}]
\[
\pi(H) = \frac{\chi(H)-2}{\chi(H)-1}
\]
for every $2$-graph $H$ with $\chi(H)\geq 2$\marginnote{I.e. $H$ contains an edge.}.
\end{theorem}
\begin{proof}
\Cref{lem:min_Tur\'an_density_2graphs} gives the lower bound. Now, consider $K_{\underbrace{t,\dotsc,t}_{k \text{ times}}}$ the complete $k$-partite graph with parts of size $t$, as depicted in \cref{fig:Ktttt}.
\begin{figure}
\begin{center}
\begin{tikzpicture}
\begin{scope}
% \node[left] at (0,0) {$\circlearrowleft$};

\foreach \y in {1,...,6}
{
\foreach \z in {1,...,\y}
{
\pgfmathsetmacro\myangley{-1*\y*60+90}
\pgfmathsetmacro\myanglez{-1*\z*60+90}
\draw (\myangley:3cm) -- (\myanglez:3cm);
\draw[xshift=4pt,yshift=-1pt] (\myangley:3cm) -- (\myanglez:3cm);
\draw[xshift=8pt,yshift=2pt] (\myangley:3cm) -- (\myanglez:3cm);
}
}
 % do a few by hand
 \pgfmathsetmacro\myangley{-1*3*60+90}
 \pgfmathsetmacro\myanglez{-1*5*60+90}
% \draw (\myangley:3cm) -- (\myanglez:2.9cm);

\foreach \x in {1,...,6}
{
 \pgfmathsetmacro\myangle{-1*\x*60+90}

\ifthenelse{\x > 1}{
\filldraw[white] (\myangle:3cm) circle (20pt);
\draw[black] (\myangle:3cm) circle (20pt) node{$t$
};
}{
\filldraw[white] (\myangle:3cm) circle (10pt);
\draw (\myangle:3cm) node[auto]{\ldots};
};

}
\draw (3,3) node[auto]{$k$ parts};

%  \pgfmathsetmacro\myangle{-1*60+90}
% \draw (\myangle:3cm) node[auto]{$\ldots$};

\end{scope}
\end{tikzpicture}
\end{center}
\caption{An illustration of $K_{tt\dotsm  t}$, where there are $k$ $t$'s in the subscript. This means we have $k$ independent sets of size $t$, and each vertex of each independent set is connected to all the vertices in all the other sets.  \label{fig:Ktttt}}
\end{figure}

For every $t$,
\[
\pi(K_{t,\dotsc,t}) \leq \frac{k-2}{k-1}
\]
by induction on $k$. Suppose for some $k$, and some $t$,
\[
\pi(K_{\underbrace{t,\dotsc,t}_{k \text{ times}}}) \geq \frac{k-2}{k-1} + \epsilon.
\]
for $\epsilon>0$. It is enough to show that for every graph $G$ with $n$ vertices such that
\[
|\edges (G)| \geq \left( \frac{k-2}{k-1}+ \epsilon \right) {n\choose 2},
\]
we must have that $G$ contains $K_{\underbrace{t,\dotsc,t}_{k \text{ times}}}$.

By \cref{lem:subgraph_with_min_vertex_degree} we may assume that every vertex of $G$ has degree
\[
\geq \left(  \frac{k-2}{k-1} + \frac{\epsilon}{2} \right)n.
\]
By the induction hypothesis, $G$ contains $K_{\underbrace{s,\dotsc,s}_{k-1 \text{ times}}}$ for every $s$. We will choose a particular $s$ depending only on $k$ and $\epsilon$, which we will specify later.

It suffices to prove that if $n$ is large compared to $s,k, \epsilon$, and $s$ is large compared to $k, t$ and $\epsilon$, and $G$ is a graph with $n$ vertices, and each vertex has degree at least $\left(  \frac{k-2}{k-1} + \frac{\epsilon}{2} \right)n$ , and $G$ contains a complete $k-1$-partite subgraph with $s$ vertices in each part, then $G$ contains a complete $k$-partite subgraph with $t$ vertices.
\lect{2}{15}
% \marginnote{Lecture 12: Monday, February 15, 2016.}

Let $A_1,A_2,\dotsc,A_{k-1} \subset V(G)$ with $|A_i| = s$ such that every vertex of $A_i$ is adjacent to every vertex of $A_j$ when $i\neq j$ \marginnote{Such a group of sets is simply $K_{\underbrace{s,\dotsc,s}_{k-1 \text{ times}}}$ and exists by the induction hypothesis.}
Let $U = A_1\cup \dotsc \cup A_{k-1}$ and let $W$ be the set of verticies in $V(G)$ which have $\geq t$ neighbors in each $A_i$.

\begin{figure}
\begin{center}
\begin{tikzpicture}
\begin{scope}
% \node[left] at (0,0) {$\circlearrowleft$};

\def\n{4}
\def\radius{.6}
\def\rotation{90}

\def\deg{360/\n}
\pgfmathsetmacro\nminusone{\n-1}

 \pgfmathsetmacro\myangle{-1*.5*\deg+\rotation}

\filldraw[white] (\myangle:5.5cm) circle (10pt);
\draw (\myangle:5.5cm) node[auto](w){$W$};

% do first one
\pgfmathsetmacro\myangley{-1*\deg+\rotation}
\draw (\myangley:3cm) -- (w);
\draw[xshift=4pt,yshift=-1pt] (\myangley:3cm) -- (w) node[near end,auto]{$\geq t$};

% do the rest
\foreach \y in {2,...,\n}
{
\pgfmathsetmacro\yminusone{\y-1}

\foreach \z in {1,...,\yminusone}
{
\pgfmathsetmacro\myangley{-1*\y*\deg+\rotation}
\pgfmathsetmacro\myanglez{-1*\z*\deg+\rotation}
\draw (\myangley:3cm) -- (\myanglez:3cm);
\draw[xshift=4pt,yshift=-1pt] (\myangley:3cm) -- (\myanglez:3cm);
\draw[xshift=8pt,yshift=2pt] (\myangley:3cm) -- (\myanglez:3cm) node[midway,auto]{$s^2$};

\draw (\myangley:3cm) -- (w);
\draw[xshift=4pt,yshift=-1pt] (\myangley:3cm) -- (w) node[near end,auto]{$\geq t$};

}
}
 % do a few by hand
 % \pgfmathsetmacro\myangley{-1*3*120+90}
 % \pgfmathsetmacro\myanglez{-1*5*120+90}
% \draw (\myangley:3cm) -- (\myanglez:2.9cm);

\foreach \x in {1,...,\n}
{
 \pgfmathsetmacro\myangle{-1*\x*\deg+\rotation}

\ifthenelse{\x = \nminusone}{
\filldraw[white] (\myangle:3cm) circle (10pt);
\draw (\myangle:3cm) node[auto]{$\ldots$};
}{
\ifthenelse{\x = \n}{
\filldraw[white] (\myangle:3cm) circle (20pt);
\draw[black] (\myangle:3cm) circle (20pt) node{$A_{k-1}$};
}{
\filldraw[white] (\myangle:3cm) circle (20pt);
\draw[black] (\myangle:3cm) circle (20pt) node{$A_\x$};
}
};

}
\end{scope}
\end{tikzpicture}
\end{center}
\end{figure}
Now, we wish to show $w:= |W|$ is large. First,
\begin{align*}
\left( \frac{k-2}{k-1}+ \epsilon \right)n(k-1)s &\leq  \sum_{v\in U}\deg(v) \leq \sum_{v\in V(G)} |N(v)\cap U|\\
&\leq \underbrace{w s(k-1)}_{\text{from verticies in }W} + \underbrace{(n-w) (s(k-2)+t)}_{\text{from verticies not in }W}\\
% &= wsn - ws + ns - n(k-2) + nt - ws + w(k-2) - wt\\
% &= wsn - ws + ns - nk + 2n + nt -ws +wk - 2w - wt\\
((k-2) + \epsilon (k-1)) n s &\leq ns (k-2) + nt + w(s-t)
\end{align*}
If we choose $s$ such that $\epsilon (k-1) s -t \geq 1$, then
\[
% &= nsk - 2ns + nt + ws - wt
n \leq n( \epsilon (k-1)s - t) \leq w (s-t) \leq ws.
\]
Then $W\geq \frac{n}{s}$. For each $v\in W$ let $(B_1^v,B_2^v,\dotsc,B_{k-1}^v)$ be the sets of neighbors of $v$ of size $t$ such that $B_i \subset A_i$. There are ${s \choose t}^{k-1}$ choices of these sequences of neighbors, so if $w > \underbrace{s(k-1)}_{\text{vertices in }U}+ (t-1) {s \choose t}^{k-1}$ \marginnote{So $|W\setminus U| \geq |W| - |U| \geq (t-1) {s \choose t}^{k-1}$.} then by pigeonhole principle, there exists $t$  entries in $W\setminus U$ which have the same $t$ neighbors in each of the $A_i$, as desired.\qedhere

\marginnote{The entries in $W\setminus U$ don't need to be independent, because we just need a subgraph, so we can just not include those edges in our subgraph.}

\end{proof}
% section turian_type_problems (end)


\documentclass{article}
\usepackage[linesnumbered, lined, boxed]{algorithm2e}
\usepackage[]{geometry}

\begin{document}
\title{Notes on N-Queens Solutions}
\author{Robert Dougherty-Bliss}
\date{\today}
\maketitle

The $n$-queens problem is this: Given an $n \times n$ chessboard, can $n$
queens be placed on it such that no queen can attack another? The answer,
proved by E.~Pauls in 1874, is yes, for $n = 1$ and $n > 3$
\cite{jordanbell07}. We list some notes on the running times of various
solutions.

\section*{Running Times}
\label{sec:running_times}

Here we will list various solutions to the $n$-queens problem and compare their
running times. Included with each are pseudocode algorithms.

\begin{table}[h]
 \caption{Running Time of $n$-Queens Solutions}
 \centering
 \begin{tabular}{lc}
     \hline
     Combinatoric Brute Force & $O(n^2(n^2!))$ \\
     Row-based Brute Force & $O(n^{n+2})$ \\
     Backtracking & $O(n!)$ \\
     Explicit Solution & $O(n)$ \\
     \hline
 \end{tabular}
\end{table}

\subsection*{Guarded Check}
\label{sub:guarded_check}

Some of the solutions check if a given answer is a solution. Here is an
$O(n^2)$ algorithm to check if this is true.

First, some definitions. The $n \times n$ chessboard is represented as $[0, n-1]
\times [0, n-1]$, indexed by row-column points $(r, c)$. The row $r = 0$ is the
top of the board, and the column $c = 0$ is the leftmost column.

The $k$th sum diagonal on a chess board is the set of points $(r, c)$ on the
board such that $r + c = k$. The $k$th difference diagonal is the set of points
$(r, c)$ on the board such that $r - c = k$. Sum diagonals run from bottom-left
to top-right, and difference diagonals run from top-left to bottom-right.

Queens on a chessboard guard their rows, columns, and diagonals. That motivates
the definition of a \textit{guarded point}. Given a point $P(r, c)$ and a set
of queens $Q$, the point $P$ is guarded by $Q$ iff there exists some $R(a, b)
\in Q$ such that $R$ and $P$ share a column, row, or diagonal. That is, iff $a
+ b = r + c$, $a - b = r - c$, $a = r$, or $b = c$. In the worst-case for a set
of $n$ queens, the running time of checking if a point is guarded is $O(n)$. To
check if an answer is a solution, simply perform this check against all $n$
points, which is $O(n)O(n) = O(n^2)$.

\begin{algorithm}
    \caption{Guarded Check}
    \KwIn{$P(r, c)$, a point, and $Q$, a set of queens}
    \KwOut{True if $P$ is guarded by $Q$, False if not}

    \ForEach{$(a, b)$ in $Q$}{
        \If{$a + b = r + c$ or $a - b = r - c$}{
            \Return{True}\;
        }
        \If{$a = r$ or $b = c$}{
            \Return{True}\;
        }
    }

    \Return{False}\;
\end{algorithm}

\subsection*{Combinatoric Brute Force}
\label{sub:combinatoric_brute_force}

A first attempt to solve the $n$-queens problem might be to try every possible
combination of $n$ distinct points from an $n \times n$ chessboard. This gives
$${n^2 \choose n} = \frac{n^2!}{n!(n^2 - n)!}$$ possible combinations. For all
$n \geq 1$, we have that $n^2 - n \geq 0$, so $n!(n^2 - n)! \geq 1$. So for all
$n \geq 1$, $$\frac{n^2!}{n!(n^2 - n)!} \leq n^2!$$ That is, to enumerate every
possible combination is $O(n^2!)$. But we also need to check if each combination
is a solution, which is $O(n^2)$. So the total worst-case running time of this
solution is $O(n^2!)O(n^2) = O(n^2(n^2!))$.

\begin{algorithm}
    \caption{Combinatoric Brute Force}
    \KwIn{$n$, a non-negative integer}
    \KwOut{A set of $(r, c)$ points that solve the $n$-queens problem, or an
              empty set if no solution exists}

    $combinations \leftarrow$ $[0, n-1] \times [0, n-1]$\;
    \ForEach{answer in combinations}{
        solved $\leftarrow$ True\;
        \ForEach{point in answer}{
            \If{point is guarded by rest of answer}{
                solved $\leftarrow$ False\;
                break\;
            }
        }

        \If{solved}{
            \Return{answer}\;
        }
    }
\end{algorithm}

\subsection*{Row-Based Brute Force}
\label{sub:row_based_brute_force}

An improvement on the previous technique is to note that no solution has two
queens placed in the same row. Then, restrict the queens from being placed in
the same row. There are $n$ choices for the first row, $n$ for the second, and
so on until the $n$th row. That gives $$\underbrace{n \times n \times n \times
\cdots \times n}_{n \ \rm times} = n^n$$ combinations to check. To enumerate all
of these is $O(n^n)$, but we also need to check each, which is $O(n^2)$. Thus the
worst case running time is $O(n^n)O(n^2) = O(n^{n+2})$. The solution algorithm is
identical except for the method of generating combinations.

\subsection*{Backtracking}
\label{sub:backtracking}

Another improvment is to use backtracking. This method starts by placing a queen
at $(0, 0)$, then moving to the next row. Once a non-guarded point is found on
that row, place a queen there, and move to the next row. Do this until there are
$n$ queens placed.

If every point on a row is guarded, then move back one row and delete the queen
there. Then attempt to find another non-guarded point in that row. If there are
none, move back another row, and attempt to delete and move the queen there. If
the queen in the first row is moved past the end of its row, then there is no
solution possible.

In the worst case, this will search roughly $n$ points in the first row, then
$n - 1$ in the next, and so on, so the worst-case running time is $O(n!)$.

\begin{algorithm}[H]
    \caption{Backtracking}
    \KwIn{$n$, a non-negative integer}
    \KwOut{A set of $(r, c)$ points that solve the $n$-queens problem, or an
              empty set if no solution exists}

    place queen at $(0, 0)$\;
    (row, col) $\leftarrow$ (0, 0)\;

    \While{number of queens $\neq n$}{
        \If{(row, col) is not guarded}{
            place a queen at (row, col)\;
            (row, col) $\leftarrow$ (row + 1, 0)\;
        } \Else {
            \While{col $= n - 1$}{
                \If{row $= 0$}{
                    \tcc{End of first row.}
                    \Return{no solution}
                }
                \tcc{End of current row; backtrack until we can move the
                previous queen.}
                (row, col) $\leftarrow$ previous queen\;
                delete previous queen\;
            }

            col $\leftarrow$ col + 1\;
        }
    }
\end{algorithm}

\subsection*{Explicit Solution}
\label{sub:explicit_solution}

This solution is due to Pauls, discussed in \cite{jordanbell07}. Pauls breaks
down $n > 3$ by congruence classes modulo 6, then offers a solution for each of
them. This requires one comparison, and then the creation of a number of sets
that are joined together. The number of elements in the sets are linear in $n$,
and so this solution is $O(n)$. Note that for Pauls the board is $[1, n] \times
[1, n]$ instead of $[0, n-1] \times [0, n-1]$. An outline of Pauls proof is
given by \cite{jordanbell07}. Another soluion and proof is given by
\cite{hoffman69}.

\begin{algorithm}[H]
    \caption{Pauls' Explicit Solution}
    \KwIn{$n$, a non-negative integer}
    \KwOut{A set of $(r, c)$ points that solve the $n$-queens problem, or an
              empty set if no solution exists}

    \If{$n = 1$}{
        \Return{$\{(1, 1)\}$}
    }

    \If{$n = 2, 3$}{
        \Return{$\emptyset$}\;
    }

    \Switch{$n \bmod 6$}{
        \Case{0, 4}{
            $A1 = \{(2k, k) : 1 \leq k \leq n/2\}$\;
            $A2 = \{(2k - 1, n/2 + k) : 1 \leq k \leq n/2\}$\;
            \Return{$A1 \cup A2$}\;
        }
        \Case{1, 5}{
            $B1 = \{(n, 1)\}$\;
            $B2 = \{(2k, k + 1) : 1 \leq k \leq (n-1)/2\}$\;
            $B3 = \{(2k - 1, (n+1)/2 + k) : 1 \leq k \leq (n-1)/2\}$\;
            \Return{$B1 \cup B2 \cup B3$}\;
        }
        \Case{2}{
            $C1 = \{(4, 1)\}$\;
            $C2 = \{(n, n/2 - 1)\}$\;
            $C3 = \{(2, n/2)\}$\;
            $C4 = \{(n-1, n/2 + 1)\}$\;
            $C5 = \{(1, n/2 + 2)\}$\;
            $C6 = \{(n - 3, n)\}$\;
            $C7 = \{(n - 2k, k + 1) : 1 \leq k \leq n/2 - 3\}$\;
            $C8 = \{(n - 2k - 3, n/2 + k + 2) : 1 \leq k \leq n/2 - 3\}$\;
            \Return{$C1 \cup C2 \cup C3 \cup C4 \cup C5 \cup C6 \cup C7 \cup C8$}\;
        }
        \Case{3}{
            \Return{$\{(n, n)\} \cup  ($solution for $n - 1)$}\;
        }
    }
\end{algorithm}

\pagebreak

\begin{thebibliography}{9}

\bibitem{jordanbell07}
    Bell, Jordan, and Stevens, Brett,
    2007:
    A survey of known results and research areas for n-queens,
    \emph{Discrete Math},
    \textbf{309},
    1--31.

\bibitem{hoffman69}
    E.J. Hoffman, and J.C. Loessi, and R.C. Moore,
    1969:
    Constructions for the Solution of the m Queens Problem,
    \emph{Math. Mag.},
    \textbf{42},
    66--72

\end{thebibliography}

\end{document}


\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\title{Judson's Abstract Algebra: Chapter 7}
\date{}

\begin{document}
\maketitle

\section*{1}

Encode IXLOVEXMATH using the cryptosystem in Example 66.

\vspace{\baselineskip}

LAORYHAPDWK

\section*{2}

Decode ZLOOA WKLVA EHARQ WKHA ILQDO, which was encoded using the cryptosystem in Example 66.

\vspace{\baselineskip}

WILLXTHISXBEXONTHEXFINAL

\section*{4}

What is the total number of possible monoalphabetic cryptosystems? How secure are such systems?

\vspace{\baselineskip}

There are $26! - 1$ possible systems (we subtract one because of the identity permutation). They are relatively insecure because of frequency analysis and other methods.

\section*{5}

Prove that a  $2 \times 2$ matrix $A$ with entries in $\mathbb{Z}_{26}$ is invertible if and only if $\gcd(\det(A), 26) = 1$.

\vspace{\baselineskip}

Assume that $A$ is invertible. This implies that there exists $A^{-1}$ such that $AA^{-1} = I$ which in turn implies

$$\det(A) \det(A^{-1}) = 1.$$

This shows that $\det(A) \in U(26)$. It is true that all $x \in U(26)$ are coprime to 26 and hence

$$\gcd(\det(A), 26) = 1.$$

Assume that $\gcd(\det(A), 26) = 1$. There exists integers $r$ and $s$ such that

\begin{align*}
\gcd(\det(A), 26) &= \gcd(ad - bc, 26) \\
&= r(ad-bc) + 26s \\
\end{align*}

Hence $1 = r(ad-bc) + 26s$ rearranging yields

$$r(ad - bc) = 1 - 26s.$$

Since $s$ is an integer the right hand side is non-zero and hence $ad - bc \neq 0$ which implies that $A$ is invertible.

\section*{6}

Given the matrix

$$A = \begin{pmatrix}
3 & 4 \\
2 & 3
\end{pmatrix},$$

use the encryption function $f(\mathbf{p}) = A \mathbf{p} + \mathbf{b}$ to encode the message CRYPTOLOGY, where $\mathbf{b} = (2,5)^t$. What is the decoding function?

\vspace{\baselineskip}

The ciphertext of the message is YIEULHOKKYPN. The decoding function is $f^{-1}(\mathbf{p}) = A^{-1} (\mathbf{p} - \mathbf{b})$. Where

$$A^{-1} = \begin{pmatrix}
3 & 4 \\
2 & 3
\end{pmatrix}.$$

\section*{7}

Encrypt each of the following RSA messages $x$ so that $x$ is divided into blocks of integers of length 2; that is, if $x = 142528$, encode 14, 25, 28 separately.

$$n=3551, E=629, x=31$$

$$y = 31^{629} \mod 3551 = 2791$$

$$n=2257, E=47, x=23$$

$$y = 23^{47} \mod 2257 = 769$$

$$n=120979, E=13251, x=142371$$

$$y_1= 14^{13251} \mod 120979 = 112135$$
$$y_2= 23^{13251} \mod 120979 = 25032$$
$$y_3= 171^{13251} \mod 120979 = 442$$

$$n=45629, E=781, x=231561$$

$$y_1 = 23^{781} \mod 45629 = 4438$$
$$y_2 = 15^{781} \mod 45629 = 16332$$
$$y_3 = 61^{781} \mod 45629 = 31594$$

\end{document}


\documentclass[12pt]{article}
\input{physics1}
\begin{document}

\section*{NYU Physics I---Problem Set 6}

Due Thursday 2018 October 18 at the beginning of lecture.

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
In lecture we dropped a pool ball from a height of about $1\,\m$. It
bounced off of the cement floor. Roughly what was the impulse
delivered to the ball from the floor? Make reasonable assumptions! And
remember that an impulse has a magnitude and a direction. And units!

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}\label{elastic}%
Finish the elastic collision problem we didn't finish in lecture on 2018-10-04:

\textsl{(a)}~Compute the momentum of each block, the kinetic energy of
each block, and the total momentum and kinetic energy in the lab
frame, before the collision.

\textsl{(b)}~Compute the center-of-mass velocity of the system by
dividing the total momentum by the total mass. Draw the system (that
is, label the blocks with their velocities and masses) in the
center-of-mass frame, before the collision.

\textsl{(c)}~Compute the momentum of each block, the kinetic energy of
each block, and the total momentum and kinetic energy in the
center-of-mass frame, before the collision. The total momentum should
be zero; if it isn't, then you have made a misake.

\textsl{(d)}~In the center-of-mass frame, in an elastic collision, the
only option is for the momenta after to have the same magnitudes as
the momenta before, but with different directions. Since we are
working in one dimension, the only non-trivial option is to make the
blocks bounce off of each other, and reverse their momenta. Reverse
them, and draw the system after the collision in the center-of-mass
frame.

\textsl{(e)}~Compute the momentum of each block, the kinetic energy of
each block, and the total momentum and kinetic energy in the
center-of-mass frame, after the collision. Do your total numbers equal those
in part \textsl{(c)} above? They should!

\textsl{(f)}~Now invert the transformation you made in going from part
\textsl{(a)} to part \textsl{(b)}; that is, transform \emph{back} to
the lab frame. Draw the system in the lab frame, after the collision.

\textsl{(g)}~Compute the momentum of each block, the kinetic energy of
each block, and the total momentum and kinetic energy in the lab
frame, after the collision. Do your total numbers equal those in part
\textsl{(a)} above? They should!

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}\label{blocks}%
In Problem Set 3, Problem 3, you computed an acceleration $a$ for the
hanging block. Now consider the energy and work.

\textsl{(a)}~If the hanging block falls by a distance $h$, what is
the change in the potential energy of the hanging block, and how much
work is done by friction on the sliding block?

\textsl{(b)}~The work done by friction is \emph{lost} to heat, so if
the system is released from rest and slides by a distance $h$, the
kinetic energy of the system should rise to a value that is related to both the
potential energy difference and the heat lost. Get that relationship
right and compute the kinetic energy you expect the system to have
when the hanging mass has dropped by a distance $h$.

\textsl{(c)}~Now interpret your answer in terms of an acceleration.
That is, compute the constant acceleration $a$ that would make the
result you computed in part \textsl{(b)} work out right. You will have
to use that $h = (1/2)\,a\,t^2$ and $v=a\,t$, which are both relevant
for constant acceleration. Does your answer agree with what you got on
Problem Set 3?

\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
In the static problem below, a beam is held horizontal by a diagonal
string (cable or tether), and a sign hangs from that beam. The beam is
attached to the wall by a pivot that is effectively frictionless, and
the strings are (effectively) massless. What is the tension $T_1$ in
the upper string, and the force $\vec{F}$ (give $x$ and $y$
components) on the beam at the pivot?
\\ \includegraphics{../mp/hanging_sign.pdf}

\paragraph{Extra \problemname\ (will not be graded for credit):}%
Re-do \problemname~\ref{elastic}, but now for the left-hand block having
mass $M$ and the right-hand block having mass $m\ll M$; that is, solve
the extreme mass-ratio problem. For initial velocities, use $v$ for
the big block and $0$ for the small block. Then draw the before and
after pictures in the lab and center-of-mass frames, just as you did
in \problemname~\ref{elastic}.

\paragraph{Extra \problemname\ (will not be graded for credit):}%
In \problemname~\ref{blocks}, It was useful to think about
conservation of energy. Why \emph{wasn't} it useful to think about
conservation of momentum? What would we have had to take into account
to think of this problem in terms of momentum?

\end{document}


\definecolor {processblue}{cmyk}{0.96,0,0,0}
\clearpage
\section{Reaching Definitions Example}
(Prepared by Namrata Priyadarshini, Shivam Bansal)

We've been looking at different types of data flow analyses and trying to tie them into a single framework. One of the data flow analysis that we looked at was reaching definitions and recall that a reaching definition basically is defined as follows:
A definition D of the form x = y + z reaches a point P in the program if there exists a path from the point immediately following D to P such that D is not killed, in other words x is not overwritten along that path.
So even if there exists one such path where from the end of D to the beginning of P such that x has not been overwritten on that path then D would be considered to be to reach P. So let's look at this example:

\begin{figure}[h!]
\begin {center}

\begin{minipage}{.5\textwidth}
\centering
\caption{Control Flow Graph}
\begin {tikzpicture}[-latex ,auto ,node distance =3.5cm and 5cm ,on grid ,
semithick ,
state/.style ={ rectangle ,top color =white , bottom color = processblue!20 ,
draw,processblue , text=blue , scale = 0.7 ,minimum width =4 cm, minimum height = 4 cm}]
\node[state] (A){} node [label = {[label distance = 0.3cm]90:},rectangle split,rectangle split parts=1]{%
  d1 : b=3
  };
\node[state] (B) [below = of A]{} node [label = {[label distance = 0.3cm]90:}, rectangle split,rectangle split parts=1] [below = of A] {%
  d2 : c = 3
  };
\node[state] (D) [below =of B]{} node [label = {[label distance = 0.65cm]90:}, rectangle split,rectangle split parts=1] [below = of B] {%
  d3 : c = 4
  %
  };
\path[->] (A) edge node [below=0.3cm] {} (B);
\path[->] (B) edge node [above=0.3cm] {}  (D);
\path[->] (B) edge [out=300,in=72,looseness=3] node[align = right][right] {} (B);
% \path[->] (B) edge [loop right] node {} (B) ;
\draw[->] (D) --++(0,-2.5cm) node [above left = 0.05cm] {} ;
\draw[<-] (A) --++(0,2.5cm) node [above left = 0.05cm] {} ;
\end{tikzpicture}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\caption{Reaching definitions}
\begin {tikzpicture}[-latex ,auto ,node distance =3.5cm and 5cm ,on grid ,
semithick ,
state/.style ={ rectangle ,top color =white , bottom color = processblue!20 ,
draw,processblue , text=blue , scale = 0.7 ,minimum width =4 cm, minimum height = 4 cm}]
\node[state] (A){} node [label = {[label distance = 0.3cm]90:},rectangle split,rectangle split parts=3]{%
  $\Phi$
  \nodepart{second}
  d1 : b=3
  \nodepart{third}
  $\{d1\}$
  };
\node[state] (B) [below = of A]{} node [label = {[label distance = 0.3cm]90:}, rectangle split,rectangle split parts=3] [below = of A] {%
  $\{d1,d2\}$
  \nodepart{two}
  d2 : c = 3
  \nodepart{three}
  $\{d1,d2\}$
  };
\node[state] (D) [below =of B]{} node [label = {[label distance = 0.65cm]90:}, rectangle split,rectangle split parts=3] [below = of B] {%
  $\{d1,d2\}$
  \nodepart{two}
  d3 : c = 4
  \nodepart{three}
  $\{d1,d3\}$
  %
  };
\path[->] (A) edge node [below=0.3cm] {} (B);
\path[->] (B) edge node [above=0.3cm] {}  (D);
\path[->] (B) edge [out=300,in=72,looseness=3] node[align = right][right] {} (B);
% \path[->] (B) edge [loop right] node {} (B) ;
\draw[->] (D) --++(0,-2.5cm) node [above left = 0.05cm] {} ;
\draw[<-] (A) --++(0,2.5cm) node [above left = 0.05cm] {} ;
\end{tikzpicture}
\end{minipage}
\end{center}
\end{figure}

It has three definitions d1, d2, d3 and the reaching definitions are given in the figure. At the beginning, we initialize the boundary conditions to the empty set. Let us assume there's no reaching definitions in the beginning. Just after d1, it is only \{d1\} and just before d2 it's actually \{d1,d2\} because there's a path from d1 and then there's a path where d2 also reaches which is the path that takes the cycle.Then if we look at the end of d2 then it's also \{d1,d2\} because there are multiple paths that
can reach that allow d2 to reach this particular point. Before d3, it's \{d1,d2\} because both d1 and d2 can reach here and then at the very end it's \{d1,d3\} and d2 cannot reach here because notice that both d2 and d3 are assigning to c and d3 is overwriting the c so d3 is killing d2 and so d2 doesn't exist here. So two important things
\begin{itemize}
    \item \{d1,d2\} are present even before d2 because of the loop
    \item d2 is not present at the exit of the program because d3 has killed d2
\end{itemize}

\begin{table}
\centering
\caption{Reaching Definitions DFA}
    \begin{tabular}{ c|c}
     Domain & Sets of Definitions \\
     \hline
     Direction  & Forward  \\
     \hline
     Transfer Function  & \begin{tabular}[x]{@{}c@{}}$Out[B]=(in[B]-kill[B]) \cup Gen[B]$ \\Gen: Locally exposed definition of B \\ Kill: Definitions overwritten by B \end{tabular}  \\
     \hline
     Meet Operator  & Set Union $\cup$  \\
     \hline
     Boundary Condition  & $Out[Entry]=\Phi$  \\
    \end{tabular}
\end{table}

If we were to look at the data flow analysis for reaching definitions the domain is basically the sets of definitions. For example $\{d1, d2, d3\}$. Direction
is forward. Transfer function $Out[B]=(in[B]-kill[B])$ where kill is defined by
statements that are uh overwriting an existing definition and gen is basically the new definition itself. So, kill is definitions over written by B, gen is the locally exposed definitions of B. So if we're talking about a basic block then it's about the locally exposed definitions. So definitions that have been made but have not been killed subsequently. Meet operator is union because we are looking at any such path so if there exists any such path we're going to consider it to reach. Boundary condition is $Out[Entry]=\Phi$.

\section{Must Reach Definitions}
So now we are going to just change this analysis slightly just to show how the small differences can give you different analysis completely. So let's say we define an analysis called must reach definition which is defined as follows: a
definition of the form x = y + z must reach point program point P if and only if D appears at least once along all paths leading to P and x is not redefined or in other words D is not killed along any path after the last appearance of D and before P.

So, basically on all possible paths D is reaching P and on none of those paths there's another statement that is killing D . So the last definition of x is because of D on all paths that are reaching P. So that's what must reach definitions says.

\begin{table}
\centering
\caption{Must Reach Definitions DFA}
    \begin{tabular}{ c|c}
     Domain & Sets of Definitions \\
     \hline
     Direction  & Forward  \\
     \hline
     Transfer Function  & \begin{tabular}[x]{@{}c@{}}$Out[B]=(in[B]-kill[B]) \cup Gen[B]$ \\Gen: Locally exposed definition of B \\ Kill: Definitions overwritten by B \end{tabular}  \\
     \hline
     Meet Operator  & Set Intersection $\cap$  \\
     \hline
     Boundary Condition  & $Out[Entry]=\Phi$  \\
    \end{tabular}
\end{table}

Data flow analysis of must reach definitions is identical with
reaching definitions but just the meet operator has changed and instead of set
union it becomes set intersection and that's going to capture the fact that we want D to reach on all parts and not just any path and so the transfer function remains the same because once again we are interested in definitions that have not been killed but everything else remains the same. The boundary condition remains the same, the direction remains the same, the domains remain the same. Just the meat operator changes and we get a completely different analysis. So that's the power of this common framework you can just change one parameter and you don't have to rewrite the algorithm, you don't have to change anything else, you can just basically reuse the existing infrastructure.

\section{Must Reach Definitions Example}

\begin{figure}[h!]
\begin {center}

\begin{minipage}{.5\textwidth}
\centering
\caption{Reaching definitions}
\begin {tikzpicture}[-latex ,auto ,node distance =3.5cm and 5cm ,on grid ,
semithick ,
state/.style ={ rectangle ,top color =white , bottom color = processblue!20 ,
draw,processblue , text=blue , scale = 0.7 ,minimum width =4 cm, minimum height = 4 cm}]
\node[state] (A){} node [label = {[label distance = 0.3cm]90:},rectangle split,rectangle split parts=3]{%
  $\Phi$
  \nodepart{second}
  d1 : b=3
  \nodepart{third}
  $\{d1\}$
  };
\node[state] (B) [below = of A]{} node [label = {[label distance = 0.3cm]90:}, rectangle split,rectangle split parts=3] [below = of A] {%
  $\{d1,d2\}$
  \nodepart{two}
  d2 : c = 3
  \nodepart{three}
  $\{d1,d2\}$
  };
\node[state] (D) [below =of B]{} node [label = {[label distance = 0.65cm]90:}, rectangle split,rectangle split parts=3] [below = of B] {%
  $\{d1,d2\}$
  \nodepart{two}
  d3 : c = 4
  \nodepart{three}
  $\{d1,d3\}$
  %
  };
\path[->] (A) edge node [below=0.3cm] {} (B);
\path[->] (B) edge node [above=0.3cm] {}  (D);
\path[->] (B) edge [out=300,in=72,looseness=3] node[align = right][right] {} (B);
% \path[->] (B) edge [loop right] node {} (B) ;
\draw[->] (D) --++(0,-2.5cm) node [above left = 0.05cm] {} ;
\draw[<-] (A) --++(0,2.5cm) node [above left = 0.05cm] {} ;
\end{tikzpicture}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\caption{Must reach definitions}
\begin {tikzpicture}[-latex ,auto ,node distance =3.5cm and 5cm ,on grid ,
semithick ,
state/.style ={ rectangle ,top color =white , bottom color = processblue!20 ,
draw,processblue , text=blue , scale = 0.7 ,minimum width =4 cm, minimum height = 4 cm}]
\node[state] (A){} node [label = {[label distance = 0.3cm]90:},rectangle split,rectangle split parts=3]{%
  $\Phi$
  \nodepart{second}
  d1 : b=3
  \nodepart{third}
  $\{d1\}$
  };
\node[state] (B) [below = of A]{} node [label = {[label distance = 0.3cm]90:}, rectangle split,rectangle split parts=3] [below = of A] {%
  $\{d1\}$
  \nodepart{two}
  d2 : c = 3
  \nodepart{three}
  $\{d1,d2\}$
  };
\node[state] (D) [below =of B]{} node [label = {[label distance = 0.65cm]90:}, rectangle split,rectangle split parts=3] [below = of B] {%
  $\{d1,d2\}$
  \nodepart{two}
  d3 : c = 4
  \nodepart{three}
  $\{d1,d3\}$
  %
  };
\path[->] (A) edge node [below=0.3cm] {} (B);
\path[->] (B) edge node [above=0.3cm] {}  (D);
\path[->] (B) edge [out=300,in=72,looseness=3] node[align = right][right] {} (B);
% \path[->] (B) edge [loop right] node {} (B) ;
\draw[->] (D) --++(0,-2.5cm) node [above left = 0.05cm] {} ;
\draw[<-] (A) --++(0,2.5cm) node [above left = 0.05cm] {} ;
\end{tikzpicture}
\end{minipage}
\end{center}
\end{figure}

So just to see an example to understand the difference between reaching definitions and must reach definitions let's take the same example with three definitions d1, d2, d3. d1 is assigning to b and d2 and d3 are assigning to c. Our reaching definitions is basically
something that we have seen before. Reaching definitions and must reach definitions are same at all points but there's a difference just before d2. It's $\{d1, d2\}$ in reaching definitions but in must reach definitions it's only $\{d1\}$ because there exists a path where d2 doesn't reach this point and that path is the straight line path without the loop and so here it's just d1 but in reaching definitions it becomes $\{d1, d2\}$. So once again for all other points actually it has the same answer. We can check this, for example just after d3. So, just before d3, on all possible paths d2 reaches d3 without getting killed so if we just take the straight line path without taking the loop d2 reached. d2 reaches even if we take a loop. We can take any iterations of the loop and d2 would still reach so on all possible paths d2 is reaching. So d2 must reach this program point and similarly d2 gets killed just after d3 and so d1 and d3 are the only definitions that must reach the point just after d3 and the reaching definitions also has the same answer in this case.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% UMB-CS110-2015S: Introduction to Computing
% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>
% Creative Commons Attribution-ShareAlike 4.0 International License
% More info: https://github.com/ghorbanzade/UMB-CS110-2015S
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \topDirectory {.}
\def \texDirectory {\topDirectory/src/main/tex}

\documentclass[12pt,letterpaper,twoside]{article}
\usepackage{\texDirectory/template/style/directives}
\usepackage{\texDirectory/template/style/assignment}
\input{\texDirectory/template/config}

\begin{document}

\doc{title}{Lab Session Problems}
\doc{points}{0}

\prepare{header}

\subsection*{Week 12}
\hfill \textbf{May 07, 2015}

Write a recursive method \texttt{isAchievable()} with following method signature that returns true if there is a group of elements in the array \texttt{array} such that sum of its values is equal to the value of parameter \texttt{target}.

\lstset{language=java,tabsize=2,numbers=none}
\begin{lstlisting}
private static boolean isAchievable(int startIndex, double[] array, double target);
\end{lstlisting}

Table \ref{tab2} represents output of the method for different sets of parameters.

\begin{table}[H]\centering
\begin{tabular}{cccc}
\hline
start & array & target & output\\
\hline
$0$ & $\{1, 2, 8\}$ & $11$ & true\\
$0$ & $\{1, 2, 8\}$ & $9$  & true\\
$1$ & $\{1, 2, 8\}$ & $9$  & false\\
$0$ & $\{1, 2, 8\}$ & $5$  & false\\
$0$ & $\{1\}$       & $1$  & true\\
$0$ & $\{\} $       & $0$  & true\\
\hline
\end{tabular}
\caption{Output of method \texttt{isAchievable()} for different parameter lists}\label{tab2}
\end{table}

For simplicity, suppose the number of elements in the set \texttt{array} is no more than 1000.

\end{document}


\documentclass[executivepaper]{article}

\usepackage{mathtools}

\everymath{\displaystyle}

\usepackage{amssymb}

\usepackage{amsfonts}

\usepackage{commath}

\usepackage{kantlipsum,graphicx}

\usepackage{amsmath}

\usepackage[utf8]{inputenc}

\usepackage{sectsty}

\usepackage{tcolorbox}

\usepackage{geometry}

\usepackage{tikz}

\usetikzlibrary{shapes,snakes}

\usepackage{float}

\setlength\parindent{3pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text

\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height

\newtheorem{definition}{Definition}

\newtheorem{theorem}{Theorem}

\newtheorem{corollary}{Corollary}[theorem]

\newtheorem{sidenote}{Side Note}

\newcommand{\KP}[1]{%
  \begin{tikzpicture}[baseline=-\dimexpr\fontdimen22\textfont2\relax]
  #1
  \end{tikzpicture}%
}
\newcommand{\KPA}{%
  \KP{\filldraw[color=gray, fill=none, thick] circle (0.3);}%
}
\newcommand{\KPB}{%
  \KP{
    \draw[color=gray,thick] (-0.3,0.3) -- (0.3,-0.3);
    \draw[color=gray,thick] (-0.3,-0.3) -- (-0.05,-0.05);
    \draw[color=gray,thick] (0.05,0.05) -- (0.3,0.3);
  }%
}
\newcommand{\KPC}{%
  \KP{%
    \draw[color=gray,thick] (-0.3,0.3) .. controls (0,-0.05) .. (0.3,0.3);
    \draw[color=gray,thick] (-0.3,-0.3) .. controls (0,0.05) .. (0.3,-0.3);
  }%
}
\newcommand{\KPD}{%
  \KP{%
    \draw[color=gray,thick] (-0.3,-0.3) .. controls (0.05,0) .. (-0.3,0.3);
    \draw[color=gray,thick] (0.3,-0.3) .. controls (-0.05,0) .. (0.3,0.3);
  }%
}

\begin{document}

\title
{
\vspace*{-40mm}
\normalfont \normalsize
\horrule{0.5pt} \\[0.4cm] % Thin top horizontal rule
\huge Topology Final Exam Study Guide\\ % The assignment title
\horrule{0.5pt} \\[0.5cm] % Thick bottom horizontal rule
}
\author{Brendan Busey} % Your name

\date{\normalsize\today} % Today's date or a custom date

\maketitle

\begin{center}

\section*{Chapter 1}

\end{center}

\subsection*{1.1 Equivalence Relations}

\begin{tcolorbox}

\begin{definition}

\textit{A binary relation $\thicksim$ on a set X is an \textbf{equivalence relation} if and only if $\forall ~ x, y, z \in$ X satisfies}

\begin{enumerate}

\item x $\thicksim$ x (reflexivity)

\item if x $\thicksim$ y, then y $\thicksim$ x (symmetry)

\item if x $\thicksim$ y and y $\thicksim$ z,  then x $\thicksim$ z (transitivity)

\end{enumerate}

\end{definition}

\end{tcolorbox}

\section*{1.2 Bijections}

\begin{tcolorbox}

\begin{definition}

\textit{A function $f: X \rightarrow Y$ is an injection (or a \textbf{one-to-one} function) if and only if for an $x_{1}, x_{2} \in X$ we have}

\begin{center}

$f(x{_1})=f(x_{2}) \implies x_{1}=x_{2}$

\end{center}

\textit{The function is a \textbf{surjection} (or an \textbf{onto} function) if and only if for every $y \in Y$, there is $x \in X$ with $f(x)=y$. The function is a \textbf{bijection} if and only if it is an injection and a surjection.}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{theorem}

\textit{Consider a function $f: X \rightarrow Y$. Then, f is a bijection if and only if f has an inverse function.}

\end{theorem}

\end{tcolorbox}

\pagebreak

\vspace*{-35mm}

\section*{1.3 Continuous Functions}

\begin{tcolorbox}

\begin{definition}

\textit{A function $f: X \rightarrow Y$ is continuous at $x_{0} \in X$ if and only if for every $\varepsilon > 0$ there is $\delta > 0$ such that $\forall ~ x \in X$, we have the implication that $d(x, x_{0}) < \delta \implies d(f(x), f(x_{0})) < \varepsilon$. A function is continuous if and only if it is continuous at each point of it s domain.}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{theorem}

\textit{Suppose A and B are regions of $\mathbb{R}^{2}$ that are bounded by polygons. Suppose $f: A \rightarrow Y$ and $g: B \rightarrow Y$ are continuous functions such that $f(x)=g(x) ~ \forall x \in A \cap B$. Then, the function $h: A \cup B \rightarrow Y$ is defined by}

\begin{center}

\[h(x)= \begin{cases}
      f(x) & if ~ x \in A \\
      g(x) & if ~ x \in B
   \end{cases}
\]

\end{center}

is continuous.

\end{theorem}

\end{tcolorbox}

\subsection*{1.4 Topological Equivalance}

\begin{tcolorbox}

\begin{definition}

\textit{A \textbf{homeomorphism} (or \textbf{topological equivalence}) is a bijection $h: X \rightarrow Y$ such that both $h$ and $h^{-1}$ are continuous. The spaces X and Y are \textbf{homeomorphic} (or \textbf{topologically equivalent}) if and only if there is a homeomorphism from X to Y.}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{The \textit{standard disk} is the set \{$(x,y) \in \mathbb{R}^{2} ~ | ~ x^2+y^2 \leq 1$\}. A \textbf{disk} is any topological space homeomorphic to the standard disk. \\[2ex]
The \textbf{standard n-dimensional ball} (or more simply, the \textbf{the standard n-ball}) is the set $\{(x_{1}, x_{2}, \ldots, x_{n}) \in \mathbb{R}^{n} ~ | ~ x_{1}^{2} + x_{2}^{2} + \cdots + x_{n}^{2} \leq 1\}$. An \textbf{n-ball} (or \textbf{n-cell}) is any topological space homeomorphic to the standard n-ball.\\[2ex]
The \textbf{standard} n-\textbf{dimensional sphere} (or more simply, the \textbf{standard} n-\textbf{sphere}) is the set $\{(x_{1}, x_{2}, \cdots, x_{n}) \in \mathbb{R}^{n} ~ | ~ x_{1}^{2} + x_{2}^{2} + \ldots + x_{n+1}^{2} = 1\}$. An n-\textbf{sphere} is any topological space homeomorphic to the standard n-sphere.}

\end{definition}

\end{tcolorbox}

\pagebreak

\vspace*{-35mm}

\subsection*{1.5 Topological Invariants}

\begin{tcolorbox}

\begin{definition}

\textit{A \textbf{path} in a space X is a continuous function $\alpha: [0,1] \rightarrow X$. Consider the equivalence relation between pairs of points in a set of X defined by $x \thicksim y$ if and only if there is a path $\alpha : [0,1] \rightarrow X$ with $\alpha(0)=x$ and $\alpha(1)=y$. The equivalence classes under this relation are called \textbf{path components} of X. A set such that every two points are joined by a path is said to be \textbf{path-connected}}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{theorem}

\textit{Suppose $\alpha : [0,1] \rightarrow A \cup B ~ is ~ a ~ path ~ \alpha(0) \in A$ and $\alpha(1) \in B$. Then, there is a sequence of points of A that converges to a point of B or else there is a sequence of points of B that converges to a point in A.}

\end{theorem}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{corollary}

\textit{A homeomorphism $h: X \rightarrow Y$ induces a bijection $h_{*}: P(x) \rightarrow P(Y)$. In particular, the number of path components of a space is topologically invariant.}

\end{corollary}

\end{tcolorbox}

\subsection*{1.6 Isotopy}

\begin{tcolorbox}

\begin{definition}

\textit{Suppose A and B are two subsets of a space X. An \textbf{Ambient isotopy} from A to B in X is a continuous function $h : X \times [0,1] \rightarrow X$ that satisfies the following three conditions. We denote $h(x,t)$ by $h_{t}(x)$.}

\begin{center}

\begin{enumerate}

\item $h_{t}: X \rightarrow X$ is a homeomorphism for every t $\in$ [0,1]

\item $h_{0} ~ is ~ the ~ identity ~ function ~ on ~ X$

\item $h_{1}(A)=B$

\end{enumerate}

\end{center}

\end{definition}

\end{tcolorbox}

\begin{center}

\section*{Chapter 2}

\end{center}

\subsection*{2.1 Knots, Links, and Equivalences}

\begin{tcolorbox}

\begin{definition}

\textit{A \textbf{knot K} is a simple closed curve in $\mathbb{R}^{3}$ that can be broken into a finite number of straight line segments $e_{1}, e_{2}, \cdots, e_{n}$ such that the intersection of any segment with $e_{k}$ with the other segments is exactly one endpoint of $e_{k}$ intersecting an endpoint of $e_{k-1}$ (or $e_{n}$ if $k=1$) and the other endpoint of $e_{k}$ intersecting an endpoint of $e_{k+1}$ (or $e_{1}$ if $k=n$).}

\end{definition}

\end{tcolorbox}

\pagebreak

\vspace*{-30mm}

\begin{tcolorbox}

\begin{definition}

\textit{Consider a triangle ABC with side AC matching one of the line segments of a knot K. In the plane determined by the triangle, we require that the region bounded by ABC intersects K only in the edge AC. A \textbf{triangular detour} involves replacing the edge AC of knot K with the two edges AB and BC to produce a new knot L. With the same notation, a \textbf{triangular shortcut} involves replacing the two edges AB and BC and L with the single edge of AC to produce knot K. A \textbf{triangular move} is either a triangular detour or a triangular shortcut. Two knots are \textbf{equivalent} if and only if there is a finite sequence of triangular moves that changes the first knot into the second.}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{A \textbf{Link} is the nonempty union of a finite number of disjoint knots.}

\end{definition}

\end{tcolorbox}

\subsection*{2.2 Knot Diagrams}

\begin{tcolorbox}

\begin{definition}[General Position Rule of Thumb]

\textit{Suppose two piecewise-linear objects are embedded in general position in $\mathbb{R}^{n}$. Suppose A is a vertex, edge, face, or analogous higher-dimensional part of one object and B is a vertex, edge, face, or analogous higher-dimensional part of the other object. If the intersection $A \cup B$ is nonempty, then.}

\begin{center}

dim($A \cap B$)=dim(A)+dim(B)-n

\end{center}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{The orthogonal projection of a knot onto a plane is a \textbf{regular projection} if and only if no vertex projects to the image of another point of the knot and there are no triple points.}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{The \textbf{crossing number} of a knot K is the minimum number of crossing points that occur in the knot diagrams for all knots equivalent K.}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{The \textbf{unknotting number} is the minimum number of times the knot must be passed through itself (\textbf{crossing switch}) to untie it}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{A \textbf{trivial knot} is a knot that is equivalent to a triangle. A \textbf{trivial link} is a link that is equivalent to the union of disjoint triangles lying in a plane}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{A knot is \textbf{alternating} if and only if it is equivalent to a knot with a diagram in which underpasses alternate with overpasses as you travel around the knot}

\end{definition}

\end{tcolorbox}

\pagebreak

\vspace*{-30mm}

\subsection*{2.3 Reidmeister Moves}

\begin{figure}[H]

\centering

\includegraphics[scale=0.5]{Reidemeister_move_1.png}

\caption{Type 1}

\end{figure}

\vspace{2mm}

\begin{figure}[H]

\centering

\includegraphics[scale=0.5]{Reidemeister_move_2.png}

\caption{Type 2}

\end{figure}

\pagebreak

\vspace*{-40mm}

\begin{figure}[H]

\centering

\includegraphics[scale=0.5]{Reidemeister_move_3.png}

\caption{Type 3}

\end{figure}

\vspace{2mm}

\begin{tcolorbox}

\begin{theorem}

\textit{If two links are equivalent, then their diagrams, subject to ambient isotopies of the plane, are related by a sequence of Reidemeister moves.}

\end{theorem}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{An \textbf{orientation} of a link is a choice of direction to travel around each component of the link. Consider a crossing a regular projection of an oriented link. Stand on the overpass and face in the direction of the orientation. The crossing is \textbf{right-handed} if and only if traffic on the underpass goes from right to left; the crossing is \textbf{left-handed} if and only if traffic on the underpass goes from left to right. In regular projection of an oriented link of two components, assign +1 to right-handed crossings and -1 to left-handed crossings. Add up the numbers assigned to crossings involving both components. One half this sum is the \textbf{linking number} of the two oriented components of the link.}

\end{definition}

\end{tcolorbox}

\subsection*{2.4 Colorings}

\begin{tcolorbox}

\begin{definition}

\textit{The diagram of a knot is \textbf{colorable} if and only if each arc can be assigned one of three colors subject to the two conditions:}

\begin{center}

\begin{enumerate}

\item At least two colors appear

\item At any crossing where two colors appear, all three colors appear

\end{enumerate}

\end{center}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{theorem}

\textit{The colorability of a knot diagram is an invariant property of the knot type.}

\end{theorem}

\end{tcolorbox}

\pagebreak

\vspace*{-20mm}

\begin{tcolorbox}

\begin{definition}

\textit{Let p be an odd number greater than two. A knot is p-colorable if at every crossing:}

\begin{center}

\begin{enumerate}

\item At least two colors appear

\item you can solve $color1 + color2 \equiv 2x ~ mod ~ (the ~ number ~ of ~ colors ~ used)$, where color1 and color2 are numbers assigned to the arcs of the knot

\end{enumerate}

\end{center}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{theorem}

\textit{The colorability of a knot diagram is an invariant property of the knot type.}

\end{theorem}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{theorem}

\textit{The representation of a knot diagram on a wheel with p colors is an invariant property of the knot type.}

\end{theorem}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{The determinant of a knot is the absolute value of its Alexander Polynominal evaluated at -1 (simply, plug-in -1 for t)}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{theorem}

\textit{A knot is p-\textbf{colorable} for prime p greater than two if and only if p divides its determinant}

\end{theorem}

\end{tcolorbox}

\subsection*{2.5 The Alexander Polynominal}

\begin{tcolorbox}

\textit{Steps in computing the Alexander Polynominal:}

\begin{center}

\begin{enumerate}

\item Label the crossings $x_{1}, x_{2}, \cdots, x_{n}$

\item Label the arcs $a_{1}, a_{2}, \cdots, a_{n}$

\item Choose an orientation for the knot

\item As you travel around the knot in the chosen orientation, stand on the overpass of each crossing. Label the overstrand with $1-t$, the left-end of the understrand $t$, and the right-end of the understrand -1

\item Create the arc/crossing matrix

\item Compute the determinant of the matrix, which is the Alexander Polynominal

\end{enumerate}

\end{center}

\end{tcolorbox}

\pagebreak

\vspace*{-30mm}

\begin{tcolorbox}

\begin{definition}

\textit{The projection of an oriented knot divides the plane into a number of regions. The \textbf{index} of one of these regions is the net number of times the projection winds counterclockwise around any point in the region.}

\end{definition}

\end{tcolorbox}

\begin{tcolorbox}

\begin{definition}

\textit{The \textbf{index} of a crossing of a knot diagram is the common value of the index of two of the regions near the crossing.}

\end{definition}

\end{tcolorbox}

\begin{tcolorbox}

\begin{theorem}

\textit{The Alexander Polynominal of an oriented knot is an invariant under Reidemeister moves.}

\end{theorem}

\end{tcolorbox}

\subsection*{2.6 Skein Relations}

\begin{tcolorbox}

\textit{Calculating the $\Delta$ polynominal is the same as calculating the Alexander Polynominal}

\end{tcolorbox}

\subsection*{2.7 The Jones Polynominal}

\begin{tcolorbox}

\textbf{Rules for the Bracket Polynominal} \textit{The Kauffman \textbf{Bracket Polynominal} of a regular projection of a link is a polynominal in integer powers of the variable A defined by the following three rules:}

\begin{center}

\begin{enumerate}
%the first rule
\item
  $\left\langle\KPA\right\rangle=1$

%the second rule
\item
  $\left\langle L \cup \KPA\right\rangle=(-A^{2}-A^{-2})\langle L\rangle$

%the third rule
\item
  $\left\langle\KPB\right\rangle=
  A\left\langle\KPC\right\rangle + A^{-1} \left\langle \KPD \right\rangle$

\end{enumerate}

\end{center}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{The \textbf{writhe} w(L) of the regular projection L of a link is the number of right-handed crossings minus the number of left-handed crossings.}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{The X(L) polynominal is defined as:}

\begin{center}

$X(L)=(-A)^{-3w(L)} \big \langle L \big \rangle$, where $\big \langle L \big \rangle$ is the bracket polynominal for L and $w(L)$ is the writhe of L

\end{center}

\end{definition}

\end{tcolorbox}

\pagebreak

\vspace*{-30mm}

\begin{tcolorbox}

\textit{Steps in calculating the Jones Polynominal:}

\begin{center}

\begin{enumerate}

\item Calculate the Bracket Polynominal

\item Calculate the $X-polynominal$

\item Substitute $t^{-\frac{1}{4}}$ in for every ``A" in the $X-polynominal$ and simplify

\end{enumerate}

\end{center}

\end{tcolorbox}

\begin{center}

\section*{Chapter 3 Surfaces}

\end{center}

\subsection*{3.1 Definition and Examples}

\begin{tcolorbox}

\begin{definition}

\textit{In a space with a way of measuring distances between points, a \textbf{neighborhood} of a point is a subset that contains all points within some positive distance of the point}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{A \textbf{surface} (or 2 \textbf{-manifold}) is a space that is homeomorphic to a nonempty subset of finite-dimensional Euclidean space and in which every point has a neighborhood homeomorphic to $\mathbb{R}^{2}$. We sometimes also wish to admit \textbf{boundary} points, which have neighborhoods homeomorphic to the half-plane $\{(x,y) \in \mathbb{R}^{2} ~ | ~ y \geq 0\}$}.

\end{definition}

\end{tcolorbox}

\subsection*{3.2 Cut-and-Paste Techniques}

\begin{tcolorbox}

\begin{definition}

\textit{Let S and T be path-connected surfaces Remove the interior of a disk from each surface by cutting along the boundaries of the disks. Glue the remaining surfaces together along the newly formed boundary components. The result surface is the \textbf{connected sum} of S and T. It is denoted S\texttt{\#}T.}

\end{definition}

\end{tcolorbox}

\subsection*{3.3 The Euler Characteristic and Orientability}

\begin{tcolorbox}

\begin{definition}

\textit{A \textbf{triangulation} of a space is a decomposition of the space into a union of disks, arcs, and points. The disks are called \textbf{faces}, the arcs are called \textbf{edges}, and the points are \textbf{vertices} of the triangulation. A face intersects other components of a triangulation only along its boundary; and the boundary of a face consists of three edges and three vertices. An edge intersects other edges and the vertices only at its endpoints; and both endpoints of an edge are vertices.}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{A triangulated space is \textbf{compact} if and only if it consists of a finite number of faces, edges, and vertices.}

\end{definition}

\end{tcolorbox}

\pagebreak

\vspace*{-30mm}

\begin{tcolorbox}

\begin{definition}

\textit{The \textbf{Euler characteristic} of a compact triangulation space S is the number of vertices minus the number of edges plus the number of faces. The Euler characteristic of S is denoted by $\chi(S)$.}

\end{definition}

\end{tcolorbox}

\begin{tcolorbox}

\begin{theorem}

\textit{Every closed, path-connected surface is homeomorphic to exactly one of:}

\begin{center}

\begin{enumerate}

\item A 2-sphere

\item A connected sum of Tori

\item A connected sum of projective planes

\end{enumerate}

\end{center}

\end{theorem}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{sidenote}

\textit{Something is orientable if it is 2-colorable or doesn't have a mobius band}

\end{sidenote}

\end{tcolorbox}

\begin{tcolorbox}

\begin{theorem}

\textit{Suppose $A$ and $B$ are triangulated so that $A \cap B$ is also triangulated. Then, $\chi(A \cup B)=\chi(A)+\chi(B)-\chi(A \cap B)$}.

\end{theorem}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{theorem}

\textit{The surface formed by taking the connected sum of g tori and cutting out disks to leave b boundary components has Euler characteristic 2-2g-b. The surface formed by taking the connected sum of n projective plane and cutting out disks to leave b boundary components has Euler characteristic 2-n-b}.

\end{theorem}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{An \textbf{orientation} of a polygonal face of a triangulated surface is the choice of one of the two possible orientations of the boundary curve of the face. A surface is \textbf{orientable} if and only if it is possible to choose orientations of all the faces of a triangulation of the surface so that whenever two faces share a common edge, the orientation of the faces induce opposite orientations on the edge.}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{$\chi(f_{1}\texttt{\#}f_{2})=\chi(f_{1}) + \chi(f_{2}) - 2$}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{With the word you come up with for the surface, if every letter does not have an inverse, the surface is not orientable. If every letter does have an inverse, it is orientable}

\end{definition}

\end{tcolorbox}

\vspace{2mm}

\begin{tcolorbox}

\begin{definition}

\textit{Just concatenate the two individual words of each surface to get a word for the connected sum of the two surfaces}

\end{definition}

\end{tcolorbox}

\pagebreak

\vspace*{-30mm}

\begin{tcolorbox}

\begin{sidenote}

\textit{The table below helps you figure out what surface is being asked for based on \textbf{Orientability} and the \textbf{Euler characterisitic}}

\vspace{2mm}

\begin{tabular}{||c c c||}

\hline

\textit{$\chi$} & \textit{$Oreintable$} & \textit{$Non-orientable$} \\ [0.5ex]

\hline\hline

2 & Sphere & \\

\hline

1 & & P \\

\hline

0 & T & P \texttt{\#} P \\

\hline

-1 &  & P \texttt{\#} P \texttt{\#} P \\

\hline

-2 & T \texttt{\#} T & P \texttt{\#} P \texttt{\#} P \texttt{\#} P  \\

\hline

-3 & & P \texttt{\#} P \texttt{\#} P \texttt{\#} P \texttt{\#} P  \\

\hline

-4 & T \texttt{\#} T \texttt{\#} T & P \texttt{\#} P \texttt{\#} P \texttt{\#} P \texttt{\#} P \texttt{\# P}  \\ [1ex]

\hline

\end{tabular}

\end{sidenote}

\end{tcolorbox}

\end{document}


\documentclass[12pt,letterpaper]{article}
\usepackage{fullpage}
\usepackage[top=2cm, bottom=4.5cm, left=2.5cm, right=2.5cm]{geometry}
\usepackage{amsmath,amsthm,amsfonts,amssymb,amscd}
\usepackage{lastpage}
\usepackage{enumerate}
\usepackage{fancyhdr}
\usepackage{mathrsfs}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{hyperref}
\usepackage[section]{minted}
\usepackage{hyperref}
\usepackage{multirow}
\usepackage{caption}
\usepackage{subcaption}
\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}

\hypersetup{%
  colorlinks=true,
  linkcolor=blue,
  linkbordercolor={0 0 1}
}

\renewcommand\lstlistingname{method}
\renewcommand\lstlistlistingname{Algorithms}
\def\lstlistingautorefname{Alg.}

\colorlet{mygreen}{green!60!blue}

\newmintedfile[cppcode]{cpp}{
bgcolor=mintedbackground,
fontfamily=tt,
linenos=true,
numberblanklines=true,
numbersep=5pt,
gobble=0,
frame=leftline,
framerule=0.4pt,
framesep=2mm,
funcnamehighlighting=true,
tabsize=1,
obeytabs=false,
mathescape=false
samepage=true, %with this setting you can force the list to appear on the same page
showspaces=false,
showtabs =false,
texcl=false,
fontsize=\small,
breaklines
}

\setlength{\parindent}{0.0in}
\setlength{\parskip}{0.05in}

% Edit these as appropriate
\newcommand\course{EC6301}
\newcommand\name{Numerical Opimization}
\newcommand\hwnumber{3}                  % <-- homework number
\newcommand\NetIDa{20211046}           % <-- NetID of person #1
\newcommand\NetIDb{Hyeonjang An}           % <-- NetID of person #2 (Comment this line out for problem sets)
\newcommand\github{\url{https://github.com/hyeonjang/numerical-optimization}}

\pagestyle{fancyplain}
\headheight 35pt
\lhead{\github\\\NetIDa\\\NetIDb}                 % <-- Comment this line out for problem sets (make sure you are person #1)
\chead{\textbf{\Large Homework \hwnumber}}
\rhead{\course \\ \name \\ \today}
\lfoot{}
\cfoot{}
\rfoot{\small\thepage}
\headsep 1.5em

\begin{document}

\section*{Problem}

\begin{enumerate}
  \item Implement the Nelder-Mead method and the Powell's method to find the minimum of
  \begin{enumerate}
    \item $f(x, y)=(x+2y)^2 + (2x+y)^2$
    \item $(x, y)=50*(y-x^2)^2 + (1-x)^2$
    \item $f(x, y)=(1.5-x+xy)^2 + (2.25-x+xy^2)^2 + (2.625 - x+ xy^3)^2$
  \end{enumerate}
  \item Use your own termination criterion. Compare and discuss their performances.
  If possible, show how the best point is moving on the contour plot of f(x, y)
\end{enumerate}

\section*{Implementation - methods}

\begin{enumerate}
\item Computation result: convergence points
\\ In the case of the first function, the results are the approximation of the value zero.
\\ In the case of the second function, Powell's method is sometimes stucked to local minima.
[0.510332, 0.263043] is the failure case to find optimization points.
\begin{center}
  \begin{tabular}{| c | c | c |} \hline
      \multirow{2}{*}{function $f(x, y)$}   & \multicolumn{2}{c|}{Convergence Points$(x, y)$} \\ \cline{2-3}
                                            & Nelder-Mead & Powell's  \\ \hline
      (a)                                   & [1.17932e-07, -1.85511e-07] & [-7.20495e-23, 5.73423e-23] \\
      (b)                                   & [1, 1] & [0.510332, 0.264043] / [0.99972, 0.999437]\\
      (c)                                   & [3, 0.5]  & [2.99989, 0.499973] \\
      \hline
  \end{tabular}
\end{center}
\item Implementation
  \\ initial points are randomly given.
  \begin{enumerate}
    % ##############################################################
    % Nelder-Mead
    % ##############################################################
    \item \textbf{Nelder-Mead method}
    \\ Three control parameters are set as $\alpha=1$, $\beta=2$, $\gamma=0.5$
    \\ The maximum iteration is 10000.
    \\ The termination condition is the "magnitude of gradient".
    \cppcode[]{../../code/multi/nelder_mead.hpp}

    \newpage

    % ##############################################################
    % Powell's
    % ##############################################################
    \item \textbf{Powell's method}
    \\ For univarite searching, I used the golden section search method.
    \\ The maximum iteration is 10000 as same as Nelder-Mead method.
    \\ When using the termination criterion as the "magnitude of gradient",
    it occurs to be stucked in local minima.
    So the termination condition is changed to "consecutive relative difference".
    However this does not largely affect to the performance.
    \cppcode[]{../../code/multi/powells.hpp}

\end{enumerate}

\newpage

\section*{Implementation - Terminatination criterion}
\item Termination criterion
\\ I have implemented all six conditions.
Also, to calculate the gradient of functions,
I used numerical method to derive gradient from function given point $(x, y)$
\begin{itemize}
% ##############################################################
% Termination criterion: gradient
% ##############################################################
\item Termination criterion
\cppcode[]{../../code/multivariate.h}
\item Gradient calculation
\cppcode[]{../../code/multivariate.cpp}
\end{itemize}

\section*{Performance and Plot}
\item Performace
\begin{center}
    \begin{tabular}{| c | l | c | c |} \hline
                  & \multirow{2}{*}{function $f(x, y)$}               & \multicolumn{2}{c|}{performance} \\ \cline{3-4}
                  &                                                   & Nelder-Mead & Powell's  \\ \hline
        (a) & $(x+2y)^2 + (2x+y)^2$                                   & 872972 ns   & 84036883 ns \\
        (b) & $50*(y-x^2)^2 + (1-x)^2$                                & 132298767 ns& 526430665 ns \\
        (c) & $(1.5-x+xy)^2 + (2.25-x+xy^2)^2 + (2.625 - x+ xy^3)^2$  & 214017830 ns& 336396522 ns \\
        \hline
    \end{tabular}
\end{center}
\begin{itemize}
  \item The convergence speed of Powell's method is worse than Nelder-Mead method for every given functions.
  \item It is because Powell's method has a dependency on the univarite method.
  \item Because I have given the initial points randomly, it happens not to converge.
  The Figure 2, which shows the result of Powell's method of the second function, is the case which cannot find the global minima.
\end{itemize}

% ##############################################################
% Plotting
% ##############################################################
\newpage
\begin{figure}
  \centering
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/NelderMead_0.png}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/Powells_0.png}
  \end{subfigure}
    \caption{$f(x, y)=(x+2y)^2 + (2x+y)^2$ }
\end{figure}

\begin{figure}
  \centering
  \begin{subfigure}[b]{0.4\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/NelderMead_1.png}
    \caption{Nelder-Mead}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.29\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/Powells_1_1.png}
    \caption{Powell's: global}
  \end{subfigure}
  \begin{subfigure}[b]{0.29\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/Powells_1_2.png}
    \caption{Powell's: local }
  \end{subfigure}
    \caption{$f(x, y)=50*(y-x^2)^2 + (1-x)^2$}
\end{figure}

\begin{figure}
  \centering
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/NelderMead_2.png}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{figures/Powells_2.png}
  \end{subfigure}
    \caption{ $f(x, y)=(1.5-x+xy)^2 + (2.25-x+xy^2)^2 + (2.625 - x+ xy^3)^2$ }
\end{figure}

\end{enumerate}
\end{document}