\documentclass[12pt, letter]{article}
\usepackage{amsmath,amssymb,hyperref,float,graphicx}
\graphicspath{{./images/}}
\restylefloat{table}
\begin{document}
\title{Air Taxi Analytic Framework}
This document provides an analytic framework for an air taxi service using electric vertical takeoff (eVTOL) aircraft.
\section{Passenger Mass}
The Survey on Standard Weights of Passengers and Baggage\footnote{EASA 2008.C.06/30800/R20090095/30800000/FBR/RLO} funded by EASA in 2009 provides passenger weights, with some data broken down by the type of trip (business/leisure), location, gender, and age. From Table 4.7 in the reference, the average weight of male passengers with carry on baggage in the winter has a mean of 93.5 kg with a standard deviation of 15.6 kg. From Table 4.9, the average checked bag weight for males in the winter is 16.5 kg with standard deviation of 5.9 kg. Assuming independence between these two distributions, the passenger mass with baggage distribution has a mean of $\mu=110 kg$ with a standard deviation of $\sigma=16.7 kg$. The payload mass estimation is framed as a statistics problem, where the payload mass based on the passenger capacity, $n_{pax}$, is calculated such that a specified fraction of passengers, $p$, can be accommodated when independently sampled from a Gaussian population distribution. The payload mass can be calculated with the following formula,
\begin{align}
	m_{pax}=\mu+erf^{-1}\left(2p-1\right)\cdot\sigma\sqrt{\frac{2}{n_{pax}}}
\end{align}
\section{Vehicle Mass}
The vehicle empty mass, $m_{empty}$, is defined as the portion of the vehicle gross takeoff mass, $m_{gross}$, that is not battery mass, $m_{batteries}$, or payload mass, $m_{payload}$. The ratio of the empty and gross mass, $f_{empty}$, is typically between 0.55 and 0.65. From these relationship, the battery mass may be determined with the constraint that the battery mass cannot be negative.
\begin{align}
	m_{empty}&=m_{gross}f_{empty}\\
	m_{payload}&=n_{pax}m_{pax}+n_{pilot}m_{pilot}\\
	m_{batteries}&=\max\left(0,m_{gross}-m_{empty}-m_{payload}\right)
\end{align}
\section{Hover Performance}
Noise produced during hover is strongly dependent on the rotor tip Mach number, $M_{tip}$. As such, a constraint may be placed to limit the tip Mach number with $M_{tip}=0.5$ being a reasonable selection. The tip speed is given by,
\begin{align}
	v_{tip}=M_{tip}a
\end{align}
where $a$ is the speed of sound. It is assumed that the vehicle extents are circumscribed by a circle of diameter, $d_{value}$. This value is also known as the ``d-value" and is a common constraint that is applied to account for helipad size limitations. The ratio of total rotor area to that area encompassed by the $d_{value}$ is given by $f_{rotorArea}$ and is dependent on vehicle configuration. Given the number of rotors, $n_{rotors}$, the individual rotor area may be defined as,
\begin{align}
	A_{disk}=\frac{\pi d_{value}^2}{4} \frac{f_{rotorArea}}{n_{rotors}}
\end{align}
The rotor solidity, $\sigma$ is related to the individual rotor thrust, $T$, and the average blade section lift coefficient, $c_l$. Due to structural and aerodynamic limitations, the rotor solidity is typically constrained to values between $\sigma_{min}=0.05$ and $\sigma_{max}=0.25$.\footnote{Rotors with higher solidity generally have small aspect ratios and are prone to 3-d structural and aerodynamic effects. Some of these 3-d effects require special compensations or modeling techniques that may not be captured with reasonable accuracy with general global models.}
\begin{align}
	T&=\frac{m_{gross}g}{n_{motors}}\\
	\sigma&=\text{median}\left(\sigma_{min},\frac{6T}{\rho v_{tip}^2 A_{disk} c_l},\sigma_{max}\right) \label{solidity}
\end{align}
Note that if the solidity is set to one of the limits, then the tip speed must be recalculated using Equation (\ref{solidity}). If the tip speed limit is exceeded, then the solution is considered invalid. The induced power for an individual rotor is given by,
\begin{align}
	P_{ind}=\frac{T^{1.5}}{\sqrt{2 \rho A_{disk}}} \kappa
\end{align}
where $\kappa$ accounts for non-ideal induced power penalties, including tip losses and partial wake contraction. The profile power for an individual rotor is given by,
\begin{align}
	P_{pro}=\frac{\rho A_{disk} v_{tip}^3 \sigma c_d}{8} \label{P_pro}
\end{align}
where $c_d$ is the average blade section drag coefficient. Note that the profile power estiamte produced by Equation \ref{P_pro} becomes non-conservative for tip speeds approaching Mach $0.7$. The total hover power draw is therefore,
\begin{align}
	P_{hover}=n_{rotors} \frac{P_{ind}+P_{pro}}{\eta_{hover}}
\end{align}
where $\eta_{hover}$ is the powertrain efficiency during hover. This efficiency covers losses in the motor, controller, wires, and any other losses.
\section{Cruise Performance}
By selecting a reasonable cruise lift coefficient, $C_L$, and prescribing a cruise speed, $V_c$, the required reference wing area, $S_{ref}$, may be determined as follows,
\begin{align}
	S_{ref}=\frac{2m_{gross}g}{\rho C_L V_c^2} \label{S_ref}
\end{align}
Given the d-value constraint, the resulting aspect ratio, $A$ may be determined using its definition. In consideration of both structural and aeroelastic constraints, a soft constraint is applied to limit the maximum aspect ratio using the p-norm.
\begin{align}
	A=\left\|\frac{d_{value}^2}{S_{ref}},A_{max}\right\|_p
