\chapter{Introduction}
In the previous chapters you have seen everything you need to create a simple 2D game. But how do you put a large project together in an orderly way? There is really no simple answer to that. You learn by practice, and not everyone agrees on the best method. Still, there are some rules that may make it easier for sure. And when you work in a group, the lead programmer will usually impose some rules that everyone has to follow. These are not necessarily good or bad rules, but they work as long as everyone follows them.

In this part of the course you will create a clone of the famous Tetris game. You will learn to develop a project step by step  without losing sight of the whole.

\begin{note}
Tetris consists of blocks which in turn consist of squares. When we talk about blocks in this course, we mean the entire block, not the squares it is made of. When a square is mentioned, we're discussing the squares that make up a block.
\end{note}

\section{Setup}
Open the `Tetris\_start' project. In it, you will find the graphics, sounds and fonts that we will use. A blank app `Tetris' is also provided, but we are not going to use it just yet.

\begin{enumerate}
	\item Create a library at the highest level of the explorer. You do this by right clicking and choosing `new library'. Name this library `Tetris parts'. A library is a green folder. The code in a library can be used from any application within your project, just like the library `Esenthel Engine' which is always present.
	\item Create a new application (blue folder). Call it `square tester'.
	\item in the application `square tester', create a code file `main'.
	\item In the library `Tetris parts', create a new folder (yellow) called `definitions'.
	\item Mark `square tester' as the active application.
\end{enumerate}

Copy the code in `Tetris/initState' to `square tester/main'. Remove this line:

\begin{code}
D.full(true);
\end{code}

This makes it easier to terminate your application when something goes wrong.

\section{Constants}
In the previous chapter you learned about constants. It is a good idea to create some important constants before you start on the actual code. You can use them anywhere in your code and easily adjust their values if necessary. Create a new code file `constants' in the folder `Tetris parts/definitions'.

To be able to change the name of the app later on, create a constant \eeClass{Str} with a provisional name.

\begin{code}
C Str APP_NAME = "Tetris";
\end{code}

The size of the standard application window is not ideal for this game. A size in pixels is required for this. Declare a constant \eeClass{int} for this purpose.

\begin{code}
// The window size on the screen, in pixels
C int WINDOW_WIDTH  = 900;
C int WINDOW_HEIGHT = 800;
\end{code}

Tetris consists of rows and columns. we also define these:

\begin{code}
// This impacts the playing field
C int SQUARES_PER_ROW = 10;
C int ROWS            = 15;
\end{code}

It is also possible to add a few constants for the scoring system. There is a fixed number of levels, and we know how much points will be rewarded for a line and a level.

\begin{code}
// The scoring system uses these
C int POINTS_PER_LINE  =  525;
C int POINTS_PER_LEVEL = 6300;
C int NUM_LEVELS       =    5;
\end{code}

The speed of the game goes up with each level. This change can also be defined as a constant.

\begin{code}
// The speed will increase every level
C float INITIAL_SPEED = 1.0;
C float SPEED_CHANGE  = 0.1;
\end{code}

When playing tetris, there is a short period after moving a block down in which you are able to move it sidewards. This period has to be defined.

\begin{code}
// The time a block can be slided to the side
// When it hits bottom
C float SLIDE_TIME = 0.25;
\end{code}

We also have to determine the size of the playing field. This is done by defining the position of the lower left corner, and defining the size of the rectangle containing the playing field.

\begin{code}
// The area reserved for the playing field
C Vec2 GAMEAREA     (-0.8, -0.8);
C Vec2 GAMEAREA_SIZE( 1.0,  1.4);
\end{code}

A new block will always appear at the top of the screen. This position can be deducted from information we already have:  SQUARES\_PER\_ROW and ROWS. In addition, there is a waiting position, top right of the playing field. You might notice we are not using \eeClass{Vec2}, but \eeClass{VecI2}. This is a vector which fits only integers. We do not want Tetris blocks midway between two positions, so there is no need for floats here.

\begin{code}
// Position for the current and next block
C VecI2 STARTPOS(SQUARES_PER_ROW / 2, ROWS - 1);
C VecI2 WAITPOS (SQUARES_PER_ROW + 4, ROWS - 3);
\end{code}

Now it is possible to calculate the size of a square with the information we already have. This has the advantage that we can modify the foregoing constants later, the size of a square being automatically adjusted.

\begin{code}
// The size of a square
C float SQUARE_SIZE = GAMEAREA_SIZE.x / SQUARES_PER_ROW;
\end{code}

\begin{note}
Of course it will rarely happen that you precisely know which constants are needed when you're just starting out on a project. In practice you will usually add a lot of constants while you are working on your project.
\end{note}

\section{Enums}
Create the code file `enumerations' in  `Tetris parts/definitions'. Add two enumerations that will be useful in your project. Firstly, there is the block type. Tetris has square blocks, T-blocks and so on. A list might look like this:

\begin{code}
enum BLOCK_TYPE
{
   BT_SQUARE     ,
   BT_T          ,
   BT_L          ,
   BT_BACKWARDS_L,
   BT_STRAIGHT   ,
   BT_S          ,
   BT_BACKWARDS_S,
   BT_NUM        , // number of block types used in the game
   BT_BACKGROUND , // special case, only for background
   BT_WALL       ,
}
\end{code}

