\documentclass[a4paper,11pt,fleqn]{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\usepackage{fontspec}
\setmainfont{DejaVuSans}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\captionsetup[figure]{skip=20pt}
\let\oldref\ref
\renewcommand{\ref}[1]{(\oldref{#1})}
\date{\today}
\author{shamaz.mazum}
\title{Math behind cl-audio-downsample library.}
\begin{document}
\maketitle
\section{Fourier transform}
The Fourier transform of function $f(x)$ is a function $F(\xi)$ defined by
\begin{equation}
F(\xi) = \int_{-\infty}^{\infty} f(x)e^{ix\xi}dx
\end{equation}
and its inverse transform is defined by
\begin{equation}
f(x) = \frac{1}{2\pi}\int_{-\infty}^{\infty} F(\xi)e^{-ix\xi}d\xi
\end{equation}
Where direct and inverse transforms exist is a really hard question to be discussed here, so I will only say
that if the inverse transform exists for a particular $F(\xi)$ then $F(\xi)$ is decaying to zero when
real part of $\xi$ moves toward infinity, in other words, $\lim_{Re \xi \to \infty} F(\xi) \to 0$.
I also will use Fourier transform operator $Ff(x)$ which means "apply Fourier transform to a function $f(x)$".
Fourier transform has some useful properties, some of them I describe below:
\begin{description}
\item[Linear property] $F[af(x)+bg(x)] = aFf(x) + bFg(x)$. This is because of linear property of integral.
\item[Shift property] $Ff(x-a) = e^{ia\xi}Ff(x)$. You can replace $x' = x - a$ in the integral to prove it.
\item[Image multiplication property] $F[f*g(x)] = Ff(x)Fg(x)$.
\end{description}
$f*g$ above is called convolution and is defined as the following:
\begin{equation}
f*g(x) = \int_{-\infty}^{\infty}f(\tau)g(x-\tau)d\tau
\end{equation}
or if your functions equal to zero when $x<0$
\begin{equation} \label{convolve2}
f*g(x) = \int_{0}^{x}f(\tau)g(x-\tau)d\tau
\end{equation}
The Fourier transform is of great importance in digital signal processing because you can think of $exp(ix\xi)$
as a harmonic oscillator with frequency $\xi$. You can write $exp(iw) = cos(w) + isin(w)$.
\section{Bandlimiting a signal}
Imagine now an oscillator which oscillates uniformly at all frequencies $\left|\xi\right| < \omega_{0}$.
Its Fourier transform will be
\begin{equation}
\label{idealfilter}
F(\xi) = \left\{
\begin{array}{rl}
1 & \text{if } \left|\xi\right| < \omega_{0},\\
0 & \text{otherwise}.
\end{array} \right.
\end{equation}
The inverse transform is $f(x) = \frac{sin(x)}{\pi x}$. There is a Shannon sampling theorem which says that every
bandlimited signal (i.e. it has no frequencies above some $f_{0}=\frac{\omega_{0}}{2\pi}$) can be represented as
shifted versions of functions $\frac{sin(\omega_{0}x)}{\pi x}$ multiplied by samples of that signal taken at frequency
$2f_{0}$ Hz. That means if you want to store a signal which contains, say, sine waves at frequency
at most 1kHz, you need to take samples at frequency 2kHz (or higher). If you choose frequency less than $2f_{0}$ then
some of high frequency data will be "misinterpreted" as low frequency data.
\section{Signal filtering}
So if you want to downsample your audio data taken with sampling frequency, say, 96kHz to sampling frequency 48kHz, taking
every second sample is not enough! If you do so, all inaudible data in the range between 24 and 48 Hz will be misinterpreted
and become audible. This thing is called aliasing. So before dropping any data you need to filter it to cut all oscillations
above $newsamplerate / 2$. To do so we will use the image multiplication property of the Fourier transform and convolve
our signal with $\frac{sin(\omega_{0}x)}{\pi x}$ using \ref{convolve2} (provided that our signal begins from time $x=0$). There is
a problem with that, although. When convolving numerically, you need to use \textbf{all} samples in you signal to get a new value
for \textbf{one} sample. That's because support of $\frac{sin(\omega_{0}x)}{\pi x}$ (i.e. set of values where the function does
not equal to zero, with possible exception of a set with measure zero) is the whole set of real numbers, $\mathbb{R}$. What we
need is a filtering function with \textbf{compact support} or in the case of functions defined on $\mathbb{R}$, \textbf{bounded
  support}. Unfortunately, these functions cannot act as an ideal low-pass filter, but they can be close to it. Usually people use
the same $\frac{sin(x)}{\pi x}$ function multiplied by some window function to make its support compact, but I propose a different
approach. I do not know, if it is known to anybody (most likely to), in this case I just "reinvented" it on my own.

\section {Inverse Fourier transform of some "noninvertable" functions}
Can you invert a Fourier image, say, $F(\xi)=1$? No, you cannot. That's because it does not die out when real part of $\xi$
moves toward infinity. But you still can "nominate" some "function" to be its inverse transformed version! To understand it
you will need a concept of weak convergence. For a functions $f \in H$, where $H$ is some Hilbert space, a sequence $f_{n} \in H$
is said to be convergent to $f$ if $\lim_{n \to \infty} \left<f_{n},g\right> = \left<f,g\right>$ for all $g \in H$. It is denoted as
$\{f_{n}\} \to^{w} f$.

 $\left<\cdot, \cdot\right>$ here is a \textbf{scalar} or \textbf{dot product} on that space $H$. If you do not
know that it means, remember orthogonal vectors on $\mathbb{R}^{2}$, i.e. vectors for which the angle between them is 90 degrees. Scalar product
of these vectors is zero. It is some measure of "independence" in the sense that if angle between two lines is changed from zero to 90 degrees, the
scalar product will change from some value to zero. Scalar product of vectors $\phi$ and $\psi$ on $\mathbb{R}^{N}$ is
$\left<\phi,\psi\right> = \sum_{i=1}^{N} \phi_{i}\psi_{i}$. $\mathbb{R}^{N}$ is an example of a Hilbert space. It turns out, that scalar product
can be defined not only on $\mathbb{R}^{N}$ but on spaces of functions. A most important example is $L^{2}(\mathbb{C})$ space, i.e. space of functions,
for which exists a Lebesgue integral $\int_{-\infty}^{\infty} {\left|f(x)\right|}^{2} dx$. For these functions there always exists an integral
$\left<f,g\right> = \int_{-\infty}^{\infty} f(x)\overline{g(x)}dx$, $f,g \in L^{2}(\mathbb{C})$. This is how scalar product can be defined for functions.
There are also orthogonal functions on $L^2$. If functions in some set are orthogonal to each other and $\left<f,f\right> = 1$ this set is called a set
of \textbf{orthonormal} functions. $L^2$ is an another example of a Hilbert space. There are some sets of orthonormal functions on a Hilbert space called
\textbf{basis}. You can represent any function on that space as a sum of basis functions: $f(x) = \sum_{i}\left<f,\phi_{i}\right>\phi_{i}$. Another important
concept is \textbf{norm} denoted as $\left\lVert\cdot\right\rVert$. In $\mathbb{R}^{N}$ it tells how long a vector is. For $L^2$ a norm is defined as
$\left\lVert f(x) \right\rVert  = \sqrt{\left<f,f\right>}$.

Back to weak convergence. Take functions $f_{n}(x) = \frac{sin(nx)}{\pi x}$. They all belong to $L^2$ with norm equals to $\sqrt{n/\pi}$. As you can see, if
$n$ rises, norm of $f_{n}(x)$ also will rise, so $f_{n}(x)$ is divergent (there cannot be an element with infinite norm). But what happens to a sequence
$\left<f_{n},\phi\right>$ when $n \to \infty$ where $\phi(x)$ is any function from $L^2(\mathbb{R})$? Follow this trick:
\begin{equation}
\begin{aligned}
\lim_{n \to \infty} \int_{-\infty}^{\infty} f_{n}(x)\phi(x)dx = \\
\lim_{n \to \infty} \int_{-\infty}^{\infty} \frac{sin(nx)}{\pi x}\phi(x)dx = \\
\phi(0) \lim_{n \to \infty} \int_{-\infty}^{\infty} \frac{sin(nx)}{\pi x} dx + \lim_{n \to \infty} \int_{-\infty}^{\infty} sin(nx) \frac{\phi(x) - \phi(0)}{\pi x} = \\
\phi(0) \lim_{n \to \infty} \int_{-\infty}^{\infty} \frac{sin(nx)}{\pi x} dx + \int_{-\infty}^{\infty} \lim_{n \to \infty} sin(nx) \frac{\phi(x) - \phi(0)}{\pi x}
\end{aligned}
\end{equation}

Integration and limit switched places because integrated function does not have any irregularities at $x=0$ now. It can be proven that for a "good enough" function $f(x)$
an integral $\int_{-\infty}^{\infty} sin(nx) f(x)dx$ converges to zero as $n \to \infty$. On the other hand $\int_{\infty}^{\infty} \frac{sin(nx)}{\pi x}$ is always 1,
no matter what value $n$ takes, so
\begin{equation}
\lim_{n \to \infty} \int_{-\infty}^{\infty} f_{n}(x)\phi(x)dx = \phi(0) = \int_{-\infty}^{\infty} \delta(x)\phi(x)dx
\end{equation}

$\delta(x)$ is called a \textbf{delta-function} and is defined simply as
\begin{equation}
\int f(x)\delta(x) dx = f(0)
\end{equation}
Surely, it's no a "real" function, but rather a functional on Hilbert space $L^{2}(\mathbb{R})$, i.e. $\left<\delta,\cdot\right>$ takes a function and returns its value
at point $x=0$. Also you can define $\left<\delta(x-a),f(x)\right> = f(a)$. You can see that by substitution $x' = x+a$.

Another very important property on delta-function is that $f*\delta = f$, i.e. convolution of any function with delta is that function. For some functions you can define
so-called \textbf{convolution algebra} where $\delta(x)$ is like 1 in "ordinary" algebra and convolution of functions is like multiplication of numbers.

Speaking of Fourier transform, $F[\frac{sin (\omega_{0} x)}{\pi x}](\xi)$ is \ref{idealfilter}. If $\omega_{0} \to \infty$, the Fourier image becomes simply $F(\xi) = 1$. Inverse
transform of that $F(\xi)$ becomes $\delta(x)$. If you want to pass your signal through such a filter (it's like identity filter, which does not change your signal), you must
convolve it with $\delta(x)$: $f*\delta = f(x)$. So as you can see, your signal is not changed indeed.

In case of discrete signals continuous convolution is replaced by discrete convolution. $f = \phi*\psi$ becomes
\begin{equation}
\label{discconv}
f_{n} = \sum_{i=-\infty}^{\infty}\phi_{i}\psi_{n-i}
\end{equation}
Surely, in practice infinity is replaced by some finite $l$, known as, if I am right, a \textbf{filter order}.

\section{My filter}
In the \ref{discconv} let $\phi_{i} = \phi_{-i}$. Let's now imagine, that our filter is itself a function, sampled at infinitely high sampling rate, while your signal is sampled at frequency
$f_{ref}=\frac{\omega_{ref}}{2 \pi}$. Let a filter function be defined as:
\begin{equation}
\phi(x) = \sum_{n=-N}^{N} \phi_{n} \delta(x+n \frac{2 \pi}{\omega_{ref}})
\end{equation}
where $\phi_{n}$ are some coefficients. Its Fourier transform, $\Phi(\xi)$ is
\begin{equation}
\Phi(\xi) = \sum_{n=-N}^{N} \phi_{n} e^{i n \frac{2 \pi}{\omega_{ref}} \xi}
\end{equation}
I used the linear and shift properties of Fourier transform and the fact that $F[\delta(x)] = 1$.

The equation above can be rewritten if members like $exp(ia\xi)$ and $exp(-ia\xi)$ are combined together. Remember, that $\phi_{n} = \phi_{-n}$.
\begin{equation}
\begin{aligned}
\sum_{n=-N}^{N} \phi_{n} e^{i n \frac{2 \pi}{\omega_{ref}} \xi} = \\
\phi_{0} + \sum_{n=1}^{N} \phi_{n} (e^{i n \frac{2 \pi}{\omega_{ref}} \xi} + e^{-i n \frac{2 \pi}{\omega_{ref}} \xi}) = \\
\phi_{0} + \sum_{n=1}^{N} \frac{\phi_{n}}{2} cos(n \frac{2 \pi}{\omega_{ref}} \xi)
\end{aligned}
\end{equation}

Good, functions like $\sqrt{\frac{1}{\omega_{ref}}}$ and $\sqrt{\frac{2}{\omega_{ref}}} \cos(n \frac{2 \pi}{\omega_{ref}} \xi)$ with
different $n$ are orthonormal to each other on a segment $[-\omega_{ref}/2, \omega_{ref}/2]$. They constitute a basis on that
segment for functions called \textbf{even functions}, that is function $f(x)$ is even if $f(x)=f(-x)$. Our ideal filter
\ref{idealfilter} is an even function. You can find $\phi_{n}$ calculating a scalar product of $F(\xi)$ in \ref{idealfilter} and
functions from our basis set and normalising. Introduce a variable $a \leq 1$, so $\omega_{0} = a \omega_{ref}/2$. We get the
following:
\begin{equation}
\begin{aligned}
\phi_{0} = \frac{2}{\omega_{ref}}\int_{0}^{a \omega_{ref}/2}d\xi = a \\
\phi_{n} = \frac{4}{\omega_{ref}}\int_{0}^{a \omega_{ref}/2}cos(n \frac{2 \pi}{\omega_{ref}} \xi)d\xi = \frac{2}{n \pi} sin (a \pi n)
\end{aligned}
\end{equation}
A sequence $\{\cdots, \phi_{2}/2, \phi_{1}/2, \phi_{0}, \phi_{1}/2, \phi_{2}/2, \cdots\}$ will constitute our filter. Note, that
these coefficients do not depend on $\omega_{ref}$. If you convolve this sequence with your signal by \ref{discconv}, you will get
a new signal, in which all frequencies above $a\omega_{ref}/2$ are cut (the original signal has frequencies up to
$\omega_{ref}/2$). The process of finding $\{\phi_{0}, \phi_{1}, \phi_{2}, \cdots\}$ is called \textbf{Fourier series}
decomposition, not to be confused with Fourier transform. Note, that Fourier transform of our filter is real-valued and you will
not get any phase shift in frequencies below cutpoint, and sometimes phase shift of $\pi$ above it, but who cares?

Good enough? No. An ideal filter has a discontinuity at $\left|\xi\right| = \omega_{0} = a \omega_{ref}/2$. Fourier series decomposition behaves very badly in the area around points of discontinuity. Even if
you choose $N$ to be large enough, that "area of bad behaviour" will be smaller and smaller, but bad behaviour will not vanish at all. It's known as \textbf{Gibbs phenomenon}. Bad behaviour expresses itself as
big oscillations around points of discontinuity. We can eliminate that behaviour by introducing a small transition region between
preserved frequencies and cut frequencies. To do this, let's find a function $f(x)$ which has following properties:
\begin{itemize}
\item is continuous and has (at least) $N$ derivatives in all points belonging to $[0,1]$;
\item $f(0) = 1$ and $f(1) = 0$;
\item $f^{(n)}(0) = f^{(n)}(1) = 0$ for $n = \overline{1,N}$
\end{itemize}

I propose two families of such functions. One is polynomial in $x$ and another is trigonometric polynomial. Let's start with
polynomial in $x$. Define $f(x)$ like so:
\begin{equation}
  \label{polydef}
  f(x) = 1 - x^{N+1}L_{1}(x) = (1-x)^{N+1}L_{2}(x)
\end{equation}
The first definition satisfies the conditions at point $x = 0$ and the second at point $x = 1$. We get an equation:
\begin{equation}
  \label{bezout1}
  (1-x)^{N+1}L_{2}(x) + x^{N+1}L_{1}(x) = 1
\end{equation}
Polynomials $x^{N+1}$ and $(1-x)^{N+1}$ are relatively prime, so \ref{bezout1} is so-called Bezout equation. You can rewrite it
like so:
\begin{equation}
  (1-x)^{N+1}P(x) + x^{N+1}P(1-x) = 1
\end{equation}
It admits a solution:
\begin{equation}
  \label{bezoutsol}
  P(x) = \sum_{n=0}^{N}C_{N+n}^{n}x^{n}
\end{equation}
Substitute now $P(1-x)$ from \ref{bezoutsol} to the first definition of $f(x)$ (remembrer, $L_1(x) = P(1-x)$) in \ref{polydef}. You will get:
\begin{equation}
  \label{poly}
  f(x) = 1 - x^{N+1}\sum_{n=0}^{N}C_{N+n}^{n}x^n
\end{equation}

I use this one of this family: $f(x) = 20x^7 - 70x^6 + 84x^5 - 35x^4+1$.

\textbf{TODO: Write about trigonometric polynomials}.

I introduce a transition region
$[\frac{a\omega_{ref}}{2} (1-b), \frac{a\omega_{ref}}{2} (1+b)]$, $b \in [0,1]$ and a function that maps transition region onto
segment $[0,1]$: $g(\omega) = \frac{\omega}{ab\omega_{ref}} - \frac{1-b}{2b}$. Then I define a new filter where $f(x)$ is one of
\ref{poly}:

\begin{equation}
\label{notsoideal}
F(\xi) = \left\{
\begin{array}{rl}
1 & \text{if } \left|\xi\right| < a\omega_{ref}(1-b)/2,\\
f(g(\left|\xi\right|)) & \text{if } a\omega_{ref}(1-b)/2 \leq \left|\xi\right| \leq a\omega_{ref}(1+b)/2,\\
0 & \text{otherwise}.
\end{array} \right.
\end{equation}
It has a transition region which width is $\frac{ab\omega_{ref}}{2}$, but it has $N$ first continuous derivatives in all of its
points. Fourier series for it will converge much faster and without Gibbs phenomenon.

Although decomposition coefficients can be calculated
explicitly, I prefer to compute them numerically by the \textbf{Simpson's formula} which is a method of precise numerical integration.

\section{Error estimation}
\textbf{This section may be out of date.}
It also would be great to know how close Fourier series decomposition is to \ref{notsoideal} or to another filter with another polynomial. Remember, that decomposed signal is in the following form:
\begin{equation}
F(\xi) = \phi_{0} + \sum_{n=1}^{N}\frac{\phi_{n}}{2}cos(\frac{2\pi}{\omega_{ref}}n\xi)
\end{equation}
A global minimum of that is somewhere "to the right" of the frequency $\xi = \omega_{0}+\epsilon$ which is $\xi = a\omega_{ref}/2+\epsilon$. I suggest the value $\left|F(\xi_{min})\right|$ as an error measure. To find
a minimum of $F(\xi)$ you need to find its differential and equate it to zero. You will get an equation (a constant multiplier, $\frac{\pi}{\omega_{ref}}$, is dropped):
\begin{equation}
F'(\xi) = \sum_{n=1}^{N}\phi_{n}n sin(\frac{2 \pi}{\omega_{ref}}n\xi) = 0
\end{equation}
As I said, we will search for a solution on a segment $\xi \in [\omega_{0}+\epsilon, \omega_{ref}/2]$. We need only one solution, which corresponds to the global minimum. $F(\xi)$ is decreasing in the range
$\xi \in [\omega_{0}-\epsilon, \omega_{0}+\epsilon]$ and continues to decrease for some $\xi \geq \omega_{0} + \epsilon$ "by inertia". So, $F'(\xi)$ is negative in this range and equals to zero in the point where
$F(\xi)$ is minimal. $F'(\xi)$ behaves in that region almost linearly, so you can find a tangent to it in the point $\xi = \omega_{0} + \epsilon$ and find out where it becomes a zero. This is a first step of so called
\textbf{Newton's method} of numerically solving equations like $f(x)=0$ for monotonous $f(x)$. I will restrict myself to that only step, because, as I said, $F'(x)$ behaves almost linearly in the region of interest.

Define $b$, so that $\epsilon = ab\omega_{ref}/2$. Then our tangent is defined as follows:
\begin{equation}
T(\xi) = A(\xi - \omega_{0} - \epsilon) + B
\end{equation}
with $\xi_{min} - \omega_{0} - \epsilon = -B/A$. I calculated $B/A$ to be
\begin{equation}
B/A = \frac{\sum_{n=1}^{N}\phi_{n}n sin(\pi n a (1 + b))}{\sum_{n=1}^{N}\phi_{n}n^{2}cos(\pi n a (1 + b))}
\end{equation}
An estimated minimum value of $F(\xi_{min})$ is
\begin{equation}
F(\xi_{min}) = \phi_{0} + \sum_{n=1}^{N}\phi_{n}cos(\pi n (a+b-\pi B/A)
\end{equation}

On \ref{errorpic} you can see a graph which represents an error estimation for two types of filters, one of them being \ref{notsoideal} (solid line) and another is the tenth order polynomial which I use (dash line).
\begin{figure}[h!]
\includegraphics[width=0.5\linewidth,angle=-90]{error.ps}
\caption{The error $\left|F(\xi_{min})\right|(N)$ of Fourier series decomposition.}
\label{errorpic}
\end{figure}

Below on \ref{filterpic} I also include a Fourier transform and a partial sum of the first 30 members of its Fourier series decomposition for my filter with $a=1/2, b=1/7$. Practically, it's better to use $N>50$ to get
more or less acceptable quality.
\begin{figure}[h!]
\includegraphics[width=200pt,angle=-90]{approx.ps}
\caption{The Fourier transform of my filter (solid) and its Fourier series decomposition (the first 30 members, dashed line).}
\label{filterpic}
\end{figure}

\section{Downsampling in cl-audio-downsample}
So, after your signal is filtered to cut all frequencies which cannot be saved with new sampling rate (suppose, you choose a filter with parameter $a$), you can just pick every $a^{-1}$-th sample, where
$a^{-1}$ is an integral ratio of an old sampling rate to a new sampling rate, $a^{-1} = f_{ref_{old}}/f_{ref_{new}}, a^{-1} \in \mathbb{N}$. Also you can resample to any sampling rate with the ratio
$N/M = f_{ref_{old}}/f_{ref_{new}}$ first inserting $N-1$ zeros between your original samples, when filtering that signal with $a=1/M$, when taking every $M$-th sample from the result. But there is more
efficient methods to do such a resampling, so my library supports only downsampling to an integral ratio of sampling frequencies (e.g. from 192kHz to 48kHz, or from 96KHz to 48kHz). Surely, it can be extended
to support any ratio, but why bother?

\section{Quality}
\textbf{This section may be out of date.}
In this section I will provide some comparison data as some measure of quality. I compared my resampler with swr, a standard resampler for FFmpeg. I used a sine wave with a frequency starting at 440Hz and increasing
to 96kHz at exponential rate as an input signal. The input signal is taken with sampling rate 192kHz and its downsampled version has a sampling rate 48kHz. The signal was generated with SuperCollider, and spectrograms
below was generated by SoX. My library easy-audio was used to read from and write to wav audio files.

\ref{spectro} is a spectrogram of the original sine wave (up) followed by spectograms of resampled versions (bottom). I used two settings for my resampler: with a transition range $b=1/7$ and a fixed filter order $N=50$
and with a transition range $b=1/20$ and an error $0.0001$. Settings which use fixed $N$ can be considered "fast" settings, and settings with "floating" $N$ and a particular error can be considered the "best".
\begin{figure}[h!]
  \begin{subfigure}{\linewidth}
  \includegraphics[width=\linewidth]{original.png}\hfill
  \caption{A spectrogram of the original wave.}
  \end{subfigure}\par\medskip
  \begin{subfigure}{\linewidth}
  \includegraphics[width=.4\linewidth]{swr50.png}\hfill
  \includegraphics[width=.4\linewidth]{swr200.png}\hfill
  \caption{Some spectrograms of the signal resampled with FFmpeg's swr}
  \end{subfigure}\par\medskip
  \begin{subfigure}{\linewidth}
  \includegraphics[width=.4\linewidth]{accurate.png}\hfill
  \includegraphics[width=.4\linewidth]{fast.png}\hfill
  \caption{The signal resampled with cl-audio-downsample with the parameters $b=1/20, error=0.0001$ (left) and $b=1/7, N=50$ (right).}
  \end{subfigure}\par\medskip
  \caption{Spectrograms of the original signal and its downsampled versions.}
  \label{spectro}
\end{figure}

\section{Conclusion}
\textbf{This section may be out of date.}
Although cl-audio-downsample shows test results comparable to FFmpeg's swr, it's no match for soxr resampler. It also has implementation limitations, e.g. it cannot downsample from 96kHz to 44.1kHZ (only to 48KHz). What's more
important, is that I observed that aliasing does not vanish much when you choose $b: 0 < b < 1/20$ with some constant error. I cannot explain it now, maybe it's just a computational error. It's also not very fast, but this is
most certainly a flaw of the implementation.

\end{document}


\documentclass{article}

\usepackage{amsmath,amssymb}
\usepackage{mathpartir}

\newcommand{\Type}{\mathsf{Type}}
\newcommand{\ctx}{\Gamma}
\newcommand{\emptyctx}{\cdot}
\newcommand{\isctx}[1]{#1\ \mathsf{ctx}}

\newcommand{\evalto}{\Longrightarrow}

\newcommand{\jdg}[3]{#1 : #3 \; \left[#2\right]}
\newcommand{\isfresh}[1]{\mathsf{fresh}\;#1}
\newcommand{\of}[1][]{:_{#1}}

\newcommand{\prd}[1]{\Pi #1 \,.\,}
\newcommand{\Eq}[3][]{\mathsf{Eq}_{#1}(#2, #3)}
\newcommand{\refl}[2][]{\mathsf{refl}_{#1}\,#2}
\newcommand{\lam}[1]{\lambda #1 \,.\,}
\newcommand{\abs}[1]{#1 .}
\newcommand{\app}[3][]{#2 \mathrel{@}^{#1} #3}

\newcommand{\subst}[2]{\{#1\}#2}

\newcommand{\anon}{\_}

\newcommand{\join}{\bowtie}
\newcommand{\splitctx}{\rightsquigarrow}
\newcommand{\ent}[1][]{\vdash_{#1}}

\newcommand{\bnfis}{\mathbin{{:}{:}{=}}}
\newcommand{\bnfor}{\mathbin{\mid}}

\newcommand{\val}[1]{\mathtt{val}\;#1}
\newcommand{\typ}{\mathtt{Type}}
\newcommand{\letin}[1]{\mathtt{let}\;#1\;\mathtt{in}\;}
\newcommand{\fra}[1]{\mathtt{forall}\;#1\,\mathtt{,}\,}
\newcommand{\equ}[2]{#1 \;\text{\texttt{==}}\; #2}
\newcommand{\rfl}[1]{\mathtt{refl}\; #1}
\newcommand{\lmb}[1]{\mathtt{lambda}\; #1 \,.\,}
\newcommand{\apl}[2]{#1 \;\texttt{@}\; #2}

\begin{document}

\section{Type theory}

\subsection{Syntax}

\begin{align*}
  \text{Expression}\ e, A, B \
    \bnfis \ & x                              & & \text{variable}\\
    \bnfor \ & \Type                          & & \text{type of types}\\
    \bnfor \ & \prd{x : A} B                  & & \text{product\footnotemark} \\
    \bnfor \ & \Eq[A]{e_1}{e_2}               & & \text{strict equality} \\
    \bnfor \ & \refl[A]{e}                    & & \text{reflexivity} \\
    \bnfor \ & \lam{x : A \,.\, B} e          & & \text{$\lambda$-abstraction\footnotemark} \\
    \bnfor \ & \app[\abs{x : A} B]{e_1}{e_2}  & & \text{application\footnotemark}
  \\
  \text{Context}\ \ctx\
     \bnfis \ & \emptyctx                     & & \text{empty context} \\
     \bnfor \ & \ctx, x : A                   & & \text{context extension}
\end{align*}
%
\footnotetext{$x$ is bound in $B$}%
\footnotetext{$x$ is bound in $B$ and $e$}%
\footnotetext{$x$ is bound in $B$}%
%
Note that both application and $\lambda$-abstraction are tagged with full typing information.

\subsection{Judgements}

\begin{align*}
  & \isctx{\ctx}                & & \text{$\ctx$ is a context}  \\
  & \ctx \ent e \of A         & & \text{$e$ has type $A$}  \\
  & \ctx \ent e_1 = e_2 \of A & & \text{$e_1$ and $e_2$ of type $A$ are equal}
\end{align*}

\subsection{Inference rules}

\subsubsection{Contexts}

The set of variables bound by $\Gamma$ is denoted by $|\Gamma|$.

\begin{mathpar}
  \infer[ctx-empty]
  { }
  {\isctx{\emptyctx}}

  \infer[ctx-extend]
  {\isctx{\ctx}
   \\
   \ctx \ent A : \Type
   \\
   x \not\in |\ctx|}
  {\isctx{(\ctx, x \of A)}}
\end{mathpar}

\subsubsection{Types}

\begin{mathpar}
  \infer[type-type]
  { }
  {\ctx \ent \Type : \Type}

  \infer[type-pi]
  {\ctx \ent A : \Type
  \\
  \ctx, x : A \ent B : \Type
  }
  {\ctx \ent (\prd{x : A} B) \of \Type}

  \infer[type-eq]
  {\ctx \ent A : \Type \\
   \ctx \ent e_1 : A \\
   \ctx \ent e_2 : A}
  {\ctx \ent \Eq[A]{e_1}{e_2} : \Type}

\end{mathpar}

\subsubsection{Terms}

\begin{mathpar}
  \infer[term-var]
  {(x : A) \in \Gamma}
  {\Gamma \ent x : A}

  \infer[term-refl]
  {\ctx \ent A : \Type \\
   \ctx \ent e : A}
  {\ctx \ent (\refl[A]{e}) : \Eq[A]{e}{e}}

  \infer[term-fun]
  {\ctx \ent A \of \Type \\
   \ctx, x : A \ent B : \Type \\
   \ctx, x : A \ent e : B
  }
  {\ctx \ent (\lam{x : A \,.\, B} e) : \prd{x : A} B}

  \infer[term-app]
  {\ctx \ent A : \Type \\
   \ctx, x : A \ent B : \Type \\
   \ctx \ent e_1 : \prd{x : A} B \\
   \ctx \ent e_2 : A}
   {\ctx \ent \app[\abs{x : A} B]{e_1}{e_2} : \subst{e_2/x}{B}}
\end{mathpar}

\subsubsection{Equality}

\begin{mathpar}
  \infer[eq-reflection]
  {\ctx \ent e : \Eq[A]{e_1}{e_2}}
  {\ctx \ent e_1 = e_2 : A}

  \infer[eq-type]
  {\ctx \ent e : A \\
   \ctx \ent A = B : \Type}
  {\ctx \ent e : B}

  \infer[eq-eq]
  {\ctx \ent e_1 = e_2 : A \\
   \ctx \ent A = B : \Type}
  {\ctx \ent e_1 = e_2 : B}

  \infer[eq-subst]
  {\ctx, x : A, y : A \ent B : \Type \\
   \ctx, z : A \ent e : \subst{z/x,z/y}{B} \\
   \ctx \ent e_1 = e_2 : A
  }
  {\ctx \ent \subst{e_1/z}{e} : \subst{e_1/x,e_2/y}{B}}
\end{mathpar}

\subsubsection{Congruence rules}

\begin{mathpar}
  \infer[cong-pi]
  {\ctx \ent A = A' : \Type \\
   \ctx, x : A \ent B = B' : \Type}
  {\ctx \ent (\prd{x : A} B) = (\prd{x : A'} B') : \Type}

  \infer[cong-refl]
  {\ctx \ent A = A' : \Type \\
   \ctx \ent e = e' : A }
  {\ctx \ent \refl[A]{e} = \refl[A']{e'} : \Eq[A]{e}{e}}

  \infer[cong-eq]
  {\ctx \ent A = A' : \Type \\
   \ctx \ent e_1 = e_1' : A \\
   \ctx \ent e_2 = e_2' : A
   }
  {\ctx \ent (\Eq[A]{e_1}{e_2}) = (\Eq[A']{e'_1}{e'_2}) : \Type}
\end{mathpar}

\section{The meta language}

\begin{align*}
  \text{Value}\ v\
    \bnfis \ & x                              & & \text{variable}\\
    \bnfor \ & (\ctx \ent e : A)              & & \text{judgement}
  \\
  \text{Computation}\ c\
    \bnfis \ & \val{v}                        & & \text{value}\\
    \bnfor \ & \letin{x = c_1} c_2            & & \text{binding}\\
    \bnfor \ & \typ                          & & \text{type of types}\\
    \bnfor \ & \fra{x} v                      & & \text{product} \\
    \bnfor \ & \equ{v_1}{v_2}                 & & \text{strict equality} \\
    \bnfor \ & \rfl{v}                        & & \text{reflexivity} \\
    \bnfor \ & \lmb{x} v                      & & \text{$\lambda$-abstraction} \\
    \bnfor \ & \apl{v_1}{v_2}                 & & \text{application}
\end{align*}

\section{Operational semantics of the kernel}

\begin{mathpar}
  \infer[eval-Type]
  { }
  {\Type \evalto \jdg{\Type}{\emptyctx}{\Type}}

  \infer[eval-Var]
  { \isfresh{\alpha}}
  { x \evalto \jdg{x}{\alpha \of[x] \Type, x \of \alpha}{\alpha}}

  \infer[eval-Prod]
  {
  c_1 \evalto \jdg{e_1}{\ctx_1}{A_1} \\
  c_2 \evalto \jdg{e_2}{\ctx_2}{A_2} \\
  \ctx_2 \splitctx (\ctx'_2, x \of[\emptyset] B)
  }
  {
  \prd{x : c_1} c_2
  \evalto
  \jdg
    {\prd{x : e_1} e_2}
    {\begin{aligned}
     & \ctx_1 \join \ctx'_2, \\
    & \anon \of[\epsilon_1] \Eq[\Type]{A_1}{\Type}, \\
    & \anon \of \prd{x : B} (\Eq[\Type]{A_2}{\Type}),\\
    & \epsilon_1 \of \Eq[\Type]{e_1}{B}
     \end{aligned}
    }{
     \Type
    }
  }

  \infer[eval-Eq]
  {
    c_1 \evalto \jdg{e_1}{\ctx_1}{A_1} \\
    c_2 \evalto \jdg{e_2}{\ctx_2}{A_2} \\
    \isfresh{\alpha}
  }{
    \Eq{c_1}{c_2}
    \evalto
    \jdg
    {
      \Eq[\alpha]{e_1}{e_2}
    }{
      \ctx_1 \join \ctx_2,
      \alpha \of[\epsilon_1,\epsilon_2] \Type,
      \epsilon_1 \of \Eq[\Type]{\alpha}{A_1},
      \epsilon_2 \of \Eq[\Type]{\alpha}{A_2}
    }{
      \Type
    }
  }

  \infer[eval-Refl]
  {c \evalto \jdg{e}{\ctx}{A}}
  {\refl{c}
   \evalto
   \jdg
   {\refl[A]{e}}
   {\ctx}
   {(\Eq[A]{e}{e})}
  }

  \infer[eval-Fun]
  {c \evalto \jdg{e}{\ctx}{A} \\
   \ctx \splitctx (\ctx', x \of[\emptyset] B)
  }{
    (\lam{x} c)
    \evalto
    \jdg
    {(\lam{x:B}{e})}
    {\ctx'}
    {(\prd{x : B} A)}
  }

  \infer[eval-App]
  {
   c_1 \evalto \jdg{e_1}{\ctx_1}{A_1} \\
   c_2 \evalto \jdg{e_2}{\ctx_2}{A_2} \\
   \isfresh{\alpha}
  }
  {
   \app{c_1}{c_2}
   \evalto
   \jdg
   {
    (\app[\abs{x : \alpha} {\app[\abs{\anon : \alpha} \Type]{\beta}{x}}]{e_1}{e_2})
   }{
    \begin{aligned}
    & \ctx_1 \join \ctx_2, \\
    & \alpha \of[\epsilon_1,\epsilon_2, \beta] \Type, \\
    & \beta \of[\epsilon_1] \alpha \to \Type, \\
    & \epsilon_1 \of \Eq[\Type]{A_1}{\prd{x : \alpha} \app[\abs{\anon : \alpha} \Type]{\beta}{x}}, \\
    & \epsilon_2 \of \Eq[\Type]{\alpha}{A_2}
    \end{aligned}
   }{
    (\app[\abs{\anon : \alpha} \Type]{\beta}{e_2})
   }
  }

\end{mathpar}
\end{document}


\chapter{Things Galois}
%This chapter is mostly optional.
%Read the first two sections and then decide
%whether you want to read the rest of this chapter.

\section{Motivation}
\prototype{$\QQ(\sqrt2)$ and $\QQ(\cbrt{2})$.}
The key idea in Galois theory is that of \emph{embeddings},
which give us another way to get at the idea of the ``conjugate'' we described earlier.

Let $K$ be a number field.
An \vocab{embedding} $\sigma : K \injto \CC$, is an \emph{injective field homomorphism}:
it needs to preserve addition and multiplication,
and in particular it should fix $1$.
\begin{ques}
	Show that in this context, $\sigma(q) = q$ for any rational number $q$.
\end{ques}

\begin{example}
	[Examples of embeddings]
	\listhack
	\begin{enumerate}[(a)]
		\ii If $K = \QQ(i)$, the two embeddings of $K$ into $\CC$ are
		$z \mapsto z$ (the identity) and $z \mapsto \ol z$ (complex conjugation).
		\ii If $K = \QQ(\sqrt 2)$, the two embeddings of $K$ into $\CC$ are
		$a+b\sqrt 2 \mapsto a+b\sqrt 2$ (the identity) and $a+b\sqrt 2 \mapsto a-b\sqrt 2$ (conjugation).
		\ii If $K = \QQ(\cbrt 2)$, there are three embeddings:
		\begin{itemize}
			\ii The identity embedding, which sends $1 \mapsto 1$ and $\cbrt 2 \mapsto \cbrt 2$.
			\ii An embedding which sends $1 \mapsto 1$ and $\cbrt 2 \mapsto \omega \cbrt 2$,
			where $\omega$ is a cube root of unity.
			Note that this is enough to determine the rest of the embedding.
			\ii An embedding which sends $1 \mapsto 1$ and $\cbrt 2 \mapsto \omega^2 \cbrt 2$.
		\end{itemize}
	\end{enumerate}
\end{example}

I want to make several observations about these embeddings,
which will form the core ideas of Galois theory.
Pay attention here!

\begin{itemize}
\ii
First, you'll notice some duality between roots: in the first example, $i$ gets sent to $\pm i$,
$\sqrt 2$ gets sent to $\pm \sqrt 2$, and $\cbrt 2$ gets sent to the other roots of $x^3-2$.
This is no coincidence, and one can show this occurs in general.
Specifically, suppose $\alpha$ has minimal polynomial
\[ 0 = c_n \alpha^n + c_{n-1} \alpha^{n-1} + \dots + c_1\alpha + c_0 \]
where the $c_i$ are rational.
Then applying any embedding $\sigma$ to both sides gives
\begin{align*}
	0 &= \sigma(c_n \alpha^n + c_{n-1} \alpha^{n-1} + \dots + c_1\alpha + c_0) \\
	% &= \sigma(c_n \alpha^n) + \sigma(c_{n-1} \alpha^{n-1})
	% + \dots + \sigma(c_1\alpha) + \sigma(c_0) \\
	&= \sigma(c_n) \sigma(\alpha)^n + \sigma(c_{n-1}) \sigma(\alpha)^{n-1}
	+ \dots + \sigma(c_1)\sigma(\alpha) + \sigma(c_0) \\
	&= c_n \sigma(\alpha)^n + c_{n-1} \sigma(\alpha)^{n-1} + \dots + c_1\sigma(\alpha) + c_0
\end{align*}
where in the last step we have used the fact that $c_i \in \QQ$, so they are fixed by $\sigma$.
\emph{So, roots of minimal polynomials go to other roots of that polynomial.}

\ii
Next, I want to draw out a contrast between the second and third examples.
Specifically, in example (b) where we consider embeddings $K = \QQ(\sqrt 2)$
to $\CC$.  The image of these embeddings lands entirely in $K$: that is, we
could just as well have looked at $K \to K$ rather than looking at $K \to \CC$.
However, this is not true in (c): indeed $\QQ(\cbrt 2) \subset \RR$,
but the non-identity embeddings have complex outputs!

The key difference is to again think about conjugates.
Key observation:
\begin{moral}
	The field $K = \QQ(\cbrt 2)$ is ``deficient'' because the minimal polynomial $x^3-2$
	has two other roots $\omega \cbrt{2}$ and $\omega^2 \cbrt{2}$ not contained in $K$.
\end{moral}
On the other hand $K = \QQ(\sqrt 2)$ is just fine because both roots of $x^2-2$ are contained inside $K$.
Finally, one can actually fix the deficiency in $K = \QQ(\cbrt 2)$ by completing it to a field $\QQ(\cbrt 2, \omega)$.
Fields like $\QQ(i)$ or $\QQ(\sqrt 2)$ which are ``self-contained'' are called
\emph{Galois extensions}, as we'll explain shortly.

\ii
Finally, you'll notice that in the examples above, \emph{the number of embeddings from $K$ to $\CC$
happens to be the degree of $K$}.
This is an important theorem, \Cref{thm:n_embeddings}.
\end{itemize}

In this chapter we'll develop these ideas in full generality, for any field other than $\QQ$.

\section{Field extensions, algebraic closures, and splitting fields}
\prototype{$\QQ(\cbrt 2)/\QQ$ is an extension, $\CC$ is an algebraic closure of any number field.}

First, we define a notion of one field sitting inside another,
in order to generalize the notion of a number field.
\begin{definition}
	Let $K$ and $F$ be fields.
	If $F \subseteq K$, we write $K/F$ and say $K$ is a
	\vocab{field extension} of $F$.

	Thus $K$ is automatically an $F$-vector space
	(just like $\QQ(\sqrt 2)$ is automatically a $\QQ$-vector space).
	The \vocab{degree} is the dimension of this space, denoted $[K:F]$.
	If $[K:F]$ is finite, we say $K/F$ is a \vocab{finite (field) extension}.
\end{definition}
That's really all. There's nothing tricky at all.

\begin{ques}
	What do you call a finite extension of $\QQ$?
\end{ques}

Degrees of finite extensions are multiplicative.
\begin{theorem}[Field extensions have multiplicative degree]
	Let $F \subseteq K \subseteq L$ be fields with $L/K$, $K/F$ finite. Then
	\[ [L:K][K:F] = [L:F]. \]
\end{theorem}
\begin{proof}
	Basis bash: you can find a basis of $L$ over $K$,
	and then expand that into a basis $L$ over $F$.
	(Diligent readers can fill in details.)
\end{proof}

Next, given a field (like $\QQ(\cbrt2)$)
we want something to embed it into (in our case $\CC$).
So we just want a field that contains all the roots of all the polynomials:
\begin{theorem}[Algebraic closures]
	Let $F$ be a field.
	Then there exists a field extension $\ol F$ containing $F$, called an \vocab{algebraic closure},
	such that all polynomials in $\ol F[x]$ factor completely.
\end{theorem}
\begin{example}
	[$\CC$]
	$\CC$ is an algebraic closure of $\QQ$, $\RR$ and even itself.
\end{example}
\begin{abuse}
	Some authors also require the algebraic closure to be \emph{minimal by inclusion}:
	for example, given $\QQ$ they would want only $\ol\QQ$ (the algebraic numbers).
	It's a theorem that such a minimal algebraic closure is unique,
	and so these authors will refer to \emph{the} algebraic closure of $K$.

	I like $\CC$, so I'll use the looser definition.
\end{abuse}

\section{Embeddings into algebraic closures for number fields}
Now that I've defined all these ingredients, I can prove:
\begin{theorem}[The $n$ embeddings of a number field]
	\label{thm:n_embeddings}
	Let $K$ be a number field of degree $n$.
	Then there are exactly $n$ field homomorphisms $K \injto \CC$,
	say $\sigma_1, \dots, \sigma_n$ which fix $\QQ$.
\end{theorem}
\begin{remark}
	Note that a nontrivial homomorphism of fields is necessarily injective
	(the kernel is an ideal).
	This justifies the use of ``$\injto$'', and we call each $\sigma_i$ an
	\vocab{embedding} of $K$ into $\CC$.
\end{remark}
\begin{proof}
	This is actually kind of fun!
	Recall that any irreducible polynomial over $\QQ$ has distinct roots (\Cref{lem:irred_complex}).
	We'll adjoin elements $\alpha_1, \alpha_2, \dots, \alpha_m$ one at a time to $\QQ$,
	until we eventually get all of $K$, that is,
	\[ K = \QQ(\alpha_1, \dots, \alpha_n). \]
	Diagrammatically, this is
	\begin{diagram}
		\QQ & \rInj & \QQ(\alpha_1) & \rInj & \QQ(\alpha_1, \alpha_2) & \rInj & \dots & \rInj & K \\
		\dInj^\id && \dInj^{\tau_1} && \dInj^{\tau_2} && \dots && \dInj_{\tau_m = \sigma} \\
		\CC & \rTo & \CC & \rTo & \CC & \rTo & \dots & \rTo & \CC \\
	\end{diagram}

	First, we claim there are exactly \[ [\QQ(\alpha_1) : \QQ] \] ways to pick $\tau_1$.
	Observe that $\tau_1$ is determined by where it sends $\alpha_1$ (since it has to fix $\QQ$).
	Letting $p_1$ be the minimal polynomial of $\alpha_1$, we see that there are $\deg p_1$ choices for $\tau_1$,
	one for each (distinct) root of $p_1$. That proves the claim.

	Similarly, given a choice of $\tau_1$, there are
	\[ [\QQ(\alpha_1, \alpha_2) : \QQ(\alpha_1)] \]
	ways to pick $\tau_2$.
	(It's a little different: $\tau_1$ need not be the identity.
	But it's still true that $\tau_2$ is determined by where it sends $\alpha_2$,
	and as before there are $[\QQ(\alpha_1, \alpha_2) : \QQ(\alpha_1)]$ possible ways.)

	Multiplying these all together gives the desired $[K:\QQ]$.
\end{proof}
\begin{remark}
	The primitive element theorem actually implies that $m = 1$
	is sufficient; we don't need to build a whole tower.
	This simplifies the proof somewhat.
\end{remark}

It's common to see expressions like ``let $K$ be a number field of degree $n$,
and $\sigma_1, \dots, \sigma_n$ its $n$ embeddings'' without further explanation.
The relation between these embeddings and the Galois conjugates is given as follows.
\begin{theorem}[Embeddings are evenly distributed over conjugates]
	\label{thm:conj_distrb}
	Let $K$ be a number field of degree $n$
	with $n$ embeddings $\sigma_1$, \dots, $\sigma_n$,
	and let $\alpha \in K$ have $m$ Galois conjugates over $\QQ$.

	Then $\sigma_j(\alpha)$ is ``evenly distributed''
	over each of these $m$ conjugates: for any Galois conjugate $\beta$,
	exactly $\frac nm$ of the embeddings send $\alpha$ to $\beta$.
\end{theorem}
\begin{proof}
	In the previous proof, adjoin $\alpha_1 = \alpha$ first.
\end{proof}

So, now we can define the trace and norm over $\QQ$ in a nice way:
given a number field $K$, we set
\[
	\Tr_{K/\QQ}(\alpha) = \sum_{i=1}^n \sigma_i(\alpha)
	\quad\text{and}\quad
	\Norm_{K/\QQ}(\alpha) = \prod_{i=1}^n \sigma_i(\alpha)
\]
where $\sigma_i$ are the $n$ embeddings of $K$ into $\CC$.

\section{Everyone hates characteristic 2: separable vs irreducible}
\prototype{$\QQ$ has characteristic zero, hence irreducible polynomials are separable.}
Now, we want a version of the above theorem for any field $F$.
If you read the proof, you'll see that the only thing that ever uses anything about the field $\QQ$
is \Cref{lem:irred_complex}, where we use the fact that
\begin{quote}
	\itshape Irreducible polynomials over $F$ have no double roots.
\end{quote}

Let's call a polynomial with no double roots \vocab{separable};
thus we want irreducible polynomials to be separable.
We did this for $\QQ$ in the last chapter by taking derivatives.
Should work for any field, right?

Nope.
Suppose we took the derivative of some polynomial like $2x^3 + 24x + 9$,
namely $6x^2 + 24$.
In $\CC$ it's obvious that the derivative of a nonconstant polynomial $f'$ isn't zero.
But suppose we considered the above as a polynomial in $\FF_3$, i.e.\ modulo $3$.
Then the derivative is zero.
Oh, no!

We have to impose a condition that prevents something like this from happening.
\begin{definition}
	For a field $F$, the \vocab{characteristic} of $F$ is the smallest
	positive integer $p$ such that,
	\[ \underbrace{1_F + \dots + 1_F}_{\text{$p$ times}} = 0 \]
	or zero if no such integer $p$ exists.
\end{definition}
\begin{example}[Field characteristics]
	Old friends $\RR$, $\QQ$, $\CC$ all have characteristic zero.
	But $\FF_p$, the integers modulo $p$, is a field of characteristic $p$.
\end{example}
\begin{exercise}
	Let $F$ be a field of characteristic $p$.
	Show that if $p > 0$ then $p$ is a prime number.
	(A proof is given next chapter.)
\end{exercise}
With the assumption of characteristic zero, our earlier proof works.
\begin{lemma}[Separability in characteristic zero]
	Any irreducible polynomial in a characteristic zero field is separable.
\end{lemma}
Unfortunately, this lemma is false if the ``characteristic zero'' condition is dropped.

\begin{remark}
	The reason it's called \emph{separable} is (I think) this picture:
	I have a polynomial and I want to break it into irreducible parts.
	Normally, if I have a double root in a polynomial, that means it's not irreducible.
	But in characteristic $p > 0$ this fails.
	So inseparable polynomials are strange when you think about them: somehow
	you have double roots that can't be separated from each other.
\end{remark}

We can get this to work for any field extension in which separability is not an issue.
\begin{definition}
	A \vocab{separable extension} $K/F$ is one in which every irreducible
	polynomial in $F$ is separable (for example, if $F$ has characteristic zero).
	A field $F$ is \vocab{perfect} if any finite field extension $K/F$ is separable.
\end{definition}
In fact, as we see in the next chapter:
\begin{theorem}
	[Finite fields are perfect]
	Suppose $F$ is a field with finitely many elements. Then it is perfect.
\end{theorem}
Thus, we will almost never have to worry about separability
since every field we see in the Napkin is either finite or characteristic $0$.
So the inclusion of the word ``separable'' is mostly a formality.

Proceeding onwards, we obtain
\begin{theorem}[The $n$ embeddings of any separable extension]
	Let $K/F$ be a separable extension of degree $n$ and let $\ol F$ be an algebraic closure of $F$.
	Then there are exactly $n$ field homomorphisms $K \injto \ol F$,
	say $\sigma_1, \dots, \sigma_n$, which fix $F$.
\end{theorem}

In any case, this lets us define the trace for \emph{any} separable normal extension.
\begin{definition}
Let $K/F$ be a separable extension of degree $n$, and let $\sigma_1$, \dots, $\sigma_n$
be the $n$ embeddings into an algebraic closure of $F$. Then we define
\[
	\Tr_{K/F}(\alpha) = \sum_{i=1}^n \sigma_i(\alpha)
	\quad\text{and}\quad
	\Norm_{K/F}(\alpha) = \prod_{i=1}^n \sigma_i(\alpha).
\]
When $F = \QQ$ and the algebraic closure is $\CC$, this coincides with our earlier definition!
\end{definition}

\section{Automorphism groups and Galois extensions}
\prototype{$\QQ(\sqrt 2)$ is Galois but $\QQ(\cbrt 2)$ is not.}
We now want to get back at the idea we stated at the beginning of
this section that $\QQ(\cbrt 2)$ is deficient in a way that $\QQ(\sqrt 2)$ is not.

First, we define the ``internal'' automorphisms.
\begin{definition}
	Suppose $K/F$ is a finite extension.
	Then $\Aut(K/F)$ is the set of \emph{field isomorphisms} $\sigma : K \to K$ which fix $F$.
	In symbols
	\[ \Aut(K/F) =
		\left\{
		\sigma : K \to K \mid
		\text{$\sigma$ is identity on $F$}
	  \right\}.
	\]
	This is a group under function composition!
\end{definition}
Note that this time, we have a condition that $F$ is fixed by $\sigma$.
(This was not there before when we considered $F = \QQ$, because we got it for free.)

\begin{example}[Old examples of automorphism groups]
	Reprising the example at the beginning of the chapter in the new notation, we have:
	\begin{enumerate}[(a)]
		\ii $\Aut(\QQ(i) / \QQ) \cong \Zc 2$, with elements $z \mapsto z$ and $z \mapsto \ol z$.
		\ii $\Aut(\QQ(\sqrt 2) / \QQ) \cong \Zc 2$ in the same way.
		\ii $\Aut(\QQ(\cbrt 2) / \QQ)$ is the trivial group, with only the identity embedding!
	\end{enumerate}
\end{example}

\begin{example}[Automorphism group of $\QQ(\sqrt2,\sqrt3)$]
	Here's a new example: let $K = \QQ(\sqrt2, \sqrt3)$.
	It turns out that $\Aut(K/\QQ) = \{1, \sigma, \tau, \sigma\tau\}$, where
	\[
		\sigma :
		\begin{cases}
			\sqrt2 &\mapsto -\sqrt2 \\
			\sqrt3 &\mapsto \sqrt3
		\end{cases}
		\quad\text{and}\quad
		\tau :
		\begin{cases}
			\sqrt2 &\mapsto \sqrt2 \\
			\sqrt3 &\mapsto -\sqrt3.
		\end{cases}
	\]
	In other words, $\Aut(K/\QQ)$ is the Klein Four Group.
\end{example}

First, let's repeat the proof of the observation that these embeddings shuffle around roots
(akin to the first observation in the introduction):
\begin{lemma}
	[Root shuffling in $\Aut(K/F)$]
	Let $f \in F[x]$, suppose $K/F$ is a finite extension,
	and assume $\alpha \in K$ is a root of $f$.
	Then for any $\sigma \in \Aut(K/F)$, $\sigma(\alpha)$ is also a root of $f$.
	\label{lem:root_shuffle}
\end{lemma}
\begin{proof}
	Let $f(x) = c_n x^n + c_{n-1}x^{n-1} + \dots + c_0$,
	where $c_i \in F$. Thus,
	\[ 0 = \sigma(f(\alpha)) = \sigma\left( c_n\alpha^n + \dots + c_0 \right)
	= c_n\sigma(\alpha)^n + \dots + c_0 = f(\sigma(\alpha)). \qedhere \]
\end{proof}
In particular, taking $f$ to be the minimal polynomial of $\alpha$ we deduce
\begin{moral}
	An embedding $\sigma \in \Aut(K/F)$ sends an $\alpha \in K$
	to one of its various Galois conjugates (over $F$).
\end{moral}

Next, let's look again at the ``deficiency'' of certain fields.
Look at $K = \QQ(\cbrt 2)$.
So, again $K / \QQ$ is deficient for two reasons.
First, while there are three maps $\QQ(\cbrt 2) \injto \CC$,
only one of them lives in $\Aut(K/\QQ)$, namely the identity.
In other words, $\left\lvert \Aut(K/\QQ) \right\rvert$ is \emph{too small}.
Secondly, $K$ is missing some Galois conjugates ($\omega \cbrt 2$ and $\omega^2 \cbrt 2$).

The way to capture the fact that there are missing Galois conjugates
is the notion of a splitting field.
\begin{definition}
	Let $F$ be a field and $p(x) \in F[x]$ a polynomial of degree $n$.
	Then $p(x)$ has roots $\alpha_1, \dots, \alpha_n$ in an algebraic closure of $F$.
	The \vocab{splitting field} of $F$ is defined as $F(\alpha_1, \dots, \alpha_n)$.
\end{definition}
In other words, the splitting field is the smallest field in which $p(x)$ splits.
\begin{example}[Examples of splitting fields]
	\listhack
	\begin{enumerate}[(a)]
		\ii The splitting field of $x^2 - 5$ over $\QQ$ is $\QQ(\sqrt 5)$.
		This is a degree $2$ extension.
		\ii The splitting field of $x^2+x+1$ over $\QQ$ is $\QQ(\omega)$,
		where $\omega$ is a cube root of unity.
		This is a degree $3$ extension.
		% In particular, the splitting field of $x^3-2$ is a degree \emph{six} extension.
		\ii The splitting field of $x^2+3x+2 = (x+1)(x+2)$ is just $\QQ$!
		There's nothing to do.
	\end{enumerate}
\end{example}
\begin{example}
	[Splitting fields: a cautionary tale]
	The splitting field of $x^3 - 2$ over $\QQ$ is in fact
	\[ \QQ( \cbrt 2, \omega ) \]
	and not just $\QQ(\cbrt 2)$!
	One must really adjoin \emph{all} the roots, and it's not necessarily the case that
	these roots will generate each other.

	To be clear:
	\begin{itemize}
	\ii For $x^2-5$, we adjoin $\sqrt 5$ and this will automatically include $-\sqrt 5$.
	\ii For $x^2+x+1$, we adjoin $\omega$ and get the other root $\omega^2$ for free.
	\ii But for $x^3-2$, if we adjoin $\cbrt 2$,
	we do NOT get $\omega\cbrt2$ and $\omega^2\cbrt2$ for free.
	Indeed, $\QQ(\cbrt 2) \subset \RR$!
	\end{itemize}
	Note that in particular, the splitting field of
	$x^3-2$ over $\QQ$ is \emph{degree six}, not just degree three.
\end{example}

In general,
\textbf{the splitting field of a polynomial can be an extension of degree up to $n!$}.
The reason is that if $p(x)$ has $n$ roots and none of them are ``related'' to each other,
then any permutation of the roots will work.

Now, we obtain:
\begin{theorem}[Galois extensions are splitting]
	For finite extensions $K/F$,
	$\left\lvert \Aut(K/F) \right\rvert$ divides $[K:F]$,
	with equality if and only if $K$ is the \emph{splitting field}
	of some separable polynomial with coefficients in $F$.
	\label{thm:Galois_splitting}
\end{theorem}
The proof of this is deferred to an optional section at the end of the chapter.
If $K/F$ is a finite extension and $\left\lvert \Aut(K/F) \right\rvert = [K:F]$,
we say the extension $K/F$ is \vocab{Galois}.
In that case, we denote $\Aut(K/F)$ by $\Gal(K/F)$ instead
and call this the \vocab{Galois group} of $K/F$.

\begin{example}
	[Examples and non-examples of Galois extensions]
	\listhack
	\begin{enumerate}[(a)]
		\ii The extension $\QQ(\sqrt2) / \QQ$ is Galois,
		since it's the splitting field of $x^2-2$ over $\QQ$.
		The Galois group has order two, $\sqrt 2 \mapsto \pm \sqrt 2$.
		\ii The extension $\QQ(\sqrt2, \sqrt 3) / \QQ$ is Galois,
		since it's the splitting field of $(x^2-5)^2-6$ over $\QQ$.
		As discussed before, the Galois group is $\Zc 2 \times \Zc 2$.
		\ii The extension $\QQ(\cbrt{2}) / \QQ$ is \emph{not} Galois.
	\end{enumerate}
\end{example}

%Here is some more intuition on what $[K:F]$ actually measures: suppose $K$ is a splitting field
%of some $(x-\alpha_1) \dots (x-\alpha_n)$, meaning $K = F(\alpha_1, \dots, \alpha_n)$.
%Then a permutation $\sigma \in \Aut(K/F)$ is determined by where it sends each $\alpha_i$.
%The dimension of $[K:F]$ measures how much ``redundancy'' there is among the $\alpha_i$.
%For example, in the case of \[ (x-\sqrt5)(x+\sqrt5) = x^2-5  \]the $\sqrt 5$ and $-\sqrt 5$ were redundant,
%in the sense that knowing $\sigma(\sqrt 5)$ tells you $\sigma(-\sqrt 5) = -\sigma(\sqrt 5)$.
%But in the $x^3-2$ case, knowing $\sigma(\cbrt{2})$ does \emph{not} tell you where
%$\omega\cbrt{2}$ should go; this is reflected in the fact that $[K:F]$ and $\Aut(K/F)$
%are both six rather than three.

To explore $\QQ(\cbrt 2)$ one last time:
\begin{example}
	[Galois closures, and the automorphism group of $\QQ(\cbrt2, \omega)$]
	Let's return to the field $K = \QQ(\cbrt 2, \omega)$,
	which is a field with $[K:\QQ] = 6$.
	Consider the two automorphisms:
	\[
		\sigma:
		\begin{cases}
			\cbrt 2 &\mapsto \omega \cbrt 2 \\
			\omega &\mapsto \omega
		\end{cases}
		\quad\text{and}\quad
		\tau:
		\begin{cases}
			\cbrt 2 &\mapsto \cbrt 2 \\
			\omega &\mapsto \omega^2.
		\end{cases}
	\]
	Notice that $\sigma^3 = \tau^2 = \id$.
	From this one can see that the automorphism group of $K$ must have order $6$
	(it certainly has order $\le 6$; now use Lagrange's theorem).
	So, $K/\QQ$ is Galois! Actually one can check explicitly that
	\[ \Gal(K/\QQ) \cong S_3 \]
	is the symmetric group on $3$ elements, with order $3! = 6$.
\end{example}
This example illustrates the fact that
given a non-Galois field extension,
one can ``add in'' missing conjugates to make it Galois.
This is called taking a \vocab{Galois closure}.

\section{Fundamental theorem of Galois theory}
After all this stuff about Galois Theory, I might as well tell you the fundamental theorem,
though I won't prove it.
Basically, it says that if $K/F$ is Galois with Galois group $G$, then:
\begin{moral}
	Subgroups of $G$ correspond exactly to fields $E$ with $F \subseteq E \subseteq K$.
\end{moral}

To tell you how the bijection goes, I have to define a fixed field.
\begin{definition}
	Let $K$ be a field and $H$ a subgroup of $\Aut(K/F)$.
	We define the \vocab{fixed field} of $H$, denoted $K^H$, as
	\[ K^H \defeq \left\{ x \in K : \sigma(x)=x \; \forall \sigma \in H \right\}. \]
\end{definition}
\begin{ques}
	Verify quickly that $K^H$ is actually a field.
\end{ques}

Now let's look at examples again.
Consider $K = \QQ(\sqrt2, \sqrt3)$,
where \[ G = \Gal(K/\QQ) = \{\id, \sigma, \tau, \sigma\tau\} \]
is the Klein four group
(where $\sigma(\sqrt2) = -\sqrt 2$ but $\sigma(\sqrt 3) = \sqrt 3$; $\tau$ goes the other way).
\begin{ques}
	Let $H = \{\id, \sigma\}$. What is $K^H$?
\end{ques}
In that case, the diagram of fields between $\QQ$ and $K$
matches exactly with the subgroups of $G$, as follows:
\begin{center}
\begin{minipage}[t]{4cm}
	\begin{diagram}
		& \QQ(\sqrt2, \sqrt 3) & \\
		\ldLine(1,2) & \dLine & \rdLine(1,2) \\
		\QQ(\sqrt2) & \QQ(\sqrt 6) & \QQ(\sqrt 3) \\
		& \ldLine(1,2) \dLine \rdLine(1,2) & \\
		& \QQ &
	\end{diagram}
\end{minipage}
\qquad
\begin{minipage}[t]{4cm}
	\begin{diagram}
		& \{\id\} & \\
		\ldLine(1,2) & \dLine & \rdLine(1,2) \\
		\{\id,\tau\} & \;\; \{\id, \sigma\tau\} \;\; & \{\id,\sigma\} \\
		& \ldLine(1,2) \dLine \rdLine(1,2) & \\
		& G &
	\end{diagram}
\end{minipage}
\end{center}
We see that subgroups correspond to fixed fields.
That, and much more, holds in general.

\begin{theorem}[Fundamental theorem of Galois theory]
	Let $K/F$ be a Galois extension with Galois group $G = \Gal(K/F)$.
	\begin{enumerate}[(a)]
	\ii There is a bijection between field towers $F \subseteq E \subseteq K$ and subgroups $H \subseteq G$:
	\[
		\left\{
		\begin{array}{c}
			K \\ \mid \\ E \\ \mid \\ F
		\end{array}
		\right\}
		\iff
		\left\{
		\begin{array}{c}
			1 \\ \mid \\ H \\ \mid \\ G
		\end{array}
		\right\}
	\]
	The bijection sends $H$ to its fixed field $K^H$, and hence is inclusion reversing.
	\ii Under this bijection, we have $[K:E] = \left\lvert H \right\rvert$ and $[E:F] = [G:H]$.
	\ii $K/E$ is always Galois, and its Galois group is $\Gal(K/E) = H$.
	\ii $E/F$ is Galois if and only if $H$ is normal in $G$. If so, $\Gal(E/F) = G/H$.
	\end{enumerate}
\end{theorem}

\begin{exercise}
	Suppose we apply this theorem for
	\[ K = \QQ(\cbrt2, \omega). \]
	Verify that the fact $E = \QQ(\cbrt 2)$ is not Galois
	corresponds to the fact that $S_3$ does not have normal subgroups of order $2$.
\end{exercise}

\section\problemhead
\begin{sproblem}[Galois group of the cyclotomic field]
	Let $p$ be an odd rational prime and $\zeta_p$ a primitive $p$th root of unity.
	Let $K = \QQ(\zeta_p)$.
	Show that \[ \Gal(K/\QQ) \cong (\ZZ/p\ZZ)^\ast. \]
	\begin{hint}
		Look at the image of $\zeta_p$.
	\end{hint}
	\begin{sol}
		It's just $\Zc{p-1}$, since $\zeta_p$ needs to get sent
		to one (any) of the $p-1$ primitive roots of unity.
	\end{sol}
\end{sproblem}

\begin{problem}[Greek constructions]
	Prove that the three Greek constructions
	\begin{enumerate}[(a)]
		\ii doubling the cube,
		\ii squaring the circle, and
		\ii trisecting an angle
	\end{enumerate}
	are all impossible.
	(Assume $\pi$ is transcendental.)
	\begin{hint}
		Repeated quadratic extensions have degree $2$, so one can
		only get powers of two.
	\end{hint}
\end{problem}

\begin{problem}
	[China Hong Kong Math Olympiad]
	\yod
	Prove that there are no rational numbers $p$, $q$, $r$ satisfying
	\[ \cos\left( \frac{2\pi}{7} \right)
		= p + \sqrt{q} + \sqrt[3]{r}.  \]
	\begin{sol}
		A similar (but not identical) problem is solved here:
		\url{https://aops.com/community/c6h149153p842956}.
	\end{sol}
\end{problem}

\begin{problem}
	Show that the only automorphism of $\RR$ is the identity.
	Hence $\Aut(\RR)$ is the trivial group.
	\begin{hint}
		Hint: $\sigma(x^2) = \sigma(x)^2 \ge 0$ plus Cauchy's Functional Equation.
	\end{hint}
\end{problem}

\begin{problem}[Artin's primitive element theorem]
	\yod
	Let $K$ be a number field.
	Show that $K \cong \QQ(\gamma)$ for some $\gamma$.
	\label{prob:artin_primitive_elm}
	\begin{hint}
		By induction, suffices to show $\QQ(\alpha, \beta) = \QQ(\gamma)$
		for some $\gamma$ in terms of $\alpha$ and $\beta$.
		For all but finitely many rational $\lambda$,
		the choice $\gamma = \alpha + \lambda \beta$ will work.
	\end{hint}
	\begin{sol}
		\url{http://www.math.cornell.edu/~kbrown/6310/primitive.pdf}
	\end{sol}
\end{problem}

\section{(Optional) Proof that Galois extensions are splitting}
We prove \Cref{thm:Galois_splitting}.
First, we extract a useful fragment from the fundamental theorem.
\begin{theorem}[Fixed field theorem]
	\label{thm:fixed_field_theorem}
	Let $K$ be a field and $G$ a subgroup of $\Aut(K)$.
	Then $[K:K^G] = \left\lvert G \right\rvert$.
\end{theorem}

The inequality itself is not difficult:
\begin{exercise}
	Show that $[K:F] \ge |\Aut(K/F)|$,
	and that equality holds if and only if
	the set of elements fixed by all $\sigma \in \Aut(K/F)$
	is exactly $F$.
	(Use \Cref{thm:fixed_field_theorem}.)
\end{exercise}
The equality case is trickier.

The easier direction is when $K$ is a splitting field.
Assume $K = F(\alpha_1, \dots, \alpha_n)$ is the splitting field of some separable polynomial $p \in F[x]$
with $n$ distinct roots $\alpha_1, \dots, \alpha_n$.
Adjoin them one by one:
\begin{diagram}
	F & \rInj & F(\alpha_1) & \rInj & F(\alpha_1, \alpha_2) & \rInj & \dots & \rInj & K \\
	\dTo^\id && \dTo^{\tau_1} && \dTo^{\tau_2} && \dots && \dTo_{\tau_n = \sigma} \\
	F & \rInj & F(\alpha_1) & \rInj & F(\alpha_1, \alpha_2) & \rInj & \dots & \rInj & K \\
\end{diagram}
(Does this diagram look familiar?)
Every map $K \to K$ which fixes $F$ corresponds to an above commutative diagram.
As before, there are exactly $[F(\alpha_1) : F]$ ways to pick $\tau_1$.
(You need the fact that the minimal polynomial $p_1$ of $\alpha_1$ is separable for this:
there need to be exactly $\deg p_1 = [F(\alpha_1) : F]$ distinct roots to nail $p_1$ into.)
Similarly, given a choice of $\tau_1$, there are $[F(\alpha_1, \alpha_2) : F(\alpha_1)]$ ways to pick $\tau_2$.
Multiplying these all together gives the desired $[K:F]$.

\bigskip

Now assume $K/F$ is Galois.
First, we state:
\begin{lemma}
	Let $K/F$ be Galois, and $p \in F[x]$ irreducible.
	If any root of $p$ (in $\ol F$) lies in $K$, then all of them do,
	and in fact $p$ is separable.
\end{lemma}
\begin{proof}
	Let $\alpha \in K$ be the prescribed root.
	Consider the set
	\[ S = \left\{ \sigma(\alpha) \mid \sigma \in \Gal(K/F) \right\}. \]
	(Note that $\alpha \in S$ since $\Gal(K/F) \ni \id$.)
	By construction, any $\tau \in \Gal(K/F)$ fixes $S$.
	So if we construct
	\[ \tilde p(x) = \prod_{\beta \in S} (x - \beta), \]
	then by Vieta's Formulas, we find that all the coefficients of $\tilde p$ are fixed by elements of $\sigma$.
	By the \emph{equality case} we specified in the exercise, it follows that $\tilde p$ has coefficients in $F$!
	(This is where we use the condition.)
	Also, by \Cref{lem:root_shuffle}, $\tilde p$ divides $p$.

	Yet $p$ was irreducible, so it is the minimal polynomial of $\alpha$ in $F[x]$,
	and therefore we must have that $p$ divides $\tilde p$.
	Hence $p = \tilde p$. Since $\tilde p$ was built to be separable, so is $p$.
\end{proof}
Now we're basically done -- pick a basis $\omega_1$, \dots, $\omega_n$ of $K/F$,
and let $p_i$ be their minimal polynomials; by the above, we don't get any roots outside $K$.
Consider $P = p_1 \dots p_n$, removing any repeated factors.
The roots of $P$ are $\omega_1$, \dots, $\omega_n$ and some other guys in $K$.
So $K$ is the splitting field of $P$.


\chapter{THE DIRECTED HMCFP} \label{ch:directed}% Must have a blank line after every section label

\section{Motivation}

To this point, the MCFP has only been formulated for undirected graphs. However, the field of social network analysis does not confine itself to directed graphs. Sociograms can present directed maps of influence in social groups~\cite{moreno1934shall}. Communities exist even among these, which motivates the \emph{directed} (H)MCFP.

\section{Formulation}

As discussed in \autoref{sec:MCF LP}, the MCF cut algorithm hierarchically solves the LP of the maximum concurrent flow problem (MCFP). The edge-path formulation is reproduced here.
\begin{align}
    \max z(G, c, d) \\
    \mathrm{s.t.} \sum_{p \in P_{ij}} f_p &= zd_{ij} \forall \{i, j\} \in D \\
    \sum_{\{p \in P:\{i,j\} \in E_p\}} f_p &\leq c_{ij} \forall \{i, j\} \in E \\
    f_p &\geq 0,  p \in P
\end{align}
Some simple extensions of this edge-path formulation can convert it into a linear program suitable for processing directed graphs.

First, we'll consider the difference in the inputs. A problem instance for the undirected MCFP involved a graph, a capacity function, and a demand function. In this case, the graph contains a set of directed edges, which alters how we define our capacity and demand functions.

In general, we may simply say that the capacity function takes a directed edge as its argument. When a reciprocal connection exists between two nodes, each direction would have a different capacity, which matches our intuition about traffic networks. In certain cases, we may want the capacity to be limited, regardless of direction. The real-world analogue is a bridge with a maximum weight. These can be represented with a complementary function $c^*\colon {i, j} \rightarrow c_e$. Importantly, the domain of $c^*$ and the domain of $c$ must be disjoint and their union must be $V$, to provide complete information about the capacity of every edge. We use~$E^*$ to represent the domain of~$c^*$. When defining the linear program, we require that $c^*_\{i, j\} = c_{(i, j)} + c_{(j, i)}$ and that $c_{(i, j)}$ and $c_{(j, i)}$ are each nonnegative.

In a similar way, we can define the directional demand~$d$ and the bidirectional demand~$d^*$ and introduce corresponding non-negativity constraints to maintain boundedness. The fairness metric then optimizes the througput proportional to $d_{i, j}$ for all directions---though $d_{i, j}$ is now defined over ordered tuples, rather than sets, of vertices. To handle directed edges, the set~$D$ is now $V \times V \setminus \{(v, v) \ \forall v \in V\}$, and we define~$D^*$ as the domain of $d^*$. The edge-path formulation for the directed MCFP is:
\begin{align}
    \max z(G, c, c^*, d, d^*) \\
    \mathrm{s.t.} \sum_{p \in P_{ij}} f_p &= zd_{ij}, \forall (i, j) \in D \\
    \sum_{\{p \in P:\{i,j\} \in E_p\}} f_p &\leq c_{ij}, \forall (i, j) \in E \\
    f_p &\geq 0,  \forall p \in P \\
    d^*_{\{i, j\}} &\geq d_{(i, j)} + d_{(j, i)}, \forall \{i, j\} \in D^* \\
    c^*_{\{i, j\}} &\geq c_{(i, j)} + c_{(j, i)}, \forall \{i, j\} \in E^*
\end{align}

Extension to a hierarchical MCFP, freezing previous flows as starting points for subsequent iterations, is trivially done via the same procedure as in \autoref{sec:maximin LP}.

\section{Discussion}

If one were to use an instance of the undirected (H)MCFP as an input for the directed version, the duplication of edges would double the number of columns in the constraint matrix. Further, the number of paths doubles since their direction becomes relevant. Consequently, the size of the constraint matrix quadruples. For this reason, it is important to reduce the problem to its undirected form when possible.

Also, in the directed case, it is possible to have fully saturated edges which fail to separate the graph because the capacity in the opposing direction exceeds the throughput attainable in the direction of saturated edges.  \todo{More.}