\end{align}
Note that if the aspect ratio is limited by the maximum constraint, then the reference area must be calculated using the definition of the aspect ratio and cruise lift coefficient must be recalculated using Equation \ref{S_ref}. With the aspect ratio known, the Oswald efficiency factor, $e$ may be estimated as follows\footnote{\href{https://bit.ly/2BhwcbZ}{Estimating the Oswald Factor from Basic Aircraft Geometrical Parameters (Eq 4)}}.
\begin{align}
	e &=\frac{1}{1.05-0.007 \pi A}
\end{align}
The drag coefficient during cruise is given by the sum of a parasitic drag from the aerodynamic surfaces, fuselage and fairing parasitic drag\footnote{Bramwell Helicopter Dynamics, Fig. 4.15, average of Clean Fixed Wing Aircraft and Experimental Helicopters} ($C_{d_f}$), and induced drag.
\begin{align}
	C_{d_f}&=\frac{0.2331}{S_{ref}} \left(\frac{m_{gross}}{1000}\right)^{2/3}\\
	C_D&=C_{D_0}+C_{d_f}+\frac{C_L^2}{\pi A e}
\end{align}
Finally, the power required during cruise is given by,
\begin{align}
	P_{cruise} = \frac{m_{gross} g V_C C_D}{C_L \eta_{cruise}}
\end{align}
where $\eta_{cruise}$ is the powertrain efficiency during cruise. This efficiency covers losses in the motor, controller, wires, and any other losses.
\section{Mission}
The mission performance is considered from a total available energy perspective. The energy available for a given mission is determined by the available energy in a battery pack and by the energy reserved for non-mission segments, such as alternate legs, reserve energy, and unusable energy. The useful energy available in a battery pack is given by,
\begin{align}
	E_{total}=\hat{E}_{cell} f_{int} f_{eol} m_{batteries}
\end{align}
where $\hat{E_{cell}}$ is the cell specific energy defined as the rated energy per mass of a battery cell, $f_{int}$ is the integration factor which is the ratio of total cell mass to total battery pack mass, and $f_{eol}$ is the battery end of life factor that accounts for pack degradation over the useful life of the pack. An alternate mission is sized to account for instances such as the primary landing site not being available. Under current standards, the alternate is sized to a particular time spent loitering typically in excess of twenty minutes. However, with typical primary mission lengths on the same order, these alternates will likely be redefined to account for the inherently constrainted mission profiles. To incorporate flexibility, energy used during alternates ($E_{alt}$) based on either loiter time ($t_{alt}$) or distance ($d_{alt}$) are addressed by considering the maximum energy of both cases.
\begin{align}
	E_{alt}=\max \left({P_C t_{alt}, \frac{P_C d_{alt}}{V_C-V_{wind}}}\right)
\end{align}
where $V_{wind}$ is the design headwind. Reserve energy $E_{res}$ is defined as a fraction of total energy $f_{res}$. If the primary mission length is not defined, then the maximum mission length is determined as follows,
\begin{align}
	E_{hover}	 &= P_{hover} t_{hover} \\
	E_{cruise} &= E_{total} - E_{hover} - E_{alt} - E_{res} \\
	t_{cruise} &= \frac{E_{cruise}}{P_{cruise}} \\ \label{t_cruise} \\
	d_{cruise} &= t_{cruise} \left( V_C - V_{wind} \right) \label{d_cruise}
\end{align}
The total time spent in flight is given by,
\begin{align}
	t_{flight}=t_{hover}+t_{cruise}
\end{align}
If the primary mission length is defined, then Equation \ref{d_cruise} is used to calculate the time spent in cruise and Equation \ref{t_cruise} is used to calculate the energy used in cruise. In both cases, if the energy required to complete the mission is less than zero, then the mission is considered infeasible.
\section{Operations}
The maximum number of trips, $N_{day}$ that may be completed in a given day by a vehicle is simply the ratio of daily operating time, $t_{day}$, to total turn around time. The total turn around time is the sum of the trip flight time and the turn around time at the pad, $t_{turn}$ which is the total time between the aircraft landing and subsequent takeoff. The number of trips per year accounts for both the scheduled availability, $a_{sch}$, and unscheduled availability, $a_{unsch}$, each of which are defined as the ratio of the time that the aircraft is available to the total time it could be available if tasks such as maintenance and weather caused no unavailability. Finally, the flight hours per year is proportional to the product of the trip length and the trips per year.
\begin{align}
	N_{day}&=\frac{t_{day}}{t_{flight}+t_{turn}} \\
	N_{year}&=365 N_{day} a_{sch} a_{unsch} \\
	H_{year}&=\frac{N_{year} t_{flight}}{3600}
\end{align}
\section{Costs}
Operating cost estimation contains many parameters that required detailed exploration, but fundametally may be broken down into several categories. These include energy cost, maintenance, battery accruals, hull accruals, insurance, training, services, and landing fees. In addition to these costs, several others exist, such as management and customer service, that may be lumped into an additional factor, $f_{ops}$. Energy costs are described as follows,
\begin{align}
	E_{flight}&=E_{hover}+E_{cruise} \\
	D_{discharge}&=\frac{E_{flight}}{E_{total}} \\
	C_{pack}&=E_{total} \left(c_{pack}+c_{cell}\right) + c_{base}\\
	R_{discharge}&=\frac{3600 E_{flight}}{t_{flight} E_{total}}
\end{align}
where $D_{discharge}$ is the depth of discharge, $C_{battery}$ is the cost of the battery pack, $c_{pack}$ is the pack component cost per $kWh$, $c_{cell}$ is the cell cost per $kWh$, $c_{base}$ is the pack component base cost, and $R_{discharge}$ is the average rate of discharge during the mission. One important value in determination of battery costs is the battery cycle life, $N_{battery}$, which is generally very difficult to estimate since it depends on a wide variety of factors such as pack temperature, cell balancing, charge rates, discharge rates, and many more. Nevertheless, a simplified model is proposed here that captures the trends observed for the cells under consideration.
\begin{align}
	N_{battery}=f_R R_{discharge}^{-k_R} D_{discharge}^{-k_D}
\end{align}
where $f_R$, $k_R$. and $k_D$ are determined based on the specific battery type and usage. The costs associated with energy, $C'_{energy}$, and battery pack accruals, $C'_{pack}$, is therefore,
\begin{align}
	\hat{C}_{pack}&=\frac{C_{pack}}{N_{battery}} \\
	\hat{C}_{energy}&=c_{elec} E_{flight}
\end{align}
Considered next are annual fixed operating costs, $C_{fixed}$. These include those items that do not vary with flight hours, such as aircraft depreciation ($C_{depreciation}$), insurance ($C_{insurance}$), pilots ($C_{pilot}$), training ($C_{training}$), and other items or services ($C_{services}$).
\begin{align}
	C_{aircraft}&=c_{aircraft} m_{empty}\\
	C_{insurance}&=C_{liability}+c_{hull} C_{aircraft}\\
	C_{depreciation}&=r_{depreciation} C_{aircraft}\\
	C_{pilot}&=c_{pilot} n_{pilot}\\
	C_{training}&=c_{training} n_{pilot}\\
	C_{fixed}&=C_{insurance}+C_{depreciation}+C_{pilot}+C_{training}+C_{services}
\end{align}
where $c_{aircraft}$ is the aircraft acquisition cost per unit mass, $C_{liability}$ is the annual liability insurance cost, $c_{hull}$ is the annual hull insurance rate, $r_{depreciation}$ is the aircraft depreciation rate, $c_{pilot}$ is the annual cost of a pilot, and $c_{training}$ is the annual cost of pilot training. Variable costs include the hourly cost of energy, battery accurals, and maintenance.
\begin{align}
	\dot{C}_{variable}&=\frac{\hat{C}_{energy}+\hat{C}_{battery}}{t_{flight}}+\dot{C}_{maintenance}
\end{align}
Finally, the total operating cost per flight hour includes the additional costs of landing fees ($c_{landing}$) and other items or services that are accounted for by including margin, $f_{operating}$.
\begin{align}
	\dot{C}&=\left(\dot{C}_{variable}+\frac{C_{fixed}+\hat{C}_{landing}N_{year}}{H_{year}}\right)f_{operating}
\end{align}
\section{Passenger Experience}
One method to determine the value that a new transportation service adds is to perform a comparative analysis between the new service and existing services. In the case of an air taxi service, both the total trip time and total trip cost as experienced by the passenger are considered. To perform a comparative analysis, trip time and trip cost models for both air taxi and ground taxi are therefore requried. A representative case considered here in which a passenger lands at an airport and needs to transfer to a hotel. In the case of the air taxi, the trip is broken down into the following segments:
\begin{table}[H]
	\begin{tabular}{|p{5in}|}
	\hline
		\\\includegraphics[width=360px]{airCase.png}\\
		\begin{enumerate}
			\item Pre-cruise phase: total time, $t_{transfer}$
			\begin{enumerate}
			  \item Transfer from gate to vertipad: 16 minutes
				\item Check-in and passenger briefing: 4 minutes
				\item Passenger and luggage loading: 2 minutes
				\item Takeoff and taxi: 2 minutes
			\end{enumerate}
			\item Cruise phase: at speed $V_C$
			\item Alight phase: total time ($t_{alight}$)
			\begin{enumerate}
				\item Taxi and land: 2 minutes
				\item Passenger and luggage unloading: 2 minute
				\item Transfer to curb with cab awaiting: 2 minute
			\end{enumerate}
			\item Drive phase: to hotel (distance $d_{last}$) at taxi speed
			\item Unload phase: 1 minute ($t_{unload}$)
		\end{enumerate}
	\\ \hline
	\end{tabular}
\end{table}
\noindent In the case of the ground taxi, the trip is broken down into the following segments:
\begin{table}[H]
	\begin{tabular}{|p{5in}|}
	\hline
		\\\includegraphics[width=360px]{groundCase.png}\\
		\begin{enumerate}
			\item Pre-drive phase: total time ($t_{curb}$)
			\begin{enumerate}
			  \item Transfer from gate to curb: 15 minutes
				\item Passenger and luggage loading: 1 minute
			\end{enumerate}
			\item Drive phase: at taxi speed
			\item Unload phase: 1 minute ($t_{unload}$)
		\end{enumerate}
		\\ \hline
	\end{tabular}
\end{table}
\noindent The total air taxi and ground taxi trip times are given by,
\begin{align}
	t_{drive}&=\frac{d_{cruise}}{V_{drive}\left(d_{cruise}\right)}\\
	t_{ground}&=t_{curb}+t_{drive}+t_{unload}\\
	t_{last}&=\frac{d_{last}}{V_{drive}\left(d_{last}\right)}+t_{unload}\\
	t_{air}&=t_{transfer}+t_{flight}+t_{alight}+t_{last}
\end{align}
The proposed ground speed model during peak traffic is detailed in Appendix \ref{APX:groundSpeed}. During peak traffic, the drive speed model takes the following form.
\begin{align}
	V_{drive}(d)=\left(11.3\frac{m}{s}\right)\frac{d}{8530m+d}\frac{1}{f_{traffic}}
\end{align}
where $f_{traffic}$ may be used to effectively increase traffic by reducing the average driving speed by that factor.
1Several different ticket pricing schemes may also be considered. For a ground taxi, a standard fare model is used. For the air taxi, pricing schemes based on value, distance, and time are considered.
\begin{align}
	P_{ground}&=c_{ground}+d_{cruise} c'_{ground}+t_{drive} \dot{c}_{ground}\\
	P_{last}&=c_{ground}+d_{last} c'_{ground}+t_{last} \dot{c}_{ground}\\
	P_{value}&=c_{value}\left(t_{ground}-t_{fly}\right)+P_{ground}-P_{last}\\
	P_{distance}&=d_{cruise} c_{distance}\\
	P_{time}&=t_{flight} c_{time}
\end{align}
The final price that will be paid by the passenger in the case of the air taxi is the sum of the price for the flying leg ($P_{flight}$) and the price for the last ground leg ($P_{last}$).
\section{Business Case}
The operator business case is determined by considering all of the revenue from ticket sales as compared against the costs. The revenue per trip is dependent on the passenger loading rate ($f_{load}$) and deadhead rate ($f_{dead}$). The passenger loading rate is defined as the average fraction of seats filled during non-empty flights. In the case of a single passenger aircraft, this value should equal unity and as more seats are added the fraction filled should decrease. The deadhead rate is defined as the fraction of flights that have no paying passengers. Note that the deadhead trips are accounted for separately from the loading rate. The revenue is determined as follows,
\begin{align}
	\hat{R} &= P_{flight} n_{pax} f_{load} \\
	\dot{R} &= \frac{3600\hat{R}}{t_{flight}} \left(1-f_{dead}\right)
\end{align}
The profit is therefore,
\begin{align}
	\dot{P} &= \dot{R} - \dot{C}  \\
	P &= \dot{P} H_{year}
\end{align}
This profit value provides the profit for a trip of a fixed length being performed throughout the year. Practically, there will be a variety of trip lengths each of which may be performed with the same aircraft. To account for a variety of trip lengths, a probability density function (PDF) of those trip lengths may be provided. Several data sources have been used to estimate the PDF including commuter trip data, a global survey of airport-to-downtown distances, taxi trip data, and distribution in cities with existing helipad infrastructure. It was found that in all cases the PDFs were similar. The airport-to-downtown cumulative distribution function (CDF) and PDF are shown below for reference with a gamma distribution fit to the data ($k=3.98$, $\theta=4.85$).
\\\includegraphics[width=250px]{airportCDF.png}\\
For each trip length, the profitability is evaluated. The weighted sum off all profitable trips represents the effective profitability for that vehicle throughout the year.
\begin{align}
	\bar{P} &= \frac{\sum_i H(P_i) P_i p_i}{\sum_i H(P_i) p_i}
\end{align}
where $H(x)$ is the Heaviside step function, $p_i$ is the probability density function and the function $f$ is equal to zero for negative input values and one for positive input values.

\section{Baseline}
A baseline analysis was performed to determine for which combinations of range and speed would yield profitable operations. The baseline parameters are listed in Appendix \ref{APX:baseline}

\appendix
\section{Ground Speed Model} \label{APX:groundSpeed}
\includegraphics[width=360px]{groundSpeedModel.png}

\section{Baseline Input Variables} \label{APX:baseline}
The baseline parameters selected were as follows,\\\\
\textbf{Physics Variables}
\begin{itemize}
	\item[$g$] Gravitational acceleration, $9.81 \frac{m}{s^2}$
	\item[$\rho$] Air density, $1.0 \frac{kg}{m^3}$
	\item[]
\end{itemize}
\textbf{Vehicle Variables}
\begin{itemize}
	\item[$d_{value}$] The diameter of the circle that circumscribes the top view of the vehicle, $14 m$
	\item[$f_{empty}$] Empty mass fraction, $0.58$
	\item[$f_{rotor}$] Fraction of d-value area covered by rotors in hover, $0.32$
	\item[]
\end{itemize}
\textbf{Hover Variables}
\begin{itemize}
	\item[$n_{rotors}$] Number of motors, $8$
	\item[$\eta_{hover}$] Hover electrical efficiency, $0.89$
	\item[$\kappa$] Induced power penalty, $1.1$
	\item[$c_l$] Blade section average lift coefficient, $0.80$
	\item[$c_d$] Blade section average drag coefficient, $0.02$
	\item[]
\end{itemize}
\textbf{Cruise Variables}
\begin{itemize}
	\item[$\eta_{cruise}$] Cruise electrical efficiency, $0.69$
	\item[$C_L$] Cruise lift coefficient, $0.55$
	\item[$AR_{max}$] Maximum aspect ratio, $12$
	\item[$C_{d_0}$] Parasitic drag from aerodynamic surfaces, $0.025$
	\item[]
\end{itemize}
\textbf{Battery Variables}
\begin{itemize}
	\item[$\hat{E}_{cell}$] Cell specific energy, $240 \frac{Wh}{kg}$
	\item[$f_{int}$] Pack integration factor, $0.75$
	\item[$f_{eol}$] Cell end of life factor, $0.90$
	\item[$k_R$] Cell degradation coefficient due to average discharge rate, $1$
	\item[$k_D$] Cell degradation coefficient due to depth of discharge rate, $2$
	\item[]
\end{itemize}
\textbf{Mission Variables}
\begin{itemize}
	\item[$f_{res}$] Reserve energy factor, $0.20$
	\item[$f_{wind}$] Headwind encountered in flight, $15 \frac{m}{s}$
	\item[$t_{hover}$] Time spent in hover, $3 min$
	\item[$t_{alt}$] Alternate mission time, $10 min$
	\item[$d_{alt}$] Alternate mission distance, $15 km$
	\item[$t_{day}$] Operating time per day, $8 hr$
	\item[$a_{sch}$] Scheduled availability rate, $0.9$
	\item[$a_{unsch}$] Unscheduled availability rate, $0.9$
	\item[$t_{turn}$] Pad turn-around time, $6 min$
	\item[$f_{dead}$] Deadhead rate, $0.3$
	\item[$f_{operating}$] Operating cost factor, $1.25$
	\item[]
\end{itemize}
\textbf{Cost Variables}
\begin{itemize}
	\item[$c_{pack}$] Specific battery cost, $250 \frac{\$}{kWh}$
	\item[$c_{elec}$] Cost of electricity, $0.2 \frac{\$}{kWh}$
	\item[$c_{aircraft}$] Specific hull cost, $550 \frac{\$}{kg}$
	\item[$r_{depreciation}$] Aircraft depreciation rate, $0.1$
	\item[$C_{liability}$] Annual liability insurance cost, $\$22000$
	\item[$c_{hull}$] Annual hull insurance specific cost, $0.045 \frac{\$}{kg}$
	\item[$C_{services}$] Annual services costs, $\$7700$
	\item[$\dot{C}_{maintenance}$] Hourly maintenance rate, $\$100$
	\item[$\hat{C}_{landing}$] Landing fee, $\$20$
	\item[$c_{pilot}$] Annual cost per pilot (including benefits), $\$280500$
	\item[$c_{training}$] Annual training cost per pilot, $\$9900$
	\item[]
\end{itemize}
\textbf{Travel Variables}
\begin{itemize}
	\item[$c_{ground}$] Taxi base fare, $\$3.5$
	\item[$c'_{ground}$] Taxi distance rate, $1.7 \frac{\$}{km}$
	\item[$\dot{c}_{ground}$] Taxi time rate, $0.55 \frac{\$}{min}$
	\item[$d_{last}$] Last leg distance, $3 km$
	\item[$t_{curb}$] Time to get from gate to drive away (for taxi trip), $16 min$
	\item[$t_{transfer}$] Time to get from gate to hover (for aircraft trip), $24 min$
	\item[$t_{unload}$] Time to unload luggage from taxi and exit, $1 min$
	\item[$t_{alight}$] Time to unload luggage from aircraft and exit, $6 min$
	\item[$c_{value}$] The passenger willingness to pay for time saved, $3\frac{\$}{min}$
	\item[]
\end{itemize}
\end{document}


%!TEX root = ../CombinatoricsNotes.tex

\section{Ramsey Theory}
\marginnote{``Every sufficiently large system contains a regular subsystem.''}

Consider a two coloring $C: [n]^{(2)}\to \{R,B\}$ where $R$ stands for red and $B$, blue.
A \defn{regular subsystem} is a subset $X\subset [n]$ such that $c$ restricted to $X^{(2)}$ takes only one value\marginnote{That is, the coloring restricted to $X$ is monochromatic.}.
The \defn{Ramsey number} $R(k,\ell)$ is the minimum number $n$ such that for every $c: [n]^{(2)} \to \{R,B\}$, there exists $X\subset[n]$ such that either
\begin{itemize}
	\item $c$ restricted to $X^{(2)}$ is identically $R$ and $|X|=k$, or
	\item \ditto{$c$ restricted to $X^{(2)}$ is identically} $B$ and $|X| = \ell$.
\end{itemize}
\begin{remark}
The existence of Ramsey numbers was first shown by Frank Ramsey (\cite{ramsey1930problem}), as a lemma to proving the decidability of a class of formulas in first order logic. Here, we will present a short proof by \erdos  and Szekeres.
\end{remark}
\begin{theorem}[\cite{erdosszekeres1935combinatorial}]
~\begin{itemize}
	\item $R(k,\ell)$ exists for all $k$ and $\ell$,
	\item $R(k,\ell) \leq R(k-1,\ell) + R(k,\ell-1)$ for $k,\ell\geq 2$, and
	\item $R(1,\ell) = R(k,1) = 1$.
\end{itemize}
\end{theorem}
\begin{proof}
Let $n = R(k-1,\ell) + R(k,\ell-1)$. Choose $v\in [n]$; then, either
\begin{enumerate}[(1)]
  \item  $v$ is joined to $\geq R(k-1,\ell)$ verticies by red edges. In this case choosing an appropriate $X$ among the red neighbors of $v$ gives the result, or
  \item $v$ is joined to $(n-1) - (R(k-1,\ell)-1) = R(k,\ell-1)$ verticies by blue edges. This case is analogous.
\end{enumerate}
This yields $R(k,\ell) \leq R(k-1,\ell) + R(k,\ell-1)$. The third point follows from the definition, and the first inductively from this inequality, using the third point as the base case.
\end{proof}
In fact, we may obtain a bound on the $R(k,\ell)$ in this way.
\begin{corollary}
\[
R(k,\ell)\leq {k+\ell -2 \choose k-1}
\]
for all $k,\ell \geq 1$.
\end{corollary}
\begin{proof}
If $k=1$ or $\ell=1$ then $R(k,\ell)=1$. Otherwise, by induction
\begin{align*}
R(k,\ell) &\leq R(k-1,\ell) + R(k,\ell)-1 \\
&\leq {k+\ell -3 \choose k-2} + {k+\ell -3 \choose k-1} = {k+\ell-2 \choose k-1}.\qedhere
\end{align*}
\end{proof}
\begin{remark}
In particular, $R(k,k) \leq {2k-2\choose k-1} \sim \frac{4^k}{\sqrt{k}}$. We in fact have $R(3,3) = 6$, $R(4,4)=18$, and $43\leq R(5,5) \leq 49$.
\end{remark}

\begin{theorem}[\cite{erdos1947someremarks}]
$R(k,k)\geq 2^{k/2}$ for $k\geq 2$.
\end{theorem}
\begin{proof}
Let $n = \floor{2^{k/2}}$ and let $c:[n]^{(2)}\to \{R,B\}$ be chosen unifomrly randomly. That is, the color of every edge in $[n]^{(2)}$ is chosen to be $R$ with probability $1/2$ or $B$ with probability $1/2$, independently of the other edges. Let $Z$ be equal to the number of sets $X\subset[n]$, $|X|=k$, such that $c$ restricted to $X^{(2)}$ is monochromatic. It is enough to show $\E[Z] < 1$. \marginnote{Since then there must be exist some coloring with $Z<1$, i.e., $Z=0$.}
For fixed $X$ as above,
\[
\Pr[c \text{ restricted to }X\text{ is monochromatic}] = \frac{1}{2^{{k\choose 2}-1}}.
\]
Then
\begin{align*}
\E[Z] &= {n\choose k} 2^{1 - {k\choose 2}}\leq \frac{n^k}{k!}2^{1 - \frac{k(k-1)}{2}}\\
&\leq \frac{2^{k^2/2}\cdot 2^{1 + (k/2) - k^2/2}}{k!} = \frac{2^{1+k/2}}{k!}<1
\end{align*}
for $k\geq 3$. One may show $R(2,2) = 2$, yielding the case $k=2$.
\end{proof}
The state of the art bounds are
\marginnote{Lower: \cite{SPENCER1975}, upper: \cite{conlon2009new}.}
% \begin{theorem*}[]
\[
(1 + O(1)) \frac{\sqrt{2}k}{e}2^{k/2}\leq R(k,k) \leq k^{- \frac{c\log k}{\log \log k}}4^k.
\]
% \end{theorem*}

\newthought{Next, if $n$ is sufficiently large} with respect to $k$ and $c:[n]\to \{R,B\}$, then $[n]$ contains a monochromatic \defn{arithmetic progression} of length $k$, that is a set\marginnote{Note that here we are discussing colorings of $[n]$, not $[n]^{(2)}$; that is, vertex colorings, not edge colorings.}
\[
\{ a, a+d ,\dotsc, a+(k-1)d\}
\]
for some $d>0$. We may write this as $a + [0,k-1]d$, where $[0,k-1] = \{ j\in \Z: 0\leq j\leq k-1\}$ and the addition and multiplication is elementwise. The \defn{Van der Waerden number} $W(k,r)$ is the minimum $n$ such that if $[n]$ is colored in $r$ colors one can always find a monochromatic arithmetic progression of length $k$.

% \missing{Missed class: Monday, March 7}
\begin{theorem}[\cite{VdWaerden1927}]
$W(k,r)$ exists for all $r,k$. \label{thm:VdW}
\end{theorem}
The proof will follow from \cref{lem:Wkmr}.
\begin{example}
\begin{itemize}
	\item $W(2,r) = r+1$ \marginnote{by pigeonhole}
	\item $W(k,1) = k$,
	\item What about $W(3,2)$? Well, \rdot\rdot\bdot\bdot\rdot\rdot\bdot\bdot \,shows $W(3,2) > 8$.  On the other hand, assuming the 5th slot is red, wlog, we reduce to two cases:
	\begin{align*}
	\vartextvisiblespace \rdotm \vartextvisiblespace \bdotm \rdotm \bdotm \vartextvisiblespace \rdotm \vartextvisiblespace\\
	\rdotm\rdotm\bdotm\bdotm\rdotm\rdotm\bdotm\bdotm\vartextvisiblespace
	\end{align*}

	Let's outline the general argument; this will give a bound $W(3,2) \leq 5 \times 65 = 325$. Color $[325]$ and divide it into $65$ intervals of length~5.
\newcommand{\vdwdots}{\rdot\bdot\bdot\rdot\rdot}
\newcommand{\firstpic}{\begin{tikzpicture}[node distance = .5cm]
	\node[draw] (n1) at (0,0) {1\,2\,3\,4\,5};
	\node[left = 1cm of n1]{a)};
	\node[draw,right= of n1] (n2)  {6\,7\,8\,9\,10};

	\node[right= .25cm of n2] (n7)  {$\dotsm$};
	\node[draw,right= .25cm of n7] (n10)  {361\,362\,363\,364\,365};
	\end{tikzpicture}}
	\newcommand{\secondpic}{\begin{tikzpicture}[node distance = .5cm]
	\node[draw] (n1) at (0,0) {\phantom{\vdwdots}};
	\node[left = 1cm of n1]{b)};

	\node[draw,label=above:$I$,right=of n1] (n2) {\vdwdots};
	\node[right= .25cm of n2] (n3)  {$\dotsm$};
	\node[draw,right=.25cm of n3,label=above:$I+5d$] (n4)  {\vdwdots};
	\node[right= .25cm of n4] (n5)  {$\dotsm$};
	\node[draw,right= .25cm of n5] (n6)  {\phantom{\vdwdots}};
	\node[draw,right= of n6] (n6p5)  {\phantom{\vdwdots}};
	\node[right= .25cm of n6p5] (n7)  {$\dotsm$};
	% \node[draw,right=.25cm of n7,label=above:$I+10d$] (n8)  {\rdot\bdot\bdot\rdot\rdot};
	% \node[right= .25cm of n8] (n9)  {$\dotsm$};
	\node[draw,right= .25cm of n7] (n10)  {\phantom{\vdwdots}};
\draw [
    thick,
    decoration={
        brace,
        mirror,
        raise=0.5cm
    },
    decorate] (n1.west) --  (n6.east) node [pos=0.5,anchor=north,yshift=-0.55cm] {$33$ intervals};
	\end{tikzpicture}}

\newcommand{\thirdpic}{\begin{tikzpicture}[node distance = .5cm]
	\node[draw] (n1) at (0,0) {\phantom{\vdwdots}};
	\node[left = 1cm of n1]{c)};
	\node[draw,label=above:$I$,right=of n1] (n2) {\rdot\bdot\bdot\rdot\rdot};
	\node[right= .25cm of n2] (n3)  {$\dotsm$};
	\node[draw,right=.25cm of n3,label=above:$I+5d$] (n4)  {\rdot\bdot\bdot\rdot\rdot};
	\node[right= .25cm of n4] (n5)  {$\dotsm$};
	\node[draw,right= .25cm of n5] (n6)  {\phantom{\vdwdots}};
	\node[draw,right=  of n6] (n6p5)  {\phantom{\vdwdots}};
	\node[right= .25cm of n6p5] (n7)  {$\dotsm$};
	\node[draw,right=.25cm of n7,label=above:$I+10d$] (n8)  {\phantom{\rdot\bdot} \textvisiblespace \phantom{\rdot} \textvisiblespace};
	\node[right= .25cm of n8] (n9)  {$\dotsm$};
	\node[draw,right= .25cm of n9] (n10)  {\phantom{\vdwdots}};
\draw [
    thick,
    decoration={
        brace,
        mirror,
        raise=0.5cm
    },
    decorate] (n1.west) --  (n6.east) node [pos=0.5,anchor=north,yshift=-0.55cm] {$33$ intervals};
	\end{tikzpicture}}
