\section{Appendix}

\subsection{Exercises}

\subsubsection{Exercise A.1}
We can choose $n_3 = max(n_1, n_2)$ such that $f_1(n) + f_2(n) \leq (C_1 + C_2)g$ whenever
$n > n_3$.

\subsubsection{Exercise A.2}
Similar to the first exercise, but now we have $C_1 C_2 h$ instead.

\subsubsection{Exercise A.3}
Logarithms of different bases differ by a constant.

\subsubsection{Exercise A.4}
The argument treats $k$ as a constant, when in reality $k = O(n)$. The answer should be
$O(n^3)$, which can be checked by looking at the closed form of the sum.

\subsubsection{Exercise A.5}
$2^{O(n)}$ and $O(2^{n})$ are not the same, since $\limsup_{n \to  \infty} \frac{2^{C_1n}}{C_{2}2^n}$
only converges to a nonzero constant when $C_1 = 1$.

\subsubsection{Exercise A.6}
$n^{k} \neq \Theta(2^n)$, $e^{-n} \neq \Theta(n^{-c})$, and $n! \neq \Theta(n^n)$, as all limits go to 0.

\subsubsection{Exercise A.7}
Take $f = n$ and $g = 2n$.

\subsubsection{Exercise A.8}
1. We can pull out the exponents as constants, so $f = \Theta(g)$.

2. $3 < 2^2$ so $f = o(g)$.

3. $n = \omega(\log^2 n)$ so $f = \omega(g)$.

4. $2^{\log n} \to \infty$ so $f = \omega(g)$.

\subsubsection{Exercise A.9}
One example is $n^{\log n}$.


\documentclass[]{BasiliskReportMemo}
\usepackage{AVS}
\usepackage{algorithmic}
\usepackage[boxed]{algorithm}

\newcommand{\submiterInstitute}{Autonomous Vehicle Simulation (AVS) Laboratory}

\newcommand{\ModuleName}{ThrusterForces}
\newcommand{\subject}{Algorithms to Map Desired Torque Vector onto a set of Thrusters }
\newcommand{\status}{Ready}
\newcommand{\preparer}{H. Schaub}
\newcommand{\summary}{Include a short summary of what this system engineering report is about.  Should be 300 words or less.     }

\begin{document}

\makeCover

%
%	enter the revision documentation here
%	to add more lines, copy the table entry and the \hline, and paste after the current entry.
%
\pagestyle{empty}
{\renewcommand{\arraystretch}{1.1}
\noindent
\begin{longtable}{|p{0.5in}|p{4.5in}|p{1.14in}|}
\hline
{\bfseries Rev}: & {\bfseries Change Description} & {\bfseries By} \\
\hline
v0.1 & Updated the thruster force evaluation to account for center of mass offsets & H. Schaub \\
v0.2 & Updated the figure and the $[C]$ matrix notation & H. Schaub \\
v0.3 & The thruster mapping logic has changed, and this documentation now reflects what the new algorithm does. & H. Schaub \\
\hline

\end{longtable}
}

\newpage
\setcounter{page}{1}
\pagestyle{fancy}

\tableofcontents
~\\ \hrule ~\\

\begin{figure}[htb]
	\centerline{
	\includegraphics[]{Figures/thrusterNotation}
	}
	\caption{Illustration of the Spacecraft Thruster Notation}
	\label{fig:thruster}
\end{figure}

\section{Introduction}
\subsection{Torque Control Axes}
This technical note describes a general algorithm that maps a desired ADCS external control torque $\bm L_{r}$ onto force commands for a cluster of thrusters.  Let $\hat{\bm c}_{j}$ be the axis about which the thrusters are to produce the desired torque.  The matrix of $N_{c}$ thruster axes rows is then given by
\begin{equation}
	[C]  = \begin{bmatrix}
		\hat{\bm c}_{1} \\ \vdots \\ \hat{\bm c}_{N_{c}}
	\end{bmatrix}
\end{equation}
The module can accept up to 3 orthogonal control axis $\hat{\bm c}_{j}$.  Let $\bar{\bm L}_{r}$ be the three-dimensional reduced set of $\bm L_{r}$ onto the set of control axes, given by:
\begin{equation}
	\bar{\bm L}_{r} = [C]^{T} [C] \bm L_{r}
\end{equation}
The goal of the thruster mapping strategy is to find a set of $\bm F$ thruster forces that yield $\bar{\bm L}_{r}$.

\subsection{Thruster to Torque Mapping Matrix}
The $i^{\text{th}}$ thruster location relative to the spacecraft point $B$ is given by $\bm r_{i}$ as illustrated in Figure~\ref{fig:thruster}.  The unit direction vector of the thruster force is $\hat{\bm g}_{t_{i}}$, while the thruster force is given by
\begin{equation}
	\label{eq:th:1}
	\bm F_{i} = F_{i} \hat{\bm g}_{t_{i}}
\end{equation}
The toque vector produced by each thruster about the body fixed point $C$ is thus
\begin{equation}
	\bm \tau_{i} = (\bm r_{i} - \bm r_{\text{COM}}) \times F_{i}  \hat{\bm g}_{t_{i}}
\end{equation}
The total torque onto the spacecraft, due to a cluster of $N$ thrusters, is
\begin{equation}
	\tau_{j} = \sum_{i=1}^{N} \bm \tau_{i}
	= \sum_{i=1}^{N}  ((\bm r_{i} - \bm r_{\text{COM}}) \times \hat{\bm g}_{t_{i}}) F_{i} = \sum_{i=1}^{N}  \bm d_{i} F_{i}
\end{equation}
where
\begin{equation}
	\label{eq:th1:1}
	\bm d_{i} =    ( \bm r_{i} - \bm r_{\text{COM}})  \times \hat{\bm g}_{t_{i}}
\end{equation}
In matrix form, the net spacecraft torque is written compactly as
\begin{equation}
	\label{eq:DF}
	 \bm\tau = \begin{bmatrix}
		 \bm d_{1} \cdots  \bm d_{N}
	\end{bmatrix} \begin{bmatrix}
		F_{1} \\
		\vdots \\
		F_{N}
	\end{bmatrix} = [D] \bm F
\end{equation}
where $[D]$ is a $3\times N$ matrix that maps the thruster forces $F_{i}$ to the spacecraft torque $\bm \tau$.

\section{ACS Thruster Force Algorithm for a Thruster Configuration with Full Torque Controllability}
Here a thruster configuration is assumed that can produce pure torque-couples without exerting a net torque onto the spacecraft.  The thrusters force values $F_{i}$ must be strictly non-negative (i.e. either 0 or positive).   Note that in this configuration having all thrusters on will produce zero net force and torque onto the spacecraft.  Thus the $F_{i} = F_{j}$ solution is in the nullspace of the mapping in Eq.~\eqref{eq:DF}.

The goal of the thruster force algorithm is to determine a set of thruster forces $\bm F$ such that the net force onto the spacecraft is
\begin{equation}
	\label{eq:th:2}
	\bm\tau = \bar{\bm L}_{r}  = [D]\bm F
\end{equation}
without bleeding torque onto the un-controlled axes.  The first step is to perform a standard minimum norm inverse solution using
\begin{equation}
	\label{eq:th:min}
	\bm F = [D]^{T}([D][D]^{T})^{-1} \bar{\bm L}_{r}
\end{equation}
The $3\times 3$ matrix $[D][D]^{T}$ is full rank and thus invertible with the assumption that this RCS configuration has a full 3D torque controllability.  This set of of thruster forces will contain $F_{i}$ values that are both positive and negative.  Next, to achieve strictly non-negative values, the minimum $F_{i}$ value is determined and subtracted from all $N$ force values.
\begin{equation}
	\bm F \leftarrow \bm F -  \text{min}(\bm F)
\end{equation}
The resulting set of $F_{i}$ forces will produce the desired control torque $\bar{\bm L}_{r}$ and achieve a net zero force onto the spacecraft.  The latter results is due to the assumption off an ACS thruster configuration that can produce pure moment couples.

\section{2-Stage Minimum Norm ACS Thruster Mapping Algorithm}
To increase the robustness of the sign-constrained minimum norm thruster force solution, as 2nd stage is included if the number of available ACS thrusters is not equal to the number of installed thrusters.  This simulates scenarios where some thrusters are now offline.    The minimum norm solution from the earlier solution is first evaluated, and then shifted by subtracting the minimum $F_{i}$ value.

Each thruster can only produce a positive force.  With off-pulsing, the nominal thrust force plus the negative correction must still yield a non-negative thrust force.  The module parameter {\tt thrForceSign} is either +1 or -1 to account for the desired force sign.  The value of this parameter is represented through $s_{F}$.  With the ACS thruster configuration this value would always be +1.

We assume that $\bm F$ elements only contain forces that are either zero or values with the desired sign.   Assume there are $M$  force values in $\bm F$ with a sign that matches $s_{F}$.  The locations of these values is provided in the $N$-dimensional array $\bm t_{\text{used}}$ which contains either 0 or 1 values.  For example, consider $N=8$ and only thrusters 2 and 6 produce  zero forces. In this case we find
\begin{equation}
	\bm t_{\text{used}} = \begin{bmatrix}
		1 & 0 & 1 & 1 & 1 & 0 & 1 & 1
	\end{bmatrix}
\end{equation}
This reduces the thruster force search to a subset of $M$ thrusters.  Let $\bar{\bm F}_{j}$ be a $M\times 1$ matrix of to be determined thruster forces.  The corresponding $3\times M$ mapping matrix $[\bar D]$ that projects $\bar{\bm F}$ onto a net body torque about point $B$ is defined as:
\begin{equation}
	[\bar D] = \begin{bmatrix} \bar{\bm d}_{1} & \cdots & \bar{\bm d}_{M} \end{bmatrix}
\end{equation}
with
\begin{equation}
	\bar{\bm d}_{i} = (\bm r_{i} - \bm r_{\text{COM}}) \times \hat{\bm g}_{i}
\end{equation}
The net torque due to $\bar{\bm F}$ is
\begin{equation}
	\bar{\bm \tau} = [\bar D] \bar{\bm F}
\end{equation}

A modified set of thruster force solutions $\bar{\bm F}$ to generate the desired torque $\bar{\bm L}_{r}$ is found through a second minimum norm operation:
\begin{equation}
	\label{eq:th:min2}
	\bar{\bm F} = [\bar D]^{T}([\bar D][\bar D]^{T})^{-1} \bar{\bm L}_{r}
\end{equation}

The next step is to sum the individual $\bar{\bm F}$ thruster solutions to the yield the net set of thruster forces required to produce $\bar{\bm L}_{r}$.  This is done using the  $\bm t_{\text{used}}$ matrix to determine which thrusters have non-zero contributions.   The final step is to evaluate the minimum $F_{i}$ force again and subtract this from all thruster force values.

\section{DV Thruster Firing Strategy}
With a DV thruster configuration the thruster force axes are parallel.  As such, this configuration cannot produce a torque along the DV thrust axis.  A slightly modified version of the above algorithm is used in this case.  With the DV configuration the attitude along the axes orthogonal to the thrust vector are controlled via off-pulsing.  As such, the thruster firing mapping must produce negative $F_{i}$ values and the {\tt thrForceSign} sign must be set to -1.

The modified algorithm still evaluates the first minimum norm inverse, but does not subtract out the $\text{min}(\bm F)$ value.  Rather, the 2nd stage is used to determine which DV thrusters produce the torque with a negative torque value to generate the corresponding $[\bar D]$ matrix.  After performing the 2nd minimum norm inverse with $[\bar D]$ the subtraction of  $\text{min}(\bm F)$ is not performed.

