\input{Setup.tex}
\begin{document}

\mainmatter

MFRs \today \\
Msc Thesis - Dynamics of adaptive neuronal networks. \\
Simon Aertssen (s181603), \today \\

\section{Writing out the whole system}
The network dynamics are described as follows:
\begin{align}
\frac{d \theta_i}{d t} &= (1 - \cos\theta_i) + (1 + \cos\theta_i)\cdot\left(\eta_i + I_i \right) \qquad \theta_i \in \T^N \nonumber \\
I_{i} &= \frac{\kappa}{\langle k\rangle} \sum_{j=1}^{N} A_{i j} P_{n}\left(\theta_{j}\right) \label{eq:FullThetaNeuronNetwork} \\
P_{n}\left(\theta_{j}\right) &= a_n (1 - \cos\theta_j) \nonumber
\end{align}

We observe synchronisation through the order parameter
\begin{align}
Z(t) = \frac{1}{N} \sum_{j=1}^N e^{\ic\theta_j}  \qquad Z(t) \in \C \label{eq:orderparameter}
\end{align}

For a fixed degree network it has been proven that the order parameter follows:
\begin{align}
\dot{Z}(t)= -\ic \frac{(Z-1)^2}{2}+\frac{(Z+1)^2}{2} \cdot \left(-\Delta+ \ic\eta_{0}
+ \ic \kappa \cdot \left(1+\frac{Z^{2} + \overline{Z}^{2} }{6} - \frac{4}{3} \Re(Z)\right)\right) \label{eq:MeanField}
\end{align}

For an arbitrary network the order parameter follows a trajectory per degree. When we assemble the whole expression for the Ott-Antonsen manifold as found in \cite{OttAntonsen2017} with $H_2(\k,t)$ as in \cite{Martens2020}, we obtain the following:
\begin{align}
\frac{\partial z(\k, t)}{\partial t} &= -\ic \frac{(z(\k, t)-1)^{2}}{2} + \frac{(z(\k, t)+1)^{2}}{2} \cdot I(\k, t) \qquad z(\k,t) \in \C^{M_\k} \nonumber \\
%I(\k) &= -\Delta(\k) + \ic \eta_{0}(\k) + i d_{n} \kappa \cdot H_n(\k,t) \label{eq:OttAntonsenSystemFull} \\
%H_n(\k,t) &= \frac{a_n}{\kmean} \sum_{\kacc} P\left(\kacc\right) a\left(\kacc \rightarrow \k\right) \cdot \left[A_{0}+\sum_{p=1}^{n} A_{p}\left(z\left(\kacc, t\right)^{p} + \overline{z}\left(\kacc, t\right)^{p}\right)\right]
I(\k, t) &= -\Delta(\k) + \ic \eta_{0}(\k) + i \kappa \cdot H_2(\k,t) \label{eq:OttAntonsenSystemFull} \\
H_2(\k,t) &= \frac{1}{\kmean} \sum_{\kacc} P\left(\kacc\right) a\left(\kacc \rightarrow \k\right) \cdot \left( 1 + \frac{z(\kacc, t)^2 + \overline{z}(\kacc, t)^2}{6} - \frac{4}{3} \Re(z(\kacc, t)) \right) \nonumber
\end{align}

$\k$ represents a two-dimensional vector of the in- an out degree as $\k = ( \kin, \kout)$ and has unique entries as it forms the support of the vector of degrees of \eqref{eq:FullThetaNeuronNetwork} as $\degree(\theta_i)$. So $z(\k,t)$ is really a vector in the complex plane that represents the mean-field dynamics on any node with degree $\k$, so we could also index as $z(t)_{\k}$. $\kacc$ represents $\k$ when $\k$ is already in use.\\

We can then find the mean field dynamics through
\begin{align}
\overline{Z}(t) &= \frac{1}{N} \sum_{\k} P(\k) z(\k, t) \qquad \overline{Z}(t) \in \C \label{eq:OttAntonsenMeanField}
\end{align}

It is important to notice that in \eqref{eq:OttAntonsenSystemFull} and \eqref{eq:OttAntonsenMeanField} we actually compute an inner vector product, which is non-commutative for complex numbers:
\begin{align}
a \cdot b = \overline{b \cdot a} \qquad a, b \in \C^r
\end{align}
This is the result of the \textsl{Conjugate} or \textsl{Hermitian} symmetry of the inner product. This is especially important in the \matlab implementation.

\section{Initial conditions}
As the systems in \cref{eq:FullThetaNeuronNetwork,eq:orderparameter,eq:MeanField,eq:OttAntonsenSystemFull,eq:OttAntonsenMeanField} describe the same dynamics for fully connected networks, it is important to be able to transform initial conditions between systems. When transforming from $\theta_i(t) \rightarrow z(\k,t) \rightarrow Z(t)$ we go from $\T^N \rightarrow \C^{M_\k}$ to $\C^{M_\k} \rightarrow \C$. If we have the same initial conditions, then all systems will predict the same behaviour. We will only map everything to $\C$.\\
The following maps can be used to transform the initial conditions, but as they do not give any qualitative information on the dynamics or distributions of the variables, they are not valid for transforming between dynamics. We discard $t=0$ for clarity. \\
Mapping operations onto the order parameter in the complex plane is straightforward:
\begin{align*}
\theta_i \xrightarrow{\hspace*{8mm}} Z &= \frac{1}{N} \sum_{j=1}^N e^{\ic\theta_j} \\
z(\k) \longrightarrow Z &= \frac{1}{N} \sum_{\k} P(\k) z(\k, t)
\end{align*}

Taking the inverse maps, we can make use of the fact that the average of a set of identical values is the value itself. For $z(\k)$ we have a weighed average which we need to undo, making sure that the whole sums up to $N$.
\begin{align*}
Z \xrightarrow{\hspace*{9mm}} \theta_{i} &= -\ic \cdot \log \left( Z \right) \\
Z \longrightarrow z(\k) &= \overline{\frac{Z \cdot n(\k)}{P(\k)}}
\end{align*}

Then, transferring between $\theta_i$ and $z(\k)$, we need to filter $\theta_i$ per degree:
\begin{align*}
z(\k) \longrightarrow \theta_i &= -\ic \cdot \log \left( \frac{z(\k)\cdot P(\k)}{n(\k)} \right) \qquad \text{ if } \degree(\theta_i) = \k \\
\theta_i \longrightarrow z(\k) &= \sum_{\k} e^{\ic \vartheta_{\k}} \qquad \qquad \vartheta_{\k} = \sum_{i = 1}^{n(\k)} \theta_i \in
\left\{ \theta_i \vert \degree(\theta_i) = \k, \forall i \leq N \right\}
\end{align*}
%Or also $\sum_i^N A_{ij} = k^{\rm in} \cup \sum_j^N A_{ij} = \kout$.

We can see how $\lim_{N \rightarrow +\infty} n(\k) = P(\k)$, which makes these maps exact for any network size.

%\newpage
%\section{Phase space}
%\subsection{Fixed degree networks}
%In the phase space, we can clearly distinguish three macroscopic states for the mean field:
%\begin{figure}[H]
%\minipage{0.32\textwidth}
%  \includegraphics[width=\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFRPSR.png}
%  \caption{PSR state}\label{fig:MFRPSR}
%\endminipage\hfill
%\minipage{0.32\textwidth}
%  \includegraphics[width=\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFRPSS.png}
%  \caption{PSS state}\label{fig:MFRPSS}
%\endminipage\hfill
%\minipage{0.32\textwidth}%
%  \includegraphics[width=\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFRCPW.png}
%  \caption{CPW state}\label{fig:MFRCPW}
%\endminipage
%\end{figure}
%For different networks this can look a little different.
%
%\subsection{Random networks}
%\begin{figure}[H]
%\minipage{0.32\textwidth}
%  \includegraphics[width=\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARPSR_random.png}
%  \caption{PSR state}\label{fig:MFRPSR}
%\endminipage\hfill
%\minipage{0.32\textwidth}
%  \includegraphics[width=\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARPSS_random.png}
%  \caption{PSS state}\label{fig:MFRPSS}
%\endminipage\hfill
%\minipage{0.32\textwidth}%
%  \includegraphics[width=\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARCPW_random.png}
%  \caption{CPW state}\label{fig:MFRCPW}
%\endminipage
%\end{figure}
%
%\subsection{Scale Free networks}
%\begin{figure}[H]
%\minipage{0.32\textwidth}
%  \includegraphics[width=\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARPSR_scalefree.png}
%  \caption{PSR state}\label{fig:MFRPSR}
%\endminipage\hfill
%\minipage{0.32\textwidth}
%  \includegraphics[width=\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARPSS_scalefree.png}
%  \caption{PSS state}\label{fig:MFRPSS}
%\endminipage\hfill
%\minipage{0.32\textwidth}%
%  \includegraphics[width=\linewidth, trim={2cm 1cm 2cm 1.5cm },clip]{../Figures/PhaseSpace/MFOARCPW_scalefree.png}
%  \caption{CPW state}\label{fig:MFRCPW}
%\endminipage
%\end{figure}
%
%
%\section{Differences between theory and practice}
%\begin{figure}[H]
%  \includegraphics[width=\linewidth]{../Figures/InspectMeanFieldFullyConnected.pdf}
%  \caption{Mean field descriptions of fully connected networks.}\label{fig:InspectMeanFieldFullyConnected}
%\end{figure}
%
%\begin{figure}[H]
%  \includegraphics[width=\linewidth]{../Figures/InspectMeanFieldFixedDegree.pdf}
%  \caption{Mean field descriptions of fixed degree networks.}\label{fig:InspectMeanFieldFixedDegree}
%\end{figure}
%
%\begin{figure}[H]
%  \includegraphics[width=\linewidth]{../Figures/InspectMeanFieldRandom.pdf}
%  \caption{Mean field descriptions of random networks.}\label{fig:InspectMeanFieldRandom}
%\end{figure}
%
%\begin{figure}[H]
%  \includegraphics[width=\linewidth]{../Figures/InspectMeanFieldScaleFree.pdf}
%  \caption{Mean field descriptions of scale-free networks.}\label{fig:InspectMeanFieldScaleFree}
%\end{figure}
%
%\begin{figure}[H]
%  \includegraphics[width=\linewidth]{../Figures/testScaleFree.png}
%  \caption{The scale-free networks seem to converge to different limit cycles.}\label{fig:testScaleFree}
%\end{figure}
%
%\begin{figure}[H]
%  \includegraphics[width=\linewidth]{../Figures/InspectMeanFieldLogNorm.pdf}
%  \caption{Mean field descriptions of log-normal networks.}\label{fig:InspectMeanFieldLogNorm}
%\end{figure}