\begin{figure*}[ht]
\begin{center}

\begin{tabular}{l}
\firstpic\\[1.25em]
 \secondpic \\[1.25em]
\thirdpic
\end{tabular}

\end{center}

\caption{a) We subdivide $[325]$ into 65 intervals of length $5$. b) By the pigeonhole principle, two of the first $2^5+1=33$ intervals have same coloring. If $I$ is the first interval; then for some $d>0$, the second is $I+5d$. c) To complete the proof, we consider $I+10d$, as described in the text.} \label{fig:VdW_ex_33int}
\end{figure*}
	Consider the first $2^5+1=33$ of them. Two of them will be colored exactly the same by pigeonhole; say interval $I$ and interval $I+5d$. If $I = [a,a+5]$, then $\{a,a+d',a+2d'\}$ is an arithmetic progression for $d'\in \{1,2\}$. Now, if either of these progressions are monochromatic, then we are done. Otherwise, say we have $\{{\color{blue} a },{\color{blue} a+d' },{ \color{red} a+2d' } \}$\sidenote{If $a$ and $a+d'$ are different colors, then choose the other $d'$.}, for $d'\in \{1,2\}$. Now, we consider the interval $I+10d$. If $a+2d' + 10d$ is red, then $\{a+2d',a+2d'+5d, a+2d' + 10d\}$ is monochromatic red. Otherwise $a,a+d'+5d, a+2d' + 10d$ is monochromatic blue.

\end{itemize}
\end{example}

A \defn{polychromatic $m$-tuple}  of arithmetic progression of length $k$ is a set $A = \{a + [0,k]d_1\} \cup \{ a + [0,k]d_2\} \cup \dotsm \cup \{a + [0,k]d_m\}$ such that $a+ [1,k]d_i$ is monochromatic for all $i$, and all of these $m$ progressions are of different colors (see \cref{fig:polymk} for an example).
\lect{3}{9}

\begin{marginfigure}
\[
 \stackrel{\text{\textvisiblespace}}{0}\,\stackrel{\rdotm}{1}\,\stackrel{\rdotm}{2}\,\stackrel{\gdotm}{3}\,\stackrel{\bdotm}{4}\,\stackrel{\text{\textvisiblespace}}{5} \,\stackrel{\gdotm}{6}\,\stackrel{\text{\textvisiblespace}}{7}\,\stackrel{\bdotm}{8}
\]
\caption{With the coloring shown, $\{ 0 + [0,2]\} \cup \{0 + [0,2]\cdot 3\} \cup \{0 + [0,2]\cdot 4\}$ is a  polychromatic $3$-tuple of length $2$.}\label{fig:polymk}
\end{marginfigure}

\begin{lemma} \label{lem:Wkmr}
If $W(k-1;r)$ exists for every $r$ then for every $m$ there exists $W(k,m,r) = n$ such that in any $r$-coloring of $[n]$ there exists a monochromatic a.p. of length $k$ or a polychromatic $m$-tuple of a.p. of length $k-1$.
\end{lemma}
\begin{remark}
With this result,  \cref{thm:VdW} follows by induction on $k$, using that $W(k;r) \leq W(k,r+1,r)$, since there cannot exist a polychromatic $r+1$-tuple when there are only $r$ colors.
\end{remark}
\begin{proof}[Proof by induction on $m$.] Base case: $m=1$. Then in a set of size $W(k-1,r)$ we may find a monochrome $(k-1)$-a.p., say $a+d[1,k]$; then for a polychromatic 1-tuple of a..p of length $k$, we simply need to add the point $a$. We may ensure this by taking a second copy of $W(k-1,r)$ to the left, yielding the bound $ W(k,1,r) \leq 2W(k-1,r)$ (see \cref{fig:vdwclaim_basecase} for an illustration).
\begin{marginfigure}
\begin{center}
\begin{tikzpicture}
 \node[draw,label={above:$W(k-1,r)$},minimum width = 2.2cm, minimum height = .7cm] (n1) at (0,0) {$a+d[1,k]$};
\node[draw,left= of n1,minimum width = 2.2cm,minimum height = .7cm,text opacity = .6, label={above:$W(k-1,r)$}] {\quad\qquad$a$};
 \end{tikzpicture}
\end{center}
\caption{Depiction  showing $ W(k,1,r) \leq 2W(k-1,r)$ by finding a monochrome  $(k-1)$-a.p. $a  + d[1,k]$ in a set of size $W(k-1,r)$ and adding in the point $a$, which may be to the left of the original set of size $W(k-1,r)$.} \label{fig:vdwclaim_basecase}
\end{marginfigure}

To show the induction step, we will first prove the following result.
\begin{claim}
 If $A+d,A+2d,\dotsc, A+(k-1)d$ are \emph{identically colored}\sidenote{For each $x\in A+d$, we have that $x,x+d,\dotsc,x+(k-2)d$ all have the same color.} polychromatic $m$-tuples of a.p. of length $(k-1)$ then $A\cup (A+d)\cup\dotsm \cup (A+ (k-1)d)$ contains a polychromatic $(m+1)$-tuple of a.p. of length $k-1$, or a monochromatic a.p. of length $k$.
\end{claim}
\begin{subproof}
~\medskip

\begin{figure*}
\begin{center}
\begin{tikzpicture}[color=black]
\def\xdiff{1}
\def\xlength{2}

\node (B1) at (0,0){};

\node (B2) at (\xdiff+\xlength,0){};

\node (B3) at (3*\xdiff+2*\xlength,0){};

\foreach \n in {1,2,3}
{
\node (B\n s0) at (B\n){\textvisiblespace};
\node (B\n s1) at (B\n s0)[right]{\rdot};
\node (B\n s2) at (B\n s1)[right]{\rdot};
\node (B\n s3) at (B\n s2)[right]{\gdot};
\node (B\n s4) at (B\n s3)[right]{\ydot};
\node (B\n s5) at (B\n s4)[right]{\textvisiblespace};
\node (B\n s6) at (B\n s5)[right]{\gdot};
\node (B\n s7) at (B\n s6)[right]{\textvisiblespace};
\node (B\n s8) at (B\n s7)[right]{\ydot};
}

\node[draw,fit = (B1s0) (B1s8),label=below:$A+d$]{};
\node[draw,fit = (B2s0) (B2s8),label=below:$A+2d$]{};
\node[draw,fit = (B3s0) (B3s8),label=below:$A+(k-1)d$]{};

\node (dots) at ($(B2s0)!0.5!(B3s8)$) {$\dotsm$};

\end{tikzpicture}

\begin{tikzpicture}[color=black]
\def\xdiff{1}
\def\xlength{2}

\node (B0) at (-\xdiff-\xlength,0){};

\node (B1) at (0,0){};

\node (B2) at (\xdiff+\xlength,0){};

\node (B3) at (3*\xdiff+2*\xlength,0){};

\foreach \n in {0,1,2}
{
\ifthenelse{\n=0}
{
\def\opt{\phantom}
\node[opacity=.4] (B\n s0) at ($(B\n) + (0,0)$){\bdot};
\node[opacity=.4] (B\n s0r) at ($(B\n) + (0,.12)$){\rdot};
\node[opacity=.4] (B\n s0g) at ($(B\n) + (0,-.12)$){\gdot};
}
{
\def\opt{}
\node (B\n s0) at (B\n){\bdot};
}

\node (B\n s1) at (B\n s0)[right]{\opt\rdot};
\node (B\n s2) at (B\n s1)[right]{\opt\rdot};
\node (B\n s3) at (B\n s2)[right]{\opt\gdot};
\node (B\n s4) at (B\n s3)[right]{\opt\ydot};
\node (B\n s5) at (B\n s4)[right]{\opt\textvisiblespace};
\node (B\n s6) at (B\n s5)[right]{\opt\gdot};
\node (B\n s7) at (B\n s6)[right]{\opt\textvisiblespace};
\node (B\n s8) at (B\n s7)[right]{\opt\ydot};
}

\node[draw,fit = (B1s0) (B1s8),label=below:$A+d$]{};
\node[draw,fit = (B2s0) (B2s8),label=below:$A+2d$]{};
\node[draw,fit = (B0s0) (B0s8),label=below:$A$]{};
% \tikzset{ar/.style={bend left,->,yshift=-3pt,shorten >=2pt,shorten <=2pt}}
\tikzset{ar/.style={bend left,->,yshift=-2pt,opacity=.4}}