\section{Performance Illustration}
\subsection{ACS Thruster Configuration}
To illustrate the performance of this algorithm, the following simulation setup is used.  Let the ACS system have a total of $N = 8$ thrusters with the following body-fixed locations:
\begin{gather*}
	\label{eq:th:loc}
	\bm r_{1} = \begin{bmatrix} +1.125, 0.0, +0.75  \end{bmatrix}^{T} \text{ m}
	\quad\quad
	\bm r_{2} = \begin{bmatrix} -1.125, 0.0, +0.75  \end{bmatrix}^{T} \text{ m}
	\\
	\bm r_{3} = \begin{bmatrix} -1.125, 0.0, +0.75  \end{bmatrix}^{T}	 \text{ m}
	\quad\quad
	\bm r_{4} = \begin{bmatrix} +1.125, 0.0, +0.75  \end{bmatrix}^{T} \text{ m}
	\\
	\bm r_{5} = \begin{bmatrix} +1.125, 0.0, -0.75  \end{bmatrix}^{T}	 \text{ m}
	\quad\quad
	\bm r_{6} = \begin{bmatrix} -1.125, 0.0, -0.75  \end{bmatrix}^{T} \text{ m}
	\\
	\bm r_{7} = \begin{bmatrix} -1.125, 0.0, -0.75  \end{bmatrix}^{T}	 \text{ m}
	\quad\quad
	\bm r_{8} = \begin{bmatrix} +1.125, 0.0, -0.75  \end{bmatrix}^{T} \text{ m}
\end{gather*}
with the force unit direction vectors:
\begin{gather*}
	\label{eq:th:gt}
	\bm g_{t_{1}} = \begin{bmatrix} +0.707107, +0.707107, 0  \end{bmatrix}^{T}
	\quad\quad
	\bm g_{t_{2}} = \begin{bmatrix} -0.707107, +0.707107, 0  \end{bmatrix}^{T}
	\\
	\bm g_{t_{3}} = \begin{bmatrix} -0.707107, -0.707107, 0  \end{bmatrix}^{T}
	\quad\quad
	\bm g_{t_{4}} = \begin{bmatrix} +0.707107, -0.707107, 0  \end{bmatrix}^{T}
	\\
	\bm g_{t_{5}} = \begin{bmatrix} +0.707107, +0.707107, 0 \end{bmatrix}^{T}
	\quad\quad
	\bm g_{t_{6}} = \begin{bmatrix} -0.707107, +0.707107, 0  \end{bmatrix}^{T}
	\\
	\bm g_{t_{7}} = \begin{bmatrix} -0.707107, -0.707107, 0  \end{bmatrix}^{T}
	\quad\quad
	\bm g_{t_{8}} = \begin{bmatrix} +0.707107, -0.707107, 0  \end{bmatrix}^{T}
\end{gather*}
\begin{figure}[htb]
	\centerline{
	\includegraphics[]{Figures/8ThrConfig}
	}
	\caption{Illustration of an 8-thruster ACS configuration}
	\label{fig:8ThrConfig}
\end{figure}
\begin{figure}[p]
	\centering
	\subfigure[Percent Torque Error]
	{\label{fig:minTorquePer}
	\includegraphics[width=0.45\textwidth]{Figures/minTorquePer}}
	\\
	\subfigure[Thruster Control Implementation Effort]
	{\label{fig:minTorqueSumF}
	\includegraphics[width=0.45\textwidth]{Figures/minTorqueSumF}}
	\subfigure[Net Thruster Disturbance Force]
	{\label{fig:minTorqueNetF}
	\includegraphics[width=0.45\textwidth]{Figures/minTorqueNetF}}
	\caption{ACS Thruster Mapping Performance Mapping Illustration Comparing the 1-stage and 2-stage minimum norm solution to the thruster mapping of a nonlinear optimization solution.}
	\label{fig:minTorque}
\end{figure}

The resulting configuration is illustrated in Figure~\ref{fig:8ThrConfig}.  In this setup the center of mass position vector is set to $\bm r_{\text{COM}} = (0,0,0)^{T} \text{ m}$.  The following plots show the thruster firing performance by considering a rang of scenarios.  The first case assumes all thrusters are available, and the $\bm r_{\text{COM}}$ vector is known perfectly.  The second and third case also have all thrusters available, but the $\bm r_{\text{COM}}$ vector knowledge is off by 10cm or 5cm in the $z$ direction.  The 4th case has the perfect $\bm r_{\text{COM}}$ vector, but the first thruster location is off by 1cm in the $y$ direction.  The 5th case again assumes a 10cm COM offset, but also that only 4/8 thrusters are available.  In essence, all the lower or upper thruster have become un-available.  The 6th and 7th case assumes perfect COM knowledge, but either the last one or last two thrusters are un-available.

The resulting performance is illustrated in Figure~\ref{fig:minTorque}.  Here 20 random $\bm L_{r}$ torques are generated, and the mean results are shown.  The $[C]$ matrix is set to the identity matrix to control all three axes.   The 1-stage minimum norm algorithm is compared to an optimal thruster firing solution which minimizes the net thruster forces used, the net disturbance torque onto the craft, all subject to producing the desired control torque.    Regarding generating the desired control torque, only when 1 or 2 thrusters were lost did the algorithm have issues generating the required torque.  In all other cases the desired torque was always produced as shown in Figure~\ref{fig:minTorquePer}.  In comparison, the 2-stage minimum norm algorithm performs very well in these latter cases where 1-2 thrusters are lost, yielding only very small torque errors on average.

The control effort required to achieve this torque is shown in Figure~\ref{fig:minTorqueSumF}.  Here the $F_{i}$ thruster force values are simply summed to have a sense of how much on-time or fuel is required for a given scenario.  If all ACS thrusters are operating and the COM is perfectly modeled is the control effort equivalent to the optimal solution.  In all other case the effort is about 10-20\% larger.  in contrast, the 2-stage minimum norm algorithm control efforts in the cases with lost thrusters is very similar to those of the optimal answers.  This illustrates the robustness achieved by adding this 2nd stage if some thrusters are lost.

Finally, to see how well this algorithm is able to avoid net disturbance forces onto the spacecraft, the results in Figure~\ref{fig:minTorqueNetF} are shown.  Overall the 1-stage algorithm did well, producing 0 net force in the ideal case and the case where the 1st thruster location is different, and matches the optimal answer for the lost thruster deck and lost single thruster case.  In the other cases there is some net disturbance force.  The 2-stage algorithm only differs here when thrusters are lost.  Here the net disturbance torque is higher than the 1-stage solution.  However, this is an expected result as the 1-stage solution produces huge torque errors, while the 2-stage solution produces a very different thruster solution which yields very small torque errors.

Overall the 2-stage thruster firing performs very well in comparison to the the optimal thruster firing solutions.  The optimal solutions are computationally very expensive and not suitable to realtime flight-software implementations.

\subsection{DV Thruster Configuration}
Next consider a DV thruster configuration where the off-thruster-axis control torques are produces through off-pulsing.  Let the DV system have a total of $N = 6$ thrusters with the following body-fixed locations:
\begin{align*}
	\label{eq:th:loc}
	\bm r_{1} &= \begin{bmatrix} 0, 0.413, -0.1671  \end{bmatrix}^{T} \text{ m}
	&
	\bm r_{2} &= \begin{bmatrix} 0.357668, 0.2065, -0.1671  \end{bmatrix}^{T} \text{ m}
	\\
	\bm r_{3} &= \begin{bmatrix} 0.357668, -0.2065, -0.1671 \end{bmatrix}^{T}	 \text{ m}
	&
	\bm r_{4} &= \begin{bmatrix} 0, -0.413, -0.1671  \end{bmatrix}^{T} \text{ m}
	\\
	\bm r_{5} &= \begin{bmatrix} -0.357668, -0.2065, -0.1671  \end{bmatrix}^{T}	 \text{ m}
	&
	\bm r_{6} &= \begin{bmatrix} -0.357668, 0.2065, -0.1671 \end{bmatrix}^{T} \text{ m}
\end{align*}
with the force unit direction vectors given by $\hat{\bm g}_{t_{i}} = (0,0,1)^{T}$ as illustrated in Figure~\ref{fig:6ThrConfig}.
\begin{figure}[t]
	\centerline{
	\includegraphics[width=0.4\textwidth]{Figures/dvThrConfig}
	}
	\caption{Illustration of an 6-thruster DV configuration}
	\label{fig:6ThrConfig}
\end{figure}

\begin{figure}[t]
	\centering
	\subfigure[Percent Torque Error]
	{\label{fig:minTorquePerDV}
	\includegraphics[width=0.4\textwidth]{Figures/dvTorquePer}}
	\subfigure[Thruster Control Implementation Effort]
	{\label{fig:minTorqueSumFDV}
	\includegraphics[width=0.45\textwidth]{Figures/dvSumF}}
	\caption{DV Thruster Mapping Performance Mapping Illustration Comparing the 1-stage and 2-stage minimum norm solution to the thruster mapping of a nonlinear optimization solution.}
	\label{fig:minTorqueDV}
\end{figure}

Figure~\ref{fig:minTorqueDV} illustrates the DV off-pulsing performance for 3 scenarios.  The 1st one has all thrusters available and no COM error.  The 2nd case adds 2cm COM offsets to the $x$ and $y$ axes, while the 3rd case has no COM error but lost an opposing set of thrusters.  Again 20 random $\bm L_{r}$ vectors are generated and the mean performance evaluated.  As only torques about the $x$ and $y$ axis can be controlled with this DV thruster configuration, the control axis matrix is set to
$$
	[C] = \begin{bmatrix}
		1 & 0 & 0 \\
		0 & 1 & 0
	\end{bmatrix}
$$

The torque implementation errors are compared in Figure~\ref{fig:minTorquePerDV}.  The 2-stage process outlined above is able to produce the required torques in all cases, illustrating good robustness to COM offsets and loosing 2/6 thrusters.  Figure~\ref{fig:minTorqueSumFDV} illustrates the net off-pulsing effort required to achieve these random control torque vectors.  The 2-stage algorithms requires slightly more off-pulsing than the optimal solution.  However, the difference isn't very large, especially in comparison to the drastically faster computational evaluation time.

\section{Module Parameters}
\subsection{$\epsilon$ Parameter}
The minimum norm inverse requires a non-zero determinant value of $[D][D]^{T}$.  For this setup, this matrix is a scalar value
\begin{equation}
	D_{2} = \text{det}([D][D]^{T})
\end{equation}
If this $D_{2}$ value is near zero, then the full 3D $\bar{\bm L}_{r}$ vector cannot be achieved.  A common example of such a scenario is with the DV thruster configuration where all $\hat{\bm g}_{t_{i}}$ axes are collinear.  Torques about these thrust axes cannot be produced.  In this case, the minimum norm solution is adjusted to only match the torques along the control matrix $[C]$ sub-space.  Torques being applied outside of $\hat{\bm c}_{j}$ is not possible as $D_{2}$ is essentially zero, indicating the other control axis cannot be controlled with this thruster configuration.

The minimum norm torque solution is now modified to use
\begin{equation}
	\bar{\bm F} = ([C][\bar D])^{T}( [C][\bar D][\bar D]^{T}[C]^{T})^{-1} [C] {\bm L}_{r}
\end{equation}
As the thruster configuration cannot produce a general 3D torque, here the $[C]$ matrix must have either 1 or 2 control axes that are achievable with the given thruster configuration.

To set this epsilon parameter, not the definition of the $[D]$ matrix components $\bm d_{i} = (\bm r_{i} \times \hat{\bm g}_{t_{i}})$. Note that $\bm r_{i} \times \hat{\bm g}_{t_{i}}$ is a scaled axis along which the $i^{\text{th}}$ thruster can produce a torque.  The value $\bm d_{i}$ will be near zero if the dot product of this axis with the current control axis $\hat{\bm c}_{j}$ is small.

To determine an appropriate $\epsilon$ value, let $\alpha$ be the minimum desired angle to avoid the control axis $\hat{\bm c}_{j}$ and the scaled thruster torque axis $\bm r_{i} \times \hat{\bm g}_{t_{i}}$ being orthogonal.  If $\bar r$ is a mean distance of the thrusters to the spacecraft center of mass, then the $d_{i}$ values must satisfy
\begin{equation}
	\frac{d_{i}}{\bar r} > \cos(90\dg - \alpha) = \sin\alpha
\end{equation}
Thus, to estimate a good value of $\epsilon$, the following formula can be used
\begin{equation}
	\epsilon \approx d_{i}^{2} = \sin^{2}\!\alpha \ \bar{r}^{2}
\end{equation}
For example, if $\bar{r} = 1.3$ meters, and we want $\alpha$ to be at least 1$\dg$, then we would set $\epsilon = 0.000515$.

\subsection{$[C]$ matrix}
The module requires control control axis matrix $[C]$ to be defined.  Up to 3 orthogonal control axes can be selected.  Let $N_{c}$ be the number of control axes.  The $N_{c}\times 3$ $[C]$ matrix is then defined as
\begin{equation}
	[C] = \begin{bmatrix}
		\hat{\bm c}_{1}
		\\
		\vdots
	\end{bmatrix}