\section{Fixpoint iteration}
In \cite{OttAntonsen2017} a fixpoint iteration is suggested to find attractive fixpoints of the system \eqref{eq:OttAntonsenSystemFull}. If we set $\frac{\partial z(\k, t)}{\partial t} = 0$ we can solve the following system:
\begin{align}
\ic \frac{(z(\k, t)-1)^{2}}{2} &= \frac{(z(\k, t)+1)^{2}}{2} \cdot I(\k) \nonumber \\
\ic \left(\frac{z(\k, t)-1}{z(\k, t)+1}\right)^2 &= I(\k) \nonumber \\
\frac{z(\k, t)-1}{z(\k, t)+1} &\equiv b(\k,t) \nonumber \\
z(\k, t) - 1 &= b(\k,t) z(\k, t) + b(\k,t)  \nonumber \\
z(\k, t) \cdot (1 - b(\k,t)) &= b(\k,t)  + 1\nonumber
\end{align}

We can then obtain the stable equilibria from:
\begin{align}
\ic b(\k,t)^2 = I(\k) \hspace{10mm} z(\k, t)_{\pm} = \frac{1 \pm b(\k,t)}{1 \mp b(\k,t)} \label{eq:fixedpointiterations}
\end{align}
where the signs are chosen so that $\vert z(\k, t) \vert \leq 1$. This works.

\section{A Newton-Raphson iteration for all fixpoints}
\subsection{Theory behind the method}
The fixpoint iteration only gives us the stable equilibria of the system \eqref{eq:OttAntonsenSystemFull}. We can obtain all equilibria and the Jacobian from a Newton-Raphson iteration. We define the equilibria $\boldsymbol{x^\ast} \in \R^n$ of a multivariate function $\boldsymbol{f}(\boldsymbol{x}) : \R^n \rightarrow \R^n$ with $\boldsymbol{f}(\boldsymbol{x}) = \boldsymbol{0}$. Expanding $\boldsymbol{f}$ as a Taylor series, we obtain:
\begin{align}
f_i(\boldsymbol{x} + \delta \boldsymbol{x}) =f_{i}(\boldsymbol{x}) + \sum_{j=1}^{n} \frac{\partial f_{i}(\boldsymbol{x})}{\partial x_{j}} \delta x_{j}+O\left(\delta \boldsymbol{x}^{2}\right) \approx f_{i}(\boldsymbol{x})+\sum_{j=1}^{n} \frac{\partial f_{i}(\boldsymbol{x})}{\partial x_{j}} \delta x_{j}, \qquad (i=1, \cdots, n)
\end{align}

We can also write this in vector notation, by setting $\boldsymbol{J}(\boldsymbol{x}) = \nabla \boldsymbol{f}(\boldsymbol{x}) = \frac{d}{d\boldsymbol{x}} \boldsymbol{f}(\boldsymbol{x}) \in \R^{n \times n}$
\begin{align}
\boldsymbol{f}(\boldsymbol{x}+\delta \boldsymbol{x}) &\approx\left[\begin{array}{c}f_{1}(\boldsymbol{x}) \\ \vdots \\ f_{N}(\boldsymbol{x})\end{array}\right]
+ \left[\begin{array}{ccc}\frac{\partial f_{1}}{\partial x_{1}} & \cdots & \frac{\partial f_{1}}{\partial x_{N}} \\ \vdots & \ddots & \vdots \\ \frac{\partial f_{N}}{\partial x_{1}} & \cdots & \frac{\partial f_{N}}{\partial x_{N}}\end{array}\right]
\left[\begin{array}{c}\delta x_{1} \\ \vdots \\ \delta x_{N}\end{array}\right]
=\boldsymbol{f}(\boldsymbol{x})+\boldsymbol{J}(\boldsymbol{x}) \delta \boldsymbol{x}
\end{align}

By assuming $\boldsymbol{f}(\boldsymbol{x}+\delta \boldsymbol{x}) = 0$ we can find that $\delta \boldsymbol{x} = -\boldsymbol{J}^{-1}( \boldsymbol{x}) \boldsymbol{f}(\boldsymbol{x})$ so that $\boldsymbol{x} + \delta \boldsymbol{x} =  \boldsymbol{x} - \boldsymbol{J}^{-1} (\boldsymbol{x}) \boldsymbol{f}(\boldsymbol{x})$. This expression converges to $\boldsymbol{x^\ast}$. When the equations are nonlinear, the equations converge to the real root as $\boldsymbol{x}_k =  \boldsymbol{x}_k - \boldsymbol{J}^{-1} ( \boldsymbol{x}_k)\boldsymbol{f}(\boldsymbol{x}_k)$. \\

For \eqref{eq:OttAntonsenSystemFull}, we can compute the Jacobian for the diagonal and off-diagonal elements separately. But as $z(\k,t)$ is a complex function, first we need to understand what the derivative of a complex function is.

\subsection{Derivatives of complex functions}
For $z = x + \ic y \in \C$ and $x,y \in R$ the conjugate is defined as $\overline{z} = x - \ic y$. That means that we can write the real and imaginary parts as:
\begin{align*}
x = \frac{z + \overline{z}}{2} \text{  and   }   y = -\ic \frac{z - \overline{z}}{2}
\end{align*}
Using the chain rule, we can write the partial derivative with respect to $z$ in function of $x$ and $y$ as $x$ and $y$ are functionally independent and find the first Wirtinger operator:
\begin{align*}
\frac{\partial}{\partial z} =\frac{\partial x}{\partial z} \frac{\partial}{\partial x}+\frac{\partial \bar{y}}{\partial z} \frac{\partial}{\partial \overline{y}}
\longrightarrow \frac{\partial x}{\partial z} = \frac{1}{2} \text{   and   } \frac{\partial y}{\partial z} =  - \frac{\ic}{2}
\longrightarrow \frac{\partial}{\partial z} = \frac{1}{2}\left(\frac{\partial}{\partial x} - \ic \frac{\partial}{\partial y}\right)
\end{align*}
We note the following properties:
\begin{align*}
\frac{\partial}{\partial z} z = 1 \hspace{10mm} \frac{\partial}{\partial z}\overline{z} = \frac{1}{2}\left(1 - \ic^2 \right) = 0
\end{align*}
Interesting for is the result of the following:
\begin{align*}
\overline{z}^2 &= (x - \ic y)^2 = x^2 - y^2 - \ic 2xy \\
\frac{\partial}{\partial z} \overline{z}^2 &=  \frac{1}{2}\cdot(2x -\ic 2y - \ic\cdot(-2y -\ic 2x)) = x -\ic y + \ic y -\ic x = 0
\end{align*}

\subsection{Derivatives of the complex mean field equations}
We can now compute derivatives of the complex functions $z(\k,t)$. We will set $z(\k, t) = z_{\k}$ and rewrite system \eqref{eq:OttAntonsenSystemFull} to help the reader:
\begin{align}
\frac{\partial z_{\k}}{\partial t} &= -\ic \frac{(z_{\k}-1)^{2}}{2} + \frac{(z_{\k}+1)^{2}}{2} \cdot I_{\k} \qquad z_{\k} \in \C^{M_\k} \nonumber \\
%I(\k) &= -\Delta(\k) + \ic \eta_{0}(\k) + i d_{n} \kappa \cdot H_n(\k,t) \label{eq:OttAntonsenSystemFull} \\
%H_n(\k,t) &= \frac{a_n}{\kmean} \sum_{\kacc} P\left(\kacc\right) a\left(\kacc \rightarrow \k\right) \cdot \left[A_{0}+\sum_{p=1}^{n} A_{p}\left(z\left(\kacc, t\right)^{p} + \overline{z}\left(\kacc, t\right)^{p}\right)\right]
I_{\k} &= -\Delta_{\k} + \ic \eta_{0_{\k}} + i \kappa \cdot H_{2_{\k}} \label{eq:OttAntonsenSystemFull_k} \\
H_{2_{\k}} &= \frac{1}{\kmean} \sum_{\kacc} P_{\k} a_{\kacc \k} \cdot \left( 1 + \frac{z_{\kacc}^2 + \overline{z}_{\kacc}^2}{6} - \frac{4}{3} \Re(z_{\kacc}) \right) \nonumber
\end{align}

The diagonal elements are found as:
\begin{equation}
\begin{aligned}[b]
\frac{\partial}{\partial z_{\k}}\left(\frac{\partial z_{\k}}{\partial t} \right) &= - \ic(z_{\k} - 1) + (z_{\k} + 1) \cdot I_{\k} +  \frac{(z_{\k}+1)^{2}}{2} \cdot \frac{\partial I(z_{\k})}{\partial z_{\k}} \\
\frac{\partial I_{\k}}{\partial z_{\k}} &= \ic \kappa \cdot \frac{\partial H_{2_{\k}}}{\partial z_{\k}} \\
\frac{\partial H_{2_{\k}}}{\partial z_{\k}} &= \frac{1}{\kmean} P_{\k} a_{\k \k} \cdot \left(\frac{2 z_{\k}}{6} - \frac{4}{3} \cdot \frac{1}{2} \right) = \frac{1}{\kmean} P_{\k} a_{\k \k} \cdot\frac{z_{\k} - 2}{3}
\end{aligned}
\label{eq:OttAntonsenSystemJacobianDiagonal}
\end{equation}