The last three values deserve extra attention. The value `BT\_NUM' is useful because the number which represents that value is equal to the highest value + 1. This makes it easy to use a random function. Since the result of a random function does not include the maximum value, we will be able to use this kind of code later on in our application:

\begin{code}
blockType type = Random(BT_NUM);
\end{code}

So why is BT\_NUM not the last value in the list? Well, the last two values are special cases. There will be special squares to draw the background and the borders of the game. And the color of such a square is determined by the block type. Because we do not want to use those types in the actual game, BT \_NUM is but before these values.

A second enumeration is used to determine the possible directions in which a block can move. A block can not upwards, only to the left, the right, or down. Blocks which are already down, do not have a direction anymore.

\begin{code}
enum DIRECTION
{
   D_LEFT ,
   D_RIGHT,
   D_DOWN ,
   D_NONE ,
}
\end{code}


\section{Some real life uses of linear algebra}


  \documentclass[8pt,a4paper,landscape,oneside]{amsart}
\usepackage{amsmath, amsthm, amssymb, amsfonts}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{color}
\usepackage{fancyhdr}
\usepackage{float}
\usepackage{fullpage}
%\usepackage{geometry}
% \usepackage[top=0pt, bottom=1cm, left=0.3cm, right=0.3cm]{geometry}
\usepackage[top=3pt, bottom=1cm, left=0.3cm, right=0.3cm]{geometry}
\usepackage{graphicx}
% \usepackage{listings}
\usepackage{subcaption}
\usepackage[scaled]{beramono}
\usepackage{titling}
\usepackage{datetime}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{bookmark}

\newcommand{\subtitle}[1]{%
  \posttitle{%
    \par\end{center}
    \begin{center}\large#1\end{center}
    \vskip0.1em\vspace{-1em}}%
}

% Minted
\usepackage{minted}
\newcommand{\code}[1]{\inputminted[fontsize=\normalsize,baselinestretch=1]{cpp}{_code/#1}}
\newcommand{\bashcode}[1]{\inputminted{bash}{_code/#1}}
\newcommand{\regcode}[1]{\inputminted{cpp}{code/#1}}

% Header/Footer
% \geometry{includeheadfoot}
%\fancyhf{}
\pagestyle{fancy}
\lhead{Ateneo de Manila University}
\rhead{\thepage}
\cfoot{}
\setlength{\headheight}{15.2pt}
\setlength{\droptitle}{-20pt}
\posttitle{\par\end{center}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

% Math and bit operators
\DeclareMathOperator{\lcm}{lcm}
\newcommand*\BitAnd{\mathrel{\&}}
\newcommand*\BitOr{\mathrel{|}}
\newcommand*\ShiftLeft{\ll}
\newcommand*\ShiftRight{\gg}
\newcommand*\BitNeg{\ensuremath{\mathord{\sim}}}
\DeclareRobustCommand{\stirling}{\genfrac\{\}{0pt}{}}

\newenvironment{myitemize}
{ \begin{itemize}[leftmargin=.5cm]
    \setlength{\itemsep}{0pt}
    \setlength{\parskip}{0pt}
    \setlength{\parsep}{0pt}     }
{ \end{itemize}                  }

% Title/Author
\title{$AdMU Progvar$}
\subtitle{Team Notebook}
\date{\ddmmyyyydate{\today{}}}

% Output Verbosity
\newif\ifverbose
\verbosetrue
% \verbosefalse

\begin{document}

\begin{multicols*}{3}
\maketitle
\thispagestyle{fancy}
\vspace{-3em}
% \addtocontents{toc}{\protect\enlargethispage{\baselineskip}}
\tableofcontents

% \clearpage

\section{Code Templates}
	\code{header.cpp}
\section{Data Structures}
  \subsection{Union Find}
    \code{data-structures/union_find.cpp}
  \subsection{Fenwick Tree}
		\subsubsection{Fenwick Tree w/ Point Queries}
			\code{data-structures/fenwick.cpp}
    \subsubsection{Fenwick Tree w/ Max Queries}
      \code{data-structures/fenwick_max.cpp}
  \subsection{Segment Tree}
    \subsubsection{Recursive, Point-update Segment Tree}
      \code{data-structures/segtree_rec.cpp}
    \subsubsection{Iterative, Point-update Segment Tree}
      \code{data-structures/segtree_iter.cpp}
    \subsubsection{Pointer-based, Range-update Segment Tree}
      \code{data-structures/segtree_pointer_lazy.cpp}
    \subsubsection{Array-based, Range-update Segment Tree}
      \code{data-structures/segtree_array_lazy.cpp}
    \subsubsection{Persistent Segment Tree (Point-update)}
      \code{data-structures/segtree_persistent.cpp}
    \subsubsection{2D Segment Tree}
      \code{data-structures/segtree_2d.cpp}
  \subsection{Treap}
		\subsubsection{Explicit Treap}
		\subsubsection{Implicit Treap}
			\code{data-structures/treap_implicit.cpp}
		\subsubsection{Persistent Treap}
  \subsection{Splay Tree}
    \code{data-structures/splay.cpp}
	\subsection{Ordered Statistics Tree}
    \code{data-structures/ordered_statistics_tree.cpp}
	\subsection{Sparse Table}
    \subsubsection{1D Sparse Table}
      \code{data-structures/sparse.cpp}
    \subsubsection{2D Sparse Table}
      \code{data-structures/sparse_2d.cpp}
  \subsection{Misof Tree}
    A simple tree data structure for inserting, erasing, and querying the nth largest element.
    \code{data-structures/misof_tree.cpp}
\section{Graphs}
	Using adjacency list:
	\code{graphs/graph_template_adjlist.cpp}
	Using adjacency matrix:
	\code{graphs/graph_template_adjmat.cpp}
	Using edge list:
	\code{graphs/graph_template_edgelist.cpp}
	\subsection{Single-Source Shortest Paths}
		\subsubsection{Dijkstra}
			\code{graphs/shortest_paths/dijkstra.cpp}
		\subsubsection{Bellman-Ford}
			\code{graphs/shortest_paths/bellman_ford.cpp}
    \subsubsection{SPFA}
      \code{graphs/shortest_paths/spfa.cpp}
	\subsection{All-Pairs Shortest Paths}
		\subsubsection{Floyd-Washall}
			\code{graphs/shortest_paths/floyd_warshall.cpp}
	\subsection{Strongly Connected Components}
		\subsubsection{Kosaraju}
      \code{graphs/scc/kosaraju.cpp}
    \subsubsection{Tarjan's Offline Algorithm}
      \code{graphs/scc/tarjan.cpp}
  \subsection{Minimum Mean Weight Cycle}
    Run this for each strongly connected component
    \code{graphs/min_mean_cycle.cpp}
	\subsection{Cut Points and Bridges}
    \code{graphs/bridges_artics.cpp}
	\subsection{Biconnected Components}
		\subsubsection{Bridge Tree}
		\subsubsection{Block-Cut Tree}
	\subsection{Minimum Spanning Tree}
		\subsubsection{Kruskal}
      \code{graphs/mst/kruskal.cpp}
		\subsubsection{Prim}
      \code{graphs/mst/prim.cpp}
	\subsection{Euler Path/Cycle}
    \subsubsection{Euler Path/Cycle in a Directed Graph}
      \code{graphs/euler_path.cpp}
    \subsubsection(Euler Path/Cycle in an Undirected Graph)
      \code{graphs/euler_path_undirected.cpp}
	\subsection{Bipartite Matching}
		\subsubsection{Alternating Paths Algorithm}
      \code{graphs/bipartite_matching/bipartite_matching.cpp}
		\subsubsection{Hopcroft-Karp Algorithm}
      \code{graphs/bipartite_matching/hopcroft_karp.cpp}
    \subsubsection{Minimum Vertex Cover in Bipartite Graphs}
      \code{graphs/bipartite_matching/bipartite_mvc.cpp}
	\subsection{Maximum Flow}
		\subsubsection{Edmonds-Karp}
			\code{graphs/max_flow/edmonds_karp.cpp}
		\subsubsection{Dinic}
			\code{graphs/max_flow/dinic.cpp}
  \subsection{All-pairs Maximum Flow}
    \subsubsection{Gomory-Hu}
      \code{graphs/max_flow/gomory_hu_tree.cpp}
  \subsection{Minimum Arborescence}
    Given a weighted directed graph, finds a subset of edges of minimum
    total weight so that there is a unique path from the root $r$ to each
    vertex. Returns a vector of size $n$, where the $i$th element is the
    edge for the $i$th vertex. The answer for the root is undefined!
    \code{graphs/arborescence.cpp}
  \subsection{Blossom algorithm}
    Finds a maximum matching in an arbitrary graph in $O(|V|^4)$ time. Be
    vary of loop edges.
    \code{graphs/blossom.cpp}
  \subsection{Maximum Density Subgraph}
    Given (weighted) undirected graph $G$. Binary search density. If $g$ is
    current density, construct flow network: $(S, u, m)$, $(u, T,
    m+2g-d_u)$, $(u,v,1)$, where $m$ is a large constant (larger than sum
    of edge weights). Run floating-point max-flow. If minimum cut has empty
    $S$-component, then maximum density is smaller than $g$, otherwise it's
    larger. Distance between valid densities is at least $1/(n(n-1))$. Edge
    case when density is $0$. This also works for weighted graphs by
    replacing $d_u$ by the weighted degree, and doing more iterations (if
    weights are not integers).
  \subsection{Maximum-Weight Closure}
    Given a vertex-weighted directed graph $G$. Turn the graph into a flow
    network, adding weight $\infty$ to each edge. Add vertices $S,T$. For
    each vertex $v$ of weight $w$, add edge $(S,v,w)$ if $w\geq 0$, or edge
    $(v,T,-w)$ if $w<0$. Sum of positive weights minus minimum $S-T$ cut is
    the answer. Vertices reachable from $S$ are in the closure. The
    maximum-weight closure is the same as the complement of the
    minimum-weight closure on the graph with edges reversed.
  \subsection{Maximum Weighted Independent Set in a Bipartite Graph}
    This is the same as the minimum weighted vertex cover. Solve this by
    constructing a flow network with edges $(S,u,w(u))$ for $u\in L$,
    $(v,T,w(v))$ for $v\in R$ and $(u,v,\infty)$ for $(u,v)\in E$. The
    minimum $S,T$-cut is the answer. Vertices adjacent to a cut edge are
    in the vertex cover.
  \subsection{Synchronizing word problem}
    A DFA has a synchronizing word (an input sequence that moves all states
    to the same state) iff.\ each pair of states has a synchronizing word.
    That can be checked using reverse DFS over pairs of states. Finding the
    shortest synchronizing word is NP-complete.
  \subsection{Max flow with lower bounds on edges}
    % TODO: Test this!
    Change edge $(u,v,l\leq f\leq c)$ to $(u,v,f\leq c-l)$. Add edge
    $(t,s,\infty)$. Create super-nodes $S$, $T$. Let $M(u) = \sum_{v}
    l(v,u) - \sum_{v} l(u,v)$. If $M(u)<0$, add edge $(u,T,-M(u))$, else
    add edge $(S,u,M(u))$. Max flow from $S$ to $T$. If all edges from $S$
    are saturated, then we have a feasible flow. Continue running max flow
    from $s$ to $t$ in original graph.
    % TODO: Was there something similar for vertex capacities that we should add?
  \subsection{Tutte matrix for general matching}
    Create an $n\times n$ matrix $A$. For each edge $(i,j)$, $i<j$, let
    $A_{ij} = x_{ij}$ and $A_{ji} = -x_{ij}$. All other entries are $0$.
    The determinant of $A$ is zero iff.\ the graph has a perfect matching.
    A randomized algorithm uses the Schwartz--Zippel lemma to check if it is
    zero.
  \subsection{Heavy Light Decomposition}
    \code{graphs/heavy_light_decomposition.cpp}
	\subsection{Centroid Decomposition}
    \code{graphs/centroid_decomposition.cpp}
	\subsection{Least Common Ancestor}
		\subsubsection{Binary Lifting}
      \code{graphs/lca/binary_lifting.cpp}
  \subsection{Counting Spanning Trees}
    Kirchoff's Theorem: The number of spanning trees of any graph is the
    determinant of any cofactor of the Laplacian matrix in $O(n^3)$.
    \begin{enumerate}
        \item Let $A$ be the adjacency matrix.
        \item Let $D$ be the degree matrix (matrix with vertex degrees on the diagonal).
        \item Get $D-A$ and delete exactly one row and column. Any row and
        column will do. This will be the cofactor matrix.
        \item Get the determinant of this cofactor matrix using Gauss-Jordan.
        \item $\text{Spanning Trees} = \left|\mathrm{cofactor}(D-A) \right|$
    \end{enumerate}
  \subsection{Erd\H{o}s-Gallai Theorem}
    A sequence of non-negative integers $d_1 \ge \cdots \ge d_n$ can be represented as the
    degree sequence of finite simple graph on $n$ vertices if and only if $d_1 + \cdots + d_n$ is
    even and the following holds for $1 \le k \le n$:
    \[
    \sum_{i=1}^n d_i \le k(k-1) + \sum_{i=k+1}^n \min\left(d_i, k\right)
    \]
  \subsection{Tree Isomorphism}
    \code{graphs/tree_isomorphism.cpp}
\section{Strings}
  \subsection{Knuth-Morris-Pratt}
    Count and find all matches of string $f$ in string $s$ in $O(n)$ time.
    \code{strings/kmp.cpp}
  \subsection{Trie}
    \code{strings/trie.cpp}
  \subsection{Suffix Array}
    Construct a sorted catalog of all substrings of $s$ in $O(n \log n)$ time using counting sort.
    \code{strings/suffix-array.cpp}
  \subsection{Longest Common Prefix}
    Find the length of the longest common prefix for every substring in $O(n)$.
    \code{strings/lcp.cpp}
  \subsection{Aho-Corasick Trie}
    Find all multiple pattern matches in $O(n)$ time. This is KMP for multiple strings.
    \code{strings/aho-corasick-trie.java}
  \subsection{Palindromic Tree}
    Find lengths and frequencies of all palindromic substrings of a string in $O(n)$ time.

    Theorem: there can only be up to $n$ unique palindromic substrings for any string.
    \code{strings/palindromic-tree.cpp}
  \subsection{Z Algorithm}
    Find the longest common prefix of all substrings of $s$ with itself in $O(n)$ time.
    \code{strings/z.cpp}
  \subsection{Booth's Minimum String Rotation}
    Booth's Algo: Find the index of the lexicographically least string rotation in $O(n)$ time.
    \code{strings/booth.cpp}
	\subsection{Hashing}
    \subsubsection{Polynomial Hashing}
      \code{strings/polynomial_hashing.cpp}
\section{Number Theory}
	\subsection{Eratosthenes Prime Sieve}
    \code{numtheory/prime-sieve.cpp}
  \subsection{Divisor Sieve}
    \code{numtheory/divisor-sieve.cpp}
  \subsection{Number/Sum of Divisors}
    If a number $n$ is prime factorized where $n = {p_1}^{e_1} \times {p_2}^{e_2} \times \cdots \times {p_k}^{e_k}$, where $\sigma_0$ is the number of divisors while $\sigma_1$ is the sum of divisors:
    \[
    \sum_{d\mid n} d^k = \sigma_k (n) = \prod \frac{{p_i}^{k(e_i)+1}-1}{p_i -1}
    \]
    \[
    \text{Product: } \prod_{d\mid n} d = n^{\frac{\sigma_1 (n)}{2}}
    \]
  \subsection{M\"{o}bius Sieve}
    The M\"{o}bius function $\mu$ is the M\"{o}bius inverse of $e$ such that $e(n) = \sum_{d\mid n} \mu(d)$.
    \code{numtheory/moebius-sieve.cpp}
  \subsection{M\"{o}bius Inversion}
    Given arithmetic functions $f$ and $g$:
    \[
    g(n) = \sum_{d\mid n} f(d) \quad \Leftrightarrow \quad f(n) = \sum_{d\mid n} \mu(d)\; g\left(\frac{n}{d}\right)
    \]
  \subsection{GCD Subset Counting}
    Count number of subsets $S \subseteq A$ such that $\gcd(S) = g$ (modifiable).
    \code{numtheory/gcd-subsets.cpp}
  \subsection{Euler Totient}
    Counts all integers from 1 to $n$ that are relatively prime to $n$ in $O(\sqrt{n})$ time.
    \code{numtheory/totient.cpp}
  \subsection{Euler Phi Sieve}
    Sieve version of Euler totient, runs in $O(N \log N)$ time. Note that $n = \sum_{d\mid n} \varphi(d)$.
    \code{numtheory/phi-sieve.cpp}
  \subsection{Extended Euclidean}
    Assigns $x,y$ such that $ax + by = \gcd(a,b)$ and returns $\gcd(a,b)$.
    \code{numtheory/extended-euclidean.cpp}
  \subsection{Modular Exponentiation}
    Find $b^e \pmod m$ in $O(log e)$ time.
    \code{numtheory/mod_pow.cpp}
  \subsection{Modular Inverse}
    Find unique $x$ such that $ax \equiv 1 \pmod m$. Returns 0 if no unique solution is found. \underline{Please use modulo solver for the non-unique case.}
    \code{numtheory/modinv.cpp}
  \subsection{Modulo Solver}
    Solve for values of $x$ for $ax \equiv b \pmod m$. Returns $(-1,-1)$ if there is no solution. Returns a pair $(x, M)$ where solution is $x \bmod M$.
    \code{numtheory/modsolver.cpp}
  \subsection{Linear Diophantine}
    Computes integers $x$ and $y$ such that $ax+by=c$, returns $(-1,-1)$ if no solution. \underline{Tries to return positive integer answers for $x$ and $y$ if possible.}
    \code{numtheory/linear-diophantine.cpp}
  \subsection{Chinese Remainder Theorem}
    Solves linear congruence $x \equiv b_i \pmod {m_i}$. Returns $(-1,-1)$ if there is no solution. Returns a pair $(x, M)$ where solution is $x \bmod M$.
    \code{numtheory/chinese-remainder.cpp}
    \subsubsection{Super Chinese Remainder}
      Solves linear congruence $a_i x \equiv b_i \pmod {m_i}$. Returns $(-1,-1)$ if there is no solution.
      \code{numtheory/super-crt.cpp}
  \subsection{Primitive Root}
    \code{numtheory/primitive_root.cpp}
  \subsection{Josephus}
    Last man standing out of $n$ if every $kth$ is killed. Zero-based, and does not kill $0$ on first pass.
    \code{numtheory/josephus.cpp}
  \subsection{Number of Integer Points under a Lines}
    Count the number of integer solutions to $Ax+By \leq C$, $0 \leq x \leq n$,
    $0 \leq y$. In other words, evaluate the sum $\sum_{x=0}^n\left\lfloor\dfrac{C-Ax}{B}+1\right\rfloor$.
    To count all solutions, let $n = \left\lfloor\dfrac{c}{a}\right\rfloor$.
    In any case, it must hold that $C-nA \geq 0$. Be very careful about overflows.
\section{Algebra}
  \subsection{Fast Fourier Transform}
    Compute the Discrete Fourier Transform (DFT) of a polynomial in $O(n \log n)$ time.
    \code{algebra/fft.cpp}
  \subsection{FFT Polynomial Multiplication}
    Multiply integer polynomials $a, b$ of size $an, bn$ using FFT in $O(n \log n)$. Stores answer in an array $c$, rounded to the nearest integer (or double).
    \code{algebra/fft-poly-mul.cpp}
  \subsection{Number Theoretic Transform}
    Other possible moduli: $2 113 929 217 (2^{25}), 2 013 265 920 268 435 457 (2^{28}, with g = 5)$
    \code{algebra/ntt.cpp}
  \subsection{Polynomial Long Division}
    Divide two polynomials $A$ and $B$ to get $Q$ and $R$, where $\frac{A}{B} = Q + \frac{R}{B}$.
    \code{algebra/poly-long-div.cpp}
  \subsection{Matrix Multiplication}
    Multiplies matrices $A_{p\times q}$ and $B_{q\times r}$ in $O(n^3)$ time, modulo \texttt{MOD}.
    \code{algebra/matmul.java}
  \subsection{Matrix Power}
    Computes for $B^e$ in $O(n^3 \log e)$ time. Refer to Matrix Multiplication.
    \code{algebra/matpow.java}
  \subsection{Fibonacci Matrix}
    Fast computation for $n$th Fibonacci $\left\{F_1,F_2,\ldots,F_n \right\}$ in $O(\log n)$:
    \[
    \begin{bmatrix}
        F_n \\
        F_{n-1}
    \end{bmatrix}
    =
    \begin{bmatrix}
        1 & 1 \\
        1 & 0
    \end{bmatrix}^n
    \times
    \begin{bmatrix}
        F_2 \\
        F_1
    \end{bmatrix}
    \]
  \subsection{Gauss-Jordan/Matrix Determinant}
    Row reduce matrix $A$ in $O(n^3)$ time. Returns \texttt{true} if a solution exists.
    \code{algebra/gauss-jordan.java}
\section{Combinatorics}
  \subsection{Lucas Theorem}
    Compute $\binom{n}{k} \bmod{p}$ in $O(p + \log_p n)$ time, where $p$ is a prime.
    \code{combs/lucas.cpp}
  \subsection{Granville's Theorem}
    Compute $\binom{n}{k} \bmod{m}$ (for any $m$) in $O(m^2 \log^2 n)$ time.
    \code{combs/granville.py}
  \subsection{Derangements}
    Compute the number of permutations with $n$ elements such that no element is at their original position:
    \[
    D(n) = (n-1) \left( D(n-1) + D(n-2) \right) =  n D(n-1) + (-1)^n
    \]
    % \subsection{Next Permutation}
    % \subsection{Next Combination}
    % \subsection{Next Arrangement}
    % \subsection{Next Partition}
    \subsection{Factoradics}
    Convert a permutation of $n$ items to factoradics and vice versa in $O(n \log n)$.
    \code{combs/factoradics.cpp}
  \subsection{$k$th Permutation}
    Get the next $k$th permutation of $n$ items, if exists, using factoradics. All values should be from $0$ to $n-1$. Use factoradics methods as discussed above.
    \code{combs/kth-permutation.cpp}
  \subsection{Catalan Numbers}
    \[
        C_n = \frac{1}{n+1}\binom{2n}{n} =  \binom{2n}{n}-\binom{2n}{n+1}
    \]
    \begin{enumerate}
      \item The number of non-crossing partitions of an $n$-element set
      \item The number of expressions with $n$ pairs of parentheses
      \item The number of ways $n+1$ factors can be parenthesized
      \item The number of full binary trees with $n+1$ leaves
      \item The number of monotonic lattice paths of an $n \times n$ grid (5-SAT problem)
      \item The number of triangulations of a convex polygon with $n+2$ sides (non-rotational)
      \item The number of permutations $\{1, \ldots, n\}$ without a 3-term increasing subsequence
      \item The number of ways to form a mountain range with $n$ ups and $n$ downs
    \end{enumerate}
  \subsection{Stirling Numbers}
    $s_1$: Count the number of permutations of $n$ elements with $k$ disjoint cycles

    $s_2$: Count the ways to partition a set of $n$ elements into $k$ nonempty subsets
    \[
    s_1(n,k) = \begin{cases}
        1 & n = k = 0 \\
        s_1(n-1,k-1) - (n-1) s_1(n-1,k) & n,k>0 \\
        0 & \text{elsewhere}
    \end{cases}
    \]
    \[
    s_2(n,k) = \begin{cases}
        1 & n = k = 0 \\
        s_2(n-1,k-1) + k s_2(n-1,k) & n,k>0 \\
        0 & \text{elsewhere}
    \end{cases}
    \]
  \subsection{Partition Function}
    Pregenerate the number of partitions of positive integer $n$ with $n$ positive addends.
    \[
    p(n,k) = \begin{cases}
        1 & n = k = 0 \\
        0 & n < k \\
        p(n-1,k-1) + p(n-k,k) & n \ge k
    \end{cases}
    \]
\section{Geometry}
  \code{geom/compgeom.cpp}
	\subsection{Dots and Cross Products}
    \code{geom/dot-cross.cpp}
  \subsection{Angles and Rotations}
    \code{geom/angles-rots.cpp}
	\subsection{Spherical Coordinates}
    \[
        \begin{array}{cc}
            x = r \cos \theta \cos \phi & r = \sqrt{x^2 + y^2 + z^2} \\
            y = r \cos \theta \sin \phi & \theta = \cos^{-1} x/r \\
            z = r \sin \theta & \phi = \mathrm{atan2}(y,x)
        \end{array}
    \]
	\subsection{Point Projection}
    \code{geom/pt-proj.cpp}
	\subsection{Great Circle Distance}
    \code{geom/great-circle.cpp}
	\subsection{Point/Line/Plane Distances}
    \code{geom/dists.cpp}
	\subsection{Intersections}
    \subsubsection{Line-Segment Intersection}
      Get intersection points of 2D lines/segments $\overline{ab}$ and $\overline{cd}$.
      \code{geom/line-seg-isect.cpp}
    \subsubsection{Circle-Line Intersection}
      Get intersection points of circle at center $c$, radius $r$, and line $\overline{ab}$.
      \code{geom/circ-line-isect.cpp}
    \subsubsection{Circle-Circle Intersection}
      \code{geom/circ-circ-isect.cpp}
	\subsection{Polygon Areas}
    Find the area of any 2D polygon given as points in $O(n)$.
    \code{geom/poly-area.cpp}
    \subsubsection{Triangle Area}
      Find the area of a triangle using only their lengths. Lengths must be valid.
      \code{geom/tri-area.cpp}
    \subsubsection*{Cyclic Quadrilateral Area}
      Find the area of a cyclic quadrilateral using only their lengths. A quadrilateral is
      cyclic if its inner angles sum up to $360^\circ$.
      \code{geom/cyc-quad-area.cpp}
  \subsection{Polygon Centroid}
    Get the centroid/center of mass of a polygon in $O(m)$.
    \code{geom/poly-centroid.cpp}
  \subsection{Convex Hull}
    Get the convex hull of a set of points using Graham-Andrew's scan. This sorts the
    points at $O(n \log n)$, then performs the Monotonic Chain Algorithm at $O(n)$.
    \code{geom/convex-hull.cpp}
  \subsection{Point in Polygon}
    Check if a point is strictly inside (or on the border) of a polygon in $O(n)$.
    \code{geom/pt-in-poly.cpp}
  \subsection{Cut Polygon by a Line}
    Cut polygon by line $\overline{ab}$ to its left in $O(n)$, such that $\angle abp$ is counter-clockwise.
    \code{geom/cut-poly.cpp}
  \subsection{Triangle Centers}
    \code{geom/tri-centers.cpp}
  \subsection{Convex Polygon Intersection}
    Get the intersection of two convex polygons in $O(n^2)$.
    \code{geom/convex-poly-isect.cpp}
  \subsection{Pick's Theorem for Lattice Points}
    Count points with integer coordinates inside and on the boundary of a polygon in
    $O(n)$ using Pick's theorem: $\text{Area} = I + B/2 - 1$.
    \code{geom/picks.cpp}
  \subsection{Minimum Enclosing Circle}
    Get the minimum bounding ball that encloses a set of points (2D or 3D) in $\Theta{n}$.
    \code{geom/min-enclosing-circ.cpp}
  \subsection{Shamos Algorithm}
    Solve for the polygon diameter in $O(n \log n)$.
    \code{geom/shamos.cpp}
  \subsection{$k$D Tree}
    Get the $k$-nearest neighbors of a point within pruned radius in $O(k \log k \log n)$.
    \code{geom/kd-tree.cpp}
  \subsection{Line Sweep (Closest Pair)}
    Get the closest pair distance of a set of points in $O(n \log n)$ by sweeping a line and
    keeping a bounded rectangle. Modifiable for other metrics such as Minkowski and
    Manhattan distance. For external point queries, see $k$D Tree.
    \code{geom/closest-pair.cpp}
  \subsection{Line upper/lower envelope}
    To find the upper/lower envelope of a collection of lines $a_i+b_i x$,
    plot the points $(b_i,a_i)$, add the point $(0,\pm \infty)$ (depending
    on if upper/lower envelope is desired), and then find the convex hull.
  \subsection{Formulas}
    Let $a = (a_x, a_y)$ and $b = (b_x, b_y)$ be two-dimensional vectors.
    \begin{itemize}
      \item $a\cdot b = |a||b|\cos{\theta}$, where $\theta$ is the angle
        between $a$ and $b$.
      \item $a\times b = |a||b|\sin{\theta}$, where $\theta$ is the
        signed angle between $a$ and $b$.
      \item $a\times b$ is equal to the area of the parallelogram with
        two of its sides formed by $a$ and $b$. Half of that is the
        area of the triangle formed by $a$ and $b$.
      \item The line going through $a$ and $b$ is $Ax+By=C$ where $A=b_y-a_y$, $B=a_x-b_x$, $C=Aa_x+Ba_y$.
      \item Two lines $A_1x+B_1y=C_1$, $A_2x+B_2y=C_2$ are parallel iff.\ $D=A_1B_2-A_2B_1$ is zero. Otherwise their unique intersection is $(B_2C_1-B_1C_2,A_1C_2-A_2C_1)/D$.
      \item \textbf{Euler's formula:} $V - E + F = 2$
      \item Side lengths $a,b,c$ can form a triangle iff.\ $a+b>c$, $b+c>a$ and $a+c>b$.
      \item Sum of internal angles of a regular convex $n$-gon is $(n-2)\pi$.
      \item \textbf{Law of sines:} $\frac{a}{\sin A} = \frac{b}{\sin B} = \frac{c}{\sin C}$
      \item \textbf{Law of cosines:} $b^2 = a^2 + c^2 - 2ac\cos B$
      \item Internal tangents of circles $(c_1,r_1), (c_2,r_2)$ intersect at $(c_1r_2+c_2r_1)/(r_1+r_2)$, external intersect at $(c_1r_2-c_2r_1)/(r_1+r_2)$.
    \end{itemize}
\section{Other Algorithms}
  \subsection{2SAT}
    \ifverbose
    A fast 2SAT solver.
    \fi
    \code{other/two_sat.cpp}
  \subsection{DPLL Algorithm}
    A SAT solver that can solve a random 1000-variable SAT instance within a second.
    \code{other/dpll.cpp}
  \subsection{Dynamic Convex Hull Trick}
    \code{other/dynamic-ch-trick.cpp}
  \subsection{Stable Marriage}
    \ifverbose
    The Gale-Shapley algorithm for solving the stable marriage problem.
    \fi
    \code{other/stable_marriage.cpp}
  \subsection{Algorithm X}
    \ifverbose
    An implementation of Knuth's Algorithm X, using dancing links. Solves the Exact Cover problem.
    \fi
    \code{other/algorithm_x.cpp}
  \subsection{Matroid Intersection}
    Computes the maximum weight and cardinality intersection of two
    matroids, specified by implementing the required abstract methods, in
    $O(n^3(M_1+M_2))$.
    \code{other/matroid_intersection.cpp}
  \subsection{$n$th Permutation}
    \ifverbose
    A very fast algorithm for computing the $n$th permutation of the list
    $\{0,1,\ldots,k-1\}$.
    \fi
    \code{other/nth_permutation.cpp}
  \subsection{Cycle-Finding}
    \ifverbose
    An implementation of Floyd's Cycle-Finding algorithm.
    \fi
    \code{other/floyds_algorithm.cpp}
  \subsection{Longest Increasing Subsequence}
    \code{other/lis.cpp}
  \subsection{Dates}
    \ifverbose
    Functions to simplify date calculations.
    \fi
    \code{other/dates.cpp}
  \subsection{Simulated Annealing}
    An example use of Simulated Annealing to find a permutation of length $n$
    that maximizes $\sum_{i=1}^{n-1}|p_i - p_{i+1}|$.
    \code{other/simulated_annealing.cpp}
  \subsection{Simplex}
    \code{other/simplex.cpp}
  \subsection{Fast Square Testing}
    An optimized test for square integers.
    \code{tricks/is_square.cpp}
  \subsection{Fast Input Reading}
    If input or output is huge, sometimes it is beneficial to optimize the
    input reading/output writing. This can be achieved by reading all input
    in at once (using fread), and then parsing it manually. Output can also
    be stored in an output buffer and then dumped once in the end (using
    fwrite). A simpler, but still effective, way to achieve speed is to use
    the following input reading method.
    \code{tricks/fast_input.cpp}
  \subsection{128-bit Integer}
    GCC has a 128-bit integer data type named \texttt{\_\_int128}. Useful
    if doing multiplication of 64-bit integers, or something needing a
    little more than 64-bits to represent. There's also
    \texttt{\_\_float128}.
  \subsection{Bit Hacks}
    \code{tricks/snoob.cpp}
\newpage
\section{Other Combinatorics Stuff}
  \begin{tabular}{@{}l|l|l@{}}
  \toprule
  Catalan	&	$C_0=1$, $C_n=\frac{1}{n+1}\binom{2n}{n} = \sum_{i=0}^{n-1}C_iC_{n-i-1} = \frac{4n-2}{n+1}C_{n-1}$  & \\
  Stirling 1st kind & $\left[{0\atop 0}\right]=1$, $\left[{n\atop 0}\right]=\left[{0\atop n}\right]=0$, $\left[{n\atop k}\right]=(n-1)\left[{n-1\atop k}\right]+\left[{n-1\atop k-1}\right]$ & \#perms of $n$ objs with exactly $k$ cycles\\
  Stirling 2nd kind & $\left\{{n\atop 1}\right\}=\left\{{n\atop n}\right\}=1$, $\left\{{n\atop k}\right\} = k \left\{{ n-1 \atop k }\right\} + \left\{{n-1\atop k-1}\right\}$ & \#ways to partition $n$ objs into $k$ nonempty sets\\
  Euler	& $\left \langle {n\atop 0} \right \rangle = \left \langle {n\atop n-1} \right \rangle = 1 $, $\left \langle {n\atop k} \right \rangle = (k+1) \left \langle {n-1\atop {k}} \right \rangle + (n-k)\left \langle {{n-1}\atop {k-1}} \right \rangle$ & \#perms of $n$ objs with exactly $k$ ascents \\
  Euler 2nd Order &  $\left \langle \!\!\left \langle {n\atop k} \right \rangle \!\! \right \rangle = (k+1) \left \langle \!\! \left \langle {{n-1}\atop {k}} \right \rangle \!\! \right \rangle +(2n-k-1)\left \langle \!\! \left \langle {{n-1}\atop {k-1}} \right \rangle  \!\! \right \rangle$ & \#perms of ${1,1,2,2,...,n,n}$ with exactly $k$ ascents \\
  Bell & $B_1 = 1$, $B_n = \sum_{k=0}^{n-1} B_k \binom{n-1}{k} = \sum_{k=0}^n\left\{{n\atop k}\right\}$ & \#partitions of $1..n$ (Stirling 2nd, no limit on k)\\
  \bottomrule
  \end{tabular}

  \vspace{10pt}
  \begin{tabular}{ll}
    \#labeled rooted trees & $n^{n-1}$ \\
    \#labeled unrooted trees & $n^{n-2}$ \\
    \#forests of $k$ rooted trees & $\frac{k}{n}\binom{n}{k}n^{n-k}$ \\
    % Kirchoff's theorem
    $\sum_{i=1}^n i^2 = n(n+1)(2n+1)/6$ & $\sum_{i=1}^n i^3 = n^2(n+1)^2/4$ \\
    $!n = n\times!(n-1)+(-1)^n$ & $!n = (n-1)(!(n-1)+!(n-2))$ \\
    $\sum_{i=1}^n \binom{n}{i} F_i = F_{2n}$ & $\sum_{i} \binom{n-i}{i} = F_{n+1}$ \\
    $\sum_{k=0}^n \binom{k}{m} = \binom{n+1}{m+1}$ & $x^k = \sum_{i=0}^k i!\stirling{k}{i}\binom{x}{i} = \sum_{i=0}^k \left\langle {k \atop i} \right\rangle\binom{x+i}{k}$ \\

    $a\equiv b\pmod{x,y} \Rightarrow a\equiv b\pmod{\lcm(x,y)}$ & $\sum_{d|n} \phi(d) = n$ \\
    $ac\equiv bc\pmod{m} \Rightarrow a\equiv b\pmod{\frac{m}{\gcd(c,m)}}$ & $(\sum_{d|n} \sigma_0(d))^2 = \sum_{d|n} \sigma_0(d)^3$ \\
    $p$ prime $\Leftrightarrow (p-1)!\equiv -1\pmod{p}$ & $\gcd(n^a-1,n^b-1) = n^{\gcd(a,b)}-1$ \\
    $\sigma_x(n) = \prod_{i=0}^{r} \frac{p_i^{(a_i + 1)x} - 1}{p_i^x - 1}$ & $\sigma_0(n) = \prod_{i=0}^r (a_i + 1)$ \\
    $\sum_{k=0}^m (-1)^k \binom{n}{k} = (-1)^m \binom{n-1}{m}$ & \\
    $2^{\omega(n)} = O(\sqrt{n})$ & $\sum_{i=1}^n 2^{\omega(i)} = O(n \log n)$ \\
    % Kinematic equations
    $d = v_i t + \frac{1}{2}at^2$ & $v_f^2 = v_i^2 + 2ad$ \\
    $v_f = v_i + at$ & $d = \frac{v_i + v_f}{2}t$ \\
  \end{tabular}
  \subsection{The Twelvefold Way}
    Putting $n$ balls into $k$ boxes.\\
  \begin{tabular}{@{}c|c|c|c|c|l@{}}
  Balls & same & distinct & same & distinct & \\
  Boxes & same & same & distinct & distinct & Remarks\\
  \hline
    - & $\mathrm{p}_k(n)$ & $\sum_{i=0}^k \stirling{n}{i}$ & $\binom{n+k-1}{k-1}$ & $k^n$ & $\mathrm{p}_k(n)$: \#partitions of $n$ into $\le k$ positive parts \\
    $\mathrm{size}\ge 1$ & $\mathrm{p}(n,k)$ & $\stirling{n}{k}$ & $\binom{n-1}{k-1}$ & $k!\stirling{n}{k}$ & $\mathrm{p}(n,k)$: \#partitions of $n$ into $k$ positive parts \\
    $\mathrm{size}\le 1$ & $[n \le k]$ & $[n \le k]$ & $\binom{k}{n}$ & $n!\binom{k}{n}$ & $[cond]$: $1$ if $cond=true$, else $0$\\
  \bottomrule
  \end{tabular}

\clearpage

\input{useful_info}

\end{multicols*}

\end{document}


%        File: symmetries-and-polynomials-notes.tex
%     Created: Thu May 17 10:00 AM 2018 P
% Last Change: Thu May 17 10:00 AM 2018 P
%
%%%%%%%%%%%%%%%%%%%%%
%   AMS packages    %
%%%%%%%%%%%%%%%%%%%%%
% \documentclass[12 pt, reqno]{amsart}

\documentclass[reqno, 12pt, letter]{article}
\usepackage[margin=1in]{geometry}
\usepackage{mdframed}

\usepackage{hyperref}
\usepackage{etex}
\usepackage[shortlabels]{enumitem}
\usepackage{amsmath}
\usepackage{amsxtra}
\usepackage{amscd}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{eucal}
\usepackage[all]{xy}
\usepackage{graphicx}
\usepackage{tikz-cd}
\usepackage{mathrsfs}
\usepackage{subfiles}
\usepackage{mathpazo}
%\usepackage{euler}
\usepackage[colorinlistoftodos, textsize=tiny]{todonotes}
\usepackage{float}
\usepackage{morefloats}
\usepackage{pdfpages}
\usepackage{thm-restate}
\usepackage[utf8]{inputenc}
\usepackage{epigraph}
\usepackage{csquotes}
\usepackage{gensymb}
% \usepackage[margin=1.5in]{geometry}

\graphicspath{ {images/} }

\RequirePackage{color}
\definecolor{myred}{rgb}{0.75,0,0}
\definecolor{mygreen}{rgb}{0,0.5,0}
\definecolor{myblue}{rgb}{0,0,0.65}

\usepackage{hyperref}
\hypersetup{citecolor=blue}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{counterexample}[theorem]{Counterexample}
\newtheorem{convention}[theorem]{Convention}
\newtheorem{question}[theorem]{Question}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{goal}[theorem]{Goal}
\newtheorem{warn}[theorem]{Warning}
\newtheorem{fact}[theorem]{Fact}
\theoremstyle{remark}
\newtheorem{notation}[theorem]{Notation}
\numberwithin{equation}{section}

\newcommand\nc{\newcommand}
\nc\on{\operatorname}
\nc\renc{\renewcommand}
\newcommand\se{\section}
\newcommand\ssec{\subsection}
\newcommand\sssec{\subsubsection}
\newcommand\bn{{\mathbb N}}
\newcommand\bc{{\mathbb C}}
\newcommand\br{{\mathbb R}}
\newcommand\bq{{\mathbb Q}}
\newcommand\bp{{\mathbb P}}
\newcommand\CF{{\mathscr F}}
\newcommand\bz{{\mathbb Z}}
\newcommand\ba{{\mathbb A}}
\newcommand\bg{{\mathbb G}}
\newcommand\fa{{\mathfrak a}}
\newcommand\fp{{\mathfrak p}}
\newcommand\fq{{\mathfrak q}}
\newcommand\fm{{\mathfrak m}}
\newcommand\fg{{\mathfrak g}}
\newcommand\fh{{\mathfrak h}}
\newcommand\fgl{{\mathfrak {gl}}}
\newcommand\fsu{{\mathfrak {su}}}
\newcommand\fsl{{\mathfrak {sl}}}
\newcommand\fso{{\mathfrak {so}}}
\newcommand\fo{{\mathfrak {o}}}
\newcommand\fu{{\mathfrak {u}}}
\newcommand\fsp{{\mathfrak {sp}}}
\newcommand\fgsp{{\mathfrak {gsp}}}

\newcommand\sca{\mathscr A}
\newcommand\scb{\mathscr B}
\newcommand\scc{\mathscr C}
\newcommand\scd{\mathscr D}
\newcommand\sce{\mathscr E}
\newcommand\scf{\mathscr F}
\newcommand\scg{\mathscr G}
\newcommand\sch{\mathscr H}
\newcommand\sci{\mathscr I}
\newcommand\scj{\mathscr J}
\newcommand\sck{\mathscr K}
\newcommand\scl{\mathscr L}
\newcommand\scm{\mathscr M}
\newcommand\scn{\mathscr N}
\newcommand\sco{\mathscr O}
\newcommand\scp{\mathscr P}
\newcommand\scq{\mathscr Q}
\newcommand\scs{\mathscr S}
\newcommand\sct{\mathscr T}
\newcommand\scu{\mathscr U}
\newcommand\scv{\mathscr V}
\newcommand\scw{\mathscr W}
\newcommand\scx{\mathscr X}
\newcommand\scy{\mathscr Y}
\newcommand\scz{\mathscr Z}

\newcommand \ra{\rightarrow}
\newcommand \xra{\xrightarrow}
\DeclareMathOperator\spec{\text{Spec }}
\DeclareMathOperator\proj{\text{Proj }}
\DeclareMathOperator\rspec{\textit{Spec }}
\DeclareMathOperator\rproj{\textit{Proj }}
\newcommand*{\shom}{\mathscr{H}\kern -.5pt om}
\newcommand*{\stor}{\mathscr{T}\kern -.5pt or}
\newcommand*{\sext}{\mathscr{E}\kern -.5pt xt}
\newcommand \mg{{\mathscr M_g}}

\makeatletter
\newcommand{\customlabel}[2]{\protected@write \@auxout {}{\string \newlabel {#1}{{#2}{\thepage}{#2}{#1}{}} }\hypertarget{#1}{#2}}
\newcommand\sh[1]{\sco_{#1}^{\rm{sh}}}
\DeclareMathOperator\id{id}
\DeclareMathOperator\tor{Tor}
\renewcommand\hom{Hom}
\DeclareMathOperator\coker{coker}
\DeclareMathOperator\ord{ord}
\DeclareMathOperator\hilb{Hilb}
\DeclareMathOperator\rk{rk}
\DeclareMathOperator\di{div}
\DeclareMathOperator\pic{Pic}
\DeclareMathOperator\lcm{lcm}
\DeclareMathOperator\rank{rank}
\DeclareMathOperator\codim{codim}
\DeclareMathOperator\vol{Vol}
\DeclareMathOperator\supp{Supp}
\DeclareMathOperator\spn{Span}
\DeclareMathOperator\im{im}
\DeclareMathOperator\End{End}
\DeclareMathOperator\sym{Sym}
\DeclareMathOperator\pgl{PGL}
\DeclareMathOperator\sat{Sat}
\DeclareMathOperator\blow{Bl}
\renewcommand\sp{\mathrm{Sp}}
\DeclareMathOperator\gsp{GSp}
\DeclareMathOperator\sgn{sgn}
\DeclareMathOperator\gal{gal}
\DeclareMathOperator\tr{tr}
\renewcommand\char{char}
\newcommand\bbf{{\mathbb F}}
\newcommand\bk{{\Bbbk}}
\newcommand\ul{\underline}
\newcommand\ol{\overline}
\DeclareMathOperator\pr{pr}
\DeclareMathOperator\ev{ev}
\DeclareMathOperator\maj{maj}
\DeclareMathOperator\inv{inv}
\DeclareMathOperator\isom{isom}
\DeclareMathOperator\mor{mor}
\DeclareMathOperator\aut{Aut}
\DeclareMathOperator\gl{GL}
\renewcommand\sl{\mathrm{SL}}
\DeclareMathOperator\mat{Mat}
\DeclareMathOperator\stab{Stab}
\DeclareMathOperator\so{SO}
\DeclareMathOperator\su{SU}
\renewcommand\u{\mathrm{U}}
\DeclareMathOperator\lie{Lie}
\DeclareMathOperator\ad{ad}
\DeclareMathOperator\Ad{Ad}
\renewcommand\o{{\rm{O}}}

\renewcommand{\thefootnote}{\fnsymbol{footnote}}
%\newcommand{\hint}[1]{\footnote{\raggedleft\rotatebox{180}{\tiny{{Hint:} #1\hfill}}}}
\newcommand{\hint}[1]{\footnote{{Hint:} #1\hfill}}

\setcounter{MaxMatrixCols}{20}

\def\listtodoname{List of Todos}
\def\listoftodos{\@starttoc{tdo}\listtodoname}

\usepackage{endnotes}

\let\footnote=\endnote

\title{Symmetries and Polynomials}
\author{Aaron Landesman and Apurva Nakade}

\usepackage{microtype}
\begin{document}

\maketitle

\section*{Introduction}
In this class we'll learn how to solve a cubic. We'll also sketch how to solve a quartic. We'll explore the connections between these solutions and group theory.
Towards the end, we'll hint towards the deep connection between polynomials and groups via Galois Theory. This connection allows one to convert the classical question of whether a general quintic can be solved by radicals to a group theory problem, which can be relatively easily answered.

The 5 day outline is as follows:
\begin{enumerate}
	\item The first two days are dedicated to studying polynomials. On the first day, we'll study a simple invariant associated to every polynomial, the discriminant.
	\item On the second day, we'll solve the cubic equation by a method motivated by Galois theory.
	\item Days $3$ and $4$ are a ``practical'' introduction to group theory. On day $3$ we'll learn about groups as symmetries of geometric objects.
	\item On day $4$, we'll learn about the commutator subgroup of a group.
	\item Finally, on the last day we'll connect the two theories and explain the Galois correspondence for the cubic and the quartic.
\end{enumerate}
There are plenty of optional problems along the way for those who wish to explore more.
Tricky optional problems are marked with $*$, and especially tricky optional problems are marked with $**$.

\newpage
\section{The Discriminant}
Today we'll introduce the discriminant of a polynomial. The discriminant of a polynomial $P$ is another polynomial $Q$ which tells you
whether $P$ has any repeated roots over $\bc$.
Here, $\bc$ denotes the complex numbers.

\subsection{Quadratic Polynomials}
\begin{definition}[Quadratic discriminant]
	\label{definition:quadratic-discriminant}
	Let $P(x) = x^2 + bx + c$ be a polynomial with $b$ and $c$ real numbers.
	The discriminant $\Delta(P)$ is by definition $b^2 - 4c$.
\end{definition}
\begin{exercise}
	\label{exercise:}
	If the polynomial $P(x) = x^2 + bx + c$ has roots $\alpha$ and $\beta$, express $b$ and $c$
	in terms of $\alpha$ and $\beta$.
\end{exercise}
\begin{exercise}
	\label{exercise:quadratic-roots}
	Still assuming the polynomial $P$ has real coefficients,
	what does the sign of the discriminant (i.e., whether $\Delta(P) > 0, < 0$ or $=0$)
	tell you about the roots $\alpha$ and $\beta$?
	\footnote{{\it Hint:} If the discriminant is $>0$ show that the roots are real, if it is equal
		to $0$, show they are the same, if it is less than $0$, show they are complex numbers
		which are not real.}
\end{exercise}
\begin{exercise}
	\label{exercise:quadratic-discriminant-in-roots}
	Express the discriminant of the polynomial $P(x) = x^2 + bx + c$ in terms of
	the roots $\alpha$ and $\beta$.
\end{exercise}

\subsection{The discriminant in general}
\begin{definition}
	\label{definition:discriminant}
	For $P(x)$ a polynomial of the form $P(x) = (x-r_1)(x-r_2) \cdots (x-r_n)$,
	define the discriminant $\Delta(P) := \prod_{1 \leq i < j \leq n} (r_i - r_j)^2$.
\end{definition}
\begin{exercise}
	\label{exercise:}
	Verify that for $P(x)$ of degree $2$, the definition of the discriminant
	of a general polynomial from \autoref{definition:discriminant} agrees with
	that of a quadratic polynomial given in \autoref{definition:quadratic-discriminant}.
	\footnote{{\it Hint:} Use \autoref{exercise:quadratic-discriminant-in-roots}.}
\end{exercise}
\begin{exercise}
	\label{exercise:discriminant-vanishing}
	Show that for $P$ a polynomial, $\Delta(P) = 0$ if and only if $P$ has a repeated root over $\bc$.
\end{exercise}
\subsection{Cubic discriminants}
\begin{exercise}
	\label{exercise:real-root-cubic}
	Show that a cubic polynomial $P(x) := x^3 + ax + bx + c$
	with real coefficients 	always has a real root.
	\footnote{{\it Hint:} Graph the cubic and show it intersects the line $P(x) = 0$.}
\end{exercise}
\begin{exercise}
	\label{exercise:}
	Using \autoref{exercise:real-root-cubic}, show that a cubic polynomial either has
	\begin{enumerate}
		\item $3$ real roots or
		\item $2$ complex conjugates roots (of the form $a + bi, a-bi$ for $a,b$ real numbers) and one real root.
		      \footnote{{\it Hint:} Factor out the real root, and use your understanding of quadratic polynomials.}
	\end{enumerate}
\end{exercise}
\begin{exercise}
	\label{exercise:discriminant-cubic-sign}
	For $P(x) = x^3 + ax^2 + bx + c$ a cubic polynomial with real coefficients, show $\Delta(P) = 0$ if and only
	if there is a repeated root over $\bc$, $\Delta(P) > 0$ if and only if $P$ has three distinct real roots, and $\Delta(P) < 0$ if and only if $P$ has two complex conjugate roots and one real root.
	Compare your answer to \autoref{exercise:quadratic-roots}.
\end{exercise}

{\it Your homework is to complete up through \autoref{exercise:discriminant-cubic-sign}. If you finish that, and still have time try the following questions.}

\subsection{Further optional questions on discriminants}

\begin{exercise}[Optional 1]
	\label{exercise:cubic-discriminant}
	An amazing fact about the discriminant is that it can always be written as a polynomial in terms of the coefficients. For the quadratic this was shown in \autoref{definition:quadratic-discriminant} and \autoref{exercise:quadratic-discriminant-in-roots}. Now let's see this for a \textbf{depressed cubic} (i.e. a cubic with coefficient of $ x^2$ equal to $0$). Consider the cubic
	\begin{align*}
		P(x) & = x^3 + px + q.
	\end{align*}
	Assume that not all three roots are the same.
	\begin{enumerate}
		\item By definition, the {\bf critical points} of $P(x)$
		      %	(the points at which $ P(x)$ attains its local max/min if at all)
		      are roots of $P'(x) = 3x^2 + p$. Find the critical points of $ P(x)$, and call them $ x_1, x_2$.
		\item Show that $ P(x_1) \cdot P(x_2) = 4(p/3)^3 + q^2$.
		\item Argue that $ P(x)$ has a repeated root over $\bc$ if and only if $ P(x_1) \cdot P(x_2) = 0$.
	\end{enumerate}
	\begin{remark}
		This is very close to the statement that $\Delta(P) = 0$ iff $P(x)$ has a repeated root, which is not coincidental. By a direct computation one can show that the discriminant of the cubic $ P(x)$ equals
		\begin{align*}
			\Delta(P) = -27P(x_1) \cdot P(x_2) = -4p^3 - 27q^2
		\end{align*}
	\end{remark}
\end{exercise}

\subsection{Counting polynomials of discriminant $0$}
The following questions are quite tricky, but fun. Only attempt them if you've already solved \autoref{exercise:cubic-discriminant}.
\begin{exercise}[Optional 2]**
	\label{exercise:repeated-roots}
	Let $P(x) = x^n + a_{n-1}x^{n-1} + \cdots + a_0$, where now the coefficients $a_i$ are
	in $\bz/p$ (i.e., take on values between $0$ and $p-1$), and the discriminant is
	also considered as a number in $\bz/p$. To make sense of discriminant, you may assume that
	every such polynomial factors uniquely as a product of irreducible polynomials with coefficients in $\bz/p$.
	Show there are $p^n$ such polynomials, and exactly
	$p^{n-1}$ of them have discriminant $0$.
	Conclude that the number of square-free polynomials of degree $n$ over $\bz/p$ is $p^n - p^{n-1}$.
	\footnote{{\it Hint:}
		You may assume that every such polynomial $p(x)$ can be written uniquely
		as $f(x)g(x)^2$,
		where $f(x)$ is square-free. (Here, $f$ and $g$ are polynomials with $\bz/p$ coefficients.)
		Then count the number of such polynomials with $\deg f = k$ by induction on $k$.}
\end{exercise}

\begin{exercise}[Optional 3]**
	\label{exercise:common-roots}
	Using a similar method to that of \autoref{exercise:repeated-roots},
	count the number of pairs of degree $n$ polynomials $(P,Q)$ for
	$P(x) = x^n + a_{n-1}x^{n-1} + \cdots + a_0$ and $Q(x) = x^n + b_{n-1}x^{n-1} + \cdots + b_0$
	with $a_i \in \bz/p, b_i \in \bz/p$ so that $P$ and $Q$ have no common irreducible factor.
	\hint{Use a method similar to that of \autoref{exercise:repeated-roots}.
As a further hint,
show that every pair of degree $n$ polynomials $(P,Q)$ can be written uniquely
as $(f \cdot p, f \cdot q)$ where $p$ and $q$ have no common factors.
Now count the number of such pairs by induction on the degree of $f$.}
\end{exercise}
\begin{remark}
	\label{remark:}
	If you did the two prior exercises \autoref{exercise:repeated-roots} and \autoref{exercise:common-roots} correctly, you may notice a striking similarity
	between the two answers. There is indeed a deeper connection, but the answer lies deep.
	Loosely speaking, if you take a polynomial $P(x)$ with no repeated factors, you can send it
	to the pair of polynomials $(P(x) + P'(x), P(x))$. Here $P'(x)$ denotes the derivative of $P(x)$.
	If $P(x) = \sum_i a_ix^i$ then $P'(x) = \sum_i  i \cdot a_i x^{i-1}$.
	\begin{exercise}
		\label{exercise:}
		Verify that the above indeed defines a map
		from the space of polynomials with no repeated factors to the
		space of pairs of polynomials with no common factors.
	\end{exercise}

	In some sense (which we do not explain) this map explains why the counts from
	\autoref{exercise:repeated-roots} and \autoref{exercise:common-roots} are so similar.
\end{remark}

\newpage
\section{Solving the Cubic}
In this section, we will discover a method to solve the cubic, motivated by Galois theory.

We'll continue working with with the \emph{depressed} cubic (the coefficient of $x^2$ is $0$)
\begin{align*}
	P(x) = x^3 + px + q
 \end{align*}
with roots $ r_1, r_2, r_3$ and come back to the more general case later.

\begin{exercise}
	\label{exercise:coefficients_depressed_cubic}
	Express the coefficients of $P(x)$ (namely $ 0,p$, and $q$) in terms of $ r_1, r_2, r_3$.
\end{exercise}

\begin{exercise}
	\label{exercise:cube_roots_of_unity}
	We need some identities about the \emph{cube roots of unity} before proceeding.
	\begin{enumerate}
		\item Find the three roots of the polynomial $ x^3 - 1$ over the complex numbers.
		\item Show that if $ \omega $ is a non-real root of $x^3 -1$ then the other non-real root is $ \omega^2$. Conclude that $ \overline{\omega} = \omega^2$.
		      The complex numbers $\omega, \omega^2,$ and $1$ are called the \textbf{cube roots of unity}.
		\item Compute $ \omega + \omega^2$.
		\item Plot $ \omega$, $\omega^2$ on the complex plane.
	\end{enumerate}
\end{exercise}
The method for solving the cubic is somewhat like induction. We reduce the problem of solving the cubic to that of solving a quadratic. For this we need to find \emph{intermediate constants} which satisfy a known {quadratic} and from which $r_1,r_2,r_3$ can be easily recovered. To this end we define
\begin{align}
	\label{equation:intermediate_variables_cubic}
	\begin{split}
		\mu_1 &:= r_1 + r_2 \omega + r_3 \omega^2 \\
		\mu_2 &:= r_1 + r_2 \omega^2 + r_3 \omega
	\end{split}
\end{align}
Our \emph{intermediate constants} are not $ \mu_1$ and $ \mu_2$ but $ \mu_1^3$ and $ \mu_2^3$.

\begin{exercise}
	Verify that
	\begin{align}
		\label{equation:intermediate_variables_cubic_1}
		r_1 = \dfrac{\mu_1 + \mu_2}{3}
		\mbox { , } r_2 = \dfrac{\omega^2 \mu_1 + \omega \mu_2}{3}
		\mbox { , } r_3 = \dfrac{\omega \mu_1 + \omega^2 \mu_2}{3}
	\end{align}
	are the solutions to Equations \eqref{equation:intermediate_variables_cubic} and $ r_1 + r_2 + r_3 = 0$.
	%(These are in fact unique solutions.)
\end{exercise}

\begin{exercise}
	\label{exercise:intermediate_variables_cubic_2}
	$ $
	\begin{enumerate}
		\item Show that $27r_1 r_2  r_3 = \mu_1^3 + \mu_2^3$. Express this in terms of $p$ and $q$.\hint{Compute $r_2 r_3$ first.}
		\item Show that $ \mu_1 \mu_2 = -3p$.\hint{Don't forget that $ (r_1 + r_2 + r_3)^2 = 0$.}
		\item Conclude that $ \mu_1^3, \mu_2^3$ are the roots of the quadratic $ x^2 + 27qx - 27p^3$. Solve it to find $ \mu_1^3, \mu_2^3$.
		\item Verify that the discriminant of this quadratic is a multiple of the discriminant $\Delta(P) = -4p^3 - 27q^2$ of the original cubic $ P(x)$.
	\end{enumerate}
\end{exercise}

\begin{mdframed}
	With all this work done, here's the algorithm for finding the roots of a depressed cubic $ x^3 + px + q$:
	\begin{enumerate}
		\item Find $ \mu_1^3$ and $ \mu_2^3$ by solving the quadratic $x^2 + 27qx - 27p^3$.
		\item This does not determine $ \mu_1$ and $ \mu_2$ uniquely. Pick $ \mu_1$ as any of the three \emph{cube roots} of $ \mu_1^3$ and use $ \mu_1 \mu_2 = -3p$ to find $ \mu_2$.
		\item Use Equations \eqref{equation:intermediate_variables_cubic_1} to find $ r_1, r_2, r_3$.
	\end{enumerate}
\end{mdframed}
\begin{exercise} $ $
	\label{exercise:cubic_formula}
	\begin{enumerate}
		\item Use this method to find the roots of $x^3 - 3x + 2$.
		\item Find a general formula for the roots of $x^3 + px + q$.
	\end{enumerate}
\end{exercise}

\begin{remark}[The idea for solving the quartic]
	\label{remark:solving_the_quartic}
	A similar inductive technique works for the quartic, however the method is too tedious to do by hand. Suppose we're trying to find the roots $ r_1, r_2, r_3, r_4$ of a quartic \begin{align*}
		P(x) & = x^4 + a_3x^3 + a_2x^2 + a_1x + a_0
	\end{align*}
	then the strategy is to find 3 {intermediate constants} $ \lambda_1, \lambda_2, \lambda_3$ such that
	\begin{enumerate}
		\item they satisfy a cubic polynomial whose coefficients can be obtained from the original coefficients and
		\item the roots $r_i$ can recovered from the $ \lambda_i$ ``easily.''		\end{enumerate}
	Such variables indeed exist:
	\begin{align}
		\label{equation:intermediate_variables_quartic}
		\begin{split}
			\lambda_1 &:= r_1 r_2 + r_3 r_4 \\
			\lambda_2 &:= r_1 r_3 + r_2 r_4 \\
			\lambda_3 &:= r_2 r_3 + r_1 r_4.
		\end{split}
	\end{align}

	{\it Your homework is to complete up through \autoref{exercise:cubic_formula} and read \autoref{remark:solving_the_quartic}. If you finish that, and still have time try the following questions.}
	\subsection{Further optional questions}

	\begin{exercise}[Optional 2]
		If our cubic is not depressed to begin with we can make a change of variable and make it one.
		\begin{enumerate}
			\item Show that if $f(x) = x^3 + ax^2 +bx +c$ is a cubic polynomial with real coefficients, one can apply a change of variables of the form $y = x + \alpha$ (for $\alpha \in \br$) so that $f(y) = y^3 + py + q$.
			\item Express $\alpha, p, q$ explicitly in terms of $a,b,c$.
		\end{enumerate}
		This problem finally provides a complete algorithm for a general cubic.
	\end{exercise}

	\begin{exercise}[Optional 2]
		Retain the notation from \autoref{remark:solving_the_quartic}.
		Here's how you recover the $ r_i$ from the $ \lambda_i$.
		\begin{enumerate}
			\item Show that $ r_1 r_2$ and $r_3 r_4$ are the roots of $ x^2 - \lambda_1 x + a_0$. This gives us all the $ r_i r_j$.
			\item Figure out a way to recover $ r_i$ if you know all the $ r_i r_j$.
		\end{enumerate}
	\end{exercise}
	We'll later see why the $ \lambda_i$ satisfy a cubic with coefficients which can be written in terms of the $ a_i$.
\end{remark}

\subsection{Roots of Unity}

Solutions of the polynomial equation $ x^n = 1$ are called \textbf{$n^{th}$ roots of unity}, where $ n$ is a positive integer. An $ n^{th}$ root of unity is called \textbf{primitive} if it not an $ m^{th}$ root of unity for any $ m < n$.

\begin{exercise}[Optional 3] $ $
	\begin{enumerate}
		\item Show that the $ n^{th}$ roots of unity are $ e^{2 \pi i k / n}$ where $ 0 \le k < n$ is a positive integer. Plot them on the complex plane.
		\item Show that there are exactly $ \phi(n)$ primitive $ n^{th}$ roots of unity, where $ \phi(n)$ is the number of positive integers less than $ n$ relatively prime to $n$.
	\end{enumerate}
	If $ \zeta_1, \dots, \zeta_k$ are all the primitive $ n^{th}$ roots of unity then the polynomial
	\begin{align*}
		\Phi_n(x) := \prod _{i=1}^k (x - \zeta_i)
	\end{align*}
	is called the $ n^{th}$ \textbf{cyclotomic polynomial}.
	\begin{enumerate}[resume]
		\item Compute the cyclotomic polynomials $ \Phi_2(x), \Phi_3(x), \Phi_4(x)$, $ \Phi_5(x)$.
		\item Compute the cyclotomic polynomials $ \Phi_p(x)$ where $ p$ is prime.
		\item Express $ x^n - 1$ as a product of cyclotomic polynomials.
		\item** Use the previous part to show that $ \Phi_n(x)$ has integer coefficients.\hint{Induction on $ n$.}
		\item* Find a formula for $ \Phi_n(x)$ in terms of $ x^n - 1$. \hint{Mobius inversion!}
		\item* Show that $\Phi_p(x)$ is an irreducible polynomial over the integers.\hint{Replace $x$ by $x+1$ and use the Eisenstein criterion.}
	\end{enumerate}
	It is also the case that the $ \Phi_n(x)$ is irreducible over the integers for all positive integers $n$. However, this fact has no easy proof.
\end{exercise}

\newpage
\section{Symmetry Groups}

Today we will explore symmetry groups of objects. Surprisingly, these will help us understand
how to solve cubic and quartic equations in future days.

\subsection{Symmetries of the triangle}

\begin{definition}
	\label{definition:automorphisms}
	For $X$ a subset of $\br^n$, we define the {\bf automorphisms} of $X \subset \br^n$ to be the set of
	reflections and rotations of $\br^n$ which send $X$ to $X$.
\end{definition}

\begin{exercise}
	\label{exercise:triangle-automorphisms}
	Show that an equilateral triangle in $\br^2$ has exactly $6$ automorphisms.
	Here, we include the {\bf identity automorphism}, denoted $\id$, which fixes every point of the triangle.
	Write down these automorphisms explicitly in terms of rotations and reflections.
\end{exercise}
\begin{remark}
	\label{remark:aut-is-group}
	Note that the composition of two automorphisms is again an automorphism.
	Also, every automorphism has an inverse because you can simply ``undo'' the rotation or reflection.
	This makes the set of automorphisms into a {\bf group}.
\end{remark}
\begin{exercise}
	\label{exercise:r-s}
	Let $s$ denote the automorphism of the equilateral triangle which is rotation by $120\degree$
	and let $r$ denote a reflection interchanging two vertices of the equilateral triangle.
	Show that $r^2= \id,$ (where $r^2$ means apply $r$ twice) $s^3 = \id$, and $rs = s^2r$ (here $rs$ means you first apply $s$, then apply $r$).
\end{exercise}
\begin{exercise}
	\label{exercise:}
	Show that all $6$ automorphisms from \autoref{exercise:triangle-automorphisms} can be expressed as compositions
	of the elements $r$ and $s$ defined in \autoref{exercise:r-s}. In this case we say that $r$ and $s$ {\bf generate}
	the automorphism group of the equilateral triangle.
\end{exercise}

\subsection{Dihedral Groups}

We now generalize from the case of triangles to all polygons.
\begin{exercise}
	\label{exercise:}
	A regular $n$-gon in $\br^2$ has $2n$ automorphisms. What are they?
	%\hint{There are $n$ rotations by $(k * 360/n)\degree$ for $0 \leq k \leq n-1$ and $n$ reflections.}
	This set of automorphisms is called the {\bf dihedral group of size $2n$}, denote $D_{2n}$.
\end{exercise}

We suggest you skip the following problem if you are pressed for time.
\begin{exercise}[Optional]
	\label{exercise:}
	Let $s$ denote the rotation of a regular $n$-gon by $(360/n) \degree$ about its center and $r$ denote an automorphism of a regular $n$-gon
	which is a reflection. Show that $r^2 = \id$, $s^n = \id$, and $rs = s^{n-1} r$. Show that $r$ and $s$ generate all automorphisms of the
	regular $n$-gon by showing the $2n$ automorphisms are $1, s, s^2, \ldots, s^{n-1}, r, rs, \ldots, rs^{n-1}$.
\end{exercise}
\begin{remark}
	\label{remark:}
	Of the $2n$ automorphisms of the regular $n$-gon, $ n$ are rotations.
	It is easy to see that the subset of rotations is closed under composition.
	In this case we say that the rotations preserving the regular $n$-gon
	form a {\bf subgroup} of all automorphisms.
	This subgroup is called {\bf the cyclic group of order $n$}, denoted $C_n$.
\end{remark}

\subsection{Symmetric Groups}
\begin{definition}
	\label{definition:}
	We define the {\bf symmetric group on $n$ elements,} $S_n$ to be the set of bijections $\left\{ 1,2,\ldots, n \right\} \ra \left\{ 1, 2, \ldots, n \right\}$
\end{definition}
Strictly speaking, the symmetric group is a little more than just this set. Given two bijections, you can compose them to get a third bijection.
This makes the set of these bijections into a group.
\begin{exercise}
	\label{exercise:}
	Show that $S_n$ (the symmetric group on $n$ elements) has size $n!$.
\end{exercise}
\begin{exercise}
	\label{exercise:}
	Show that $S_3$ can be identified with the automorphisms of the equilateral triangle.
\end{exercise}

\begin{exercise}
	\label{exercise:tetrahedron-automorphisms}
	Show that the automorphisms of the tetrahedron in $\br^3$ are identified with $S_4$. \footnote{{\it Hint:} Consider the action of the automorphisms of the $4$ vertices.}
\end{exercise}
\begin{exercise}
	\label{exercise:tetrahedron-rotations}
	Show that inside the group of all automorphisms of the tetrahedron (of size $24 = 4!$, which is the size of $S_4$), there are $12$ rotations.
	Show that these rotations form a subgroup of $S_4$. This is known as the {\bf alternating group on $4$ elements}, denoted $A_4$.
\end{exercise}

{\it Your homework is to complete up through \autoref{exercise:tetrahedron-rotations}. If you finish that, and still have time try the following questions.}

\subsection{Further optional questions on symmetry groups}
\begin{exercise}[Optional 1]*
	\label{exercise:cube}
	Inside all automorphisms of the cube, there is a subgroup of rotations.
	What is the size of this group? Can you identify this group?
	\hint{Look at the long diagonals.}
\end{exercise}

\begin{exercise}[Optional 2]
	\label{exercise:octahedron}
	Let $G$ be the group from \autoref{exercise:cube}, which you found was the group of rotations of the cube.
	Identify the group of rotations of the octahedron with the same group $G$.
	%	Show that inside the automorphisms of the cube, there is a subgroup of order $4$, whose $3$ non-identity elements consist of $180 \degree$ rotations.
	%	This is known as the {\bf Klein-$4$ group,} denoted $K_4$.
	\hint{Look at the four diagonals joining opposite sides. Alternatively, use \autoref{exercise:cube} and that the octahedron is ``dual'' to the cube (the faces of the cube correspond to the vertices of the octahedron and the faces of the octahedron correspond to the vertices of the cube).}
\end{exercise}

\begin{exercise}[Optional 3]**
	\label{exercise:dodecahedron}
	Determine the number of rotations of the dodecahedron. Do the same for the number of rotations of the icosahedron.
	Identify these two groups. That is, construct a bijection between these groups respecting composition.
	Show that these are subgroups of $S_5$.
	\hint{For identifying this as a subgroup of $S_5$,
		one can show there are $5$ cubes which can be inscribed in a dodecahedron, and the rotations permute these cubes.}
\end{exercise}

\newpage
\section{Commutators and symmetric polynomials}
Today we discuss commutators of groups in order to apply them to solving the cubic and quartic.
Tomorrow we will explain how these commutators let us solve the cubic and quartic equations.

\begin{definition}
	\label{definition:}
	For $G$ a group and $g_1, \ldots, g_n \in G$, the subgroup of
	$G$ {\bf generated by $g_1, \ldots, g_n$}
	is the smallest subgroup of $G$ containing $g_1, \ldots, g_n$.
	That is, the elements of the subgroup
	generated by $g_1, \ldots, g_n$ are
	all products in $g_1, \ldots, g_n, g_1^{-1}, \ldots, g_n^{-1}$.
\end{definition}

\begin{definition}
	\label{definition:}
	Let $G$ be a group. The {\bf commutator subgroup} of $G$, denoted $\left[ G,G \right]$ is the subgroup of $G$ generated
	by elements of the form $ghg^{-1}h^{-1}$ for $g, h$ elements of $G$.
	Here $g^{-1}$ denotes the inverse of $g$.
\end{definition}
\begin{remark}
	\label{remark:}
	It is important that the commutator subgroup is the group {\em generated}
	by all commutators (i.e., all elements of the form $ghg^{-1}h^{-1}$)
	and not just the set of all commutators.
	Indeed, the product of two commutators need not be closed a commutator,
	and hence the set of commutators may not be a subgroup.
	That said, in most of the examples we consider below,
	it will coincidentally work out that the set of commutators already forms
	a group, but this is a coincidence of small groups.
\end{remark}

\begin{remark}
	\label{remark:}
	We will mostly be concerned with the case that $G$ is the symmetric group, or some group of automorphisms of a subset $X \subset \br^n$.
	In the case of $X \subset \br^n$, if $g$ and $h$ are two automorphisms of $X$, $ghg^{-1}h^{-1}$ means that you first apply $h^{-1}$, then apply $g^{-1}$, then
	apply $h$, then apply $g$.
\end{remark}
\begin{exercise}
	\label{exercise:}
	Let $G = S_3$ (it may help to think about this as automorphisms of an equilateral triangle).
	Let $r$ denote the reflection (in terms of $S_3$ this sends $1 \mapsto 2, 2 \mapsto 1, 3\mapsto 3$)
	and $s$ denote rotation by $120 \degree$ (in $S_3$ this sends $1 \mapsto 2, 2 \mapsto 3, 3 \mapsto 1$).
	Show that $rsr^{-1}s^{-1} = s$.
	Show that the commutator $\left[ S_3, S_3 \right]$ is generated by $s = rsr^{-1}s^{-1}$, and hence is exactly the subgroup
	with elements $\left\{ \id, s, s^2 \right\}$.
\end{exercise}
\begin{exercise}
	\label{exercise:}
	Let $G = C_3$ (the group of rotations of the triangle). Show that the commutator is just the identity automorphism, $\left[ C_3, C_3 \right] = \left\{ \id \right\}$.
	In other words, show that for any $g, h \in C_3$, $ghg^{-1}h^{-1} = \id$.
	More generally, show that if $G = C_n$, $\left[ C_n, C_n \right] = \left\{ \id \right\}$.
\end{exercise}

\begin{exercise}
	\label{exercise:klein-4}
	Let $X$ be a rectangle.
The group of automorphisms of $X$ is called $K_4$, the {\bf Klein-$4$} group.
	\begin{enumerate}
		\item Show that the Klein-$4$ group has size $4$ and is generated by reflections about the $x$-axis and $y$-axis.
		\item Show that $\left[ K_4, K_4 \right] = \left\{ \id \right\}$.
	\end{enumerate}
\end{exercise}

%\begin{exercise}
%	\label{exercise:}
%	Let $G = D_{2n},$ the automorphisms of the regular $n$-gon.
%	For $r$ a reflection and $s$ a rotation by $(360/n) \degree$, show
%	Show that $rsr^{-1}s^{-1} = s^2$.
%	Show that the commutator $\left[ D_{2n}, D_{2n} \right]$ is generated by $s^2 = rsr^{-1}s^{-1}$
%	(i.e., it is all powers of $s^2$).
%	Depending on whether $n$ is even or odd, determine the size of $\left[ D_{2n}, D_{2n} \right]$.
%\end{exercise}

\subsection{Alternating Groups}

\begin{definition}
	\label{definition:alternating}
	The $n$th {\bf alternating group}, denoted $A_n$ is by definition $A_n := \left[ S_n, S_n \right]$, the commutator of $S_n$.
\end{definition}
\begin{exercise}[Reality check]
	\label{exercise:low-alternating-groups}
	Verify that $A_3 = C_3$.
\end{exercise}

{\it Your homework is to complete up to \autoref{exercise:low-alternating-groups}. If you have time, attempt the following optional
problems}

\subsection{Further optional questions on Geometric computations of commutators}
We now give some geometric ways to see various commutator subgroups of $S_4$.
\begin{exercise}[Optional 1]
	\label{exercise:}
	Using that the automorphisms of the tetrahedron can be identified with $S_4$ from \autoref{exercise:tetrahedron-rotations} (by the action of
	$S_4$ on the $4$ vertices of the tetrahedron),
	show that the rotations of the tetrahedron can be identified with $A_4$. For this problem, you may assume that $A_4$ has size $12$, and
	it is the only subgroup of $S_4$ of size $12$.
\end{exercise}

\begin{exercise}[Optional 2]
	\label{exercise:}
	The Klein-$4$ group (introduced in \autoref{exercise:klein-4})
	can be viewed as a subgroup of $S_4$. Specifically, the three non-identity elements are
	given by the three ways of swapping two pairs of disjoint elements. (For example, one of them would be $1 \mapsto 2, 2 \mapsto 1, 3\mapsto 4, 4 \mapsto 3$.)
	\begin{enumerate}
		\item Using the identification of automorphisms of the tetrahedron with $S_4$ from \autoref{exercise:tetrahedron-automorphisms}
		      (by the action of
		      $S_4$ on the $4$ vertices of the tetrahedron),
		      describe the $4$ automorphisms of $S_4$ lying in the Klein-$4$ subgroup.
		\item Show these are all given by rotations, so $K_4 \subset A_4$ using \autoref{exercise:tetrahedron-rotations}. (Technically speaking, we did
		      not verify that the group of rotations was $A_4 = \left[ S_4, S_4 \right]$. Feel free to assume this, or prove it as an extra challenge.
		      If you want help proving it or would like to develop a better understanding $A_4$, ask for \autoref{appendix:commutators-s4}.)
		\item* 	Can you use this description to show $K_4 = \left[ A_4, A_4 \right]$? (Again, ask for \autoref{appendix:commutators-s4} if you would like to
		      prove this algebraically.)
	\end{enumerate}
\end{exercise}

\begin{exercise}[Optional 3]*
	\label{exercise:}
	Recall that in \autoref{exercise:cube}, we identified the rotations of the cube with $S_4$.
	Geometrically describe which rotations lie in the subgroup $A_4 \subset S_4$.
	Geometrically describe which rotations lie in the subgroup $K_4 \subset S_4$.
	Can you use these geometric descriptions to verify $A_4 = \left[ S_4, S_4 \right]$ and $K_4 = \left[ A_4, A_4 \right]$?
\end{exercise}
\begin{exercise}[Optional 4]
	\label{exercise:cross-ratio}
	Given four distinct ordered complex numbers $a,b,c,d$, the {\bf cross ratio} is defined as
	\begin{align*}
		\mathrm{r}(a,b;c,d) := \frac{(c-a)(d-b)}{(c-b)(d-a)}.
	\end{align*}
	Note that $S_4$ acts on the set $\left\{ a,b,c,d \right\}$ by permuting the elements of this set. Show that $K_4 \subset S_4$ preserves the cross ratio.
	That is, if $\sigma \in K_4$ then then $\mathrm{r}(a,b;c,d) = \mathrm{r}(\sigma(a),\sigma(b);\sigma(c),\sigma(d))$.
	Find an example of some set of four complex numbers $(a,b,c,d)$ for which $K_4$ is exactly the subgroup of $S_4$ that preserves
	the cross ratio.
\end{exercise}

\newpage
\section{The Galois Correspondence}
So far we've talked about solving cubic and quartics and some concepts from Group theory. Today we'll see the connection between these and hint towards the deeper connection called the Galois Correspondence.

\subsection{Symmetries \& Polynomials}

Let $ P(x) = x^n + a_{n-1} x^{n-1} + \dots + a_1 x + a_0$ be a polynomial with roots $ r_1, r_2, \dots, r_n$.

\begin{exercise}
	\label{exercise:elementary-symmetric-functions}
	For $ n=3$, find $ a_i$ as a function of the $ r_i$. (We've already done this for the depressed cubic.) Similar identities hold for all $ n$.
\end{exercise}
\begin{remark}
	Each $ a_i$ is a (multi-variable) polynomial in the roots $ r_i$. These polynomials are called the \textbf{elementary symmetric polynomials}. They are called `symmetric' because they remain unchanged upon permuting the roots $ r_i$. We say that the symmetric group $S_n$ acts on the polynomials by permuting the variables, and the `symmetric' polynomials are exactly the ones which are unchanged or \textbf{fixed} by this group action.