\newcommand\ar[4]{
	\draw[#1]
	($(#2.east) + (-.16,.11) $) edge[ar] ($(#3.north)$);
	\draw[#1]
	($(#3.north)$) edge[ar] ($(#4.north)$);
}
\ar{red}{B0s0r}{B1s1}{B2s2}

\ar{green}{B0s0g}{B1s3}{B2s6}
\ar{blue}{B0s0}{B1s0}{B2s0}

% \draw[blue]
% 	(B0s0) edge[ar] (B1s0)
% 	edge [ar] (B2s0);
% \draw[red]
	% (B0s0) edge[ar]
	% (B1s1) edge [ar] ($(B2s2.north)$);
% \draw[green]
% 	(B0s0) edge[ar] ($(B1s3.north)$)
% 	edge [ar] (B2s6);

% \node (dots) at ($(B1s8)-(B1s0)$) {$\dotsm$};

\end{tikzpicture}
\end{center}

\caption{Upper: an example of identically colored $m$-tuples of arithmetic progressions (with $k=3$). Below: Possible constructions of a monotone $k$-a.p.} \label{fig:VdWlemmafig}
\end{figure*}

% \missingfigure{Box labelled $A+d$ with blank, red, red, green, yellow, blank, green, blank, yellow. Box $A+2d$ with same dots. Horizontal dots. Box $A+(k-1)d$ with same dots. Now add a blue dot to the beginning of each, and draw a box to the far left labelled $A$. The far left element is $a$. Then $a$ to 0-slot in $A+d$ to 0-slot of $A+2d$ is a.p. Another is $a$ to $1$-slot in $A+d$ to $2$-slot in $A+2d$. Antoher is $a$ to first green of $A+d$ to second green of $A+2d$. And $a$ to first yellow in $A+d$ to second yellow in $A+2d$.(In this example, $k-1=2$)}
% Let $c$ be denote the coloring. Each $A+\ell d$ for $\ell\in[k-1]$ has the same set of colors:
% \[
%  c(A+d):= \{c(x): x\in A+d\} = c(A+2d) = \dotsm = c(A+(k-1)d).
%  \]
%  We write $A+d=\bigcup_{i=1}^m \{a+d+d_i[0,k-1]\}$ where each $a+d+d_i[0,k-1]$ is monochromatic and differently colored from $a+d+d_j[0,k-1]$ for $i\neq j$.  In this language, the identical coloring assumption is that $\{ a+\ell d + s d_i: \ell \in [k-1] \}$ is monochromatic for each $s \in [0,k-1]$.

%  Now, we look at each element of $A$ in turn. Consider the first element, $a$. If $c(a) \in c(A+d)$, then let $c(a) = c(a+d+sd_i)$ for $s\in [k-1]$. Then, by our identical coloring assumption,
%  \[
%  \{ a, a+d+sd_i,a+2d+sd_i, \dotsc,a+(k-1)d  +sd_i \}
%  \]
%  is a monochromatic a.p. of length $k$.  Let us consider an arbitrary element of $A$, $a+ xd_j$ for $x \in [0,k-1]$ and $i\in[m]$. If $c(a+xd_j) = c(a + d + sd_i)$ for $i\in[m]$ and $s\in[0,k-1]$, then

 Write $A+d=\bigcup_{i=1}^m \{a+d+d_i[0,k-1]\}$ where each $a+d+d_i[0,k-1]$ is monochromatic and differently colored from $a+d+d_j[0,k-1]$ for $i\neq j$. In this language, the identical coloring assumption is that $\{ a+\ell d + s d_i: \ell \in [k-1] \}$ is monochromatic for each $s \in [0,k-1]$.
 %Then the a.p. $a+sd+d_i[1,k-1]$ is monochromatic for every $i=1,\dotsc,m$ and $s=1,\dotsc,k-1$ (the color does not depend on $s$).
In particular,
\[
 P':=\{a+d,a+2d,\dotsc,a+(k-1)d\}
 \] is a monochromatic $(k-1)$-a.p.  If it  is the same as color as $a+d+d_i$ for some $i$, then
 \[
 \{ a+d, a+d+d_i,a+d+2d_i,\dotsc,a+d+(k-1)d_i\}
 \]
is a monochromatic $k$-a.p.
Otherwise,
%
% Indeed, if $A\cup(A+d)\cup \dotsm \cup (A+(k-1)d)$ contains no monochromatic $k$-term a.p. then
% \[
%  P':=\{a+d,a+2d,\dotsc,a+(k-1)d\}
%  \] all are of the same color and different from the color of other a.p. in $A+sd$.
%
consider
\[
 P_i':=\{a+d+d_i,a+2d+2d_i,\dotsc,a+(k-1)d+(k-1)d_i\}
 \] which is an a.p. of the same color as
 \[
 \{a+d+d_i,a+d+2d_i,\dotsc,a+d+(k-1)d_i\}.
 \]
and thus a different color from $P'$. Then $P'\cup P_1'\cup\dotsc\cup P_m'\cup\{a\}$ is a polychromatic $(m+1)$-tuple. \qedhere \marginnote{This is the meat of the proof.}
\end{subproof}

Now let $M = W(k,m,r)$ and $N = W(k-1,r^M)$. We will show that $W(k,m+1;r)\leq 2MN$.

% \missingfigure{Partition into two intervals of length $MN$, and the second into $N$ intervals of length $M$ (by underbraces and overbraces). I can think of the second half as a coloring of $N$ into $r^M$ colors (we encode the coloring of an interval of length $M$ as a single color of the $r^M$ colors). }
\begin{figure*}
\begin{center}
\begin{tikzpicture}[node distance = .5cm, every node/.style={minimum height=.7cm}]
	\node[draw,left= of n1] (nL)  {\qquad\qquad\qquad\qquad\qquad\qquad\qquad\quad};

	\draw [
    thick,
    decoration={
        brace,
        mirror,
        raise=0.5cm
    },
    decorate] (nL.west) --  (nL.east) node [pos=0.5,anchor=north,yshift=-0.55cm] {$MN$};

	\node[draw,label=below:] (n1) at (0,0) {\qquad\qquad\quad};
	\node[draw,right= of n1] (n2)  {\qquad\qquad\quad};

	\node[right= .25cm of n2] (n3)  {$\dotsm$};
	\node[draw,right= .25cm of n3] (n4)  {\qquad\qquad\quad};

		\draw [
    thick,
    decoration={
        brace,
        mirror,
        raise=0.5cm
    },
    decorate] (n1.west) --  (n4.east) node [pos=0.5,anchor=north,yshift=-0.55cm] {$N$ intervals};

    \draw [
    thick,
    decoration={
        brace,
        raise=0.5cm
    },
    decorate] (n1.west) --  (n1.east) node [pos=0.5,anchor=north,yshift=1.2cm] {$M$};

 \draw [
    thick,
    decoration={
        brace,
        raise=0.5cm
    },
    decorate] (n2.west) --  (n2.east) node [pos=0.5,anchor=north,yshift=1.2cm] {$M$};
     \draw [
    thick,
    decoration={
        brace,
        raise=0.5cm
    },
    decorate] (n4.west) --  (n4.east) node [pos=0.5,anchor=north,yshift=1.2cm] {$M$};
	\end{tikzpicture}
\end{center}
\caption{We think of coloring each interval  of size $M$ on the right side into $r$ colors as assigning the entire interval one of $r^M$ colors.}\label{fig:vdw_ind_step}
\end{figure*}
We divide $2MN$ into an interval of size $MN$ followed by $N$ intervals of size $M$, as shown in \cref{fig:vdw_ind_step}.
By choice of $N$, there are intervals $(k-1)$ intervals on the right side of the form $I,I+d,I+2d,\dotsc,I+(k-2)d$  which are identically colored.

By the choice of $M$, we may assume $I$ contains a polychromatic $m$-tuple of a.p. of length $(k-1)$ which we will call $A+d$. The first interval of size $MN$ serves to include $A$. The induction step is finished by the claim.
\end{proof}
The proof yields very poor bounds for $W(k;r)$. The current best bounds are
\marginnote{LHS: folklore with a randomized construction. RHS: \cite{Gowers2001}.}
\[
(1 + o(1)) \frac{r^k}{erk} < W(k;r) \leq 2^{2^{r^{2^{2^{k+9}}}}}.
\]
It's conjectured that the upper bound can be improved substantially:
\begin{conjecture*}
 $W(k;2) \leq 2^{k^2}$.
\end{conjecture*}
Let us proceed to the Hales-Jewett theorem.
 It may be informally stated as the following: in a $\overbrace{t\times t\dotsm \times t}^{d \text{ dimensional}}$ game of tic-tac-toe with $r$ players, a draw is impossible as long as $d$ is large enough compared to $r$ and $t$.
Let $A$ be a finite alphabet of size $t$, typically $[0,t-1]$.
Then $A^d$ is the set of ordered $d$-tuples of elements of $A$, or words of length $d$ in the alphabet $A$.

In tic-tac-toe, $A = \{0,1,2\}$, and $d=2$ (see \cref{fig:tic-tac-toe}). We think of each player having a color; a coloring of $\{0,1,2\}^2$ by two colors then corresponds to the moves made by both the players. A draw is impossible if  in any coloring of $\{0,1,2\}^2$, there is a monochromatic ``3-in-a-row'', i.e.,  row, column, or diagonal.
\begin{marginfigure}
\begin{center}
\begin{tikzpicture}

\def\xshift{3.5}

\tikzset{side/.style={gray, thin}}

\draw[step=1cm,gray,very thin] (0,0) grid (3,3);

\foreach \x in {0,1,2}
{
\node[side] at ($ (-.3,.5) +(0,\x) $)  {\x};
\node[side] at ($ (.5,-.3) +(\x,0) $)  {\x};
	\foreach \y in {0,1,2}
	{
	\node at ($ (\x,\y) + (0.5,0.5) $) {\x\y};
	}
}
\end{tikzpicture}
\end{center}
\caption{A depiction of  words in tic-tac-toe: elements of $\{0,1,2\}^2$.} \label{fig:tic-tac-toe}
\end{marginfigure}
% \missingfigure{3x3 grid, labelled 0,1,2 going up and going right from bottom left. Write ordered pairs in the boxes. Possible roots: $\tau_1=0\star$, $\tau_2=\star\star$. The line associated with $\tau_1$ is the first column. The linea ssociated with $\tau_2$ is the diagonal. The middle row is a combinatorial line associated with $\star 1$. The diagonal from top left to bottom right is not a combinatorial line.}
\begin{figure*}[ht]

\begin{center}
\begin{tikzpicture}
\tikzset{side/.style={gray, thin}}
\tikzset{combline/.style={draw, DarkBlue, rounded corners=5pt, thick}}

\def\xshift{4};

\begin{scope}
\draw[step=1cm,gray,very thin] (0,0) grid (3,3);

\foreach \x in {0,1,2}
{
\node[side] at ($ (-.3,.5) +(0,\x) $)  {\x};
\node[side] at ($ (.5,-.3) +(\x,0) $)  {\x};
	\foreach \y in {0,1,2}
	{
	\node at ($ (\x,\y) + (0.5,0.5) $) {\x\y};
	}
}
\def\off{.15};

\draw[combline,label=above:$0\stars$] (\off,\off) rectangle (1-\off,3-\off);

\node[above,DarkBlue] at (.5,3-\off){$0\star$};
\end{scope}

\begin{scope}[shift={(\xshift,0)}]

\draw[step=1cm,gray,very thin] (0,0) grid (3,3);

\foreach \x in {0,1,2}
{
% \node[side] at ($ (-.3,.5) +(0,\x) $)  {\x};
\node[side] at ($ (.5,-.3) +(\x,0) $)  {\x};
	\foreach \y in {0,1,2}
	{
	\node (\x\y) at ($ (\x,\y) + (0.5,0.5) $) {\x\y};
	}
}
\def\off{.15};
%rotate around={30:(-1,0.5)}

\draw[combline,label=above:$0\stars$,rotate around={-45:(.5,0.5)}] (\off,\off) rectangle ($ (1-\off,1.41*3-4*\off) $);

\node[above,DarkBlue] at (3-.5*\off,3-2*\off){$\star\star$};
\end{scope}

\begin{scope}[shift={(2*\xshift,0)}]
\draw[step=1cm,gray,very thin] (0,0) grid (3,3);

\foreach \x in {0,1,2}
{
% \node[side] at ($ (-.3,.5) +(0,\x) $)  {\x};
\node[side] at ($ (.5,-.3) +(\x,0) $)  {\x};
	\foreach \y in {0,1,2}
	{
	\node (\x\y) at ($ (\x,\y) + (0.5,0.5) $) {\x\y};
	}
}
\def\off{.15};
%rotate around={30:(-1,0.5)}

\draw[combline,label=above:$0\stars$] (\off,1+\off) rectangle ($ (3-\off,2-\off) $);

\node[right,DarkBlue] at (3-1.5*\off,1.5){$\star 1$};
\end{scope}

\begin{scope}[shift={(3*\xshift,0)}]

\draw[step=1cm,gray,very thin] (0,0) grid (3,3);

\foreach \x in {0,1,2}
{
% \node[side] at ($ (-.3,.5) +(0,\x) $)  {\x};
\node[side] at ($ (.5,-.3) +(\x,0) $)  {\x};
	\foreach \y in {0,1,2}
	{
	\node (\x\y) at ($ (\x,\y) + (0.5,0.5) $) {\x\y};
	}
}
\def\off{.15};
%rotate around={30:(-1,0.5)}

\begin{scope}[xshift=2cm]
\draw[combline,Red,rotate around={45:(.5,0.5)}] (\off,\off) rectangle ($ (1-\off,1.41*3-4*\off) $);
\end{scope}

% \node[above,DarkBlue] at (3-.5*\off,3-2*\off){$\star\star$};
\end{scope}

\end{tikzpicture}

\end{center}
\caption{Three examples of combinatorial lines in $\{0,1,2\}^2$, followed by a nonexample.  From left to right, combinatorial lines corresponding to roots $\tau_1 = 0\star$, $\tau_2 = \star\star$, and $\tau_3 = \star 1$, respectively, followed by the set $\{02,11,20\}$ in red which is not a combinatorial line. So in tic-tac-toe, not every ``3-in-a-row'' is a combinatorial line, but every combinatorial line is a ``3-in-a-row'', which is enough to show that draws are impossible if we can always find a monochromatic combinatorial line.  } \label{fig:comb_lines_in_tic_tac_toe}
\end{figure*}

Moving back to the general development, a \defn{root} $\tau$ is a word of length $d$ in the alphabet $A\cup \{\star\}$, where $\star$ is a symbol not in $A$, which contains at least one $\star$.
For a root $\tau$ and $a\in A$, the word $\tau(a)$ is obtained by substituting $a$ instead of $\star$ everywhere in $\tau$. A \defn{combinatorial line} in $A^d$ is a set $L_\tau:=\{ \tau(a): a\in A\}$ where $\tau$ is a root of length $d$. See \cref{fig:comb_lines_in_tic_tac_toe} for examples and nonexamples of combinatorial lines in tic-tac-toe. With these definitions, we may formulate the Hales-Jewett theorem as follows.
\begin{theorem}[\cite{halesJewett1963regularity}] \label{thm:HJ}
For every $r$ and $t$, there exists $d= \HJ(t,r)$ such that if $A$ is an alphabet with $|A|=t$ and $A^d$ is colored in $r$ colors, then there exists a monochromatic combinatorial line.
\end{theorem}
\begin{remark}
The same is true for every $d' \geq d$.
\end{remark}
Before proving the Hales-Jewett theorem, we'll discuss an application.
Let $V\subset \Z^d$ be a finite collection of vectors. $U$ is called a homothetic copy of $V=\{v_1,v_2,\dotsc,v_t\}$ if $U = u +\lambda V = \{ u + \lambda v_1,u+\lambda v_2,\dotsc, u+\lambda v_t\}$ for some $u\in \Z^d$ and $\lambda\in \Z$. Homothetic copies are a generalization of arithmetic progressions: for $d=1$ and $V = \{0,1,\dotsc,k-1\}$, a homothetic copy of $V$ is exactly an arithmetic progression of length $k$. See  \cref{fig:homothetic_ex} for a two dimensional example.
\begin{marginfigure}[2cm]
\begin{center}
\begin{tikzpicture}[scale=.5]
% \draw[step=1cm,gray,very thin] (0,0) grid (4,5);
\def\rad{1.5pt}

\foreach \x in {0,1,...,4}
{
	\foreach \y in {0,1,...,5}
	{
		\filldraw[black] (\x,\y) circle (\rad);
	}
}
\filldraw[LightGreen] (0,0) circle (3*\rad);
\filldraw[LightGreen] (0,1) circle (3*\rad);
\filldraw[LightGreen] (1,0) circle (3*\rad);

\def\lam{2};
\def\ux{1};
\def\uy{2};

\filldraw[LightBlue] ($ (\ux ,\uy) + \lam*(0,0)  $)  circle (3*\rad);
\filldraw[LightBlue] ($ (\ux ,\uy)  + \lam*(0,1)  $) circle (3*\rad);
\filldraw[LightBlue] ($ (\ux ,\uy)  + \lam*(1,0)  $) circle (3*\rad);

\end{tikzpicture}
\end{center}
\caption{An example of homothetic copies in $\Z^2$: the green dots are $V = \{(0,0),(0,1),(1,0)\}$, and the blue dots are $U= u +\lambda V$ for $u = (1,2)$ and $\lambda=2$.} \label{fig:homothetic_ex}
\end{marginfigure}
\begin{theorem}[Gallai (late 1930s), \cite{Wit_paper}]\marginnote{According to \textcite[page 22]{Ramsey_Yesterday_today_tomorrow}, this theorem was communicated from Gallai to Rado in the late 1930s, and was published in 1943 (\cite{Rado_note}). The theorem was independently proven by Wit in 1952.}
Let $\Z^d$ be colored in $r$ colors and let $V\subset \Z^d$ be finite. Then there exists a monochromatic homothetic copy of $V$.
\end{theorem}
\begin{remark}
In fact, one can replace $\Z^d$ by $[n]^d$ where $n$ depends on $V$ and $r$, yielding an analog of van der Waerden's theorem.
\end{remark}
\begin{proof}
The proof will be based on the  HJ theorem.

We will take an appropriately large hypercube and project it into $\Z^d$ such that a combinatorial line in the hypercube projects to a homothetic copy of $V$.
Let $V = \{v_1,\dotsc,v_t\} =: A$. Let $n$ be such that every $r$-coloring of $A^n$ contains a monochromatic combinatorial line.

Define $f: A^n\to \Z^d$ by $f((a_1,a_2,\dotsc,a_n)) = \sum_{i=1}^n a_i$ where $a_i \in V$. If $\chi$ is the coloring of $\Z^d$ into $r$-colors, then we can define $\chi': A^n \to [r]$ by $\chi'(a) = \chi(f(a))$. By the choice of $n$, there exists a root $\tau$ such that $\tau(v_1)$, $\tau(v_2)$, \ldots, $\tau(v_t)$ all receive the same color. Then $\{f(\tau(v_1)), f(\tau(v_2)), \ldots,f( \tau(v_t))\}$ is a homothetic copy of $V$, as follows. If $\tau = a_1a_2\dotsm a_n$ then set  $u := \sum_{i: a_i\neq \star} a_i$, and $\lambda$  the number of $\star$'s in $\tau$. Then $f(\tau(v_i)) = u+ \lambda v_i$.

\flavor{This is the end, but let me make you believe that this is the end.}

For example, consider $V=\{v_1,v_2,v_3\}$ and $\tau= v_1 v_2 \star v_1 \star$. Then we're claiming $\{f(\tau(v_1)),f(\tau(v_2)),f(\tau(v_3))\}$ is a homothetic copy of $V$. E.g.,
\[
f(\tau(v_1)) =  v_1 + v_2 + v_1  +v_1 + v_1 =4v_1  + v_2 = \underbrace{v_1+v_2 +v_1}_{u} + \underbrace{2}_\lambda v_1. \qedhere
\]
\end{proof}
\flavor{Paraphrase: Proofs by logicians are the hardest; I can follow it but I don't understand why things are happening.}

\lect{3}{14}
% \marginnote{Lecture X: Monday, March 14, 2016.}

\begin{proof}[Proof of \cref{thm:HJ}]
Let $n = \HJ(t,r)$. We will prove its existence by induction on $t$ for fixed $r$.
First, $\HJ(1,r)=1$, since combinatorial lines of length 1 are certainly monochromatic.

Now, the induction step. Assume $n = \HJ(t-1,r)$. Let $n\ll N_1 \ll N_2 \ll \dotsm \ll N_n$. Specifically, $N_1 = r^{t^n}$ and $N_i = r^{t^n + \sum_{j=1}^{i-1} N_j}$ for $i\geq 2$, and $N = \sum_{i=1}^n N_i$. We will show that $\HJ(r,t)\leq N$, i.e. if $\chi: A^N \to [r]$, then $\chi$ contains a monochromatic combinatorial line.

% \missingfigure{ long versions of \textvisiblespace labelled $N_1$ to $N_n$ }
\begin{figure}
\begin{center}
\vspace{\baselineskip}
\begin{tikzpicture}[node distance = 1cm]
\def\ydif{.1};
\def \nmax {3};
\coordinate (1A) at (0,0);

\coordinate (1Au) at ($ (1A) + \ydif*(0,1) $);
\draw (1A) -- (1Au);

\coordinate[right= of 1A] (1B);
\coordinate (1Bu) at ($ (1B) + \ydif*(0,1) $);
\draw (1B) -- (1Bu);

\draw (1A) -- (1B) node[midway, label={below:$N_1$}]{};

\foreach \n in {2,3,...,\nmax}
{
	\pgfmathparse{int(\n -1 )};

	\coordinate[right= of \pgfmathresult B] (\n A);

	\coordinate (\n Au) at ($ (\n A) + \ydif*(0,1) $);
	\draw (\n A) -- (\n Au);

	\coordinate[right= of \n A] (\n B);
	\coordinate (\n Bu) at ($ (\n B) + \ydif*(0,1) $);
	\draw (\n B) -- (\n Bu);

	\draw (\n A) -- (\n B) node[midway, label={below:$N_\n$}]{};
}

% \pgfmathparse{};
\pgfmathsetmacro{\nplusone}{int(\nmax +1)}

\node[right = of \nmax B] (\nplusone B) {$\dotsm$};

\pgfmathparse{int(\nmax +2)};

\pgfmathsetmacro{\nplustwo}{int(\nmax +2)}

\coordinate[right= of \nplusone B] (\nplustwo A);

\coordinate (\nplustwo Au) at ($ (\nplustwo A) + \ydif*(0,1) $);
\draw (\nplustwo A) -- (\nplustwo Au);

\coordinate[right= of \nplustwo A] (\nplustwo B);
\coordinate (\nplustwo Bu) at ($ (\nplustwo B) + \ydif*(0,1) $);
\draw (\nplustwo B) -- (\nplustwo Bu);

\draw (\nplustwo A) -- (\nplustwo B) node[midway, label={below:$N_n$}]{};

\end{tikzpicture}
% \vspace{-.5\baselineskip}
\end{center}
\caption{A depiction of $N_1,\dotsc,N_n$. We aim to show $\HJ(t,r) = N:= \sum_{i=1}^n N_i$.} \label{fig:HJ1}
\end{figure}
We will say $a,b\in A^n$ are \emph{neighbors} if they differ in only one position and one of them has symbol $0$ in this position and the other has the symbol $1$; that is, if $a = a_1a_2\dotsm a_{i-1} 0 a_{i+1} \dotsm a_n$, and $b =a_1a_2\dotsm a_{i-1} 1 a_{i+1} \dotsm a_n$ for some $1\leq i \leq n$.

Let $\tau$ be a root of length $N$ such that $\tau = \tau_1\dotsm \tau_n$ and $\tau_i$ is a root of length $N_i$. For $a \in A^n$, $a = a_1\dotsm a_n$, define
\[
\tau(a) = \tau_1(a_1)\tau_2(a_2)\dotsm \tau_n(a_n).
\]
For example, suppose we have a root $\tau=\overbrace{\star}^{\tau_1} \overbrace{2\star}^{\tau_2} \overbrace{\star 3\star}^{\tau_3}$. Then $\tau(012) = 021232$.
Given $\tau = \tau_1\tau_2\dotsm \tau_n$ as above, define $\chi_\tau: A^n \to [r]$ by $\chi_\tau(a) = \chi(\tau(a))$.
Now, we're not guaranteed that we have monochromatic combinatorial lines in $A^n$, but we will try to compress to $A^{n-1}$ where we do have such lines.
\begin{claim}
There exist roots $\tau_1,\tau_2,\dotsc,\tau_n$ such that $\tau_i$ has length $N_i$, and, if $\tau=\tau_1\dotsm \tau_n$, then
\[
\chi_\tau(a) = \chi_\tau(b)
\]
for any pair of neighbors $a$ and $b$ in $A^n$.
\end{claim}
We accept this claim for now to finish the proof. Define $\chi'_\tau$ as the restriction $\chi_\tau': (A\setminus \{0\})^n \to [r]$ of $\chi_\tau$. Then $\chi_\tau'$ contains a monochromatic combinatorial line. That is, there exists $\nu = \nu_1\nu_2\dotsm \nu_n$ with $\nu_i\in (A\setminus\{0\})\cup \{\star\}$ such that $\nu(1),\nu(2),\dotsc,\nu(t-1)$ all have the same color. We wish to show that the line corresponding to $\tau(\nu)$ is monochromatic in $\chi: A^N\to[r]$, where we write $\tau(\nu) := \tau_1(\nu_1)\dotsm \tau_n(\nu_n)$ with $\tau_i(\star)=\tau_i$.
\marginnote{If $\nu = (12\star)$, then $\tau(\nu) = 122\star 3\star$, using our example $\tau$ from earlier.}
That is, we want $\tau(\nu(0))$, $\tau(\nu(1))$,\ldots, $\tau(\nu(t-1))$ to receive the same color in $\chi$. So we want $\chi_\tau(\nu(a))$ to be the same for $a=0,1,\dotsc,t-1$.

But $\chi_\tau(\nu(1)) = \dotsm = \chi_\tau(\nu(t-1))$ by the choice of $\nu$. So it remains to show that $\chi_\tau(\nu(0))=\chi_\tau(\nu(1))$.  While $\nu(0)$ and $\nu(1)$ may differ in several positions, in each position one has 1 and the other has 0, so we may change them one at a time using that $\chi_\tau$ acts the same on neighbors, until we see they have the same coloring.

Thus, it remains to prove the claim. We will construct the roots $\tau_1,\dotsc,\tau_n$ in reverse order.
Suppose $\tau_{i+1},\dotsc,\tau_n$ are constructed.\marginnote{The case $\tau_n$ is similar to the generic step we consider here.}
% \missingfigure{Intervals $N_1, N_2$, \ldots $N_{i-1}$, $N_i$ with $W_k$, $N_{i+1}$ with $\tau_{i+1}$, \ldots, $N_n$ with $\tau_n$. Overbrace from $N_1$ to $N_{i-1}$ by $M$.}
For $0\leq k\leq N_i$, let
\[
W_k = \underbrace{0\dotsm 0}_k \underbrace{1\dotsm 1}_{N_i-k}\in A^{N_i}
\]
Let $M = \sum_{j=1}^{i-1}N_i$. Define a coloring  $\chi_k : A^{M+ n-i} \to [r]$ as
\[
\chi_k(x_1 \dotsm x_M y_{i+1}\dotsm y_{n}) =  \chi(x_1\dotsm x_M W_k \tau_{i+1}(y_{i+1})\dotsm \tau_n(y_n)).
\]
See \cref{fig:vdwWk} for a depiction of this definition.
\begin{figure*}[ht]
\begin{center}
\begin{tikzpicture}[node distance = 1cm]
\def\ydif{.1};
\def\dotsdist{.5};

\setcounter{numint}{0};
\coordinate (0B) at (0,0);
\stepcounter{numint}

\newcommand{\vdwinterval}[3][1]{
	\def\n{\thenumint};
	\pgfmathparse{int(\thenumint - 1)};

	\coordinate[ node distance = #1 cm, right= of \pgfmathresult B] (\n A);

	\coordinate (\n Au) at ($ (\n A) + \ydif*(0,1) $);
	\draw (\n A) -- (\n Au);

	\coordinate[right= of \n A] (\n B);
	\coordinate (\n Bu) at ($ (\n B) + \ydif*(0,1) $);
	\draw (\n B) -- (\n Bu);

	\draw (\n A) -- (\n B) node[midway, label={below:$N_{#2}$},yshift=.2cm]{#3};

	\stepcounter{numint}
}
\vdwinterval{1}{\phantom{$W_k$}$\cdot$\phantom{$W_k$}}
\vdwinterval{2}{\phantom{$W_k$}$\cdot$\phantom{$W_k$}}

\newcommand{\vdwdots}{
	\def\n{\thenumint};
	\pgfmathparse{int(\thenumint - 1)};

	\node[node distance = \dotsdist cm, right = of \pgfmathresult B] (\n B) {$\dotsm$};
	\stepcounter{numint}
}
\vdwdots
\vdwinterval[\dotsdist]{i-1}{\phantom{$W_k$}$\cdot$\phantom{$W_k$}}
\vdwinterval{i}{$W_k$}
\vdwinterval{i+1}{$\tau_{i+1}(\cdot)$}
\vdwdots
\vdwinterval[\dotsdist]{n}{$\tau_n(\cdot)$}

\draw [
    thick,
    decoration={
        brace,
        raise=0.65cm
    },
    decorate] (1A.west) --  (4B.east) node [pos=0.5,anchor=north,yshift=1.35cm] {$M$};

\end{tikzpicture}
\end{center}
\caption{An illustration of how $\chi_k$ acts on words in $A^{M+n-i}$. First, we write such a word as $x_1\dotsm x_m y_{i+1}\dotsm y_n$ where $x_j \in A^{N_j}$ (for $j\in [i-1]$) and $y_j \in A$ (for $j=i+1,\dotsc,n$). Then, $\chi_k$ acts on such a word by creating a word of size $A^N$ as follows, which it plugs into $\chi$.  First, $x_1,\dotsc,x_m$ are not modified (visualized by empty slots of the appropriate size in the figure). Then  the word $W_k \in A^{N_i}$ is concatenated, followed by $\tau_{j}(y_j) \in A^{N_j}$ for $j= i+1,\dotsc,n$.} \label{fig:vdwWk}
\end{figure*}
% Suppose $\tau_{i+1}$
Now, $N_i > t^{M+n - i}$, so there exist $k,\ell$ such that $\chi_k = \chi_\ell$, by the pigeonhole principle. WLOG $k< \ell$. Let $\tau_i = \underbrace{0\dotsm0}_k \underbrace{\star\dotsm\star}_{\ell-k} \underbrace{1\dotsm 1}_{N_i - \ell}$. Then $\tau_i(0) = W_\ell$ and $\tau_i(1) = W_k$.

Now, let's show that the resulting $\tau = \tau_1\dotsm \tau_n$ satisfies the claim. Suppose $a = a_1a_2\dotsm a_{i-1} 0 a_{i+1} \dotsm a_n$, and $b =a_1a_2\dotsm a_{i-1} 1 a_{i+1} \dotsm a_n$. Then
\begin{align*}
\chi_\tau(a) &= \chi(\tau_1(a_1)\tau_2(a_2)\dotsm \tau_{i-1}(a_{i-1})W_\ell \tau_{i+1}(a_{i+1})\dotsm \tau_n(a_n)) \\
&= \chi_\ell (\tau_1(a_1)\tau_2(a_2)\dotsm \tau_{i-1}(a_{i-1})W_\ell a_{i+1}\dotsm a_n)\\
&= \chi_k (\tau_1(a_1)\tau_2(a_2)\dotsm \tau_{i-1}(a_{i-1}) a_{i+1}\dotsm a_n)\\
&= \chi_\tau(b).\qedhere
\end{align*}
\end{proof}
%should 7.8
\begin{theorem}[Density Hales-Jewett theorem, \cite{DensityHJ}] \label{thm:HJ_density}
For every $\epsilon>0$ and each $t$, there exist $n$ such that if $|A| = t$ and $Z \subset A^n$ with $|Z| \geq \epsilon t^n$ then $Z$ contains a combinatorial line.
\end{theorem}
\begin{remark}
This theorem implies \cref{thm:HJ}. If we consider an $r$-coloring as a partition $Z_1,\dotsc,Z_r$ of $A^n$, then we have some $i$ such that $|Z_i| \geq \frac{1}{r}t^n$ by the pigeonhole principle. Then \cref{thm:HJ_density} with $\epsilon= \frac{1}{r}$ implies that $Z_i$ contains  combinatorial line, proving \cref{thm:HJ}.
\end{remark}

%thm. 7.9
\begin{theorem}[\cite{szemeredi1975sets}]
$\forall \, \epsilon>0$ and $\forall\, k$, $\exists N > 0$ such that if $A\subset [N]$ with $|A| \geq \epsilon N$, then $A$ contains an arithmetic progression of length $k$.
\end{theorem}

%thm. 7.10
\begin{theorem}[\cite{green2008primes}]
For every $k$, the set of primes contain arithmetic progressions of length $k$. \marginnote{Since the density of primes goes to zero, the density theorem above does not help.}
\end{theorem}

If we wanted to formulate a density version of Ramsey's theorem, how it would it go? For every $t$ and $\epsilon>0$, there exists $N$ such that if $G$ is a graph on $N$ verticies  and $|G|\geq \epsilon {N\choose 2}$, then $G$ contains $K_t$.
But this is equivalent to $\pi(K_t) = 0$, which is false for $t\geq 3$.

\newthought{Let us} move on. Consider a finite sequence $A=(a_1,\dotsc,a_n)$. Then we say $(a_{i_1},a_{i_2},\dotsc,a_{i_k})$ is an \defn{increasing subsequence}[subsequence!increasing] of $A$ if $i_1 < i_2 < \dotsb< i_k$ and $a_{i_1}\leq a_{i_2} \leq \dotsm \leq a_{i_k}$. Likewise, $(a_{i_1},a_{i_2},\dotsc,a_{i_k})$ is a \defn{decreasing subsequence}[subsequence!decreasing] of $A$ if $i_1 < i_2 < \dotsb< i_k$ and $a_{i_1}\geq a_{i_2} \geq \dotsm \geq a_{i_k}$.

\begin{problem}
For all $k$, does there exist a number $f(k)$ such that every sequence of length at least $f(k)$ contains an increasing or decreasing subsequence of length $k$?
\end{problem}

Indeed, such an $f(k)$ exists: $f(k) \leq R(k,k)$. Given a sequence $(a_n)_{n=1}^{R(k,k)}$, we can create a coloring on $[R(k,k)]$ as follows: given an edge $\{i,j\}\in [R(k,k)]^{(2)}$  with $i<j$, we color $\{i,j\}$ red if $a_i\leq  a_j$, and blue otherwise. Then by the definition of $R(k,k)$, we are guaranteed  a monochromatic complete graph on $k$ verticies. This yields an increasing subsequence if the monochromatic $K_k$ is red, and decreasing if the $K_k$ is blue. This yields an exponential bound on $f(k)$. But we can do better.
\begin{theorem}[\cite{erdosszekeres1935combinatorial}]
For all $k,\ell\geq 2$ any sequence of length at least $(k-1)(\ell-1)+1$ contains an increasing subsequence of length $k$ or a decreasing subsequence of length $\ell$.
\end{theorem}
\begin{remark}
In the case $k=\ell$, this is a quadratic bound on $f(k)$.
\end{remark}
\begin{proof}[Proof by induction on $k+\ell$]
If $k=2$, say, then any sequence of length $\ell$ is decreasing or not.
For the induction step, let $n = (k-1)(\ell-1) + 1$,  $A=(a_1,\dotsc,a_n)$ be a sequence, and $Z$ be the set of last elements of increasing subsequences of length $k-1$ in $A$. Then, $Z = (a_{i_1},a_{i_2},\dotsc,a_{i_z})$ with $i_1< \dotsm < i_z$, where $z = |Z|$. For contradiction, assume $A$ violates the claim.

Then $A\setminus Z$ contains no increasing subsequences of length $k-1$ and no decreasing subsequences of length $\ell$. So $|A\setminus Z| \leq (k-2)(\ell-1)$. Then $|Z| \geq (k-1)(\ell-1)+1 - (k-2)(\ell-1)\geq \ell$. So if $Z$ is decreasing we are done. If not, then there exists $s$ such that $a_{i_s} \leq a_{i_{s+1}}$. Then let $(b_{i_1},b_{i_2},\dotsc,b_{i_{k-1}} = a_{i_s})$ be an increasing sequence ending in $a_{i_s}$. Then this sequence extends to a length $k$ sequence by adding $a_{i_{s+1}}$.
\end{proof}
\lect{3}{16}
% \marginnote{Lecture X: Wednesday, March 16, 2016.}
Let us consider a pigeonhole proof of this result.
\begin{proof}	As before, let $A = (a_1,\dotsc,a_n)$ be a sequence.
For every $s\in[n]$, we will associate to $a_s$ two numbers:
\begin{itemize}
	\item $i_s$, the length of the longest increasing subsequence ending in $a_s$,
	\item $d_s$, the length of the longest decreasing subsequence ending in $a_s$.
\end{itemize}
If $A$ contains no subsequence we need then $1\leq i_s\leq k-1$ and $q\leq d_s\leq \ell-1$ so there are $(k-1)(\ell-1)$ possible pairs.

So there exist $1\leq s<t \leq n$ such that $(i_s,d_s) = (i_t,d_t)$ by the pigeonhole principle. Suppose, by symmetry, that $a_s\leq a_t$. Then an increasing subsequence of length $i_s$ ending in $a_s$ can be extended to a subsequence of length $i_{s+1}$ ending in $a_t$. This is a contradiction to $i_t=i_s$.
\end{proof}


\documentclass[letterpaper,11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[htt]{hyphenat}
\usepackage{courier}

\begin{document}
\title{\Huge{Problem Set 1}\\
\vspace{0.125in}
\Large{MIT 6.0002}\\
\large{Introduction to Computational Thinking and Data Science\\
as Taught in Fall 2016}
}
\author{
John L. Jones IV}
\maketitle
\pagebreak
\section*{Problem A.1}
What were your results from \texttt{compare\_cow\_transport\_algorithms}? Which algorithm runs faster? Why? \\
\\
Using \texttt{ps1\_cow\_data.txt} the results were: \\
\texttt{
  greedy\_cow\_transport:\\
  length =  6 trips \\
  time = .000145 seconds \\
  \\
  brute\_force\_cow\_transport: \\
  length =  5 trips \\
  time = 0.48294 seconds \\
}
\\
The algorithm \texttt{greedy\_cow\_transport} does not iterate through every possible combination of trips
like \texttt{brute\_force\_cow\_transport}.
In my implementation of \texttt{greedy\_cow\_transport}, first the input dictionary of cows is copied to a
list of cow names \texttt{sorted} from largest to smallest weight.
The python \texttt{sorted} function utilizes a Timsort which is $\mathcal{O}(n\log{}n)$.
Then \texttt{greedy\_cow\_transport} removes any cow which is larger than \texttt{limit},
an $\mathcal{O}(n)$ operation.
The sorted list is then utilize to select the cows which can fit on the ship.
Starting at the big end of the list,
iterate and select cows that can fit onto the ship without exceeding the payload \texttt{limit}.
Since the list has been sorted, this is an $\mathcal{O}(n\log{}n)$ operation.
The python \texttt{sorted} function's Timsort and
selecting cows operation dominate the run time,
making \texttt{greedy\_cow\_transport} $\mathcal{O}(n\log{}n)$.
In comparison, \texttt{brute\_force\_cow\_transport} must first create all permutations of the possible trips,
$\mathcal{O}(n^{2})$.
Then evaluate each of these trips, $\mathcal{O}(n^{2})$.
This emphasizes Professor John Guttag's quote from Lecture 1, ``many optimization problems are inherently exponential.
What that means is there is no algorithm that provides an exact solution to this problem whose worst case running time
is not exponential in the number of items."

\section*{Problem A.2}
Does the greedy algorithm return the optimal solution? Why/why not? \\
\\
No, the greedy algorithm \emph{does not} return the optimal solution.
The nature of this ``knapsack'' problem is $\mathcal{O}(n^{2})$.
However, a reasonable solution can be solve in $\mathcal{O}(n\log n)$ with \texttt{greedy\_cow\_transport}.
With \texttt{ps1\_cow\_data.txt} \texttt{greedy\_cow\_transport} returns a solution $1000$ times faster than
\texttt{brute\_force\_cow\_transport}.

\section*{Problem A.3}
Does the brute force algorithm return the optimal solution? Why/why not? \\
\\
Yes, the brute force algorithm does return the optimal solution.
All possible solutions are found then evaluated.
The optimal solution is guaranteed to be produced and returned.
However, this comes at a great cost to run-time speed.
With \texttt{ps1\_cow\_data.txt} \texttt{brute\_force\_cow\_transport} produces a solution $1000$ times slower
than the greedy algorithm.

\section*{Problem B.1}
Explain why it would be difficult to use a brute force algorithm to solve this problem if there were $30$ different egg weights.
You do not need to implement a brute force algorithm in order to answer this. \\
\\
Brute force requires all possible solutions to be solved then evaluated.
The width of the search tree grows linearly with the number of egg weights.
The number of nodes grows exponentially with number of egg weights.
Therefore, the computational complexity grows exponentially with the number of egg weights.
Observe:
1. This problem can be separated into smaller similar sub-problems therefore a recursive solution is possible.
2. It is possible to have re-occurring sub-problems.
Since these two conditions are true, a dynamic programming approach, which uses a memo,
allows the optimal solution to be found in much less run time than a typical brute-force approach.
The same recursive solution without a memo is so slow, I did not have the patience to see if it worked on $n = 99$.

\section*{Problem B.2}
If you were to implement a greedy algorithm for finding the minimum number of eggs needed, what would the objective function be?
What would the constraints be? What strategy would your greedy algorithm follow to pick which eggs to take?
You do not need to implement a greedy algorithm in order to answer this.\\
\\
Always take the largest egg available, if and only if the largest egg does not exceed the available weight.

\section*{Problem B.3}
Will a greedy algorithm always return the optimal solution to this problem?
Explain why it is optimal or give an example of when it will not return the optimal solution.\\
\\
No the greedy algorithm will not always return the optimal solution.
For example, if the egg weights are (1,5,7) and the target weight is 10. The optimal solution is 2 (2 * 5 = 10).
The greedy solution would return 4 (1 * 7 + 3 * 1 = 10).

\end{document}


\section{Econometric Theory}
\subsection{Model and Estimation}
The econometric model used to forecast and its estimation method are closely related to Hansen \cite{hansen2009averaging} and Andrews \cite{andrews93}.\footnote{Andrews considers GMM as the primary estimation method.} The model we are interested in is a linear time series regression with a possible structural break in the conditional mean. The observations we have are time series $\{y_t,x_t\}$ for $t = 1,...,T$, where $y_t$\footnote{Since we are interested in forecasting, $y_t$ can be thought of as the variable to be predicted for the next period using currently available information $x_t$.} is the scalar dependent variable and $x_t$ is a $k\times 1$ vector of related predictors and possibly lagged values of $y_t$, $k$ is the total number of regressors or predictors included. Parameters are estimated by ordinary least squares. The forecasting model allowing for structural break is:
\begin{equation} \label{mod:1}
	y_t = x_t'\beta_1 I_{[t<m]} + x_t'\beta_2 I_{[t \geq m]} + e_t
\end{equation}
where $I_{[\bullet]}$ is an indicator function, $m$ is the time index of the break and $E(e_t|x_t) = 0$. The break date is restricted to the interval $[m_1,m_2]$ which is bounded away from the ends of the sample on both sides, $1 < m_{1} < m_{2} < T$. In practice, a popular choice is to use the middle $70\%$ portion of the sample. We assume that all information relevant for forecasting is included in the regressors $x_t$, and the source of model misspecification comes solely from the uncertainty about parameter stability. This is in contrast to many applied econometric models where model misspecification bias comes from the wrong choice of regressors but the parameters are assumed stable.

We can also use a stable linear model to forecast:
\begin{equation} \label{mod:2}
	y_t = x_t'\beta + e_t
\end{equation}
The traditional pre-test procedure starts with performing a test for structural breaks\footnote{This can be done in various ways. One is to treat various possible number of breaks as different models, then select one according to some information criterion, e.g., AIC, SIC or Mallow's. Another way is hypothesis testing, following the relevant testing procedures outlined in Andrews \cite{andrews93}, Bai and Perron \cite{bai_perron98} and Elliot and Muller \cite{elliott_muller_RES2006}.}, either by using Andrews' SupF or SupW test, or Bai and Perron's multiple-break test, and then decide to keep the stable or unstable model.

As an alternative to model selection, we can combine these two models by assigning weight $w$ to model~\ref{mod:1} and $1 - w$ to model~\ref{mod:2}, where $w \geq 0$. So the combined predictive model is
\begin{equation} \label{mod:3}
    y_{t} = w \left\{ x_t'\beta_1 I_{[t<m]} + x_t'\beta_2 I_{[t \geq m]} \right\} + (1 - w) \left\{ x_t'\beta \right\} + e_t
\end{equation}
With the forecasting model ready, next, we are going to present the cross-validation criterion in detail which is crucial in determining the optimal weight $w$ in equation~\ref{mod:3}.


\section{single scatterer}

We derive the matrix for a single scatter in a quasi-1D channel of height w (where y goes from 0 to w) and the defect is at x = 0. The incident amplitude is A, reflection is B, and transmission is C.  These are later normalized to 1, r, and t, respectively.

For simplicity we assume there are two open channels (N=2) and two closed channels ($N_c$=2) and that the incident light is only in channel 2. The algorithm can be duplicated for any arbitrary open channel. It doesn't make sense to say the incident light is in the closed channel since those are not propagating modes. The algorithm show works for arbitrary number of open and closed channels. We show that closed channels can be ``folded'' into the open channels, which maintains conservation of information. The rank of the matrix is reduce from $N+N_c$ to N but the terms become messier.

Method for matrix setup: match boundary conditions for the amplitude and derivative at the scatterer.
% see Ben's notes, 20080617
The general equation describing the system is
\begin{equation}
A_2 \chi_2(y) \exp(i k_2 x) + \sum_{n=1}^4 B_n \chi_n(y) \exp(-i k_n x) =
\sum_{n=1}^4 C_n \chi_n(y) \exp(i k_n x)
\label{singlescattererwave}
\end{equation}
where if $n>N$, then $k_n = i \kappa_n$.

Boundary condition: amplitudes match at x = 0. For each channel, multiply both sides by
\begin{equation}
\int dy \chi_m(y)
\end{equation}
which by orthogonality with $\chi_n(y)$ yields $\delta_{nm}$, so at x=0,
\begin{equation}
\begin{gathered}
B_1 = C_1 \\
A_2 + B_2 = C_2 \\
B_3 = C_3 \\
B_4 = C_4
\end{gathered}
\end{equation}

In order to have the derivatives match we detour to the Schr\"{o}dinger equation:

\begin{equation}
(-\frac{\hbar^2}{2 m}(\frac{d^2}{dx^2}+\frac{d^2}{dy^2})+\gamma \delta(x)\delta(y-y_o))\Psi = E \Psi
\end{equation}
(equation 1 in \cite{1990_Bagwell}).

separation of variables:
\begin{equation}
\Psi = \sum_n D_n(x) \chi_n(y)
\end{equation}

\begin{equation}
-\frac{\hbar^2}{2 m} \frac{d^2}{dy^2} \chi_n(y) = E_n \chi_n(y)
\end{equation}

boundary condition: $\chi_n(y)$ = 0 for y = 0 and y = w.

\begin{equation}
\begin{gathered}
\chi_n(y) = \sqrt{\frac{2}{w}sin(\frac{n \pi}{w}y} \\
E_n = \frac{\hbar^2}{2 m}(\frac{n \pi^2}{w})^2
\end{gathered}
\end{equation}

\begin{equation}
-\frac{\hbar^2}{2 m}\sum_m D_m^{''}(x) \chi_m(y) +
\sum_m D_m(x) E_m \chi_m(y) +
\gamma \delta(x) \sum_m D_m(x) \chi_m(y) \delta(y-y_o) =
E_{total} \sum_m D_m(x) \chi_m(y)
\end{equation}
where $E_m \chi_m(y)$ = $\chi_m^{''}(y)$. Multiply both sides by
$\int dy \chi_n(y)$ to get $\delta_{mn}$ which leads to
\begin{equation}
-\frac{\hbar^2}{2 m} D_n^{''}(x) +D_n(x) E_n +
\delta(x) \sum_m D_m(x) \gamma \chi_n(y_o) \chi_m(y_o) = D_n(x) E
\end{equation}
re-arranging, we get Bagwell's equation 4,
\begin{equation}
\frac{d^2}{dx^2}D_n(x) + (\frac{E-E_n}{\hbar^2})D_n =
\delta(x) \sum_m D_m(x) \Gamma_{nm}
\label{Bagwellsequ4}
\end{equation}
where
\begin{equation}
\begin{gathered}
k_n^2 = \frac{E-E_n}{\hbar^2}2 m \\
\Gamma_{nm} = \chi_n(y_o) \chi_m(y_o)
\end{gathered}
\end{equation}
Now we can match derivatives at x=0. Integrate over a small region, applying
\begin{equation}
\int_{0-\epsilon}^{0+\epsilon}dx
\end{equation}
to equation \ref{Bagwellsequ4}

\begin{equation}
\frac{dD_n}{dx}|^{+\epsilon}_{-\epsilon} + k_n^2 D_n 2 \epsilon =
\sum_m D_m(0) \Gamma_{nm}
\end{equation}
which is Bagwell's equation 18. Now let $\epsilon \rightarrow$ 0
\begin{equation}
\frac{dD_n(+)}{dx} - \frac{dD_n(-)}{dx} = \sum_m^4 D_m(0) \Gamma_{nm}
\end{equation}
Where $D_{n}(+)$ is the derivative of the wave function x component on the left side of the scatterer, and similarly $D_{n}(+)$ is on the right side of the scatterer. Apply to equation \ref{singlescattererwave}
\begin{equation}
i k_n C_n - (i k_2 A_2 \delta_{2 n} - i k_n B_n) =
\sum_{m=1}^4 C_m \Gamma_{nm}
\end{equation}
from the fist set of boundary conditions, $B_1=C_1$, $A_2+B_2=C_2$, $B_3=C_3$, $B_4=C_4$, thus $B_2=C_2-A_2$

For channels 1,3, and 4 =n
\begin{equation}
2 i k_n C_n = \sum_{m=1}^4 C_m \Gamma_{nm}
\end{equation}
and for channel 2,
\begin{equation}
\begin{gathered}
i k_2 (C_2 - A_2 +B_2) = i k_2 (C_2 -A_2 + (C_2 - A_2)) = 2 i k_2 (C_2 -A_2) = \sum C_m \Gamma_{2m} \\
-2 i k_2 A_2 = (\sum_m C_m \Gamma_{2m}) - 2 i k_2 C_2 \\
-2 i k_2 = (\sum_m (\frac{C_m}{A_2}) \Gamma_{2m}) - 2 i k_2 \frac{C_2}{A_2}
\end{gathered}
\end{equation}
Define $C_m/A_2$ as transmission $t_{2m}$ so that coefficients are normalized to incident unity. [Note: 1 with respect to each channel, so that if there are 2 input channels the incidence is actually 2 (?)]

The four sums can be written as a matrix
\begin{equation}
 \left( \begin{array}{c}
0 \\
-2 i k_2 \\
0 \\
0  \end{array} \right) =
 \left( \begin{array}{cccc}
\Gamma_{11}-2 i k_1 & \Gamma_{12}         & \Gamma_{13}              & \Gamma_{14} \\
\Gamma_{21}         & \Gamma_{22}-2 i k_2 & \Gamma_{23}              & \Gamma_{24} \\
\Gamma_{31}         & \Gamma_{32}         & \Gamma_{33}+2 i \kappa_3 & \Gamma_{34} \\
\Gamma_{41}         & \Gamma_{42}         & \Gamma_{43}              & \Gamma_{44}+2 i \kappa_4 \end{array} \right)
 \left( \begin{array}{c}
t_21 \\
t_22 \\
t_23 \\
t_24 \end{array} \right)
\end{equation}

Where the left side vector is the input, and the right side matrix are the transmission coefficients. Note that there were two (open) input channels, which correspond to the upper 2 elements, and the lower elements correspond to the closed channels, which can not be inputs.


\section{Model Approach }

%%%
%%% SECTION: GOVERNNG EQNS
%%%
\subsection{Governing Equations}

Assume a volume of an incompressible porous medium with porosity, $\phi$, that does not vary in time, containing $N_\mathrm{p}$ immiscible fluid phases.  The volume fraction of each phase is,
\begin{equation}
V_\alpha = \phi S_\alpha,
\end{equation}
where the subscript, $\alpha$, denotes the phase, and $S_\alpha$ is the saturation of that phase such that,
\begin{equation}\label{e:total}
\sum_{\alpha=1}^{N_\mathrm{p}} S_\alpha = 1.
\end{equation}

\subsubsection{Darcy's Law}

Darcy's Law states that for a phase $\alpha$ in a porous medium \cite{bear_1972},
\begin{equation}\label{e:darcy}
\mathbf{q}_\alpha = -\frac{k_{\mathrm{r}\alpha}}{\mu_\alpha}\mathbf{K} \left( \nabla P_\alpha - \rho_\alpha \mathbf{g} \right),
\end{equation}
where $\mathbf{q}_\alpha$ is a volumetric flux rate, known as the Darcy velocity; $k_{\mathrm{r}\alpha}$ is the relative permeability of the phase and is a function of $S_\alpha$; $\mu_\alpha$ is the dynamic viscosity of the fluid phase; $\mathbf{K}$ is a 2nd rank tensor describing the permeability of the porous medium; $P_\alpha$ is the fluid pressure of phase $\alpha$; $\rho_\alpha$ is the mass density of phase $\alpha$; and, $\mathbf{g}$ is the gravitational acceleration vector.

The Darcy velocity can be rewritten in terms of the (interstitial or average) velocity of the fluid, $\mathbf{v}_\alpha$, as,
\begin{equation}
\mathbf{q}_\alpha = V_\alpha \mathbf{v}_\alpha = \phi S_\alpha \mathbf{v}_\alpha.
\end{equation}
Then, we can rewrite Eqn. \ref{e:darcy} as,
\begin{equation}\label{e:darcy2}
S_\alpha \mathbf{\Lambda}_\alpha \mathbf{v}_{\phi\alpha} = - \nabla P_\alpha + \rho_\alpha \mathbf{g},
\end{equation}
with,
\begin{eqnarray}
\mathbf{v}_{\phi\alpha} & = & \phi \mathbf{v}_\alpha,\\
\mathrm{and} \quad \mathbf{\Lambda}_\alpha & = & \frac{\mu_\alpha}{k_{\mathrm{r}\alpha}}\mathbf{K}^{-1}.\label{e:absorption}
\end{eqnarray}

\subsubsection{Mass conservation}

Conservation of mass for each fluid phase implies \cite{bear_1972},
\begin{equation}\label{e:mass}
\phi \frac{\partial}{\partial t}(\rho_\alpha S_\alpha) + \nabla\cdot(\rho_\alpha S_\alpha  \mathbf{v}_{\phi \alpha}) - Q_\alpha = 0,
\end{equation}
where $Q_\alpha$ is a mass flux rate describing sources ($Q_\alpha >0$) or sinks ($Q_\alpha <0$) of phase $\alpha$.

\subsubsection{Fick's Law}

The transport of a conservative substance (e.g.\ salt), with constant mass, in a partially saturated flow can be described by Fick's Law \cite{helmig_1997},
\begin{equation}\label{e:transport}
\phi \frac{\partial}{\partial t}(\rho_\alpha S_\alpha X_\alpha^\kappa) + \nabla \cdot \left( \rho_\alpha S_\alpha X_\alpha^\kappa \mathbf{v}_{\phi\alpha} - \rho_\alpha \mathbf{D}_\alpha^\kappa \nabla X_\alpha^\kappa \right) - R_\alpha^\kappa = 0
\end{equation}
where $R_\alpha^\kappa$ is a source rate for component $\kappa$ in phase $\alpha$; $\mathbf{D}_\alpha^\kappa$ is the 2nd rank hydrodynamic dispersion tensor for component $\kappa$ in phase $\alpha$ (see below); and, $X_\alpha^\kappa$ is the mass fraction of component $\kappa$ in phase $\alpha$ such that,
\begin{equation}
\sum_{\kappa = 1}^{N\mathrm{c\alpha}} X_\alpha^\kappa = 1 \quad \forall\, \alpha,
\end{equation}
and $N_\mathrm{c\alpha}$ is the number of components that phase $\alpha$ can partition into.

It is worth noting that the dispersion tensor, $\mathbf{D}_\alpha^{\kappa}$, may be rewritten in terms of an effective diffusive part and a purely dispersive part, e.g.\ \cite{scheidegger_1961},
\begin{equation}
\mathbf{D}_\alpha^\kappa = (\phi S_\alpha D^{\kappa}_{\mathrm{e} \alpha} + \delta^{\kappa}_{\mathrm{T} \alpha} q_\alpha ) \mathbf{I} + (\delta^{\kappa}_{\mathrm{L} \alpha} - \delta^{\kappa}_{\mathrm{T} \alpha}) \frac{\mathbf{q}_\alpha \mathbf{q}_\alpha}{q_\alpha},
\end{equation}
where $D^{\kappa}_{\mathrm{e} \alpha}$ is the effective molecular diffusion of component $\kappa$ in phase $\alpha$ such that $D^{\kappa}_{\mathrm{e} \alpha} = D^{\kappa}_{\mathrm{m} \alpha} / \tau$, where $D^{\kappa}_{\mathrm{m} \alpha}$ denotes the molecular diffusion coefficient of component $\kappa$ in phase $\alpha$, and $\tau$ is the tortuosity of the porous medium.  The parameters $\delta^{\kappa}_{\mathrm{L} \alpha}$ and $\delta^{\kappa}_{\mathrm{T} \alpha}$ represent the longitudinal and transverse dispersivities of component $\kappa$ in phase $\alpha$, respectively; $\mathbf{I}$ is the 2nd rank unit tensor; and, $q_\alpha = | \mathbf{q}_\alpha |$.

\subsubsection{Fourier's Law}

Assuming local thermal equilibrium, or equivalently rapid heat transfer between the phases, the temperature of all the phases, $T_\alpha$, and the temperature of the porous medium, $T_s$, will be the same i.e.\ $T_\alpha = T_{s} = T$ \cite{hassanizadeh_1993}.  Then, considering the thermal energy of all the fluid phases as well as the porous medium, the energy conservation equation of the system can be described by Fourier's Law as \cite{helmig_1997},
\begin{eqnarray}
& {} & N_\mathrm{p} (1-\phi) c_s \rho_s \frac{\partial T}{\partial t} + N_\mathrm{p} \lambda_s \nabla^2 T \nonumber \\
& {} & {} + \sum_{\alpha = 1}^{N_\mathrm{p}} \left\{ \phi c_\alpha \frac{\partial}{\partial t}(\rho_\alpha S_\alpha T) +  \nabla \cdot \left[ S_\alpha \mathbf{v}_{\phi \alpha} \left(c_\alpha \rho_\alpha T + P_\alpha \right) \right] - U_\alpha \right\} = 0.\label{e:energy}
\end{eqnarray}
Here, $\rho_s$, $c_s$ and $\lambda_s$ are the mass density, the average heat capacity and the heat conductivity, respectively, at constant pressure, of the partially saturated porous medium; $c_\alpha$ is the average heat capacity of phase $\alpha$; and, $U_\alpha$ represents heat flux rate sources or sinks of phase $\alpha$.

%%%
%%% SECTION: CONSTITUTIVE EQNS.
%%%
\subsection{Constitutive Equations}

\subsubsection{Equation of State}

We can express the equation of state as a linearized function of the state variables i.e.\ pressure, temperature and mass fraction of component $\kappa$ in phase $\alpha$, and density of phase $\alpha$,
\begin{equation}\label{e:eos}
\rho_\alpha = \tilde{\rho}_\alpha + \gamma_\alpha^P (P_\alpha - \tilde{P}_\alpha) - \gamma_\alpha^T (T-\tilde{T}_\alpha) + \gamma_\alpha^\kappa (X_\alpha^\kappa - \tilde{X}_\alpha^{\kappa}),
\end{equation}
where parameters with a tilde above them ($\tilde{\ \cdot\ }$) represent an approximation of that parameter in the state space; and,
\begin{eqnarray}
\gamma_\alpha^P & =\ \rho_\alpha \beta_\alpha^P\ = & \frac{\partial \rho_\alpha}{\partial P_\alpha}, \label{e:gammaP}\\
\gamma_\alpha^T & =\ \rho_\alpha \beta_\alpha^T\ = & - \frac{\partial \rho_\alpha}{\partial T}, \label{e:gammaT}\\
\mathrm{and} \quad \gamma_\alpha^\kappa & =\ \rho_\alpha \beta_\alpha^\kappa\ = & \frac{\partial \rho_\alpha}{\partial {X_\alpha^\kappa}}\label{e:gammaX},
\end{eqnarray}
with $\beta_\alpha^P$, $\beta_\alpha^T$ and $\beta_\alpha^\kappa$ representing the compressibility coefficient, thermal expansion coefficient and the coefficient of volume expansion due to component $\kappa$ in phase $\alpha$, respectively.

\subsubsection{Capillary Pressure and Relative Permeability}

The capillary pressure, $P_{\mathrm{c} \alpha \gamma}$, relates the interfacial tension between two phases, $\alpha$ and $\gamma$, in the porous material as,
\begin{equation}\label{e:capillary}
P_{\mathrm{c} \alpha \gamma} = P_\alpha - P_\gamma,
\end{equation}
where $P_\alpha$ is the pressure of the non-wetting phase and $P_\gamma$ is the pressure of the wetting phase. The capillary pressure is usually expressed as a monotonic function of the saturation of the wetting phase (i.e.\ $S_\gamma$), and may be obtained from empirical data, or by using an analytical model such as that of Brooks and Corey \cite{brooks_1964} or Van Genuchten \cite{vangenuchten_1980} in the case of two-phase flow.

Likewise, the relative permeability of a phase, $k_{\mathrm{r}\alpha}$, is dependent on the saturation of that phase, and possibly the saturation of other phases if $N_\mathrm{p} > 2$.  $k_{\mathrm{r}\alpha}$ indicates the perturbation of that phase due to the presence of the other phases and may also be obtained from empirical data or by using an analytical model.  In any case, for all $\alpha$,
\begin{equation}
0 \leq k_{\mathrm{r}\alpha} \leq 1.
\end{equation}

%%%
%%% SECTION: NUMERICAL MODEL FOR COMPRESSIBLE 2-PHASE FLOW
%%%
\subsection{Numerical Model for Compressible Two-Phase Flow}

We consider a system of just two compressible, immiscible fluids (i.e.\ $N_\mathrm{p} = 2$), a wetting phase (hereafter subscripted $w$) and a non-wetting phase (hereafter subscripted $n$).  We assume negligible solute concentration changes and neglible temperature changes, thus reducing  Eqn. \ref{e:eos} to,
\begin{equation}\label{e:eos2}
\rho_\alpha = \tilde{\rho}_\alpha + \gamma_\alpha^P (P_\alpha - \tilde{P}_\alpha).
\end{equation}

\subsubsection{Temporal discretization}\label{s:t_discretization}

We use a backward (implicit) Euler method to discretize the time derivatives in Eqn. \ref{e:mass},
\begin{equation}
\frac{\phi}{\Delta t} S^n_\alpha \left( \rho^{n+1}_\alpha-\rho^n_\alpha \right) + \frac{\phi}{\Delta t} \rho^n_\alpha \left( S^{n+1}_\alpha-S^n_\alpha \right) + \nabla \cdot \left( \tilde{\rho}^{n+1}_\alpha \tilde{S}^{n+1}_\alpha \mathbf{v}^{n+1}_{\phi \alpha} \right) - Q^{n+1}_\alpha = 0,
\end{equation}
where $\Delta t$ is a fixed time increment; variables with a tilde above them ($\tilde{\ \cdot\ }$) are calculated explicitly using a Picard (fixed point) iteration method (e.g.\ see Chapter 9 of Press \textit{et al.}, \cite{press_2008}); and, superscripts denote time level.

Dividing this equation by the mass density of the phase at the current time level, $\rho^n_\alpha$, summing over the phases, and making use of Eqn. \ref{e:total} we get,
\begin{equation}\label{e:t_discretization}
\sum_{\alpha = w,n} \frac{1}{\rho^n_\alpha} \left[ \frac{\phi}{\Delta t} \rho^{n+1}_\alpha S^n_\alpha + \nabla \cdot \left( \tilde{\rho}^{n+1}_\alpha \tilde{S}^{n+1}_\alpha \mathbf{v}^{n+1}_{\phi \alpha} \right) - Q^{n+1}_\alpha \right] - \frac{\phi}{\Delta t} = 0.
\end{equation}

Finally, substituting Eqn. \ref{e:eos2} into Eqn. \ref{e:t_discretization} to eliminate $\rho^{n+1}_\alpha$ we get,
\begin{equation}\label{e:cty}
\sum_{\alpha = w,n} \frac{1}{\rho^n_\alpha} \left\{ \frac{\phi}{\Delta t} S^n_\alpha \left[ \tilde{\rho}^{n+1}_\alpha + \gamma_\alpha^P \left( P^{n+1}_\alpha - \tilde{P}^{n+1}_\alpha \right) \right] + \nabla \cdot \left( \tilde{\rho}^{n+1}_\alpha \tilde{S}^{n+1}_\alpha \mathbf{v}^{n+1}_{\phi \alpha} \right) - Q^{n+1}_\alpha \right\} - \frac{\phi}{\Delta t} = 0.
\end{equation}

This equation can be rewritten in terms of the explicit variables, $P^{n+1}_\alpha$ and $\mathbf{v}^{n+1}_{\phi \alpha}$, as,
\begin{eqnarray}
\frac{\phi}{\Delta t} \sum_{\alpha = w,n} \frac{1}{\rho^n_\alpha} \gamma^P_\alpha S^n_\alpha P^{n+1}_\alpha + \sum_{\alpha = w,n} \frac{1}{\rho^n_\alpha} \nabla \cdot \left( \tilde{\rho}^{n+1}_\alpha \tilde{S}^{n+1}_\alpha \mathbf{v}_{\phi \alpha}^{n+1} \right) {} & = & \nonumber \\
\frac{\phi}{\Delta t} - \sum_{\alpha = w,n} \frac{1}{\rho^n_\alpha} \left[ \frac{\phi}{\Delta t} S^n_\alpha \left( \tilde{\rho}^{n+1}_\alpha - \gamma^P_\alpha \tilde{P}^{n+1}_\alpha \right) - Q^{n+1}_\alpha \right] & {} & \label{e:cty_t}
\end{eqnarray}

Likewise, the temporal discretization of Eqn. \ref{e:darcy2} at time level $(n+1)$ may be written as,
\begin{equation}\label{e:darcy_t}
\tilde{S}^{n+1}_\alpha \tilde{\mathbf{\Lambda}}^{n+1}_\alpha \mathbf{v}^{n+1}_{\phi\alpha} +\left( \nabla  - \gamma_\alpha^P \mathbf{g} \right) P^{n+1}_\alpha = (\tilde{\rho}^{n+1}_\alpha - \gamma_\alpha^P \tilde{P}^{n+1}_\alpha) \mathbf{g}.
\end{equation}

\subsubsection{Spatial discretization}\label{s:x_discretization}

To discretize Eqns. \ref{e:cty_t} and \ref{e:darcy_t} we assume a finite-element mesh such that the velocity field is discretized with $\mathcal{N}$ discontinuous piecewise-linear (P1$_\mathrm{DG}$) degrees-of-freedom and the pressure field is discretised with $\mathcal{M}$ continuous quadratic (P2) degrees-of-freedom (see Figure \ref{f:discretization}a) as introduced by Cotter \textit{et al.} \cite{cotter_2007}, i.e.
\begin{equation}
\mathbf{v}^n_{\phi \alpha} = \sum_{j=1}^\mathcal{N} \hat{\mathbf{v}}^n_{\phi \alpha,j} N_j \quad \mathrm{and} \quad P^n_\alpha = \sum_{j=1}^\mathcal{M} \hat{P}^n_{\alpha,j} M_j.
\end{equation}

\begin{figure}[h]
\vbox{
\hbox{\hspace{1cm}
  \includegraphics[width=15.0cm,height=19.cm]{./doc_figures/discretization}}
\vspace{-14cm}}
%    \epsfig{file=figures/discretization.eps}
    \caption[]{(a) Example of discretization scheme used in formulation involving P1$_\mathrm{DG}$-P2 elements \cite{cotter_2007}.  Shaded nodes represent degrees-of-freedom for the scalar field (i.e.\ $P_\alpha$) whilst white nodes represent degrees-of-freedom for the vector field (i.e.\ $\mathbf{v}_{\phi \alpha}$).  $\Omega$ is the volume of the domain and $\Gamma$ is its bounding surface.  (b) Control volumes of the same elements, outlined by dashed lines.  $\Omega_\mathrm{CV}$ is the volume of the control volume and $\Gamma_\mathrm{CV}$ is its bounding surface.\label{f:discretization}}
\end{figure}

Then, multiplying Eqn. \ref{e:darcy_t} for each phase by the basis function $N_i$ and integrating over the entire volume of the system, $\Omega$, we get the following matrix equation:
\begin{equation}\label{e:darcy_matrix}
\tilde{\mathbf{A}}^{n+1} \mathbf{v}^{n+1} + \mathbf{B} \mathbf{p}^{n+1} = \tilde{\mathbf{h}}^{n+1},
\end{equation}
where,
\begin{eqnarray}
\mathbf{v}^{n+1} & = & \left[ \hat{\mathbf{v}}^{n+1}_{\phi w} \quad \hat{\mathbf{v}}^{n+1}_{\phi n} \right]^T,\\
\mathbf{p}^{n+1} & = & \left[ \hat{P}^{n+1}_w \quad \hat{P}^{n+1}_n \right]^T,\\
\tilde{\mathrm{A}}^{n+1}_{i,j} & = & \int_\Omega N_i \left[ \begin{array}{c c}
\tilde{S}^{n+1}_w \tilde{\mathbf{\Lambda}}^{n+1}_w & 0 \vspace*{1mm}\\
0 & \tilde{S}^{n+1}_n \tilde{\mathbf{\Lambda}}^{n+1}_n
\end{array} \right] N_j\: d\Omega,\\
\mathrm{B}_{i,j} & = & \int_\Omega N_i \left[ \begin{array}{c c}
\nabla - \gamma^P_w \mathbf{g} & 0 \vspace*{1mm}\\
0 & \nabla - \gamma^P_n \mathbf{g}
\end{array} \right] M_j\: d\Omega,\\
\mathrm{and} \quad \tilde{\mathrm{h}}^{n+1}_{i} & = & \int_\Omega N_i \left[ \begin{array}{c}
(\tilde{\rho}^{n+1}_w - \gamma_w^P \tilde{P}^{n+1}_w) \mathbf{g} \vspace*{2mm}\\
(\tilde{\rho}^{n+1}_n - \gamma_n^P \tilde{P}^{n+1}_n) \mathbf{g}
\end{array} \right] d\Omega.
\end{eqnarray}

Now we consider control volumes, $\Omega_\mathrm{CV}$, with bounding surfaces $\Gamma_\mathrm{CV}$, around each node (see Figure \ref{f:discretization}b), such that,
\begin{equation}
\Omega = \sum_i \Omega_{\mathrm{CV}_i}\quad \mathrm{and} \quad P^n_\alpha = \sum_{j=1}^\mathcal{X} \hat{P}^n_{\alpha,j} \chi_j
\end{equation}
where $\chi_j$ is a basis function that is unity on the control volume and zero elsewhere.  We also enforce $\sum_\alpha S_\alpha = 1$ in each control volume as per Eqn. \ref{e:total}.  Then, multiplying Eqn. \ref{e:cty_t} by the basis function $\chi_i$ and integrating over the control volumes we get the following matrix equation:
\begin{equation}\label{e:cty_matrix}
(\mathbf{M}^n)^T \mathbf{p}^{n+1} + (\tilde{\mathbf{C}}^{n+1})^T \mathbf{v}^{n+1} = \phi - (\tilde{\mathbf{r}}^{n+1})^T \mathbf{1}
\end{equation}
where,
\begin{eqnarray}
\mathrm{M}^n_{i,j} & = & \int_{\Omega_\mathrm{CV}} \chi_i \left[ \begin{array}{c}
\phi \gamma_w^P S^n_w / \rho^n_w \vspace*{2mm}\\
\phi \gamma_n^P S^n_n / \rho^n_n
\end{array} \right] \chi_j\ d\Omega_\mathrm{CV},\\
\tilde{\mathrm{C}}^{n+1}_{i,j} & = & \int_{\Gamma_\mathrm{CV}} \chi_i \left[ \begin{array}{c}
\Delta t\, \tilde{\rho}_w^{n+1} \tilde{S}_w^{n+1} \mathbf{n} / \rho^n_w \vspace*{2mm}\\
\Delta t\, \tilde{\rho}_n^{n+1} \tilde{S}_n^{n+1} \mathbf{n} / \rho^n_n
\end{array} \right] N_j\ d\Gamma_\mathrm{CV},\\
\tilde{\mathrm{r}}^{n+1}_i & = & \int_{\Omega_\mathrm{CV}} \chi_i \left[ \begin{array}{c}
\left\{ \phi S^n_w \left( \tilde{\rho}^{n+1}_w - \gamma^P_w \tilde{P}^{n+1}_w \right) - \Delta t\, Q^{n+1}_w \right\} / \rho^n_w \vspace*{2mm}\\
\left\{ \phi S^n_n \left( \tilde{\rho}^{n+1}_n - \gamma^P_n \tilde{P}^{n+1}_n \right) - \Delta t\, Q^{n+1}_n \right\} / \rho^n_n
\end{array} \right] d\Omega_\mathrm{CV},\\
\mathrm{and} \quad \mathbf{1} & = & \left[ 1\quad 1 \right]^T.
\end{eqnarray}

\subsubsection{Numerical model}

Combining Eqns. \ref{e:darcy_matrix} and \ref{e:cty_matrix} we get,
\begin{equation}
\left[ \begin{array}{c c}
\tilde{\mathbf{A}}^{n+1} & \mathbf{B}\\
(\tilde{\mathbf{C}}^{n+1})^T & (\mathbf{M}^n)^T
\end{array} \right]
\left[ \begin{array}{c}
\mathbf{v}^{n+1}\\
\mathbf{p}^{n+1}
\end{array} \right] =
\left[ \begin{array}{c}
\tilde{\mathbf{h}}\\
\phi - (\tilde{\mathbf{r}}^{n+1})^T \mathbf{1}
\end{array} \right].
\end{equation}
This equation together with Eqns. \ref{e:total} and \ref{e:eos2} (for each of the phases), and appropriate means of calculating $k_{\mathrm{r}w}(S^n_w)$ and $k_{\mathrm{r}n}(S^n_n)$ in Eqn. \ref{e:absorption}, constitutes our numerical model for compressible two-phase fluid flow in a porous medium.

%%%
%%% SECTI0ON: TEST CASES
\subsection{Test cases}

\subsubsection{Buckley-Leverett problem}

\begin{itemize}
\item Example of isothermal multiphase flow.
\item Displacement of oil by water in 1D / 2D.
\item No gravity.
\item No capillary pressure.
\item No dispersion.
\item Comparison with analytical solution.
\end{itemize}

\subsubsection{McWhorter problem}

\begin{itemize}
\item Example of isothermal multiphase flow.
\item Displacement of oil by water in 1D / 2D.
\item No gravity.
\item Inclusion of capillary pressure.
\item Comparison with quasi-analytical solution.
\end{itemize}

\subsubsection{Five-spot waterflood problem}

\begin{itemize}
\item Example of isothermal multiphase flow.
\item Displacement of oil by water in 2D.
\item One injector, one producer; or, Two injectors, two producers.
\item No gravity.
\item Water front shape and diffusivity allows comparison of different numerical techniques.
\end{itemize}

\subsubsection{Heat pipe simulation}

\begin{itemize}
\item Example of non-isothermal multiphase/multicomponent flow.
\item Influence of heat flux on water-steam system.
\item Inclusion of advection, conduction diffusion and capillary effects.
\item Comparison with semi-analytical solution.
\end{itemize}