The off-diagonal elements are found as
\begin{equation}
\begin{aligned}[b]
\frac{\partial}{\partial z_{\kacc}}\left(\frac{\partial z_{\k}}{\partial t} \right) &= \frac{(z_{\k} + 1)^{2}}{2} \cdot \frac{\partial I_{\k}}{\partial z_{\kacc}} \\
\frac{\partial I_{\k}}{\partial z_{\kacc}} &= \ic \kappa \cdot \frac{\partial H_{2_{\k}}}{\partial z_{\kacc}} \\
\frac{\partial H_{2_{\k}}}{\partial z_{\kacc}} &= \frac{1}{\kmean} P_{\kacc} a_{\kacc \k} \cdot \frac{z_{\kacc} - 2}{3}
\end{aligned}
\label{eq:OttAntonsenSystemJacobianOffDiagonal}
\end{equation}

\subsection{First results}
I cannot seem to converge close enough.
\begin{figure}[H]
\centering
\includegraphics[width = 0.75\textwidth]{../Figures/ProblemsWithNewtonRaphson.png}
\end{figure}

The reason that this method does not work is because the field $H_2(\k,t)$ is non-holomorphic. We can verify this with the Cauchy-Riemann equations:
\begin{align*}
z(\k,t) &= x(\k,t) + \ic \cdot y(\k,t)\\
f\left( z(\k,t) \right) &= u\left(x(\k, t), y(\k, t) \right) + \ic v\left(x(\k, t), y(\k, t) \right)\\
&= \frac{1}{\kmean} \sum_{\kacc} P\left(\kacc\right) a\left(\kacc \rightarrow \k\right) \cdot \left( 1 + \frac{z(\kacc, t)^2 + \overline{z}(\kacc, t)^2}{6} - \frac{4}{3} \Re(z(\kacc, t)) \right)\\
&= \frac{1}{\kmean} \sum_{\kacc} P\left(\kacc\right) a\left(\kacc \rightarrow \k\right) \cdot \left( 1 + \frac{x(\kacc, t)^2}{3} - \frac{4}{3} x(\kacc, t) \right)
\end{align*}
This leaves us with only $u$ defined as a real-valued function, so that the Cauchy-Riemann equations do not hold: the function is non-holomorphic.

\subsection{Mapping onto $\R^2$}
$\bar{z}_{\k}$ and $\Re(z_{\k})$ are non-holomorphic. Try again by separating the real and imaginary part: \\
$z(\k,t) = x(\k,t) + \ic y(\k,t)$.
\begin{align*}
\dot{x_{\k}}
&=f_{\k} \left(x_{\k}, y_{\k}, \eta_{0}, \Delta, \kappa \right) \\
&=(x_{\k}-1) y_{\k}-\frac{(x_{\k}+1)^{2}-y_{\k}^{2}}{2} \Delta-(x_{\k}+1) \cdot y_{\k} \cdot \left[\eta_{0}+ \kappa \cdot H_{2_{\k}}\right] \\
\dot{y_{\k}} &= g_{\k} \left(x_{\k}, y_{\k}, \eta_{0}, \Delta, \kappa \right) \\
&=-\frac{(x_{\k}-1)^{2}-y_{\k}^{2}}{2}-(x_{\k}+1) y_{\k} \Delta+\frac{(x_{\k}+1)^{2}-y_{\k}^{2}}{2} \cdot \left[\eta_{0} + \kappa \cdot H_{2_{\k}} \right]
\end{align*}

The Jacobian can then be found from taking the derivatives?
\begin{align*}
\frac{\partial f_{\k}}{\partial x_{\k}} &= y_{\k}-(x_{\k}+1) \cdot \Delta-y_{\k} \cdot \left[\eta_{0} + \kappa \cdot H_{2_{\k}} \right] - (x_{\k}+1) \cdot y_{\k} \cdot \left(\kappa \cdot \frac{\partial H_{2_{\k}}}{\partial x_{\k}}\right)\\
\frac{\partial f_{\k}}{\partial y_{\k}} &= (x_{\k}-1)+y_{\k} \cdot \Delta-(x_{\k}+1) \cdot \left[\eta_{0} + \kappa \cdot H_{2_{\k}} \right] \\
\frac{\partial g_{\k}}{\partial x_{\k}} &= -(x_{\k} - 1) - y_{\k} \cdot \Delta + (x_{\k} + 1) \cdot \left[\eta_{0} + \kappa \cdot H_{2_{\k}} \right] + \left( \frac{(x_{\k} + 1)^2 - y_{\k}^2}{2} \right) \cdot \left(\kappa \cdot \frac{\partial H_{2_{\k}}}{\partial x_{\k}}\right) \\
\frac{\partial g_{\k}}{\partial y_{\k}} &= y_{\k} - (x_{\k} + 1)\cdot \Delta - y_{\k} \cdot \left[\eta_{0} + \kappa \cdot H_{2_{\k}} \right] \\
\frac{\partial H_{2_{\k}}}{\partial x_{\k}} &= \frac{1}{\langle k\rangle} P_{\k} a_{\k \k} \cdot(x_{\k}-2) \cdot \frac{2}{3} \\
\frac{\partial H_{2_{\k}}}{\partial y_{\k}} &= 0
\end{align*}

And the off-diagonal elements:
\begin{align*}
\frac{\partial f_{\k}}{\partial x_{\kacc}} &= - (x_{\k}+1) \cdot y_{\k} \cdot \left(\kappa \cdot \frac{\partial H_{2_{\k}}}{\partial x_{\kacc}}\right)\\
\frac{\partial f_{\k}}{\partial y_{\kacc}} &= 0 \\
\frac{\partial g_{\k}}{\partial x_{\kacc}} &= \left( \frac{(x_{\k} + 1)^2 - y_{\k}^2}{2} \right) \cdot \left(\kappa \cdot \frac{\partial H_{2_{\k}}}{\partial x_{\kacc}}\right) \\
\frac{\partial g_{\k}}{\partial y_{\kacc}} &= 0\\
\frac{\partial H_{2_{\k}}}{\partial x_{\kacc}} &= \frac{1}{\langle k\rangle} P_{\kacc} a_{\kacc \k} \cdot(x_{\kacc}-2) \cdot \frac{2}{3} \\
\frac{\partial H_{2_{\k}}}{\partial y_{\kacc}} &= 0
\end{align*}

What dimensions does the Jacobian have now? $2 n \times 2 n$.

\subsection{From the order parameter}
What if we take the Jacobian straight from the OA order parameter? If $z(\k,t) = x(\k,t) + \ic y(\k,t)$:
\begin{align}
\overline{Z}(t) &= \frac{1}{N} \sum_{\k} P(\k) \cdot \left( x(\k,t) + \ic y(\k,t) \right) = \frac{1}{N} \sum_{\k} P(\k) x(\k,t) + \ic \frac{1}{N} \sum_{\k} P(\k) y(\k,t)
\end{align}

\bibliographystyle{utphys}
\small{\bibliography{references}}

\label{LastPage}~

\end{document}


\documentclass{article}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}{Definition}[section]

\begin{document}
\paragraph{}Things to study:
\begin{itemize}
    \item Point.
    \item Distance between points.
    \item Line.
    \item Plane.
    \item
\end{itemize}
\section{Linear algebra}
\begin{definition}{(Dot).}
is an abstract idea to represent a place on a nth dimension.
\end{definition}
\paragraph{} On one dimension we can say that a dot is an $x \in S$ on which $S$ is a set. Similarly on the two and three dimension we have:
$$(x,y) \in S^{2},$$
$$(x,y,z) \in S^{3},$$
In general we will be working from now on with the real numbers: $\mathbb{R}^n$, where $n$ is the dimension.
\subsection{Operations}
\begin{definition}{Addition (+)}
Given two points $P_1$ and $P_2$, we say that the addition of these two points will be equal to some other point. And it is represented as:
$$P_1 + P_2 = P_3,$$
also a more general on nth dimension sum will be:
$$(x_1, y_1, z_1, \dots, m_1) + (x_2, y_2, z_2, \dots, m_2) = (x_1 + x_2, y_1 + y_2, z_1 + z_2, \dots, m_1 + m_2)$$
\end{definition}
\begin{definition}{Dot Product ($\cdot$)}
Given two points $P_1$ and $P_2$, we say that the addition of these two points will be equal to some scalar k. Then
$$P_1 = (x_1, y_1, z_1, \dots, m_1), P_2 = (x_2, y_2, z_2, \dots, m_2)$$
\begin{align*}
    P_1 \cdot P_2 &= P_3\\
    (x_1, y_1, z_1, \dots, m_1) \cdot (x_2, y_2, z_2, \dots, m_2) &=  x_1 x_2 + y_1 y_2 + z_1 z_2 + \dots + m_1 m_2
\end{align*}
\end{definition}
\begin{definition}{Scalar product}
The scalar product is...
\end{definition}
\end{document}


%
% 150
%
\chapter{Asymptotic Expansions and Summable Series}

\Section{Simple example of an asymptotic expansion.}

Consider the function $f(x) = \int_{x}^{\infty} t^{-1} e^{x-t}
\dmeasure t$, where $x$ is real and positive, and the path of
integration is the real axis.

By repeated integrations by parts, we obtain
$$
f(x) = \frac{1}{x} - \frac{1}{x^{2}} + \frac{2!}{x^{3}} - \cdots +
\frac{ (-)^{n-1} (n-1)!}{x^{n}} + (-)^{n} n! \int_{x}^{\infty}
\frac{e^{x-t} \dmeasure t}{t^{n+1}}.
$$