\end{remark}

% \begin{exercise}
% 	Check that the $a_i$ remain unchanged upon permuting the roots $r_i$ in the case $ n=3$.
% \end{exercise}
%
% In group theoretic terminology, we say that the symmetric group $ S_n$ \textbf{acts} on the set of polynomials in $ n$ variables by permuting the variables.
% That is, we can ``apply'' $\sigma$ to a polynomial $Q$ to obtain the polynomial $\sigma(Q)$ defined by
% \begin{align*}
% 	(\sigma(Q))(r_1, r_2, \dots, r_n) := Q(r_{\sigma(1)}, r_{\sigma(2)}, \dots, r_{\sigma(n)}).
% \end{align*}
% \begin{definition}
% 	\label{definition:}
% 	A polynomial $Q(r_1, r_2, \dots, r_n)$ is {\bf symmetric} if for all $\sigma \in S_n $,
% 	\begin{align*}
% 		\sigma(Q) (r_1, r_2, \dots, r_n)= Q(r_1, r_2, \dots, r_n)
% 	\end{align*}
% 	In other words, the polynomial remains the same after reordering the variables.
% \end{definition}
The reason for the `elementary' in `elementary symmetric' is the following theorem:
\begin{theorem}
	\label{theorem:fundamental_theorem_symmetric_polynomials}
	Any symmetric polynomial can be expressed as a polynomial in the elementary symmetric polynomials.
	Hence, any symmetric polynomial $ Q(r_1, r_2, \dots, r_n)$ in the roots $ r_i$ of a polynomial $ P(x)$ can be expressed as a polynomial in its coefficients $ a_i$.