\end{equation}

Not that in python the matrix is given in a 1D form by defining {\tt controlAxes\_B}.  Thus, the $\hat{\bm c}_{j}$ axes are concatenated to produce the input matrix $[C]$.

\subsection{{\tt thrForceSign} Parameter}
Before this module can be run, the parameter {\tt thrForceSign} must be set to either +1 (on-pulsing with the ACS configuration) or -1 (off-pulsing with the DV configuration).

\bibliographystyle{unsrt}
\bibliography{references}

\end{document}


% !TEX root = ../main.tex
\newpage
\section{\theory Hebbian Learning and Synaptic Plasticity} \label{sec:HebbianLearningAndSynapticPlasticity}
\vspace{1mm}
\begin{quote}
\textsl{When an axon of cell A is near enough to excite a cell B and repeatedly or persistently takes part in firing it, some growth process or metabolic change takes places in one or both cells such that A's efficiency, as one of the cells firing B, is increased.}\cite{Hebb1949}
\end{quote}

This quote from psychologist Donald Hebb has influenced the neuroscientific community since 1949. In its essence, Hebb postulated that neurons that \textsl{fire together, wire together}. It has since become known as \textsl{Hebbian learning}, and is simply modelled as a positive correlation between the action potentials of spiking neurons. It has been proven in vivo in many studies \cite{ChrolCannon2014}, just like its counterpart, \textsl{anti-Hebbian learning}, where a negative correlation can be found. In many applications, both processes are present.

\subsection{Spike-timing dependant plasticity}
One specific temporal interpretation of these ideas is \textsl{spike-timing-dependent plasticity} (\STDP), where the relative timing of action potentials from the pre- and postsynaptic neuron determine causality \cite{Kempter1999, Gerstner2002}. If the postsynaptic neuron B fires right after the presynaptic neuron A, then we can expect the synaptic strength from post- to presynaptic neuron to increase, and vice versa. Whether A pushes B or B listens to A  is trivial.

Let us say that neuron $\theta_i$ spikes at time $t_i$ and that neuron $\theta_j$ spikes at $t_j$. Taking the time difference $\Delta t_{ij}$ as $t_j - t_i$, we can say that when $\Delta t_{ij} > 0$ the spikes are correlated (there exists a temporally causal relation), and we can model an increase in synaptic strength of the connection from $\theta_i$ to $\theta_j$, which we will gather in the \textsl{coupling matrix} $K_{ij}$. In the light of anti-Hebbian learning we can decrease $K_{ij}$ when $\Delta t_{ij} < 0$, as there is no causal relation. We will find an expression for $\Delta K_{ij}$ in function of $\Delta t_{ij}$ so that at each time-step we can update $K_{ij} \leftarrow K_{ij} + \Delta K_{ij}$.\\

We can think of the coupling matrix as the continuous interpretation of $\kappa A_{ij}$, where synaptic strength and network topology go hand in hand. This also means that we need to redefine some concepts:
\begin{align}
\kinbi = \sum_{j=1}^{N} \rvert K_{i j} \rvert \hspace{15mm}
\koutbj = \sum_{i=1}^{N} \rvert K_{i j} \rvert \hspace{15mm}
\kmean &= \frac{1}{N} \sum_{i,j=1}^{N} \rvert K_{i j} \rvert \hspace{15mm}  \label{eq:redefineFromK}  %\hat{\kmean} = \frac{1}{N} \sum_{i,j=1}^{N} K_{i j}
\end{align}
The absolute value ensures that we capture the magnitude of the coupling strength. %The reason we want to distinguish between $\kmean$ and $\hat{\kmean}$ is that for some parts of the investigation it is beneficial to study how inhibitive and excitatory coupling strengths influence each other.\\

Also the network of Theta neurons needs a redefinition:
\begin{align}
\dot{\theta}_{i} &=\left(1-\cos \theta_{i}\right)+\left(1+\cos \theta_{i}\right) \cdot \left[\eta_{i} + I_{i}(t)\right] \qquad \theta_i \in \T^N  \label{eq:thetaneuronnetwork_adaptive} \\
I_{i}(t) &=\frac{1}{\kmean} \sum_{j=1}^{N} K_{i j} \cdot \mathcal{P}_{n}(\theta_{j}) \label{eq:thetaneuronnetworkcurrent_adaptive}
\end{align}

The functions $W(t)$ that relate $\Delta t_{ij}$ to $\Delta K_{ij}$ are called \textsl{learning windows},  as they define a range in which $K_{ij}$ is able to adapt or \textsl{learn}, and also when learning is optimal. When signals between neurons show a very large time difference (negative or positive) we do not expect them to be correlated. %Because the learning windows are generally not symmetrical we can also expect the coupling matrix to be asymmetrical.
The magnitude of these functions is small, as it is assumed that learning dynamics happen at a slower timescale than the neuronal dynamics.

Another characteristic is the integral over the learning window. A window with a negative integral directs synaptic strengths mostly towards inhibitory behaviour, and vice versa with a positive integral. An integral of zero would mean that both inhibitory and excitatory synapses are stimulated equally. It has been proven that $\int W(\tau) \mathop{d\tau}$ is the magnitude of the correlation between signals \cite{Gerstner2002}. \\

%The magnitude of change is modulated by an asymmetric biphasic learning window around pulses originating from the postsynaptic neuron. Asymmetric because the peak is not situated at 0 and the integral over the window is generally positive, biphasic because this allows both to strengthen and weaken coupling strengths \cite{Gerstner2002}.

This approach simplifies modelling the neuronal back-propagation, where another pulse is generated as an echo of the action potential which travels through the neuron dendrites (so, backwards). This behaviour is believed to adjust the presynaptic weights, though it is a controversial subject \cite{Gerstner2002}. \\

In recent years, criticism on \STDP has been growing, as experimental data has shown that \STDP is usually accompanied by homeostatic plasticity of the neurons excitability and the synaptic strength. Basing our learning behaviour on the correlation between neuronal activity can be quite unstable: changes to the synaptic strength cause changes in the postsynaptic firing rate, which generates further changes to the synaptic strength in a positive feedback loop. Processes like \textsl{intrinsic plasticity} (\IP), where one neuron's excitability changes over time as to self-regulate sensitivity to incoming action potentials, or \textsl{synaptic scaling}, where synapse characteristics are adjusted in unison to counteract positive feedback loops, have proven to stabilise the synchronisation \cite{ChrolCannon2014, Kirkwood2019}. When \STDP and \IP are combined, it seems like the two process balance each other out and stable network topologies can be found \cite{Song2017}.

\subsection{Formulations of \STDP as a model}
\subsubsection{The Kempter method}
%Analysis of a distinct \STDP model was done in \cite{Kempter1999}.
\cite{Kempter1999} proposed a distinct \STDP model. Following the notation, we will denote the sequence of action potentials, the \textsl{spike train}, coming from each neuron $\theta_i$ as $S_i^{\rm out}(t) = \sum_{n} \delta (t-t_{i}^{n})$, where $t_{i}^{n}$ is the time that $\theta_i$ has fired. Similarly, we will denote the spike train coming into each neuron $\theta_i$ as $S_i^{\rm in}(t) = \sum_{f} \delta (t-t_{i}^{f})$ with $t_{i}^{f}$ being the time that a neighbouring neuron has spiked. Now we can say that the synaptic strengths are adjusted as:
\begin{align}
\Delta K_{ij} &= \int_{t}^{t+\mathcal{T}} w^{\rm{out}} S_i^{\rm out}(\tau) + w^{\rm{in}} S_{j}^{\rm {in}}(\tau) \mathrm{d}\tau
+ \iint_{t}^{t+\mathcal{T}} W( \tau^\prime - \tau) S_{i}^{\rm out}(\tau) S_{j}^{\rm in}( \tau^\prime) \mathrm{d} \tau \mathrm{d} \tau^\prime
\label{eq:KempterSTDPFormulation1} \\
&= \sum_{t_i^{n}\in \mathcal{T}} w^{\mathrm{out}} + \sum_{t_{j}^{f} \in \mathcal{T}} w^{\mathrm{in}} + \sum_{t_{j}^{f}, \: t_i^{n} \in \mathcal{T}} \hspace{-2mm} W (t_{j}^{f}-t_i^{n} ) \label{eq:KempterSTDPFormulation2}
\end{align}
with $\mathcal{T}$ the time domain over which learning takes place. $w^{\mathrm{in}} > 0$ and $w^{\mathrm{out}} < 0$ are small weights on the in- and outgoing action potentials. In \eqref{eq:KempterSTDPFormulation1} we can recognise the correlation between signals as a convolution over the learning window. We will refer to \eqref{eq:KempterSTDPFormulation2} as the Kempter method. \\

The following learning window is proposed:
\begin{align}
W(t)_K = A
\begin{cases}
\left[\left(1-\frac{t}{\tilde{\tau}_{p}}\right) - \left(1-\frac{t}{\tilde{\tau}_{n}}\right)\right] \cdot \exp \left( \frac{t}{\tau_{\rm syn}} \right) & \text{for } t \leq 0 \\
 \exp \left(-\frac{t}{\tau_{p}}\right) - \exp \left(-\frac{t}{\tau_{n}} \right) & \text{for } t > 0
\end{cases} \label{eq:learningwindowKempter1999}
\end{align}
Here $t$ is the delay between presynaptic spike arrival and postsynaptic firing, $A$ is a small learning parameter and all $\tau$'s are time constants. The values are given as $A = 10^{-5}$, $\tau_{\rm syn} = 5$ ms, $\tau_{p} = 1$ ms and $\tau_{n} = 20$ ms. $\tilde{\tau}_{p} \equiv \tau_{\rm syn} \tau_{p} / (\tau_{\rm syn} + \tau_{p})$ and $\tilde{\tau}_{n} \equiv \tau_{\rm syn} \tau_{n} / (\tau_{\rm syn} + \tau_{n})$. $\int W(\tau)_K \mathop{d \tau} = 4.75 \times 10^{-8}$ so that the correlation is positive. \\

$w^{\mathrm{in}}$ and $w^{\mathrm{out}}$ are necessary for $K_{ij}$ to reach an equilibrium, which is proven from the average learning dynamics. Using an inhomogeneous Poisson process with time-dependent intensities to generate spike trains, the learning equation \eqref{eq:KempterSTDPFormulation2} is found to converge to a stable equilibrium, also when different types of noise are added to selections of neurons \cite{Kempter1999}. The authors do understand the concept of topology, as the variation of the coupling strength between nodes is examined, but they did not investigate the relation between coupling strength and spiking behaviour. The question will now be whether convergence of the synaptic strength still occurs when we will apply \STDP to our network of Theta neurons, as changes to the coupling strength will also influence the spiking dynamics between neurons, which in turn will affect the learning again. The distribution of spikes in each spike train might not be coming from a recognisable distribution.\\

To counteract the excitatory nature of the learning window, the authors propose $w^{\mathrm{in}} = A$ and $w^{\mathrm{out}} = -1.0475 \cdot A$ so that the amplitude of these weights is on the same order as the magnitude of the learning window \cite{Kempter1999}. This is a regulatory process, as neurons are punished for sending out  many spikes over time by decreasing their influence over neighbours more than the increase in influence of their neighbours over them. This threshold can be overcome by teaching the neurons to spike at the right time (with respect to its neighbours' spikes) as then the learning window yields an increase in synaptic strength.%This process is inherently asymmetric. \\

\subsubsection{The Song method}
Another formulation of \STDP as a mathematical model can be found in \cite{Song2000}. It is postulated without being concerned about the biological aspect too much, simplifying some of the ideas of \cite{Kempter1999}. The synaptic strengths are simply updated with:
\begin{align}
\Delta K_{ij} &= K^{\rm max} \cdot \sum_{t_{j}^{f}, \: t_i^{n} \in \mathcal{T}} \hspace{-2mm} W (t_{j}^{f}-t_i^{n} ) \label{eq:SongSTDPFormulation}
\end{align}
where $K^{\rm max}$ is the maximum allowed synaptic strength, so that we can think of \eqref{eq:SongSTDPFormulation} as taking a percentage of the maximum coupling. The authors also constrain $0 \leq K_{ij} \leq K^{\rm max}$, as there is no regulatory process like in \eqref{eq:KempterSTDPFormulation2}. In their further work on \STDP and \IP the authors booked remarkable progress, and their work on the Izhikevich model is very interesting for our application \cite{Song2017}. We will refer to \eqref{eq:SongSTDPFormulation} as the Song method.

The learning window is then again defined as a discontinuous function:
\begin{align}
W(t)_S =
\begin{cases}
A_{n} \cdot \exp \left(\frac{t}{\tau_n}\right)  & \text{for } s \leq 0 \\
A_{p} \cdot \exp \left(\frac{-t}{\tau_p}\right) & \text{for } s > 0
\end{cases} \label{eq:learningwindowSong2000}
\end{align}
where $A_p = 0.005$, $A_n = -0.00525$ and $\tau_p = \tau_n = 20$ ms. $\int W(\tau)_S \mathop{d \tau} = -5.0 \times 10^{-6}$ so we expect the weights to be suppressed towards a negative value. Interestingly, the line between reward and punishment is very thin, as the largest increase and largest decrease in synaptic strength lie right next to each other on the spectrum. \\

As $K_{ij}$ is only allowed to be positive, the negative correlation of the learning window pushes most of the synaptic strengths towards zero. The range of coupling strengths is also very restricted and only allowed to change over a small interval: $K^{\rm max}$ = 0.03 \cite{Song2000, Song2017, ChrolCannon2012}. The learning dynamics, encoded into the topology of the network, show how the node degrees are pushed towards 0, with only a small group of neurons managing to learn the optimal spike timing. The spiking rate of all nodes in the network converges to a normal distribution. However, no mention is made of convergence of the node degrees, as the learning procedure is halted artificially.\\

Recently, triphasic learning windows have been used to account for when it takes too long for the postsynaptic neuron to fire, and thus to decorrelate the relation between neurons that spike too soon and too late. These learning windows are curves that were fitted to experimental data of the cortex and the hippocampus \cite{ChrolCannon2014}.
Extending the work of \cite{Song2000} we can find a brief investigation of network topology and clustering using triphasic windows, \cite{ChrolCannon2012}. The method is as in \eqref{eq:learningwindowSong2000}, with the following learning window:
\begin{align}
W(t)_C = A_{p} \cdot \exp \left(\frac{-\left(t - 15 \right)^{2}}{ \tau_{p}}\right) - A_{n} \cdot \exp \left(\frac{-\left(t - 20\right)^{2}}{ \tau_{n}}\right)  \label{eq:learningwindowChrolCannon2012}
\end{align}
where $A_{p}=0.23$, $A_{n}=0.15$, $\tau_{p}=200$ and $\tau_n = 2000$. $\int W(s)_C \mathop{d s} = -6.0 \times 10^{-3}$. \\

When comparing the qualities of the different learning windows presented here, one can quickly notice the difference in magnitude between the learning windows. That does not necessarily include the magnitude of the correlation, but the magnitude of the window itself. In \eqref{eq:learningwindowKempter1999}, the learning rate is a few orders of magnitude smaller than in \eqref{eq:learningwindowChrolCannon2012} and this resulted in extremely slow convergence when testing. For \eqref{eq:learningwindowSong2000} this issue was solved in \cite{ChrolCannon2012} by using $A _p = 0.1$ and $A_n = -0.12$. In the same spirit, we will therefore use $A = 8.0 \times 10^{-2}$ in \eqref{eq:learningwindowKempter1999}. These alterations yield $\int W(\tau)_S \mathop{d \tau} = -4.0 \times 10^{-4}$ and $\int W(\tau)_K \mathop{d \tau} = 3.8 \times 10^{-4}$.\\

%The learning windows generally have $W(t^{\ast}) = 0$ for $t^{\ast} \geq 0$. This means that no learning will take place when the delay between neuron spikes is exactly $t^{\ast} \geq 0$. The triphasic windows show two of those points.

\begin{figure}[H]
\centering
\includegraphics[width = \textwidth]{../Figures/Learning/LearningWindows.pdf}
\caption{Three different biphasic learning windows. Left: with $W_K$ the the learning spectrum is quite narrow. Middle: we can see how in $W(t)_s$ a slightly larger emphasis is put on the anti-Hebbian learning. Right: a triphasic window can punish the synaptic strength when signals arrive either too early or too late. For simplicity, we will use the same colour to identify the results from using the different windows.}
\label{fig:LearningWindows}
\end{figure}

It is important to notice that learning only occurs when neurons spike, so that equilibrium states will halt the learning process. However, these states were rarely encountered during the testing process, and it seems like there continues to exist enough randomness in the states of $\theta_i$ to persist spiking.
When implementing \STDP, a time-step smaller than 0.01 is necessary, otherwise important details in the learning dynamics that are captured by the shape of the learning window will be lost.

Another important observation is that when computing the time delay between spikes of the same neuron, $t_{i}^{f}-t_i^{n}$ will always be zero by definition. It is much simpler to perform this operation than to filter it out. In the case that $W(0)$ is zero, $K_{ii}$ will not change. Though for $W_S$ and $W_C$ we have $W(0) < 0$ so that $K_{ii}$ will always be decrease in magnitude. Conclusions can therefore not be drawn from self-coupling.

%We can model intrinsic plasticity by adjusting the neuron's excitability as the inverse of the firing rate: he more spikes that a neuron will receive, the less affected it is \cite{Song2017}.  An observed phenomenon is that the excitability evolves together with the coupling strength, but that at the extremes this relation reverses \cite{Debanne2017, Debanne2018}.  These types of plasticities should be relatively easy to implement but have no impact on the network topology.

\subsection{Synaptic Scaling}
There is no upper or lower bound on the synapse strength, and generally connection strengths are nonzero. Positive reinforcement loops might disturb the learning process, which would not be beneficial for the model. One technique we can apply to keep the strengths within a definitive range is to scale homeostatically - a method where any increases in synaptic strength will balance out any decreases by scaling:
\begin{align}
K_{ij}^s = K_{ij} \frac{\frac{1}{N} \sum_{i,j} K_{ij}}{\sum_{i} K_{ij}}
\end{align}
In this way, the out-degrees will remain constant. Using this approach, something has to remain constant, whether that is $\kmean$, or $\kmean^2$ or any other property of the adjacency matrix. However, this property is not one we are after: we want a method that is able to change the network topology entirely.

\subsection{Intrinsic Plasticity} \label{sec:IP}
Instead of scaling the weights to preserve a certain quantity in the network, we can allow the neurons to adjust their sensitivity to incoming signals. So when some synaptic strengths are increased, we can reduce the excitability, and vice-versa. This should counteract positive feedback.

If we look at the formulation of the network of Theta neurons \eqref{eq:thetaneuronnetworkcurrent_adaptive}, we can see that $\eta_i$ is the threshold on $I_i(t)$ for which the result of the \PRC will be positive or negative. The neuron action potentials $\mathcal{P}_n(\theta_j)$ are scaled by the coupling matrix and the mean node degree. We expect that when neurons learn to adapt $K_{ij}$ and $\eta_i$, the two will try to cancel each other out.

In \cite{Song2017} an \IP method is introduced in detail. We can simply update $\eta_{i} \leftarrow \eta_{i} + \eta_{\max } \cdot \phi_{i}$, where:
\begin{minipage}{.45\textwidth}
   \centering
   \begin{figure}[H]
	\centering
	\includegraphics[width = \textwidth]{../Figures/Learning/IPlearningFunction.pdf}
	%\caption{The learning behaviour for intrinsic plasticity as proposed in \cite{Song2017}.}
	\label{fig:IPlearningFunction}
	\end{figure}
\end{minipage}
\begin{minipage}{.55\textwidth}
\begin{align}
	\phi_{i} (t) =
	\begin{cases}
	-\alpha \cdot \exp \left(\frac{T_{\min }-t}{T_{\rm min }}\right) \hspace{10mm} t<T_{ \rm min } \\
	\alpha \cdot \exp \left(\frac{t-T_{\rm max }}{T_{\max }}\right) \hspace{12mm} t >T_{\rm max } \\
	0 \hspace{24.5mm} T_{ \rm min } \leq t \leq T_{\rm max }
	\end{cases}
\end{align}
\vspace{10mm}
\end{minipage}
The argument $t$ represents the time that has passed between successive spike of the same neuron, the \textsl{inter-spike interval} (\ISI). This is always a positive number. \\

The results of introducing \IP seem to stabilise the resulting topologies in the Song method. Many more nodes seem to survive with a node degree that is not at the extremes, and there seems to exist an interesting relation between in- and out-degree vectors \cite{Song2017}.

%\begin{figure}[H]
%\centering
%\includegraphics[width = 0.5\textwidth]{../Figures/Learning/IPlearningFunction.pdf}
%\caption{The learning behaviour for intrinsic plasticity as proposed in \cite{Song2017}.}
%\label{fig:IPlearningFunction}
%\end{figure}

%\textcolor{red}{QUESTION}: \textsl{is it necessary to include more background theory on Hebbian Learning?}

Writing/Mainmatter/Hebbian Learning and Plasticity.tex


\SecDef{prelim}{Preliminaries}

In this chapter I use a specific notation to simplify expressions. A vector $v \in \field{n}$ is considered a row vector. Any matrix $L \in \F_2^{n\times m}$ defines a linear mapping $\varphi \colon \F_2^n \rightarrow \F_2^m, \ x \mapsto xL$.

\subsection{Higher-Order Derivatives, Affine Equivalence and Algebraic Immunity of Boolean Functions}

Boolean functions have several applications in cryptography, e.g., for designing stream ciphers. In order to resist algebraic attacks, the notion of algebraic immunity was introduced in 2004 as follows.

\begin{definition}[Algebraic immunity~\cite{EC:MeiPasCar04}]
Let $f\colon \F_2^n \rightarrow \F_2$. An $n$-bit Boolean function $g \neq 0$ is called an \emph{annihilator} of $f$, if $f g = 0$. The set of annihilators of $f$ together with $g=0$ form a vector space, denoted by $\AN(f)$. We denote by $\AN_d(f)$ the subspace of annihilators of $f$ with algebraic degree at most $d$ together with the zero-function. The \emph{algebraic immunity} of $f$, denoted $\AI(f)$, is defined as the minimum $k$ for which $\AN_k(f) \cup \AN_k(f+1) \neq \{0\}$.
\end{definition}

An important concept for Boolean function is the notion of affine equivalence.

\begin{definition}[Domain Affine Equivalence]
Two Boolean functions $f,g\colon \F_2^n \rightarrow \F_2$ are called \emph{domain affine equivalent} if there exists a linear bijection $\varphi \colon \F_2^n \rightarrow \F_2^n$ and a vector $c \in \F_2^n$ such that $g = f \circ (\varphi + c)$. If $c = 0$, $f$ and $g$ are called \emph{linear equivalent}.
\end{definition}
I remark that, in the literature, \emph{domain affine equivalence} of Boolean functions is called simply \emph{affine equivalence}. I specify the term to avoid ambiguity, as, for example, $g$ and $g\oplus1$ are not domain affine equivalent in general.
It is well known that the weight, the algebraic degree and the dimensions of the annihilator spaces (and thus the algebraic immunity) are invariant under domain affine equivalence.

\subsection{Orthogonal Matrices and Preservation of Nonlinear Invariants}

In~\cite{NonlinInv}, Todo, Leander and Sasaki introduced the \emph{nonlinear invariant attack} and successfully distinguished the block ciphers Midori, Scream and iScream from a random permutation for a significant fraction of weak keys. For an $n$-bit permutation $G \colon \F_2^n \rightarrow \F_2^n$, the main idea consists in finding a non-constant $n$-bit Boolean function $f$ and a constant $\varepsilon \in \F_2$ such that
$$
\forall x \in \F_2^n\colon f(x) = f(G(x)) + \varepsilon.
$$

Such a function $f$ is called an \emph{invariant} for $G$.
In order to find an invariant for the cipher, Todo \etal. observed that if $L \in \F_2^{n \times n}$ is an orthogonal matrix, i.e., if $\inprod{xL, yL} = \inprod{x, y}$ for all $x,y \in \F_2^n$, then for all Boolean functions $f \in \BF{t}{2}$ it is
\eql{target_equation}{
\forall X \in \F_2^{t \times n} \colon
\bigoplus_{i=1}^n f\big( (X^\top)_i \big) =
\bigoplus_{j=1}^n f\big( ((XL)^\top)_j \big).
}
In other words, \emph{any} Boolean function $f\colon \F_2^t \rightarrow \F_2$ of algebraic degree at most 2 gives rise to an invariant over the linear layers of Midori, Scream and iScream of the form
$(x_1,\dots,x_n) \mapsto f(x_1)+\dots f(x_n)$, where $n$ denotes the number of S-boxes, $t$ denotes the bit length of the S-box and $x_i \in \F_2^t$.

We illustrate this from a slightly different point of view on the example of the linear layer used in Midori (see~\cite{AC:BBISHA15}), which is defined by the following matrix:
\eql{midori}{
L = \matb{
0 & 1 & 1 & 1 \\
1 & 0 & 1 & 1 \\
1 & 1 & 0 & 1 \\
1 & 1 & 1 & 0
}.
}
It is easy to see that $L$ is orthogonal. Thus, according to \EqRef{target_equation}, for \emph{any} $f \in \BF{t}{2}$ and all $x_1,x_2,x_3,x_4 \in \F_2^t$, the following equation holds:
\eq{
    &f(x_1) + f(x_2) + f(x_3) + f(x_4) = \\ &f(x_2+x_3+x_4)+f(x_1+x_3+x_4)+f(x_1+x_2+x_4)+f(x_1+x_2+x_3).
}

Consider an alternative way of proving this. The arguments of $f$ form an affine subspace of dimension 3, namely
$$
x_1 + \Span(x_1+x_2, x_1+x_3, x_1+x_4).
$$
Therefore, the equation is equivalent to
$$
    \delta_{x_1+x_2}\delta_{x_1+x_3}\delta_{x_1+x_4}f(x_1) = 0,
$$
which is clearly true for any $f \in \BF{t}{2}$ and any $x_1,x_2,x_3,x_4$ since all third-order derivatives of a quadratic function are equal to zero. This observation gives new insights on how to generalize the linear layer in order to preserve \emph{higher-degree invariants}.

\begin{proposition}
\PropLabel{expanding-linear-high-degree}
Let $d \ge 2$ be an integer. Then there exists a matrix $L \in \F_2^{n \times m}$ with $n = d+2, m=2^{d+1}-d-2$ and full rank $n$ such that for any $t \ge 1$ and any $f \in \BF{t}{d}$, the following property holds:
\eql{invariant_preserving_linear}{
\forall X \in \F_2^{t \times n} \colon
\bigoplus_{i=1}^n f\big( (X^\top)_i\big) =
\bigoplus_{j=1}^m f\big( ((XL)^\top)_j \big).
}
An example of such $L$ is given by a matrix with columns taken as all vectors from $\field{n}$ with an odd Hamming weight greater or equal to 3.
\end{proposition}
\begin{proof}
For any $t \ge 1$ and any $x_0,\ldots,x_{d+1}\in \F_2^t$ consider the $(d+1)$-dimensional affine subspace
\[V = x_0 + \Span(x_0+x_1,x_0+x_2,\ldots,x_0+x_{d+1})\;.\]
For any Boolean function $f$ of degree $d$, any $(d+1)$-th derivative vanishes. Therefore, $\bigoplus_{v \in V} f(v) = 0$. This can be equivalently written as
\eql{higher-order-expanding}{
    & f(x_0) + f(x_1) + \ldots + f(x_{d+1}) = \\
    & = \bigoplus_{\substack{I \subseteq \{1, \ldots, d+1\} \\ |I| \ge 2 ~\text{even}}}f(x_0 + \bigoplus_{i \in I}x_i) +
        \bigoplus_{\substack{I \subseteq \{1, \ldots, d+1\} \\ |I| \ge 3 ~\text{odd}}}f(\bigoplus_{i \in I}x_i) \\
    & = \bigoplus_{\substack{I \subseteq \{0, \ldots, d+1\} \\ |I| \ge 3 ~\text{odd}}}f(\bigoplus_{i \in I}x_i)
    .
}
The right-hand side contains $2^{d+1}-d-2$ applications of $f$. Let $Y$ be the set of the linear functions defining the arguments of $f$ in the right-hand side of \EqRef{higher-order-expanding}, i.e.,
$$
Y =
\pset{ \bigoplus_{i \in I}x_i ~\biggm|~ I \subseteq \{0, \ldots, d+1\}, \ |I| \ge 3 ~\text{odd} },
$$
and let $L$ be the matrix of the linear function that maps $(x_0, x_1, \ldots, x_{d+1})$ to $(y_1, y_2, \ldots, y_{2^{d+1}-d-2})$, where $y_i \in Y$ and all $y_i$ are pairwise different. Then, \EqRef{higher-order-expanding} is equivalent to \EqRef{target_equation} with the described $L$.

Since $m \ge n \ge 4$, any unit vector from $\F_2^n$ can be expressed a linear combination of 3 columns of $L$, e.g., $$
(1,0,0,0,\ldots,0)=(1,1,1,0,\ldots,0)+(1,0,1,1,\ldots, 0)+(1,1,0,1,\ldots,0).
$$
We conclude that $L$ has full rank $n$.
\end{proof}

\begin{example}
For $d=2$ we obtain the orthogonal matrix given in \EqRef{midori}. For $d=3$ we obtain an expanding linear mapping $\varphi: \field{5} \to \field{11}$ defined by the following $5 \times 11$ matrix $L$:
$$
L = \matb{
0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
0 & 1 & 1 & 1 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\
1 & 0 & 1 & 1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\
1 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\
1 & 1 & 1 & 0 & 1 & 1 & 0 & 1 & 0 & 0 & 1 \\
}.
$$
\end{example}


\documentclass{homework}
\course{Math 5522H}
\author{Jim Fowler}
\input{preamble}

\begin{document}
\maketitle

\begin{inspiration}
I don't think derivatives are evil, per se --- I think they are dangerous.
\byline{Warren Buffett}
\end{inspiration}

\section{Terminology}

\begin{problem}
  What is a half-space?  Define convex hull.
\end{problem}

\begin{problem}
  Define the Wirtinger partial derivatives $\displaystyle\frac{\partial}{\partial z}$ and $\displaystyle\frac{\partial}{\partial \conj{z}}$.
\end{problem}

\begin{problem}
  What are the Cauchy-Riemann equations?
\end{problem}

\section{Numericals}

\begin{problem}\label{cauchy-riemann-polar}What are the Cauchy-Riemann equations\ldots in polar coordinates?
\end{problem}

\begin{problem}
  For a natural number $n$ define $f : \mathbb{C} \to \mathbb{C}$ by
  \[
    f(r \cos \theta + i \, r\sin \theta) = r^n \cos \left( n \theta \right) + i \, r^n \sin \left( n \theta \right).
  \]
  Use \ref{cauchy-riemann-polar} to verify that $f$ satisfies the
  Cauchy-Riemann equations.
\end{problem}

\begin{problem}
  On a certain domain, define $f(z) = \log \abs{z} + i \cdot \Arg z$
  and verify that $f$ satisfies the Cauchy-Riemann equations.
\end{problem}

\begin{problem}
  Compute $\displaystyle\frac{\partial}{\partial z} \left( z \conj{z} \right)$.
\end{problem}

\begin{problem}\label{harmonic-conjugate}Let $u(x,y) = e^y \sin x$.  Find $v(x,y)$ so that $u$ and $v$
  satisfy the Cauchy-Riemann equations.  Such a function $v$ is a
  \textbf{harmonic conjugate} of $u$.
\end{problem}

\section{Exploration}

\begin{problem}\label{cayley-transform}Relate the upper half-plane
  $H = \{ z \in \mathbb{C} : \Imag z > 0 \}$ and the open disk
  $D = \{ z \in \mathbb{C} : \abs{z} < 1 \}$ by finding $a,b,c,d \in \C$ so that the M\"obius transformation
  \[f(z) = \frac{az + b}{cz + d}\] yields a bijection $f : H \to D$.
\end{problem}

\begin{problem}\label{harmonic-necessary}Given $u : \mathbb{R}^2 \to \mathbb{R}$, is it always possible to
  find a function $v : \mathbb{R}^2 \to \mathbb{R}$ so that $u$ and
  $v$ satisfy the Cauchy-Riemann equations?
\end{problem}

\begin{problem}\label{gauss-lucas}For $p \in \C[x]$, show that the convex hull of the zeroes of $p$
  contains the zeroes of $p'$.  This is the \textbf{Gauss-Lucas
    theorem}.
\end{problem}

\begin{problem}
  Suppose the smooth function $f : \C \to \C$ satisfies the
  Cauchy-Riemann equations.  Does $f'$ also satisfy the Cauchy-Riemann
  equations?
\end{problem}

\begin{problem}
  Suppose $f : \R^2 \to \R^2$ satisfies the Cauchy-Riemann equations,
  and consider curves $\gamma_1, \gamma_2 : (-1,1) \to \R^2$ passing
  through the origin so that $\gamma_1(0) = \gamma_2(0) = (0,0)$.
  Relate the angle between the curves $\gamma_1$ and $\gamma_2$ to the
  angle between the curves $f \circ \gamma_1$ and $f \circ \gamma_2$.
  (This is related to \ref{tj-versus-jt}.)
\end{problem}

\begin{problem}
  Suppose $f : \C \to \C$ is smooth and holomorphic.  Show that the
  real part of $f$ is harmonic (cf.~\ref{harmonic-function}).
\end{problem}

\begin{problem}
  Let's redo \ref{abels-theorem} in the context of complex analysis.
  Consider a sequence $(a_n)$ of complex numbers so that
  $\sum_{n=0}^\infty a_n$ converges to $L$.  Then
  $\lim_{z \to 1^{-}} \sum_{n=0}^\infty a_n z^n = L$ provided
  $z \to 1$ in a \textbf{Stolz sector}, i.e., suppose there is some
  $K$ so that $|1-z| \leq K(1-|z|)$.
\end{problem}

\section{Prove or Disprove and Salvage if Possible}

As always with PODASIPs, many of statements below are incorrect.  For
full credit, you must not only salvage these false statements, but
also explain why the statement is false (e.g., perhaps by exhibiting a
counterexample).

\begin{problem}
  Suppose $f : \R^2 \to \R^2$ and $g : \R^2 \to \R^2$ are smooth (but
  not necessarily holomorphic when regarded as functions from $\C$ to
  $\C$).  Then by the chain rule,
  \[
    \frac{\partial}{\partial z} \left( f \circ g \right) =
    \frac{\partial f}{\partial z} \frac{\partial g}{\partial z} + \frac{\partial f}{\partial \conj{z}} \frac{\partial g}{\partial \conj{z}}.
  \]
  and similarly
  \[
    \frac{\partial}{\partial \conj{z}} \left( f \circ g \right) =
    \frac{\partial f}{\partial \conj{z}} \frac{\partial g}{\partial \conj{z}} + \frac{\partial f}{\partial z} \frac{\partial g}{\partial z}.
  \]
\end{problem}

\begin{problem}\label{schwarz-reflection-principle}If $f : \C \to \C$ is holomorphic, then $z \mapsto \overline{f(\conj z)}$ is holomorphic.
\end{problem}

\begin{problem}\label{cauchy-riemann-alone-not-sufficient}Suppose $u, v : \mathbb{R}^2 \to \mathbb{R}$ satisfy
  \[
    \frac{\partial u}{\partial x}(0,0)=\frac{\partial v}{\partial y}(0,0)
    \mbox{ and }
    \frac{\partial u}{\partial y}(0,0)=-\frac{\partial v}{\partial x}(0,0).
  \]
  Then $f : \C \to \C$ given by $f(x+iy) = u(x,y) + i \, v(x,y)$ is holomorphic at $0$.
\end{problem}

\begin{problem}\label{open-mapping-theorem-preview}There is a nonconstant holomorphic function with constant absolute value.
\end{problem}

\begin{problem}\label{schwarzian-derivative}For $f : \mathbb{C} \to \mathbb{C}$, the \textbf{Schwarzian derivative} of $f$ is
  \[ (Sf)(z)=\left({\frac{f''(z)}{f'(z)}}\right)'-{\frac12}\left(\frac{f''(z)}{f'(z)}\right)^2={\frac {f'''(z)}{f'(z)}}-{\frac32}\left(\frac{f''(z)}{f'(z)}\right)^2. \]
  If $f$ is a M\"obius transformation, then $(Sf)(z) = 0$.
\end{problem}

\end{document}


\newpage{}
\newpage{}

\hypertarget{a002---simply-an-average}{%
\section{A002 - Simply an average}\label{a002---simply-an-average}}

\hypertarget{description}{%
\subsection{Description}}

Another algorithm could just calculate an average. Take all tasks and
their durations, divide them by their count. Is this better?

From visually reviewing the data we know that most tasks have a duration
of a few hours max. Some take very long.

An average is not just an average as we know. There are several ways to
calculate one:

\begin{itemize}
\tightlist
\item
  there is the ``simple average'' that includes all data (A002.1)
\item
  there is the possibility of a boxplot like calculation, include only
  the middle n\% of the values (A002.2)
\end{itemize}

\hypertarget{using-the-algorithm-from-powershell}{%
\subsection{Using the algorithm from powershell}}

\hypertarget{a002.1}{%
\subsubsection{A002.1}}

Have a look at Quality-Assurance\_A002\_1\_swe2020.ps1 if you need more.
But actually it is just calculating the average. It is not even
necessary to do this in a programming language alltogether.

\begin{verbatim}
$averageTaskDuration = ($historicData.DurationInSeconds | Measure-Object -Average).Average

$anyEstimation = $averageTaskDuration
\end{verbatim}

\hypertarget{a002.2}{%
\subsubsection{A002.2}}

For that average let us only use the middle 90\% of duration values.
That will cut extreme points and should reduce the error.

Quality-Assurance\_A002\_2\_swe2020.ps1:

\begin{verbatim}
$historicData = $historicData | Sort-Object DurationInSeconds
$count = ($historicData | Measure-Object).Count
$fivePercent = [int]($count * 0.05)
$historicData = $historicData[$fivePercent..($count-$fivePercent)]
\end{verbatim}


%!TEX root = ../main.tex
%-------------------------------------------------------------------------------
\section{Improvements}\label{Computation}
%-------------------------------------------------------------------------------
The implementation of EKW models poses several computational challenges. Among them are numerical integration, global optimization, function approximation, and efficient parallelization. We now describe some of our efforts to align \verb+respy+ and \verb+estimagic+ with the state-of-the-art in computational methods. We have concluded our preparatory work and actively seek input from domain experts for further improvements and joint publication.
%-------------------------------------------------------------------------------
\subsection{Numerical integration}
%-------------------------------------------------------------------------------
The solution of EKW models requires the evaluation of millions of integrals to determine the future value of each action in each state. In \citet{Eisenhauer.2020c}, we draw on the extensive literature on numerical integration \citep{Davis.2007, Gerstner.1998} to improve the precision and reliability of their solution. The current practice in economics is to implement a random Monte Carlo integration which introduces considerable numerical error and computational instabilities \citep{Judd.2011}.\\

\noindent We consider the optimality equation in a generic time period $t$ to clarify the structure of the integral. Let $v^{\pi}_{t}(s_t, a_t)$ denote the action-specific value function of choosing action $a_t$ in state $s_t$ while continuing with the optimal policy going forward.
%
\begin{align*}
v^{\pi}_{t}(s_t, a_t) & = u_t(s_t, a_t) + \delta\,\E_{s_t} \left[\left.v^{\pi^*}_{t + 1}(s_{t + 1})\,\right\vert\,\mathcal{I}_t\,\right] \\
& =  u_t(s_t, a_t) + \delta\, \int_S v^{\pi^*}_{t + 1}(s_{t + 1})\, \diff p_t(a_t, s_t)\\
& =  u_t(s_t, a_t) + \delta\, \int_S \max_{a_{t + 1} \in A}\bigg\{v^{\pi^*}_{t + 1}(s_{t + 1}, a_{t + 1})\bigg\}\diff p_t(a_t, s_t).
\end{align*}

\noindent Let's consider an atemporal version of the typical integral from \citet{Keane.1997} as an example. As outlined earlier, individuals can choose among five alternatives. Each of the alternative-specific utilities is, in part, determined by a stochastic continuous state variable $\epsilon$. The transition of all other state variables $x$ is deterministic. This results in a five-dimensional integral of the following form:
%
\begin{align*}
   \int_{\epsilon}\, \max_{a\in A} \bigg\{v^{\pi^*}(x, \epsilon, a)\bigg\} \phi_{\mu, \Sigma}(\epsilon) \diff\epsilon \quad\forall\, x \in X,
\end{align*}

\noindent where $\epsilon$ follows a multivariate normal distribution with mean $\mu$, covariance matrix $ \Sigma$, and probability density function $\phi_{\mu, \Sigma}$.
%-------------------------------------------------------------------------------
\subsection{Global optimization}
%-------------------------------------------------------------------------------
The calibration of EKW models is challenging due to a large number of parameters and multiplicity of local minima. In \citet{Eisenhauer.2020b}, we draw on the literature on global optimization to assess and improve the reliability of the calibrations \citep{Locatelli.2013, Nocedal.2006}.\\

\noindent We conduct a benchmarking exercise using \citet{Keane.1994, Keane.1997} as a well-known and empirically-grounded test case. Depending on the calibration procedure, particular challenges arise. For example, while likelihood-based calibration requires smoothing of the choice probabilities, simulation-based calibration involves the optimization of a noisy function. We provide guidelines for selecting the appropriate algorithm in each setting and showcase diagnostics to assess the reliability of the calibration results.


\documentclass[letterpaper, 10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb,scrextend}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{silence}
\WarningFilter{latex}{You have requested package}
\input{ltx/pkg/preamble}

\begin{document}

\lhead{MAT224 Linear Algebra II}
\chead{Linear Transformations, Image \& Kernel}
\rhead{Week 04}

\title{Linear Algebra II \\ \Large{MAT224}}
\author{Lennart Döppenschmitt}
% \maketitle
% \tableofcontents

\section*{Linear Transformations Part II}%
\label{sec:title}

\textbf{Textbook:} Section 2.2

\lb
\textbf{Announcements}
\begin{itemize}
\item
The last hour before the lecture next week will be a review session!
Please collect your questions and email me if you would like to discuss anything
particular. (include MAT224 in subject, thanks)

\item
All vector spaces from now on, unless stated otherwise,
will be assumed to be finite dimensional.
\end{itemize}

\lb
Remember that a basis encodes a vector $\vec v ∈ V$ as an $n$-tuple.
We can use the same idea to encode linear transformations

\lb
\textbf{Example 2.2.2}
\lb
Let $V = W = \R^2$ with the standard basis $ \cb{\vec e_1, \vec e_2}$.
Define $ \map{V}[T]{W}$ by
\[ T(\vec e_1) = \vec e_1 + \vec e_2 \]
\[ T(\vec e_2) = \vec 2 e_1 - 2 \vec e_2 \]
\vspace{50pt}

\newpage
\lb
\textbf{Algorithm}
\lb
Given a linear transformation $ \map{V}[T]{W}$ given as a `formula',
this is how to compute its matrix in two chosen bases
\[ α = \cb{\vec{α}_1, \ldots \vec{α}_m} \]
of $V$ and
\[ β = \cb{\vec{β}_1, \ldots \vec{β}_n} \]
of $W$
\lb
\begin{enumerate}
    \item For each basis element $\vec{α}_i$ in $V$, compute $T(\vec{α}_i)$.
    \item Find the coorindate vector $γ^β(T(\vec{α}_i)) = [ T(\vec{α}_i) ]_β$.
    \item Assemble these coordinate vectors as columns in a matrix
\end{enumerate}

\lb
\textbf{Discussion}
\lb
Apply the above algorithm to find the matrix representing the derivative
$ \frac{d}{dx}$ from $\pol{2}{\R}$ to itself.
Choose the basis on $\pol{2}{\R}$ consisting of monomials $α = \cb{1, x, x^2}$.

\newpage
\lb
\textbf{Definition 2.2.6}
\lb
Let $T$ be a linear transformation between finite dimensional vector spaces $V$ and $W$
with bases $α$ and $β$ respectively.
The \emph{matrix of the linear transformation} $T$ with respect to bases $α$ and $β$ is the
matrix $[T]_α^β$ satisfying
\[ [T]_α^β \cdot [\vec v]_α = [T(\vec v) ]_β \]

\newpage
\lb
\textbf{Discussion}
\begin{enumerate}
    \item
        What does he `size' of the matrix $[T]_α^β$ depend on?
    \item
        What is the matrix of the identity transformation $ \map{V}[\tx{id}_V]{V}$?
\end{enumerate}

\lb
\textbf{Exmaple}
\lb
We compute the matrix of the linear transformation $ \map{\pol{3}{\R}}[\tx{ev}_2]{\R}$

\newpage
\lb
\textbf{Discussion}
\lb
On the contrary, given a matrix $A ∈ \mat{n, m}{\R}$, does this give us a
linear transformation? What are the domain and codomain?

\vspace{300pt}
\lb
\textbf{Summary}
\begin{enumerate}
    \item
        The upshot of this section is that linear transformations are completely interchangable
        with matrices!
        The identification depends on the choice of bases for the domain and codomain.
    \item
        The operations
        \begin{itemize}
            \item matrix of a linear transformation $[T]_α^β$
            \item linear transformation of a matrix $T_A$
        \end{itemize}
        are inverse to each other.
\end{enumerate}

\newpage
\lb
We now rephrase the \emph{algorithm} from before in more mathematical terms.
(Remember, abstraction is a powerful tool!)
\lb
\textbf{Proposition}
\lb
In the context of the above definition, the matrix of $T$ can be computed as
\[ [T]_α^β = γ^β \circ T \circ (γ^α)^{-1}\]
\begin{proof}
\end{proof}

\vspace{200pt}
\lb
\textbf{Discussion}
\lb
Without doing a lot of work, can you argue what the matrix
representing the composition $F \circ T$ is assuming you know $[F]$ and $[T]$?

\newpage

\section*{Imge and Kernel}%
\label{sec:Imge and Kernel}

\textbf{Textbook:} Section 2.3

\lb
\textbf{Definition (2.3.1 \& 2.3.10)}
\lb
For a linear transformation $ \map{V}[T]{W}$, we define
\begin{enumerate}
    \item
        the \emph{preimage} $T^{-1}(S)$ of $S \subseteq W$ under $T$ as all $\vec v ∈ V$ that map into $S$.
    \item
        the \emph{kernel} $\ker(T)$ of $T$  as all $\vec v ∈ V$ that map to $\vec 0$ under $T$,
    \item
        the \emph{image} $\tx{im}(T)$ of $T$ as all $\vec w ∈ W$ such that $\vec w = T(\vec v)$ for some $\vec v ∈ V$,
\end{enumerate}

\lb
\textbf{Example}
\begin{itemize}
    \item
    The kernel of $\map{\pol{n}{\R}}[\frac{d}{dx}]{\pol{n}{\R}}$ are all constant polynomials,
    while the image consists of polynomials of degree $n-1$.

    \item
    The kernel of the evaluation map $\map{\pol{n}{\R}}[\tx{ev}_2]{\pol{n}{\R}}$ are all
    polynomials that have a root at $x = 2$. What is the image?

    \item
    What is the image of the linear transformation defined in example 2.2.2 $\map{\R^2}[T]{\R^2}$?
    \[ T(\vec e_1) = \vec e_1 + \vec e_2 \]
    \[ T(\vec e_2) = \vec 2 e_1 - 2 \vec e_2 \]
\end{itemize}

\newpage
\lb
\textbf{Proposition 2.3.2 \& 2.3.11}
\lb
For every linear transformation $\map{V}[T]{W}$
\begin{enumerate}
    \item $\ker(T)$ is a subspace in $V$
    \item $\tx{im}(T)$ is a subspace in $W$.
\end{enumerate}
\begin{proof}
\end{proof}

\vspace{300pt}
\lb
\textbf{Proposition 2.3.7}
\lb
The subspace $\ker(T)$ is the solution space to the homogeneous system of $[T]_α^β$.
\begin{proof}
\end{proof}

\vspace{200pt}
\lb
\textbf{Example}
\lb
Example of computation to find $\ker(T)$

\newpage
\lb
\textbf{Observation}
\lb
The subspace $\tx{im}(T)$ is the space of all $ \vec b ∈ \R^n$ such that the system
$[T]_α^β \vec x = \vec b$ has a solution.

\vspace{200pt}
\lb
\textbf{Proposition 2.3.12}
\lb
If $ \cb{\vec v_1, \ldots, \vec v_k}$ spans $V$, then $ \cb{T(\vec v_1), \ldots, T(\vec v_k)}$
spans $\tx{im}(T)$.
\begin{proof}
\end{proof}

\vspace{200pt}
\lb
\textbf{Definition}
\lb
For a matrix $A = [ a_1, a_2, \ldots, a_m] ∈ \mat{n, m}{\R}$ we denote
the span of the columns of $A$ by
\[ \tx{col}(A) = \spn{a_1, \ldots, a_m} \]

\lb
\textbf{Proposition}
\lb
For every linear transformation $\map{V}[T]{W}$
\[ \tx{im}(T) = \tx{col}([T]_α^β) \]
\begin{proof}
\end{proof}

\newpage
\lb
\textbf{Example}
\lb
Example computation to find $\tx{im}(T)$

\vspace{300pt}
\lb
Notice that the columns might not be independent,
in which case the columns are a spanning set of the image, but not a basis.

\lb
\textbf{Theorem}
\lb
Given a linear transformation $\map{V}[T]{W}$ with matrix $[T]_α^β$ for some bases $α$ and $β$.
Let $R = \tx{RREF}([T]_α^β)$ be the reduced row echolon form of $[T]_α^β$.
\lb
Then if the leading 1s in are $R$ lie in columns
$j_1, j_2,\ldots, j_r$, the columns $j_1, j_2,\ldots, j_r$ of $[T]_α^β$ are a basis for
$ \tx{col}([T]_α^β)$
\begin{proof}
\end{proof}

\vspace{100pt}
\lb
\textbf{Discussion}
\lb
Suppose a linear transformation $\map{V}[T]{W}$ is given in a some bases $α$ and $β$ by
\[ [T]_α^β = \begin{pmatrix} 1 & 2 & 0 & 1 \\ 1 & 2 & 1 & 0 \end{pmatrix} \]
Find a basis for $\tx{im}(T)$ and $\ker(T)$.

\newpage
\lb
\textbf{Theorem 2.3.17 (Rank-Nullity)}
\lb
For any linear transformation $\map{V}[T]{W}$
\[ \dim(V) = \dim(\ker(T)) + \dim( \tx{im}(T)) \]

\lb
\textbf{Remark}
\begin{itemize}
    \item
        $\dim( \tx{im}(T))$ is the same as the rank of $[T]_α^β$ and by abuse of
        notation also referred to as $\tx{rank}(T)$.
    \item
        Some books refer to $\dim(\ker(T))$ as the \emph{nullity} of $T$.
\end{itemize}

\begin{proof}
\end{proof}

\vspace{300pt}
\lb
\textbf{Theorem}
\lb
A linear transformation $T$ is injective if and only if $\ker(T) = \cb{\vec 0}$
\begin{proof}
\end{proof}

\newpage
\lb
\textbf{True or False}
Let $\map{V}[T]{W}$ be a linear transformation
\begin{enumerate}
    \item[$\square$]
        If $T$ is an isomorphism, then $\dim(V) = \dim(W)$.
    \item[$\square$]
        If $\dim(V) > \dim(W)$, $T$ has to be injective.
    \item[$\square$]
\end{enumerate}

\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz}
\setlength{\parindent}{0pt}

\newtheorem*{theorem}{Theorem}
\newtheorem*{definition}{Definition}
\newtheorem*{lemma}{Lemma}
\newtheorem*{corollary}{Corollary}
\newtheorem{example}{Example}
\newtheorem*{trick}{Trick}
\newtheorem*{question}{Question}

\title{Lecture 16: Double Integrals}
\author{}
\date{}

\begin{document}

\maketitle

\section{Definition of Double Integrals}

For single-variable functions, we use integral to calculate the area under the
function curve. For a multivariable function with two independent variables
$z = f(x, y)$, we define double integrals to calculate the volume under the
function graph over a region $R$ in the $x$$y$-plane. The notation is
$\iint_R f(x, y)dA$.

\bigskip

Definition of double integrals:

If we cut the region $R$ into small pieces of area $\Delta A_i$, then the volume
can be calculated as
\begin{equation*}
  V \approx \sum_i f(x_i, y_i) \Delta A_i
\end{equation*}
If we take the limit of $\Delta A_i$ to 0, then it becomes the double integral
\begin{equation*}
  \iint_R f(x, y) dA = \lim_{\Delta A_i \to 0} \sum_i f(x_i, y_i) \Delta A_i
\end{equation*}

\section{Calculation of Double Integrals}

To compute a double integral $\iint_R f(x, y) dA$, we can take slices of the
function graph along one dimension and use integral to get the area of slices.
In this way, the area of all slices becomes a function of another dimension,
then we can use the integral again to sum up those slices to get the volume.

More concretely, let $S(x)$ denote the area of slices by plane parallel to
$y$$z$-plane. Then
\begin{equation*}
  \iint_R f(x, y) dA = \int_{x_min}^{x_max} S(x) dx
\end{equation*}
For a given $x_0$, the area of the slice
\begin{equation*}
  S(x_0) = \int_{y_min(x_0)}^{y_max(x_0)} f(x, y) dy
\end{equation*}
Therefore, the double integral
\begin{equation*}
  \begin{split}
    \iint_R f(x, y) dA &= \int_{x_min}^{x_max} S(x) dx \\
                       &= \int_{x_min}^{x_max} \int_{y_min(x_0)}^{y_max(x_0)} f(x, y) dy dx
  \end{split}
\end{equation*}
This calculation method is called \textbf{iterated integral}, because we iterate
twice through both dimensions to get the integral.

Notice that the bounds of the outer integral are numbers, and the bounds of the
inner integral are numbers or functions depending on the variable of the outer
integral. The bounds of both outer and inner integrals are determined by the
region of the double integral.

\section{Examples of Double Integral}

\begin{example}
  Find the value of the double integral of the function $z = 1 - x^2 - y^2$ over
  the region $R$ as $0 \leq x \leq 1$, $0 \leq y \leq 1$.

  Solution:

  By using iterated integrals,
  \begin{equation*}
    \iint_R f(x, y) dA = \int_0^1 \int_0^1 1 - x^2 - y^2 dy dx
  \end{equation*}
  For the inner integral,
  \begin{equation*}
    \begin{split}
      \int_0^1 1 - x^2 - y^2 dy &= (y - x^2y - \frac{y^3}{3})|_0^1 \\
                                &= 1 - x^2 - \frac{1}{3} \\
                                &= \frac{2}{3} - x^2 \\
    \end{split}
  \end{equation*}
  For the outer integral,
  \begin{equation*}
    \begin{split}
      \int_0^1 \frac{2}{3} - x^2 dx &= (\frac{2x}{3} - \frac{x^3}{3})|_0^1 \\
                                    &= \frac{2}{3} - \frac{1}{3} \\
                                    &= \frac{1}{3} \\
    \end{split}
  \end{equation*}
  Therefore, the value of the double integral is $\frac{1}{3}$.
\end{example}

\begin{example}
  Find the value of the double integral of the function $z = 1 - x^2 - y^2$ over
  the region $R$ as
  \begin{equation*}
    \begin{cases}
      x^2 + y^2 \leq 1 \\
      x \geq 0 \\
      y \geq 0 \\
    \end{cases}
  \end{equation*}

  By the equation of the region $R$, we can get that for any given $x_0$, the
  range of $y$ in the region $R$ is $[0, \sqrt{1 - x^2}]$.

  By using iterated integrals,
  \begin{equation*}
    \iint_R f(x, y) dA = \int_0^1 \int_0^{\sqrt{1 - x^2}} 1 - x^2 - y^2 dy dx
  \end{equation*}
  For the inner integral,
  \begin{equation*}
    \begin{split}
      \int_0^{\sqrt{1 - x^2}} 1 - x^2 - y^2 dy &= (y - x^2y - \frac{y^3}{3})|_0^{\sqrt{1 - x^2}} \\
                                               &= \sqrt{1 - x^2} - x^2\sqrt{1 - x^2} - \frac{(1 - x^2)^{\frac{3}{2}}}{3}\\
                                               &= \frac{2}{3}(1 - x^2)^{\frac{3}{2}} \\
    \end{split}
  \end{equation*}
  For the outer integral,
  \begin{equation*}
    \begin{split}
      \int_0^1 \frac{2}{3}(1 - x^2)^{\frac{3}{2}} dx &= \int_0^{\frac{\pi}{2}} \frac{2}{3}(1 - \sin^2\theta)^{\frac{3}{2}} d(\sin\theta) \\
                                                     &= \frac{2}{3} \int_0^{\frac{\pi}{2}} \cos^4\theta d\theta \\
                                                     &= \frac{2}{3} \int_0^{\frac{\pi}{2}} (\frac{1 + \cos 2\theta}{2})^2 d\theta \\
                                                     &= \frac{1}{6} \int_0^{\frac{\pi}{2}} (1 + 2\cos2\theta + \cos^2 2\theta) d\theta \\
                                                     &= \frac{1}{6} \int_0^{\frac{\pi}{2}} (1 + 2\cos2\theta + \frac{1 + \cos 4\theta}{2}) d\theta \\
                                                     &= \frac{1}{12} \int_0^{\frac{\pi}{2}} (3 + 4\cos2\theta + \cos 4\theta) d\theta \\
                                                     &= \frac{1}{12} (3\theta + 2\sin2\theta + \frac{1}{4}\cos 4\theta)|_0^{\frac{\pi}{2}} \\
                                                     &= \frac{1}{12} \cdot \frac{3\pi}{2} \\
                                                     &= \frac{\pi}{8} \\
    \end{split}
  \end{equation*}
  Therefore, the value of the double integral is $\frac{\pi}{8}$.
\end{example}

\section{Exchange the Order of Iterated Integrals}

In theory, no matter in which order we calculate the iterated integral, the
values always exist and are the same. However, in practice an order requires
much more complex computation than the other; sometimes we might not even be
able to compute the double integral with a specific order, but able to do it
with the other order. Therefore, we need to be mindful about the order of
iterated integral we use.

In some cases, we can exchange the order of an iterated integral, with some
adaption to the bounds of integrals.

\begin{example}
  \begin{equation*}
    \int_0^1 \int_0^2 dx dy = \int_0^2 \int_0^1 dy dx
  \end{equation*}
  For rectangle regions, the bounds of the inner integral don't depend on the
  variable of the outer integral, so we can exchange the inner integral and
  outer integral freely.

  From the perspective of the definition of iterated integrals, for rectangle
  regions, slices of either direction don't change the set of small pieces of
  area $dA_i$ to sum up.
\end{example}

\begin{example}
  Find the value of $\int_0^1 \int_x^{\sqrt{x}} \frac{e^y}{y} dy dx$.

  It is too difficult to calculate $\int_x^{\sqrt{x}} \frac{e^y}{y} dy$, so we
  need to consider exchanging the order of integrals.

  By looking at the region, we derive that
  \begin{equation*}
    \int_0^1 \int_x^{\sqrt{x}} \frac{e^y}{y} dy dx = \int_0^1 \int_{y^2}^y \frac{e^y}{y} dx dy
  \end{equation*}
  and the one on the right-hand side is doable.

  For the inner integral,
  \begin{equation*}
    \begin{split}
      \int_{y^2}^y \frac{e^y}{y} dx &= \frac{xe^y}{y}|_{y^2}^y \\
                                    &= e^y - ye^y \\
    \end{split}
  \end{equation*}
  For the outer integral,
  \begin{equation*}
    \begin{split}
      \int_0^1 e^y - ye^y dy &= (2e^y - ye^y)|_0^1 \\
                             &= 2e - e - 2 \\
                             &= e - 2 \\
    \end{split}
  \end{equation*}
  Therefore, the value of $\int_0^1 \int_x^{\sqrt{x}} \frac{e^y}{y} dy dx$ is
  $e - 2$.
\end{example}

\end{document}


\chapter{Bonus: Let's solve Pell's equation!}
This is an optional aside, and can be safely ignored.
(On the other hand, it's pretty short.)

\section{Units}
\prototype{$\pm 1$, roots of unity, $3-2\sqrt2$ and its powers.}
Recall according to \Cref{prob:OK_unit_norm} that $\alpha \in \OO_K$ is invertible
if and only if \[ \NK(\alpha) = \pm 1. \]
We let $\OO_K^\times$ denote the set of units of $\OO_K$.

\begin{ques}
	Show that $\OO_K^\times$ is a group under multiplication.
	Hence we name it the \vocab{unit group} of $\OO_K$.
\end{ques}

What are some examples of units?
\begin{example}
	[Examples of units in a number field]
	\listhack
	\begin{enumerate}
		\ii $\pm 1$ are certainly units, present in any number field.

		\ii If $\OO_K$ contains a root of unity $\omega$ (i.e.\ $\omega^n=1$),
		then $\omega$ is a unit.
		(In fact, $\pm 1$ are special cases of this.)

		\ii Of course, not all units of $\OO_K$ are roots of unity.
		For example, if $\OO_K = \ZZ[\sqrt3]$ (from $K = \QQ(\sqrt3)$) then
		the number $2+\sqrt3$ is a unit, as its norm is
		\[ \NK(2+\sqrt3) = 2^2 - 3 \cdot 1^2 = 1. \]
		Alternatively, just note that the inverse $2-\sqrt3 \in \OO_K$ as well:
		\[ \left( 2-\sqrt3 \right)\left( 2+\sqrt3 \right) = 1. \]
		Either way, $2-\sqrt3$ is a unit.

		\ii Given any unit $u \in \OO_K^\times$, all its powers are also units.
		So for example, $(3-2\sqrt2)^n$ is always a unit of $\ZZ[\sqrt2]$, for any $n$.
		If $u$ is not a root of unity, then this generates infinitely many new units in $\OO_K^\times$.
	\end{enumerate}
\end{example}

\begin{ques}
	Verify the claims above that
	\begin{enumerate}[(a)]
		\ii Roots of unity are units, and
		\ii Powers of units are units.
	\end{enumerate}
	One can either proceed from the definition
	or use the characterization $\NK(\alpha) = \pm 1$.
	If one definition seems more natural to you, use the other.
\end{ques}

\section{Dirichlet's unit theorem}
\prototype{The units of $\ZZ[\sqrt3]$ are $\pm(2+\sqrt3)^n$.}

\begin{definition}
	Let $\mu(\OO_K)$ denote the set of roots of unity
	contained in a number field $K$ (equivalently, in $\OO_K$).
\end{definition}
\begin{example}[Examples of $\mu(\OO_K)$]
	\listhack
	\begin{enumerate}[(a)]
		\ii If $K = \QQ(i)$, then $\OO_K = \ZZ[i]$. So
		\[ \mu(\OO_K) = \{\pm1, \pm i\} \quad\text{where } K = \QQ(i). \]
		\ii If $K = \QQ(\sqrt3)$, then $\OO_K = \ZZ[\sqrt 3]$. So
		\[ \mu(\OO_K) = \{\pm 1\} \quad\text{where } K = \QQ(\sqrt 3). \]
		\ii If $K = \QQ(\sqrt{-3})$, then $\OO_K = \ZZ[\half(1+\sqrt{-3})]$.
		So
		\[ \mu(\OO_K)
			= \left\{ \pm 1, \frac{\pm 1 \pm \sqrt{-3}}{2} \right\}
			\quad\text{where } K = \QQ(\sqrt{-3})
		\]
		where the $\pm$'s in the second term need not depend on each other;
		in other words $\mu(\OO_K) = \left\{ z \mid z^6=1 \right\}$.
	\end{enumerate}
\end{example}
\begin{exercise}
	Show that we always have that $\mu(\OO_K)$
	comprises the roots to $x^n-1$ for some integer $n$.
	(First, show it is a finite group under multiplication.)
\end{exercise}

We now quote, without proof, the so-called Dirichlet's unit theorem,
which gives us a much more complete picture of what the units in $\OO_K$ are.
Legend says that Dirichlet found the proof of this theorem
during an Easter concert in the Sistine Chapel.
\begin{theorem}
	[Dirichlet's unit theorem]
	Let $K$ be a number field with signature $(r_1, r_2)$ and set
	\[ s = r_1 + r_2 - 1. \]
	Then there exist units $u_1$, \dots, $u_s$ such that every unit
	$\alpha \in \OO_K^\times$ can be written \emph{uniquely} in the form
	\[ \alpha = \omega \cdot u_1^{n_1} \dots u_s^{n_s} \]
	for $\omega \in \mu(\OO_K)$ is a root of unity,
	and $n_1, \dots, n_s \in \ZZ$.
\end{theorem}
More succinctly:
\begin{moral}
We have $\OO_K^\times \cong \ZZ^{r_1+r_2-1} \times \mu(\OO_K)$.
\end{moral}
A choice of $u_1$, \dots, $u_s$ is called a choice of \vocab{fundamental units}.

Here are some example applications.
\begin{example}
	[Some unit groups]
	\listhack
	\begin{enumerate}[(a)]
		\ii Let $K = \QQ(i)$ with signature $(0,1)$.
		Then we obtain $s = 0$, so Dirichlet's Unit theorem says that there are no
		units other than the roots of unity.
		Thus
		\[ \OO_K^\times = \{\pm 1, \pm i\} \quad\text{where } K = \QQ(i). \]
		This is not surprising,
		since $a+bi \in \ZZ[i]$ is a unit if and only if $a^2+b^2 = 1$.

		\ii Let $K = \QQ(\sqrt 3)$, which has signature $(2,0)$.
		Then $s=1$, so we expect exactly one fundamental unit.
		A fundamental unit is $2+\sqrt3$ (or $2-\sqrt3$, its inverse) with norm $1$, and so we find
		\[ \OO_K^\times = \left\{ \pm (2+\sqrt3)^n \mid n \in \ZZ \right\}.  \]

		\ii Let $K = \QQ(\sqrt[3]{2})$ with signature $(1,1)$.
		Then $s=1$, so we expect exactly one fundamental unit.
		The choice $1 + \sqrt[3]{2} + \sqrt[3]{4}$. So
		\[ \OO_K^\times
			= \left\{ \pm \left( 1+\sqrt[3]{2}+\sqrt[3]{4} \right)^n \mid n \in \ZZ \right\}. \]
	\end{enumerate}
\end{example}

I haven't actually shown you that these are fundamental units,
and indeed computing fundamental units is in general hard.

\section{Finding fundamental units}
Here is a table with some fundamental units.
\[
	\begin{array}{rl}
		d & \text{Unit} \\ \hline
		d=2 & 1+\sqrt 2 \\
		d=3 & 2+\sqrt3 \\
		d=5 & \half(1+\sqrt5) \\
		d=6 & 5+2\sqrt6 \\
		d=7 & 8+3\sqrt7 \\
		d=10 & 3+\sqrt{10} \\
		d=11 & 10+3\sqrt11
	\end{array}
\]

In general, determining fundamental units is computationally hard.

However, once I tell you what the fundamental unit is, it's not too bad
(at least in the case $s=1$) to verify it.
For example,
suppose we want to show that $10 + 3\sqrt{11}$ is a fundamental unit of $K = \QQ(\sqrt 11)$,
which has ring of integers $\ZZ[\sqrt{11}]$.
If not, then for some $n > 1$, we would have to have
\[ 10 + 3 \sqrt{11} = \pm \left( x+y\sqrt{11} \right)^n. \]
For this to happen, at the very least we would need $\left\lvert y \right\rvert < 3$.
We would also have $x^2-11y^2 = \pm 1$.
So one can just verify (using $y= 1,2$) that this fails.

The point is that: Since $(10,3)$ is the \emph{smallest}
(in the sense of $\left\lvert y \right\rvert$)
integer solution to $x^2-11y^2 = \pm 1$, it must be the fundamental unit.
This holds more generally, although in the case that $d \equiv 1 \pmod 4$
a modification must be made as $x$, $y$ might be half-integers (like $\half(1+\sqrt5)$).
\begin{theorem}
	[Fundamental units of pell equations]
	Assume $d$ is a squarefree integer.
	\begin{enumerate}[(a)]
		\ii If $d \equiv 2,3 \pmod 4$,
		and $(x,y)$ is a minimal integer solution to $x^2-dy^2 = \pm 1$,
		then $x + y \sqrt d$ is a fundamental unit.
		\ii If $d \equiv 1 \pmod 4$,
		and $(x,y)$ is a minimal \emph{half-integer} solution to $x^2-dy^2 = \pm 1$,
		then $x + y \sqrt d$ is a fundamental unit.
		(Equivalently, the minimal integer solution to $a^2 - db^2 = \pm 4$
		gives $\half (a + b \sqrt d)$.)
	\end{enumerate}
	(Any reasonable definition of ``minimal'' will work, such as sorting by $\left\lvert y \right\rvert$.)
\end{theorem}

\section{Pell's equation}
This class of results completely eradicates Pell's Equation.
After all, solving
\[ a^2 - d \cdot b^2 = \pm 1 \]
amounts to finding elements of $\ZZ[\sqrt d]$ with norm $\pm 1$.
It's a bit weirder in the $d \equiv 1 \pmod 4$ case, since in that case $K = \QQ(\sqrt d)$
gives $\OO_K = \ZZ[\half(1+\sqrt d)]$, and so the fundamental unit may not actually be a solution.
(For example, when $d = 5$, we get the solution $(\half, \half)$.)
Nonetheless, all \emph{integer} solutions are eventually generated.

To make this all concrete, here's a simple example.
\begin{example}[$x^2-5y^2 = \pm 1$]
	Set $K = \QQ(\sqrt 5)$, so $\OO_K = \ZZ[\half(1+\sqrt 5)]$.
	By Dirichlet's unit theorem, $\OO_K^\times$ is generated by a single element $u$.
	The choice
	\[ u = \frac 12 + \frac 12 \sqrt 5 \]
	serves as a fundamental unit,
	as there are no smaller integer solutions to $a^2-5b^2=\pm 4$.

	The first several powers of $u$ are
	\[
	\begin{array}{rrr}
		\renewcommand{\arraystretch}{1.4}
		n & \multicolumn{1}{c}{u^n} & \text{Norm} \\ \hline
		-2 & \half(3-\sqrt5) & 1 \\
		-1 & \half (1-\sqrt5) & -1 \\
		0 & 1 & 1 \\
		1 & \half(1+\sqrt5) & -1 \\
		2 & \half(3+\sqrt5) & 1 \\
		3 & 2 + \sqrt 5 & -1 \\
		4 & \half(7+3\sqrt5) & 1 \\
		5 & \half(11+5\sqrt5) & -1 \\
		6 & 9 + 4\sqrt 5 & 1
	\end{array}
	\]
	One can see that the first integer solution is $(2,1)$, which gives $-1$.
	The first solution with $+1$ is $(9,4)$.
	Continuing the pattern, we find that every third power of $u$ gives an integer solution
	(see also \Cref{prob:unit_cubed}),
	with the odd ones giving a solution to $x^2-5y^2=-1$ and
	the even ones a solution to $x^2-5y^2=+1$.
	All solutions are generated this way, up to $\pm$ signs
	(by considering $\pm u^{\pm n}$).
\end{example}

\section\problemhead
\begin{problem}[Fictitious account of the battle of Hastings]
	Determine the number of soldiers in the following battle:
	\begin{quote}
		The men of Harold stood well together,
		as their wont was, and formed thirteen squares,
		with a like number of men in every square thereof, and woe
		to the hardy Norman who ventured to enter their redoubts;
		for a single blow of Saxon war-hatched would break his lance
		and cut through his coat of mail . . .
		when Harold threw himself into the fray the Saxons
		were one might square of men, shouting the battle-cries,
		``Ut!'', ``Olicrosse!'', ``Godemite!''
	\end{quote}
	% The answer can be found by hand.
	% You may assume that the army has size at least $1$ and
	% at most one billion.
\end{problem}
\begin{problem}
	\label{prob:unit_cubed}
	Let $d > 0$ be a squarefree integer,
	and let $u$ denote the fundamental unit of $\QQ(\sqrt d)$.
	Show that either $u \in \ZZ[\sqrt d]$,
	or $u^n \in \ZZ[\sqrt d] \iff 3 \mid n$.
\end{problem}
\begin{problem}
	Show that there are no integer solutions to
	\[ x^2 - 34y^2 = -1 \]
	despite the fact that $-1$ is a quadratic residue mod $34$.
\end{problem}