In connexion with the function $f(x)$, we therefore consider the
expression
$$
u_{n-1} = \frac{ (-)^{n-1} (n-1)!}{x^{n}},
$$
and we shall write
$$
\sum_{m=0}^{n} u_{m} = \frac{1}{x} - \frac{1}{x^{2}} +
\frac{2!}{x^{3}} - \cdots + \frac{ (-)^{n} n!}{x^{n+1}} = S_{n}(x).
$$
Then we have $\absval{u_{m}/u_{m-1}} = mx^{-1} \rightarrow \infty$.
\emph{The series $\sum u_{m}$ is therefore divergent for all values of
$x$}. In spite of this, however, the series can be used for the
calculation of $f(x)$; this can be seen in the following way.

Take any fixed value for the number $n$, and calculate the value of
$S_{n}$. We have
$$
f(x) - S_{n}(x) = (-)^{n+1} (n+1)! \int_{x}^{\infty} \frac{e^{x-t}
\dmeasure t}{t^{n+2}},
$$
and therefore, since $e^{x-t} \leq 1$,
$$
\absval{ f(x) - S_{n}(x) } = (n+1)! \int_{x}^{\infty} \frac{e^{x-t}
\dmeasure t}{t^{n+2}} < (n+1)! \int_{x}^{\infty} \frac{\dmeasure
t}{t^{n+2}} = \frac{n!}{x^{n+1}}.
$$
For values of $x$ which are sufficiently large, the right-hand member
of this equation is very small. Thus, if we take $x \geq 2n$, we have
$$
\absval{ f(x) - S_{n}(x)} < \frac{1}{2^{n+1} n^{2}},
$$
which for large values of $n$ is very small. It follows therefore that
\emph{the value of the function $f(x)$ can he calculated with great
accuracy for large values of $x$, by taking the sum of a suitable
number of terms of the series $\sum u_{m}$}.

Taking even fairly small values of $x$ and $n$
$$
S_{5}(10) = 0.09152, \quad 0 < f(10) - S_{5}(10) < 0.00012.
$$
%
% 151
%

The series is on this account said to be an asymptotic expansion of
the function $f(x)$. The precise definition of an asymptotic expansion
will now be given.

\Section{Definition of an asymptotic expansion.} A divergent series
$$
A_{0} + \frac{A_{1}}{z} + \frac{a_{2}}{z^{2}} + \cdots +
\frac{A_{n}}{z^{n}} + \cdots,
$$
in which the sum of the first $(n + 1)$ terms is $S_{n}$, is said to
be an \emph{asymptotic expansion} of a function $f(z)$ for a given
range of values of $\arg$, if the expression $R_{n}(z) = z^{n}[f(z) -
S_{n}(z)]$ satisfies the condition
$$
\lim_{ \absval{z} \rightarrow \infty } R_{n}(z) = 0 \quad (\textrm{$n$
fixed}),
$$
even though
$$
\lim_{n \rightarrow \infty} \absval{R_{n}(z)} = \infty \quad
(\textrm{$z$ fixed}).
$$
When this is the case, we can make
$$
\absval{ z^{n} [f(z) - S_{n}(z)] } < \eps,
$$
where $\eps$ is arbitrarily small, by taking $\absval{z}$ sufficiently
large.

We denote the fact that the series is the asymptotic expansion of
$f(z)$ by writing
$$
f(z) \sim \sum_{n=0}^{\infty} A_{n} z^{-n}.
$$

The definition which has just been given is due to
\Poincare\footnote{TODO}. Special asymptotic expansions had, however,
been discovered and used in the eighteenth century by Stirling,
Maclaurin and Euler. Asymptotic expansions are of great importance in
the theory of Linear Differential Equations, and in Dynamical
Astronomy; some applications will be given in subsequent chapters of
the present work.

The example discussed in \hardsectionref{8}{1} clearly satisfies the
definition just given: for, when $x$ is positive, $\absval{x^{n} [f(x)
- S_{n}(x)]} < n! x^{-1} \rightarrow 0$ as $x \rightarrow \infty$.

%\begin{Remark} For the sake of simplicity, in this chapter we shall
for the most part consider asymptotic expansions only in connexion
with real positive values of the argument. The theory for complex
values of the argument may be discussed by an extension of the
analysis.

\Subsection{Another example of an asymptotic expansion.} As a second
example, consider the function $f(x)$, represented by the series
$$
f(x) = \sum_{k=1}^{\infty} \frac{c^{k}}{x+k},
$$
where $x > 0$ and $0 < c < 1$.

%
% 152
%

The ratio of the $k$th term of this series to the $(k- l)$th is less
than $c$, and consequently the series converges for all positive
values of $x$. We shall confine our attention to positive values of
$x$. We have, when $x > k$,
$$
\frac{1}{x+k} = \frac{1}{x} - \frac{k}{x^{2}} + \frac{k^{2}}{x^{3}} -
\frac{k^{3}}{x^{4}} + \frac{k^{4}}{x^{5}} - \cdots.
$$

If, therefore, it were allowable\footnote{It is not allowable, since
$k>x$ for all terms of the series after some definite term.} to expand
each fraction $\frac{1}{x+k}$ in this way, and to rearrange the series
for $f(x)$ in descending powers of $x$, we should obtain the formal
series
$$
\frac{A_{1}}{x} + \frac{A_{2}}{x^{2}} + \cdots + \frac{A_{n}}{x^{n}} +
\cdots,
$$
where
$$
A_{n} = (-)^{n-1} \sum_{k=1}^{\infty} k^{n-1} c^{k}.
$$
But this procedure is not legitimate, and in fact $\sum_{n=1}^{\infty}
A_{n} x^{-n}$ diverges. We can, however, shew that it is an asymptotic
expansion of $f(x)$.

For let
$$
S_{n}(x) = \frac{A_{1}}{x} + \frac{A_{2}}{x^{2}} + \cdots +
\frac{A_{n}}{x^{n}} %TODO: verify correct subscript; book is
inconsistent
$$