\end{theorem}
\begin{exercise}
	As an example, show that $ r_1^2 + r_2^2 + r_3^2  = a_2^2 - 2 a_1$ for $ n=3$.
\end{exercise}
\begin{remark}
	You can assume \autoref{theorem:fundamental_theorem_symmetric_polynomials} without proof. The proof of this theorem, which is a careful application of the multinomial theorem and induction, also gives an algorithm for finding these polynomials.
\end{remark}

We've already encountered several examples of this:
\begin{exercise}[\textbf{Discriminant}]
	Verify that for any polynomial $ P(x)$ the discriminant $\Delta(P) = \prod_{1 \leq i < j \leq n} (r_i - r_j)^2$ is symmetric. Conclude that $\Delta(P)$ can be expressed in terms of the coefficients of $ P(x)$! This explains the existence of the formulae $\Delta = b^2 - 4c$ and $-4p^3 - 27q^2$ in quadratic and cubic cases.
\end{exercise}

\begin{remark}[\textbf{Cubic}] Recall that for the cubic $ P(x)=x^3 + px + q$, we defined the intermediate variables
	\begin{align*}
		\mu_1 & = r_1 + r_2 \omega + r_3 \omega^2 \\
		\mu_2 & = r_1 + r_2 \omega^2 + r_3 \omega
	\end{align*}
	By an explicit computation, one can show that $ \mu_1^3 + \mu_2^3$ and $\mu_1^3  \mu_2^3$ are symmetric in $ r_1, r_2, r_3$, which explains the existence of the formulae $ \mu_1^3 + \mu_2^3 = -27q$ and $ \mu_1^3 \mu_2^3 = -27p$.
\end{remark}

\begin{exercise}[\textbf{Quartic}]
	\label{exercise:quartic-lambda}
	Recall that for a quartic $ P(x)$, we defined the intermediate variables
	\begin{align*}
		\lambda_1 & = r_1 r_2 + r_3 r_4 \\
		\lambda_2 & = r_1 r_3 + r_2 r_4 \\
		\lambda_3 & = r_2 r_3 + r_1 r_4
	\end{align*}
	\begin{enumerate}
		\item Show that $ \lambda_1 + \lambda_2 + \lambda_3$, $ \lambda_1 \lambda_2 + \lambda_1 \lambda_3 + \lambda_2 \lambda_3$, and $ \lambda_1 \lambda_2 \lambda_3$ are symmetric in $r_i$.
		\item Conclude that the coefficients of $ (x-\lambda_1)(x-\lambda_2)(x-\lambda_3)$ can be expressed in terms of the coefficients of $ P(x)$.
	\end{enumerate}
\end{exercise}

Hopefully now you're convinced that there was some reason behind choosing these intermediate variables. Which brings us to the question: Do such variables exist for all degrees?
% A set of polynomials $ \mathscr{S} = \{ Q_i(r_1, r_2, \dots, r_n) \}_i$ is said to be \textbf{fixed point-wise} by an element $ \sigma \in S_n$ if
% 	\begin{align*}
% 	(\sigma(Q_i))(r_1, r_2, \dots, r_n) = Q_i(r_{\sigma(1)}, r_{\sigma(2)}, \dots, r_{\sigma(n)})
% 	\end{align*}
% for every $ Q_i \in \mathscr{S}$.
%
% \begin{remark}
% 	The symmetric polynomials are fixed point-wise by every element of $ S_n$.
% \end{remark}
%
% \begin{remark}
% 	For a set of polynomials $ \mathscr{S}$, the subset of elements of $ S_n$ that fix $ \mathscr{S}$ point-wise is always a subgroup of $ S_n$, called the \textbf{stabilizer} of $ \mathscr{S}$.
% \end{remark}
\begin{exercise}
	Let $ P(x)$ be a cubic polynomial.
	\begin{enumerate}
		\item Check that $ \omega \mu_1 = r_3 + r_1 \omega + r_2 \omega^2$.
		\item Show that $ \mu_1^3$ (and similarly $ \mu_2^3$) remains unchanged if we cyclically permute $ r_1, r_2, r_3$.
		\item Show that $ \mu_1^3$ and $ \mu_2^3$ get interchanged if we swap $ r_2$ and $ r_3$. (The same is in fact true if we swap any two of the $ r_i$.)
	\end{enumerate}
	We say that $ \mu_1^3, \mu_2^3$ are \textbf{fixed} by $ A_3$ (because $ A_3$ consists of the cyclic permutations and $ id$).
	% \begin{enumerate}
	%
	% 	\item Find $ \omega \cdot \mu_1$ and $ \omega^2\cdot \mu_1$ in terms of the roots $ r_1, r_2, r_3$.
	% 	\item Find the subgroup of $ S_3$ which fixes the set $\{ \mu_1^3, \mu_2^3 \}$.
	% 	 What do the elements not in this subgroup do to it? (Remember that $ \omega^3 = 1$.)
	% \end{enumerate}