Then S\{x)= i ('- -4 + lf + ... + izyi)

k = l\ \ xj J x + k'

so that TODO

Now TODO converges for any given value of n and is equal to C, say;
and hence fc=i

TODO

Consequently TODO

Example. If TODO, where x is positive and the path of integration is
the

J X

real axis, prove that

TODO

[In fact, it was shewn by Stokes in 1857 that

TODO

the upper or lower sign is to be taken according as TODO. ]
%\end{Remark}
\Section{Multiplication of asymptotic expansions.}

We shall now shew that two asymptotic expansions, valid for a common
range of values of arg', can be multiplied together in the same way
as ordinary series, the result being a new asymptotic expansion.

TODO

For let TODO

%
% 153
%
and let Sn\{z) and Tn\{z) be the sums of their first (n + 1) terms; so
that, n being fixed,

f(z) - Sn (Z) = (Z-X <t> (Z) - Tn \{z) = (z).

Then, if C = om + iB,n-i + . . . + mo. it is obvious that*

SJz)Tn\{z)= i C,nZ--+0(z-).

But f\{z) Cf> (Z) = \{Sn (Z) + (Z-)] [Tn \{z) + (-»)\}

= Sn \{Z) Tn (Z) + (Z-)

TO =

This result being true for any fixed value of n, we see that

TODO

\Subsection{Integration of asymptotic expansions.}

We shall now shew that it is permissible to integrate an asymptotic
expansion term by term, the resulting series being the asymptotic
expansion of the integral of the function represented by the original
series.

For let TODO and let TODO.

TODO

Then, given any positive number e, we can find Xq such that TODO when
x>Xo,

and therefore

TODO

But TODO and therefore TODO.

On the other hand, it is not in general permissible t to
diflFerentiate an asymptotic expansion; this may be seen by
considering TODO.

\Subsection{Uniqueness of an asymptotic expansion.}

A question naturally suggests itself, as to whether a given series can
be

* See \hardsubsectionref{2}{1}{1}; we use o (2~") to denote any function i/- (z) such that
3" i/- (2) -»- as | 2, -*- x . t For a theorem concerning
differentiation of asymptotic expansions representing analytic
functions, see Kitt, Bull. American Math. Soc. xxiv. (1918), pp.
225-227.

%
% 154
%

the asymptotic expansion of several distinct functions. The answer to
this is in the affirmative. To shew this, we first observe that there
are functions L \{x) which are represented asymptotically by a series
all of whose terms are zero, i.e. functions such that lim xL \{x) =
for every fixed value of n. The

TODO

function e~ is such a function when x is positive. The asymptotic
expansion* of a function J\{x) is therefore also the asymptotic
expansion of

J\{x) + L(x).

On the other hand, a function cannot be represented by more than one
distinct asymptotic expansion over the whole of a given range of
values of z; for, if

TODO

then TODO

which can only be if TODO,

Important examples of asymptotic expansions will be discussed later,
in connexion with the Gamma-function (Chapter xii) and Bessel
functions (Chapter xvii).

\Section{Methods of 'summing' series.}

We have seen that it is possible to obtain a development of the form

f(x)= i A,,x~'" + R,,\{x),

m =

00

where Rn(x)- co as ?i- > oo, and the series S) A.,nX~ does not
converge.

m =

We now consider what meaning, if any, can be attached to the ' sum '
of a non- convergent series. That is to say, given the numbers ao,
a, a, ..., we wish to formulate definite rules by which we can
obtain from them a

TODO

number 8 such that S = 'S, an if 2 a converges, and such that aS'
exists

TODO

when this series does not converge.

\Subsection{Borel's method of summation.} We have seen \hardsubsectionref{7}{8}{1}) that

00 /"»

2 anz"" = e-(f) (tz) dt,

n=0 J

where (tz) = X ", the equation certainly being true inside; the
circle

00

of convergence of S az'. If the integral exists at points z
outside this circle, we define the ' Borel sum ' of S a,i2" to mean
the integral.

* It has been shewn that when the coefficients in the expansion
satisfy certain inequaUties, there is only one analytic function with
that asymptotic expansion. See PJiil. Trans. 213, a, (1911), pp.
279-313.

t Borel, Leo)is stir les Series Diveryentes (1901), pp. 97-115.

%
% 155
%

Thus, whenever R(z)< I, the ' Bore] sum ' of the series S 2'' is

»=o

1 e-*e''dt = \{l-z)-\

J

If the ' Borel sum ' exists we say that the series is ' summable (B).'

\Subsection{Elder's* method of summation.} A method, practically due
to Euler, is suggested by the theorem of \hardsectionref{3}{7}l;

00 00

the ' sum ' of S a,i may be defined as lim S ctn' when this limit
exists.

n=0 2:-1-0 n=0

Thus the ' sum ' of the series 1 - 1 + 1 - 1 + ... would be lim (1 - X
+ cc- - ...) = lim (1 + x)~ = i.

\Subsection{Cesdro's-f method of summation.}

Let Sn = «! + ao + . . . + «n; then if S = lim - (s, + Sj +    +
n) exists, we say that S Un is 'summable (C'l),' and that its sum
(CI) is S. It is necessary to establish the 'condition of
consistency;!:,' namely that S= 2 a when this series is convergent.

00 n

To obtain the required result, let TODO, then we have

m = l m = l

to prove that TODO.

Given e, we can choose n such that

so TODO

Then, if i > n, we have

n+p

% a,

m=n-rl

< e for all values of p, and

TODO

Since TODO is a positive decreasing sequence, it follows from Abel's
inequality \hardsubsubsectionref{2}{3}{0}{1}) that

TODO

Therefore

TODO

* Instit. Cale. Diff. (1755). See Borel, loc. cit. Introduction, t
Bulletin des Sciences Math. (2), xiv. (1890), p. 114. + See the end of \hardsectionref{8}{4}.

%
% 156
%
Making v-x, we see that, if S be any one of the limit points (§
2'21) of S, then

n I

S - % a,  e. Therefore, since | s - 5,1 ! < e, we have

This inequality being true for every positive value of e we infer, as
in\hardsubsectionref{2}{2}{1}, that S =s; that is to say S has the unique limit s;
this is the theorem which had to be proved.

Example 1. Frame a definition of 'uuiforui .summability (Cl) of a
series of variable terms.'

Example 2. TODO

\Subsubsection{TODO:Cesdrds general method of summation.}

A series TODO is said to be 'summable (Cr)' if TODO exists, where

It follows from \hardsubsectionref{8}{4}{3} example 2 that the 'condition of consistency'
is satisfied; in fact it can be proved* that if a series is summable
(C/) it is also summable \{Cr) when r>r'; the condition of consistency
is the particular case of this result when r = 0.

\Subsection{The method of summation of Rieszi.}

A more extended method of ' summing ' a series than the preceding is
by means of

hm 2 ( 1 - - cin,

in which X,i is any real function of n which tends to infinity with n.
A series for which this limit exists is said to be 'summable \{Rr)
with sum-function X.'

\Section{Hardy's convergence theorem.}

s summable ( a,i=0(l/?i),

Let S an he a series tuhick is summable \{G 1). Then if

w=l

the series TODO converges.

n=\

* Bromwich, Infinite Series, § 122. t Comptes Rendus, cxlix. (1910),
pp. 18-21.

X Proc. London Math. Sac. (2), viii. (1910), pp. 302-304. For the
proof here given, we are indebted to Mr Littlewood.

Let Sn = a I + a. +. + cin; then since S Un is summable \{G 1), we
have

%
% 157
%

M = l

Si + So+ ... + Sn = n[s + (l)j,

where s is the sum ((71) of X «».

Let TODO and let

Sm-s = t,a, \{m = l, 2, ... n),

ti + to+ ... +tn = (Tn

With this notation, it is sufficient to shew that, if j a | < Kn~,
where K is independent of n, and if On = n.o (1), then tn -> sis n ->
cc .

Suppose first that a, a, ... are real. Then, if tn does not tend
to zero, there is some positive number h such that there are an
unlimited number of the numbers t,i which satisfy either (i) t > h
or (ii) tn < -h. We shall shew that either of these hypotheses implies
a contradiction. Take the former*, and choose n so that tn > h.

Then, when r = 0, 1,2,

< K/n.

Now plot the points P,. whose coordinates are (r, tn+r) in a Cartesian
diagram. Since tnr+i-tn+r = an+r+i, the slope of the line PrPr+i is
less than = arc tan (K/n).

Therefore the points Pq, Pj, P.,, ... lie above the line y = h - xtan
6. Let Pk be the last uf the points P, Pj, ... which lie on the left
of a;'= hcot 6, so that TODO.

Draw rectangles as shewn in the figure. The area of these rectangles
exceeds the area of the triangle bounded by y = h - x tan 6 and the
axes; that is to say

TODO

* The reader will see that the latter hypothesis involves a
contradiction by using arguments of a precisely similar character to
those which will be employed in dealing with the former hypothesis.

%
% 158
%

But I (Tn+k - 0"7i-i ! < I 0'7i+A; ! + I n-i \

= (n + k).o\{l) + \{n-l).o(l) = n.o\{l), since k  hnK~, and h, K
are independent of n.

Therefore, for a set of values of n tending to infinity,

h-K~n <n.o\{l), which is impossible since h'-K~ is )iot o (1)
as /i-> x .

This is the contradiction obtained on the hypothesis that lim tn> h >
0; therefore Urn tn  0. Similarly, by taking the corresponding case
in which tn - h, we arrive at the result lim tn  0. Therefore
since lim tn > lim tn,

we have lim t = lim tn = 0,

and so tn - > 0.

That is to say Sn -> s, and so 2 a,i is convergent and its sum is s.

If an be complex, we consider R (a) and / (a) separately, and find

TODO

that S R\{an) and S /(c/) converge by the theorem just proved, and so
TODO

The reader will see in Chapter ix that this result is of great
importance in the modern theory of Fourier series.

Corollary. If TODO be a function of TODO such that TODO

throughout a domain of values of TODO, and if TODO, where K is
independent of |,

2 a () converges uniformly throughoxit the domain. n=i

For, retaining the notation of the preceding section, if n() does
not tend to zero uniformly, we can find a positive number h
independent of n and | such that an infinite sequence of values of n
can be found for which t (») > A or i () <-h for some point
TODO of the domain*; the value of  depends on the value of n under
consideration.

We then find, as in the original theorem,

TODO

for a set of values of n tending to infinity. The contradiction
implied in the inequality shews that h does not exist, and so
rt(|)-9-0 uniformly.

* It is assumed that « () is real; the extension to complex
variables cau be made as in the former theorem. If no such number h
existed, < (|) would tend to zero uniformly.

t It is essential to observe that the constants involved iu the
inequality do not depend on |,j. For if, say, K depended on TODO
would really be a function of n and might be o (1) qua function of n,
and the inequality would not imply a contradiction.

%
% 159
%

REFERENCES.

H. PoiNCAR, Acta Mathematica, viii. (1886), pp. 295-344.

E. BoREL, Lecons sur les Series Divergentes (Paris, 1901).

T. J. Pa. Bromwich, Theory of Infinite Series (1908), Ch. xi.

E. W. Barnes, Phil. Trans, of the Royal Society, 206, a (1906), pp.
249-297.

G. H. Hardy and J. E. Littlewood, Proc. London Math. Soc. (2), xi.
(1913), pp. 1-16*.

G. N. Watson, Phil. Trans, of the Royal Society, 213, a (1911), pp.
279-313.

S. Chapman +, Proc. London Math. Soc. (2), ix. (1911), pp. 369-409.

Miscellaneous Examples.

/" e~ 1 2 ! 4 !

:; :idt~ - ~ + - - ...

when X is real and positive.

2. Discuss the representation of the function

f(x)=\{'' <\{t)e-dt

(where x is supposed real and positive, and is a function subject to
certain general con- ditions) by means of the series

TODO

Shew that in certain cases (e.g. ((;) = e'") the series is
absolutely convergent, and represents TODO for large positive values
of $x$ but that in certain other cases the series is the asymptotic
expansion of $f(x)$.

3. Shew that

for large positive values of z.

TODO

(Legendre, Exerdces de Calc. Int. (1811), p. 340.) 4. Shew that if,
when x>0,

TODO

Shew also that/(.r) can be expanded into an absolutely convergent
series of the form

TODO \addexamplecitation{\Schlomilch.}

' ' A.=i(+l)(.r-i-2)...( + -\}

5. Shew that if the series 1+0 + 0-1+04-1 + + 0-1 + ..., in which two
zeros precede each -1 and one zero precedes each +1, be 'summed' by
Ceskro's method, its sum is f. \addexamplecitation{Euler, Borel.}

6. Shew that the series 1-21 + 4! - ... cannot be summed by Borel's
method, but the series l+0-2! + + 4! + ... can be so summed.

* This paper contains many references to recent developments of the
subject. t A bibliography of the literature of summable series will be
found on p. 372 of this memoir.


\documentclass[serif,xcolor=pdftex,dvipsnames,table,hyperref={bookmarks=false,breaklinks}]{beamer}

\input{../config.tex}

\settitlecard{6}{NumPy 2}

\begin{document}
\lstset{style=custompython}

\maketitlepage
%
% \section{Announcements}
% \subsection{Foo}
%
% \begin{frame}[t]{Announcements}
% 	\begin{itemize}
% 		\item Assignment 2 is due tonight at 11:55pm.
% 		\item Quiz 3 will be posted tonight and due next Tuesday.
% 		\item Assignment 3 will go out tomorrow and will be due next Thursday.
% 	\end{itemize}
% \end{frame}

\section{Shape Manipulation and Broadcasting}
\subsection{Foo}

\begin{frame}[t,fragile]{Shape Manipulation}
	% reshape, resize, ravel, flat, T, -1 for auto reshaping
	NumPy provides various functions for changing the shape/size of an array. The most basic is \verb|reshape| which returns an array with a new shape.
	\pause
	\begin{lstlisting}
		>>> A = np.arange(9)
		>>> A
		array([0, 1, 2, 3, 4, 5, 6, 7, 8])
		>>> A.reshape((3,3))
		array([[0, 1, 2],
		       [3, 4, 5],
		       [6, 7, 8]])

		>>> A.shape = (3,3)
		>>> A
		array([[0, 1, 2],
		       [3, 4, 5],
		       [6, 7, 8]])
	\end{lstlisting}
\end{frame}

\begin{frame}[t]{Shape Manipulation}
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide7}.png}
\end{frame}

\begin{frame}[t,fragile]{Shape Manipulation}
	% reshape, resize, ravel, flat, T, -1 for auto reshaping
	Python allows you to specify a \textbf{single} unknown dimension using $-1$.
	\pause
	\begin{lstlisting}
		>>> A = np.arange(6)
		>>> A.
		>>> A.reshape((2,-1))
		array([[0, 1, 2],
		       [3, 4, 5]])
		>>> A.reshape((-1,2))
		array([[0, 1],
		       [2, 3],
		       [4, 5]])
	\end{lstlisting}
\end{frame}

% \begin{frame}[t,fragile]{Shape Manipulation}
% 	% reshape, resize, ravel, flat, T, -1 for auto reshaping
% 	Python allows you to specify a \textbf{single} unknown dimension using $-1$.
% 	\pause
% 	\begin{lstlisting}
% 		>>> A = np.arange(6)
% 		>>> A.reshape((2,-1))
% 		array([[0, 1, 2],
% 		       [3, 4, 5]])
% 		>>> A.reshape((-1,2))
% 		array([[0, 1],
% 		       [2, 3],
% 		       [4, 5]])
% 	\end{lstlisting}
% \end{frame}

% \begin{frame}[t]{Shape Manipulation}
% 	% resize
% \end{frame}

\begin{frame}[t,fragile]{Shape Manipulation}
	% reshape, resize, ravel, flat, T, -1 for auto reshaping
	Other useful functions return specific shapes:
	\pause
	\begin{lstlisting}
		>>> A.ravel()
		array([0, 1, 2, 3, 4, 5])

		>>> A.transpose() # Also use a.T
		array([[0, 3],
		       [1, 4],
		       [2, 5]])
	\end{lstlisting}
\end{frame}

\begin{frame}[t,fragile]{Fancy Indexing}
	% Indexing with arrays of bools
  	NumPy arrays can be indexed with arrays of booleans. This is sometimes called \emph{masking}.

	\pause
	\begin{lstlisting}
		>>> A = np.arange(10)
		>>> B = (A%2) == 0
		>>> A[B] # Select all even numbers
		array([0, 2, 4, 6, 8])

		>>> A = np.array([[0,-1],[2,3],[-3,2]])
		>>> A
		array([[ 0, -1],
		       [ 2,  3],
		       [-3,  2]])
		>>> B = A.sum(1) < 0
		>>> A[B,:] # Select all rows whose sum is < 0
		array([[ 0, -1],
		       [-3,  2]])
	\end{lstlisting}
\end{frame}

\begin{frame}[t,fragile]{Fancy Indexing}
	% Indexing with arrays of ints
	% Q: what happens to element assignment when index list contains duplicates?
  	Arrays can also be indexed using other \textbf{integer} arrays.

	\pause
	\begin{lstlisting}
		>>> A = 2*np.arange(10)
		>>> B = np.array([1,4,5,7])
		>>> A[B]
		array([ 2,  8, 10, 14])

		>>> A = np.arange(6).reshape((2,3))
		>>> A
		array([[0, 1, 2],
		       [3, 4, 5]])
		>>> B = np.array([0,0,1])
		>>> C = np.array([1,2,2])
		>>> A[B,C] # One array for each dimension
		array([1, 2, 5])
	\end{lstlisting}
\end{frame}

% \begin{frame}[t]{Interactive Demo}
% \end{frame}

\begin{frame}[t,fragile]{Broadcasting}
	In most cases, when the shapes of two arrays do not match, NumPy will not let you perform elementwise operation between them.
	\pause
	\begin{lstlisting}
		>>> A = np.arange(6).reshape((2,3))
		>>> A
		array([[0, 1, 2],
		       [3, 4, 5]])
		>>> B = np.arange(5)
		>>> A * B
		Traceback (most recent call last):
		  File "<stdin>", line 1, in <module>
		ValueError: operands could not be broadcast together with shapes (2,3) (5,)
	\end{lstlisting}
\end{frame}

\begin{frame}[t,fragile]{Broadcasting}
	In some special cases, NumPy will replicate one or more of the inputs so that it can perform the desired operation. This is called \textbf{broadcasting}.
	\pause
	\begin{lstlisting}
		>>> A = np.arange(6).reshape((2,3))
		>>> A
		array([[0, 1, 2],
		       [3, 4, 5]])
		>>> B = np.arange(3)
		>>> A * B # B is copied for each row of A
		array([[ 0,  1,  4],
		       [ 0,  4, 10]])
	\end{lstlisting}
\end{frame}

\begin{frame}[t]{Broadcasting}
	% Broadcasting 2d
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide08}.png}
\end{frame}

\begin{frame}[t]{Broadcasting}
	% Broadcasting 2d
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide09}.png}
\end{frame}

\begin{frame}[t]{Broadcasting}
	% Broadcasting 2d
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide10}.png}
\end{frame}

\begin{frame}[t]{Broadcasting}
	% Broadcasting 2d
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide11}.png}
\end{frame}

\begin{frame}[t]{Broadcasting}
	% Broadcasting 2d
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide12}.png}
\end{frame}