\end{exercise}

\begin{exercise}
	Let $ P(x)$ be a quartic polynomial.
	\begin{enumerate}
		\item Show that each of the $ \lambda_i$ remains unchanged if we swap $ r_1$ with $r_2$ and $ r_3$ with $ r_4$. Similarly for the other pairs of pairs.
		\item Convince yourself that these and $ id$ are the only permutations in $ S_4$ that leave each of the the $ \lambda_i$ unchanged.
	\end{enumerate}
	We say that the $ \lambda_i$ are \textbf{fixed} by the Klein 4 group $K_4$.
\end{exercise}

\begin{exercise}For an arbitrary polynomial $ P(x)$ let $\sqrt{\Delta(P)} := \prod_{1 \leq i < j \leq n} (r_i - r_j)$.
	\begin{enumerate}
		\item Show that $ \sqrt{\Delta(P)}$ changes sign if we swap $ r_1$ with $ r_2$.
		\item Show that $ \sqrt{\Delta(P)}$ remains unchanged if perform even number of swaps; $ r_i$ with $ r_j$.
	\end{enumerate}
	We say that $ \sqrt{\Delta(P)}$ is \textbf{fixed} by the entire $ A_n$. For a justification of this, ask for \autoref{appendix:alternating}.
\end{exercise}