\begin{frame}[t]{Broadcasting}
	% Broadcasting 2d
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide13}.png}
\end{frame}

\begin{frame}[t,fragile]{Interactive Demo}
	\centering
	\Huge{Interactive Demo}
	\normalsize
	\begin{enumerate}
		\item How do you set all of the negative elements in an array to zero?
		\item Recall that you can set an entire slice of an array by using indexed assignment. What happens when assign to a slice indexed by an array and there are duplicates in the \textbf{index} array?
		\begin{itemize}
			\item For example: \verb|a[np.array([1,1,2])] = np.array([1,2,3])|
		\end{itemize}
		\item Use broadcasting to calculate the outer product of two one dimensional arrays (i.e. $A\otimes B = AB^T$).
	\end{enumerate}
\end{frame}

% \begin{frame}[t,fragile]{Interactive Demo}
% 	\centering
% 	\Huge{Interactive Demo}
% 	\normalsize
% 	\begin{enumerate}[<+->]
% 		\item How do you set all of the negative elements in an array to zero?
% 		\begin{itemize}[<+->]
% 			\item \verb|A[A < 0] = 0|
% 		\end{itemize}
% 		\item Recall that you can set an entire slice of an array by using indexed assignment. What happens when assign to a slice indexed by an array and there are duplicates in the \textbf{index} array?
% 		\begin{itemize}
% 			\item It will use that last index
% 		\end{itemize}
% 		\item Use broadcasting to calculate the outer product of two one dimensional arrays (i.e. $A\otimes B = AB^T$).
% 	\end{enumerate}
% \end{frame}

% \begin{frame}[t]{Broadcasting}
% 	Example: Broadcasting to calculate an outer product, $\mathbf{a}\mathbf{b}^T$.
% 	\pause
% 	\begin{lstlisting}
% 		>>> a = np.array([1,2,3])
% 		>>> b = np.array([4,5,6])
% 		>>> a.reshape((3,1)) * b.reshape((1,3))
% 		array([[ 4,  5,  6],
% 		       [ 8, 10, 12],
% 		       [12, 15, 18]])
% 	\end{lstlisting}
% \end{frame}

\section{Miscellaneous NumPy}
\subsection{Foo}

\begin{frame}[t,fragile]{Reductions}
	% sum, cumprod, cumsum
	Reductions compute aggregate statistics on the array. For example:

	\pause
	\begin{lstlisting}
		>>> A = np.arange(6).reshape((3,2))
		>>> A.sum()
		15
	\end{lstlisting}
\end{frame}

\begin{frame}[t,fragile]{Reductions}
	% sum, cumprod, cumsum
	Most reductions take an argument \verb|axis| which allow you to specify the dimension along which the aggregation takes place.

	\pause
	% picture
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide14}.png}
\end{frame}

\begin{frame}[t,fragile]{Reductions}
	% sum, cumprod, cumsum
	Most reductions take an argument \verb|axis| which allow you to specify the dimension along which the aggregation takes place.

	% picture
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide15}.png}
\end{frame}

\begin{frame}[t,fragile]{Reductions}
	% sum, cumprod, cumsum
	Most reductions take an argument \verb|axis| which allow you to specify the dimension along which the aggregation takes place.

	% picture
	\centering
	\includegraphics[width=4.5in]{{../Figures/array_slicing/Slide16}.png}
\end{frame}

\begin{frame}[t,fragile]{Reductions}
	% sum, cumprod, cumsum
	Other common reductions are:

	\pause
	\begin{lstlisting}
		>>> A = np.arange(6).reshape((3,2))
		>>> A.prod(axis=0)
		array([ 0,  6, 20])
		>>> A.max(axis=1) # Also min
		array([1, 3, 5])
		>>> A.argmax(axis=1) # Also argmin
		array([1, 1, 1])
		>>> A.mean(axis=1)
		array([ 0.5,  2.5,  4.5])
		>>> A.std(axis=-1) # -1 corresponds to the last dimension
		array([ 0.5,  0.5,  0.5])
		>>> np.median(A,axis=1) # Not a member function
		array([ 0.5,  2.5,  4.5])
	\end{lstlisting}
	% picture
\end{frame}

\begin{frame}[t,fragile]{Stacking}
	% hstack, vstack, column_stack, concatenate
	NumPy provides a number of functions for combining arrays.

	\pause
	\begin{lstlisting}
		>>> A = np.ones((3,4))
		>>> B = np.ones((3,4))
		>>> np.vstack((A,B)).shape # first dimension
		(6, 4)
		>>> np.hstack((A,B)).shape # second dimension
		(3, 8)
		>>> np.stack((A,B)).shape # new dimension
		(2, 3, 4)
		>>> np.concatenate((A,B),axis=0).shape # any dimension
		(6, 4)
		>>> np.concatenate((A,B),axis=1).shape # any dimension
		(3, 8)
	\end{lstlisting}
	\pause
	Analogues to each of these functions exist for splitting arrays.