\subsection{The Correspondence}
Let us explicitly describe the correspondence between polynomials and symmetry groups:
\begin{enumerate}
	\item[Cubic:] To solve the cubic, we used variables fixed by $A_3 \subset S_3$, namely $\{\mu_1^3, \mu_2^3 \}$.
	      \begin{itemize}
					\item The fact that we can solve for the solutions of the original cubic in terms of the $\mu_i^3$ corresponds to the fact that $\left[ S_3, S_3 \right] = A_3$.
					\item The fact that we can solve for the $\mu_i^3$ corresponds to the fact that $\left[ A_3, A_3 \right] = \{ \id \}$.
	      \end{itemize}
	\item[Quartic:]
		To solve the quartic, we used variables fixed by $K_4 \subset S_4$, namely $\{\lambda_1, \lambda_2, \lambda_3 \}$.
	      \begin{itemize}
		      \item The fact that we can solve for the solutions of the original quartic in terms of the $\lambda_i$ corresponds to the fact that $K_4$ and $S_4$ are related by a sequence of commutators $\left[ S_4, S_4 \right] = A_4$ and $\left[ A_4, A_4 \right] = K_4$.
					\item The fact that we can solve for the $\lambda_i$ corresponds to the fact that $\left[ K_4, K_4 \right] = \{ \id \}$.
	      \end{itemize}
\end{enumerate}
What happens for $n>4$? The sequence of successive commutators for symmetric groups looks like
\begin{align*}
	S_3 & \supset [S_3, S_3] = A_3 \supset [A_3, A_3] = \{ \id \}                          &                      \\
	S_4 & \supset [S_4, S_4] = A_4 \supset [A_4, A_4] = K_4 \supset [K_4, K_4] = \{ \id \} &                      \\
	S_n & \supset [S_n, S_n] = A_n \supset [A_n, A_n] = A_n \supset [A_n, A_n] = A_n \cdots                                & \text{ if } n \geq 5
\end{align*}
Taking iterated commutators of $S_n$ for $n \geq 5$ does not eventually shrink to the identity. Because of this, the methods for solving the cubic and quartic do not generalize to a higher degree polynomials.
\begin{theorem}
	A general polynomial of degree $ \ge 5$ cannot be solved using radicals.
\end{theorem}
\begin{proof}[Sketch of a sketch of a proof] $ $
	\begin{enumerate}
		\item If we can solve a general degree $ n$ polynomial by radicals, then we should be able to find a sequence of intermediate variables which satisfy lower degree polynomials. {This part is not hard if you think about what a solution in terms of radicals means.}
		\item Such intermediate variables should be fixed by subgroups of $ S_n$ which can be obtained by successively taking commutators of $ S_n$. {This is the crucial discovery of Galois that establishes the connection between groups and polynomials.}
		\item For $ n \ge 5$ no such subgroups exist because for $ n \ge 5$ the commutators stabilize: $[S_n, S_n] = A_n$ and $ [A_n, A_n] = A_n$.
		(For a series of exercises proving this, ask for \autoref{appendix:alternating}.)
	\end{enumerate}
\end{proof}

\begin{figure}[H]
	\begin{center}
	\includegraphics[scale=.5]{bring-radical.png}
\end{center}
\caption{
It turns out that one can solve quintics in terms of ``generalized
	radicals'' if one also allows something called the
	``Bring radical.''
	The Bring radical allows you to find a solution
	to an equation of the form $x^5 + ax + 1$.
%	This suggests the following joke below in \autoref{figure:bring-radicals}.
Image from \url{https://en.wikipedia.org/wiki/Talk\%3ABring_radical}}
		\label{figure:bring-radicals}
\end{figure}

\newpage

\iffalse
{\it Your homework is to read up through this point and complete up through \autoref{exercise:tetrahedron-rotations}. If you finish that try the following questions.}

\subsection{Further optional questions: Symmetric Polynomials}
We'll sketch out a proof for the fundamental theory of symmetric polynomials for $ n=2$.
\begin{theorem}
	\label{theorem:fundamental_theorem_symmetric_polynomials}
	Any symmetric polynomial in $ r_1, r_2$ can be expressed as a polynomial in $ r_1 + r_2$ and $r_1 r_2$.
\end{theorem}
\begin{exercise}[Optional 1]
	\begin{enumerate}
		\item Show that it suffices to prove the above theorem for polynomials of the form $ r_1^k r_2^l + r_1^l r_2^k$ for some positive integers $l,k$.
	\end{enumerate}
	We'll induct on the sum $ l+k$.
	\begin{enumerate}[resume]
		\item Prove a few base cases.
		\item Reduce the problem to polynomials of the form $ r_1^l + r_2^l$.
		\item* Use the binomial theorem to prove the inductive step.
	\end{enumerate}
\end{exercise}

\begin{exercise}[Optional 2] **
	Try proving the above theorem for $ n=3$. The steps are \emph{almost} the same as above with the binomial theorem being replaced by the multinomial theorem. There is one step which fails. Can you spot it? Can you think of a way to fix it? Can you prove it for general $n$?
\end{exercise}
\fi

\newpage
\appendix
\section{Commutators of $S_4$}
\label{appendix:commutators-s4}
In this appendix, we outline some exercises to compute commutators of $S_4$.
To this end, it will be useful to have cycle notation.

\begin{exercise}
	\label{exercise:}
	Define a ``cycle notation'' for elements in $S_n$. See \autoref{figure:cycle-notation} for a pictorial description.
	\begin{figure}[h!]
		\includegraphics[scale=1.5]{cycle-1.png}
		\includegraphics[scale=1.5]{cycle-2.png}
		\caption{This is a depiction of two elements thought of as elements of $S_8$. The first corresponds the the permutation fixing $2$ and $5$,
			and sending $1 \mapsto 4, 4 \mapsto 6, 6 \mapsto 8, 8\mapsto 3, 3 \mapsto 7, 7\mapsto 1$.
			The corresponding cycle notation for the first picture is $(146837)(2)(5)$ (where each parenthesized group of numbers
			correspond to a cycle in the above diagram). Similarly, the second permutation has cycle notation $(14625837)$.}

		\label{figure:cycle-notation}\end{figure}
\end{exercise}
\begin{remark}
	\label{remark:}
	If $s \in S_n$ is an element with certain cycle notation, we often omit all singletons from the cycle notation.
	So, for example, we denote the element of $S_8$ with cycle notation $(146837)(2)(5)$ simply as $(146837)$.
\end{remark}

You may prove the following facts, or assume them if you'd like:
\begin{fact}
	\label{fact:transpositions}
	\begin{enumerate}
		\item The symmetric group is generated by elements with cycle notation of the form $(ij)$. These elements are called {\bf transpositions}. That is, transpositions switch (transpose) two numbers in $\left\{ 1, \ldots, n \right\}$ and preserve the rest.
		\item If a group is generated by a collections of elements, the commutator subgroup is generated by commutators of those elements.
	\end{enumerate}
\end{fact}
\begin{exercise}
	\label{exercise:commutators-generate}
	Using \autoref{fact:transpositions}, show that $A_n$ is generated by commutators of transpositions.
\end{exercise}

\begin{exercise}
	\label{exercise:}
	Compute $A_4$ as a subgroup of $S_4$ in the following steps:
	\begin{enumerate}
		\item Show that $(123)(4)$ is the commutator of $(12)$ (the transposition switching $1$ and $2$) and $(13)$.
		\item Show that in general, the commutator of two transpositions is either a $3$-cycle when the transpositions have one element in common
		      (i.e., an element with cycle notation of the form $(abc)$
		      for $a,b,c \in \left\{ 1,2,3,4 \right\}$ distinct integers) or it is the identity permutation.
		\item Conclude from \autoref{exercise:commutators-generate} that $3$-cycles generate $A_4$.
		\item Compute the set of elements in $A_4$. Show it has size $12$.
		      \hint{You should get that $A_4$ contains all three cycles, together with the four elements $\id, (12)(34), (13)(24), (14)(23)$.}
	\end{enumerate}
\end{exercise}
\begin{exercise}
	\label{exercise:klein-4-commutator}
	Compute the commutator $\left[ A_4, A_4 \right]$. Show it has order $4$ and is explicitly given by the elements $\id, (12)(34), (13)(24), (14)(23)$.
	This is the Klein-$4$ group.
\end{exercise}

\newpage
\section{Commutators of $S_n$ and $A_n$}
\label{appendix:alternating}

For this appendix, we assume you have already read \autoref{appendix:commutators-s4}. In particular, we assume you are familiar with cycle notation
and the notion of transpositions.
The purpose of this appendix is to show $A_n$ is its own commutator for $n \geq 5$.
We do this in two subsections. In the first subsection, we give an alternate definition of $A_n$, and show that this agrees with the previous
definition \autoref{definition:alternating}. In the second section, we show $\left[ A_n, A_n \right] = A_n$ for $n \geq 5$.

\subsection{Equivalence of two definitions of $A_n$}

In this subsection, we give an alternate definition of $A_n$, from which it will be easier to show $\left[ A_n, A_n \right] = A_n$ for $n \geq 5$.
Recall above we defined the alternating group $A_n$ as the commutator $[S_n, S_n]$. For the purposes of this appendix,
we make the following alternate definition, and then verify $A_n$ is in fact $[S_n,S_n].$

\begin{definition}[Separate definition for this appendix]
	\label{definition:alternating-group-2}
	The {\bf alternating group}, $A_n$, is the subgroup of $S_n$ consisting of all elements $g \in S_n$ that can be written as a product of
	an even number of transpositions.
\end{definition}
\begin{exercise}
	\label{exercise:}
	Verify that the definition of $A_n$, \autoref{definition:alternating-group-2}, is well defined by showing that $A_n$ is in fact a subgroup.
\end{exercise}
\begin{exercise}
	\label{exercise:}**
	Suppose $g\in S_n$ can be written as products of transpositions in two ways, say $g = t_1 \cdots t_n$ and $g = r_1 \cdots r_m$ for $t_i, r_j$
	transpositions. Show $n \equiv m \bmod 2$.
	\hint{This is a bit tricky, and there are many ways to do it. Here is one nice one:
		Let $\sigma \in S_n$ be some permutation.
		Draw a picture with $1, 2, \cdots, n$ listed at the top and the bottom. Draw curves connecting $i$ to $\sigma(i)$ so that
		the lines always intersect transversely (i.e., no two curves are tangent at an intersection point).
		Check that the number of intersections of lines is well defined modulo $2$.
		Using that this number of intersections is well defined $\bmod 2$, check that
		the parity of the number of intersections agrees with the parity of the number of transpositions.
		Use this to conclude.}
\end{exercise}
\begin{exercise}
	\label{exercise:}
	Show that $\# A_n = \# S_n / 2 = n!/2$.
	\hint{Use \autoref{definition:alternating-group-2} to define a map $S_n \rightarrow C_2$ (where $C_2$ is the cyclic group of order $2$)
		so that $A_n$ is the set of elements mapping to the identity.}
\end{exercise}

\begin{exercise}
	\label{exercise:3-cycles}
	In this exercise, we show $A_n$ is generated by $3$-cycles.
	\begin{enumerate}
		\item Show that every $3$ cycle (i.e., a permutation written in cycle notation as $(ijk)$) lies in $A_n$.
		\item Show that every element in $A_n$ is a product of $3$-cycles. \hint{Show that if $i,j,k,l$ are distinct then $(ij)(kl)$ can be expressed as a product of two $3$-cycles. Then, expand any element as a product of transpositions and express any pair of transpositions as a product of one or two $3$-cycles.}
		\item Conclude $A_n$ is generated by $3$-cycles.
	\end{enumerate}
\end{exercise}

\begin{exercise}
	\label{exercise:}
	In this exercise, we check $\left[ S_n, S_n \right] = A_n$.
	\begin{enumerate}
		\item Show that $\left[ S_n, S_n \right] \subset A_n$. \hint{Expand commutators as products of transpositions and count their parity.}
		\item Show every $3$-cycle is a commutator. \hint{Consider the commutator of two transpositions.}
		\item Use \autoref{exercise:3-cycles} to conclude that $\left[ S_n, S_n \right] = A_n$.
	\end{enumerate}
\end{exercise}

\subsection{Commutator of $A_n$}
We now use our new definition of $A_n$, \autoref{definition:alternating-group-2}, to prove $\left[ A_n, A_n \right] = A_n$ when $n \geq 5$.
The proof is surprisingly easy, given what we have shown so far.
We start with the following warm-up computation.
\begin{exercise}[Warm up]
	\label{exercise:A-5-3-cycles}
	Show that in $A_5$, the commutator of $(123)$ and $(345)$ is $(235)$. That is, check $(123)(345)(132)(354) = (235)$.
\end{exercise}

\begin{exercise}
	\label{exercise:3-cycles-in-commutator}
	If $n \geq 5$, check that every $3$-cycle can be expressed as a commutator of two $3$-cycles.
	\hint{Relabel the numbers from \autoref{exercise:A-5-3-cycles}.}
\end{exercise}

\begin{exercise}
	\label{exercise:}
	Show $\left[ A_n, A_n \right] = S_5$.
	\hint{Recall from \autoref{exercise:3-cycles} that $A_n$ is generated by $3$-cycles. Then use \autoref{exercise:3-cycles}.}
\end{exercise}

\newpage
\theendnotes
\end{document}