\end{frame}

\begin{frame}[t,fragile]{Copy}
	Because the contents of an array are mutable, we often need to copy the contents of an array to avoid overwriting the original.

	\pause
	\begin{lstlisting}
		>>> A = np.ones((3,4))
		>>> B = A
		>>> B is A
		True
		>>> B = A.copy() # Create a new copy of 'A' in memory
		>>> B is A
		False
	\end{lstlisting}
\end{frame}

\begin{frame}[t,fragile]{Basic Linear Algebra}
	% cross, dot, outer, svd, vdot, inv, trace
	NumPy implements many of the standard linear algebra functions:

	\begin{itemize}[<+->]
		\item \verb|np.dot(A,B)|: $A^T B$
		\item \verb|np.outer(A,B)|: $A B^T$
		\item \verb|np.trace(A)|: $tr(A)$
		\item \verb|np.inv(A)|: $A^{-1}$
		\item \verb|np.svd(A)|: Singular value decomposition.
		\item And many more...
	\end{itemize}

\end{frame}

\begin{frame}[t,fragile]{File I/O}
	NumPy has two main sets of File I/O functions. \verb|load| and \verb|save| read and write .npy files.

	\pause
	\begin{lstlisting}
		>>> np.save("my_array.npy",my_array)
		>>> my_array = np.load("my_array.npy")
	\end{lstlisting}

	\pause
	\verb|loadtxt| and \verb|savetxt| read and write text files. The \verb|delimiter| argument specifies what character will be used to separate entries and defaults to tab.

	\pause
	\begin{lstlisting}
		>>> np.savetxt("my_array.csv",my_array,delimiter=',')
		>>> my_array = np.loadtxt("my_array.npy",delimiter=',')
	\end{lstlisting}
\end{frame}

\begin{frame}[t,fragile]{'Object' Arrays}
	In general arrays store only a single type, however, you can create mixed type arrays by setting the data type to \verb|object|. In python, everything an \verb|object| so these arrays can store anything.

	\pause
	\begin{lstlisting}
		>>> A = np.array([1,2.0,"string"],dtype=object)
		>>> A + A
		array([2, 4.0, 'stringstring'], dtype=object)
		>>> A / 3
		Traceback (most recent call last):
		  File "<stdin>", line 1, in <module>
		TypeError: unsupported operand type(s) for /: 'str' and 'int'
	\end{lstlisting}
\end{frame}

\begin{frame}[t,fragile]{Interactive Demo}
	\centering
	\Huge{Interactive Demo}
	\normalsize
	\begin{enumerate}
		\item What is the difference between the reductions \verb|sum| and \verb|cumsum|?
		\item \verb|view()| can be used in a similar way as copy, but has a slightly different effect. Try to figure out what view does.
	\end{enumerate}
\end{frame}
%
%
% \section{Pandas}
% \subsection{Foo}

\end{document}


\input{structure.tex}
\graphicspath{{10_fig/}}
\title{第十章\ 复杂性}

\begin{document}

\maketitle

There are great complexities in the science of complexity, since our world contains all kinds of complexities. In this part, we take a glance of the complexity world by a few examples.

\textbox{Complexities in simple functions}{
    Do you understand a complex function $f(z)=z^2+C$?
    Do you understand a real function $g(x)=R(x-x^2)$?
    If you think you do, take a look at the following images:

    \marginnote{\cg{0.382}{BPlt}}
    \cg{1.0}{MBPlt}

    The 4 figures in the left are results of iteratively apply $f(z)$ (at various zoom levels) and the figure in the right is the result of iteratively apply $g(x)$. Did you realize the complexities contained in these functions?

    In these figures, there is a hidden number $4.669201609\cdots$. Can you find it out?
}

\marginnote{\cg{0.37}{Britain-fractal-coastline-combined}
Image from Wikipedia, CC BY-SA 3.0}
\textbox{How to measure the length of a coastline?}{
    Let's measure the coastline of Britain by a straight and rigid ruler.

    The length is indicated by the first image to the left.

    Let's use a shorter ruler to do the measurement again. Oh, I got a result longer than before. Even shorter ruler? Even longer results. Thanks to the fact that the world is made of atoms, which gives us a short distance cutoff. Otherwise, with infinitely short rulers, I would have measured the coastline of Britain with infinite length!

    The Britain has a coastline with infinite length classically? Are you serious?
}

\textbox{Four dimensional human beings}{
    From scientific fictions, you may have heard of beings living in 4 dimensional space (excluding time). They are said to appear and disappear suddenly in our view as 3 dimensional beings.

    Do you admire them? What if I tell you that we are actually 4 dimensional beings? Can you imagine in which sense this may be real?
}

\section{Iteration: from Population of Rabbits to Chaos}

\textbox{The logistic map $R(x-x^2)$ as generations of rabbits}{
    Let's consider models about the population of rabbits on an island after generations of self-reproduction.

    In the simplest model, the rabbits has a constant self-reproduction rate $R$, i.e. after a generation, the number of rabbits becomes $n_{k+1} = R n_k$. The number of rabbits then increase or decrease exponentially by $n_1 = R n_0, ~ n_2 = R^2 n_0, $ etc.

    This model is too simple. It did not take into account that if there are too many rabbits, the lack of resource on the island will course massive death of the rabbits and thus the population would decrease. To take this into account in a simple toy model, we let
    \begin{align}
        n_{k+1} = R (n_k - \frac{n_k^2}{S} )~,
    \end{align}
    where $S$ is a constant. Now the iteration equation appears to have two parameters $R$ and $S$. An equation with two parameters introduce additional complexity to study. However, without lose of generality, one can redefine $x_k \equiv n_k/S$. Then the iteration equation for $x_k$ is
    \begin{align}
        x_{k+1} = R (x_k - x_k^2)~.
    \end{align}
    This stands for iteratively apply a function $g(x) = R(x-x^2)$, and calculate $g(g(g(\ldots g(x_0)\ldots )))$ with an initial value $x_0$. This function is known as the logistic map.
}

\marginnote{\cg{0.37}{logisticXk} Plots of $x_k$ for different values of $R$. The black solid curve is for $x_0=0.2$ and the red dashed curve is for $x_0 = 0.205$. The difference is minor for small $R$ but is huge for the chaotic case, indicating a sensitive initial condition dependence.}
\textbox{Behavior of $R(x-x^2)$ with different values of $R$}{
    How do iterations of $x_{n+1}=R(x_n-x_n^2)$ behave at large $n$ for different $R$? One can easily write a computer program to test that. And the result for $n\rightarrow \infty$ is as follows:
    \begin{itemize}
        \item For $0<R<1$: $x_\infty =0$. Because the birth rate is too low to compensate the death.
        \item For $1<R<3$: $x_\infty = (R-1)/R$. This value is known as an attractor since it can be obtained from any $0<x_0<1$. To get it, assuming there is a stationary limit, and solve the equation $x_\infty = R( x_\infty - x_\infty^2 )$.
        \item For $3<R<3.44949$: there is no unique limit $x_\infty$. Instead, at large $k$, $x_k$ oscillates with two possible values. This can be understood as: for one generation, there are too many rabbits thus many died. The next year, there are more resources and then can support more rabbits.
        \item For $3.44949 < R < 3.54409$: $x_k$ oscillates with 4 possible values. This is hard to understand, but can be tested easily numerically. Further, for $3.54409 < R < 3.56407$: $x_k$ oscillates with 8 possible values; For $3.56407<R<3.56876$: $x_k$ oscillates with 16 possible values; ... When one increases $R$ a bit, the period doubles.
        \item For $R>3.56995$, one can no longer find oscillatory behavior. The behavior of $x_k$ at large $k$ looks random, and is exponentially sensitive to small variation in initial condition $x_0$. This behavior is known as \emph{chaos}.
    \end{itemize}
}

\textbox{The Bifurcation Plot}{
    The plot of the logistic map is best known in the form of the below bifurcation plot. Here one clearly note the doubling of periods and eventually the emergence of chaos as $R$ increases.
    \marginnote{If you zoom in the bifurcation plot, you will find some self-similarities in its substructures.}
    \cg{0.8}{BPltFramed}
}

\needspace{0.2\textwidth}
\mtextbox{The Mandelbrot Set}{
    For the complex function $f(z)=z^2+C$, the Mondelbrot set is a plot about how fast the sequence $f(0), f(f(0)), \cdots$ diverges or converge. The complexities in this iteration in the complex plane of $C$ is plotted at the beginning of this part. Along the real axis, the plot has self-similarity and the period is determined by the Feigenbaum constant. The relation to the logistic map is plotted in the below figure.
    % Image: Wikipedia released to the public domain
    \cg{0.7}{Verhulst-Mandelbrot-Bifurcation-Wikipedia-public-domain}
    To study the Mandelbrot set in more details, you will find that at different parts of the Mandelbrot set, iterations converge to different number of points. This is very similar to the logistic map. Also note the self similarities in the Mandelbrot set. We will come back to self similarities later.
    \mnewline
    You can find on the site \href{https://sites.google.com/site/logicedges/}{logicedges} the zoom of the above connection and more videos about complexity.
}
% 恒纪元
\textbox{The orderly era: period doubling and the Feigenbaum constant}{
    From the above observations, we note that the oscillation has $2^n$ possible values for a range of $R$: $R_n < R < R_{n+1}$. At large $n$:
    \begin{align}
        \delta \equiv \lim_{n\rightarrow \infty} \frac{R_{n+1}-R_n}{R_{n+2}-R_{n+1}} = 4.669201609\cdots ~.
    \end{align}
    This number $\delta$ is known as the Feigenbaum constant. Interestingly, the Feigenbaum constant is not only the ratio for rabbit birth rate, but rather it is a universal constant of nature. The periodicity of a broad class of non-linear behaviors has the same limiting behavior.
}

% 乱纪元
\textbox{The chaotic era: the classical loss of determinism}{
    In the framework of classical mechanics, Laplace proposed that if a smart demon knows the initial position and velocity of all particles in the universe, the demon can predict the future. It is known as the Laplace's demon.

    Now we know that determinism is (at least apparently) lost in quantum mechanics. Thus, Laplace's proposal does not work. However, even in the framework of classical mechanics, due to chaos, Laplace's proposal does not practically work either. This is because a tiny small error in the knowledge of the initial condition will be amplified exponentially fast in a chaotic system. As a result, it is exponentially hard to predict the future even in the classical sense.

    \tcblower

    In the 1890s, Poincare studied the 3-body problem and noted that the solutions are exponentially sensitive to initial conditions. This is the starting point of the study of chaos. But for decades, his work was largely forgotten.

    In 1961, Lorenz tried to use 12 nonlinear PDEs to model the change of weather. One day, he wanted to re-run a previous simulation from the middle using data printouts. However, he found that his previous calculation is not reproducible. He struggled and eventually found the reason: the result is exponentially sensitive to the initial condition. This re-discovery is the modern start for chaos study and is later known as the ``butterfly effect'': ``Hurricane formed because a butterfly flapped her wings several weeks earlier''.
}

\section{Fractals: Dimensions Reloaded}

To understand how coastlines would have infinite classical length, let us consider a toy model, known as the Koch's snowflake.

\marginnote{\cg{0.35}{koch_edit}}
\textbox{Koch's snowflake}{
    Starting from a straight line, shrink it by $1/3$ and fold it 4 times, as the figure to the right. Do it \emph{infinitely many times}. Then you get the Koch's snowflake. We observe a few features of the Koch's snowflake:
    \titem{
        \item The snowflake is self-similar. Take a part and zoom in, you find the same image as the original whole image. This non-trivial self-similarity is known as a fractal structure. Though coastlines do not have exact fractal structure, they have fractal-like structures that the part ``looks like'' the whole after zooming in. You can try to see this feature yourself by zooming in Google Map.
        \item What's the length of lines in the snowflake? Let's take the initial straight line to have length $L$. Then the first iteration of shinking-folding procedure gives a length $(4/3)L$, the second iteration gives $(4/3)^2L$, ... and the $n$-th iteration gives $(4/3)^nL$. As $n \rightarrow \infty $, the length diverges. Thus, the Koch's snowflake fits an line with infinite length into a finite width (and height).
        \item Due to the folding (roughness), the snowflake appears to have a bit of ``thickness'' if you look from far away. Thus, the snowflake appears in some sense like a two-dimensional object instead of a one-dimensional line. However, if you look infinitely close, the snowflake looks one dimensional again. What's the dimension of the slowflake?
    }
}
To study the dimension of the Koch's snowflake, let us generalize our definition of spatial dimensions.
\textbox{The dimension of the snowflake: Hausdorff dimension}{
    How to formally define spatial dimensions? There are many ways. Among which one is by the scaling behavior of objects. Take a square for example, it has trivial self-similarity. Cut its length of edges by $1/2$, you get 4 self-similar squares.

    \mtextbox{Sierpinski triangle}{
        As another example of fractals, the below image is the Sierpinski triangle.
        \cg{0.8}{sierpinski}
        When you cut edges by 1/2, you get 3 self-similar pieces. Thus $D_H = \log 3 / \log 2$.
    }
    \cg{0.5}{square-similar}
    In general, if you cut its length of edges in $1/M$ intervals, and you get $N$ self-similar squares. What's the relation between $M$ and $N$? Of course, $N = M^2$, and thus
    \begin{align}
        \frac{\log N}{\log M} = 2~.
    \end{align}
    Recall that the square is a two-dimensional object. Is this $2$ appearing at the right hand side a coincidence? You can try a 3-dimensional box, or higher dimensional objects. Soon you can be convinced that it's not a coincidence. And in general you have:
    \begin{align}
        D_H \equiv \mbox{(dimension)} = \frac{\log \mbox{(number of self-similar pieces)}}{\log \mbox{(number of subdivision of edges)}}~.
    \end{align}
    Space dimension defined in this way is known as the Hausdorff dimension.
    \tcblower
    What's the Hausdorff dimension for Koch's snowflake? Cutting the length by 1/3 and we get 4 self-similar pieces. Thus $D_H = \log 4 / \log 3 \simeq 1.26$. It's an object somewhere between dimension 1 and 2. This is a mathematical way of the above argument that roughness turns into line width.

    You can find a list of beautiful fractals and their Hausdorff dimensions \href{https://en.wikipedia.org/wiki/List_of_fractals_by_Hausdorff_dimension}{on Wikipedia}.
}

\marginnote{\cg{0.2}{boxDim}}
\textbox{Coastlines and other fractal-like objects}{
    For coastlines, there is no precise self-similarity but at best statistical self-similarity. Nevertheless, one can still count the fractal dimension by scaling properties: Draw grid lines on the map. Count how many boxes cross the coastline. And study how the number of boxes scales when we shrink the intervals between grid lines. One finds that the UK coastline has a box counting dimension of 1.25. The dimension of coastlines of Norway, Australia and South Africa are 1.52, 1.13 and 1.05, respectively. The smaller dimension, the smoother the coastlines.
    \tcblower
    \twocol{0.7}{0.1}{0.18}{Fractal-like structures are abundant in nature. For example, the fractal dimension of cauliflowers is measured to be about 2.8. This is intuitive since a cauliflower is a 3-dimensional object and has holes in it arising from fractal structures.}{\cg{1}{cauliflowers}}
}

\textbox{The Kleiber's Law: Metabolic rate for organisms}{
    Let's change topic to a bit of biology. Guess what's the relation between metabolic rate and mass for organisms? Are they linearly proportional?

    \cg{0.7}{metabolic1}

    \marginnote{\cg{0.35}{WBE} Image from West, Brown, Enquist, Science 276, 122 (1997). See also their paper on Science 284, 1677 (1999).}

    Here is a plot by Hemmingsen on Reports of the Steno Memorial Hospital (1960). Interestingly, the metabolic rate scale as $M^{3/4}$. This strange power is known as the Kleiber's law. The factor 3 in $3/4$ is intuitive -- this is how mass scales with length. However, where does the factor of 4 come from? Researchers further found that the heart rate and growth rate scales as $-1/4$, and the blood circulation time and life span scales as $1/4$ of animal mass, respectively. Again, the mysterious factor of $4$ arises.
    \tcblower
    In the 1990s, West, Brown and Enquist noted that fractal-like structure (such as blood vessels) is more efficient in deliver materials in the body of animals. The fractal-like structure in 3-dimension corresponds to 4 dimensions if no fractal-like structure is used. Thus, in the fractal sense, we effectively live in 4 spatial dimensions!
}

\section{Epilogue: Summary and What's Next}

\textbox{Further reading about the content}{
    \titem{
        \item There is an excellent online course \href{https://www.complexityexplorer.org/courses}{``Introduction to Complexity''} by Melanie Mitchell. She also has a book \href{https://www.amazon.com/Complexity-Guided-Tour-Melanie-Mitchell/dp/0199798109}{Complexity: A Guided Tour}.
        \item For more formal textbooks, see, for example, \href{https://www.amazon.com/Fractal-Geometry-Mathematical-Foundations-Applications/dp/0470848626/ref=pd_cp_b_3}{Fractal Geometry: Mathematical Foundations and Applications} by Falconer.
        \item Many models here can be simulated in a modeling language \href{https://ccl.northwestern.edu/netlogo/}{``NetLogo''}. The model source code is simple and fun to read thanks to the language features provided by NetLogo.
    }
}

\textbox{What's next?}{
    You may like to learn about information, emergent behaviors, networks, genetic algorithms and cellular automata in the world of complexity from the suggested further readings.

    Complexity is an interdisciplinary science. You may find your next steps in how to route computer networks, how to recommend goods to customers, how brain works in life science, how birds fly in groups, how to reach a person using your social connections, how to plan the expansion of a city, how to design a algorithm for a robot, how to make more precise weather forecast, and even how a black hole absorbs matter.
}

\printindex

\end{document}


\vsssub
\subsubsection{~$S_{mud}$: Dissipation by viscous mud (Ng)} \label{sec:BT9}
\vsssub

\opthead{BT9}{NRL/SWAN}{M. Orzech and E. Rogers}

\noindent
To activate viscous mud effects with the Ng routines, the user specifies
{\code BT9} in the switch parameter file. The Ng method computes $k_i$ as:
\begin{equation}\label{eq:dmud3}
  k_i \approx {D_{mud}} \equiv \frac{\delta_m({B_r'}+{B_i'}){k_1}^2}{sinh2{k_1}{d}+2{k_1}{d}},
\end{equation}
Here, ${\delta_m}$ is the Stokes boundary layer thickness for mud, ${d}$ is
water depth, and ${k_1}$ is leading order term of the real part of the
mud-modified wave number $k_{mud}$, respectively, in a Taylor expansion about
the mud-water interface, and ${D_{mud}}$ is the leading order term in the full
expansion of $k_i$. $B'$ is a complex coefficient affecting the depth profile
of the velocities.  For additional details, see \para\ref{sec:BT8} and
\cite{art:Ng00}.


%---------------------------Diagonal---------------------------
\section{Diagonal}

This metric is the ratio of the minimum diagonal length to the maximum diagonal length:
\[
q = \frac{D_{\min}}{ D_{\max}}.
\]
Note that if $D_{\max} < DBL\_MIN$, we set $q = DBL\_MAX$.

\hexmetrictable{diagonal}%
{$1$}%                                        Dimension
{$[0.65,1]$}%                                 Acceptable range
{$[0,1]$}%                                    Normal range
{$[1,DBL\_MAX]$}%                             Full range
{$1$}%                                        Cube
{--}%                                         Citation
{v\_hex\_diagonal}%                           Verdict function name