\documentclass[gr-notes.tex]{subfiles}

\begin{document}

\setcounter{chapter}{5}

\chapter{Curved Manifolds}

\setcounter{section}{8}

\section{Exercises}

\textbf{1}
Determine if the following sets are manifolds, and why. List any exceptional points.

(a) Phase space in Hamiltonian mechanics is generally smooth, though it may contain singular points, depending on the system described. So it is a manifold, excluding the singularities.

(b) The interior of a circle in 2D Euclidean space is smooth everywhere, and is therefore a manifold.

(c) The set of permutations of $n$ objects is not a manifold, as it is discontinuous.

(d) The set of solutions to $xy (x^2 + y^2 - 1)$ is a manifold. The solutions form a unit circle, ($x^2 + y^2 = 1$), as well as lines which span the $x$- and $y$-axes ($x=0$, $y=0$). The singular values occur at the points of intersection: $(0, 0)$, $(0, \pm1)$, and $(\pm1, 0)$.

\textbf{2}
On which of the manifolds in Exercise 1 is it customary to use a metric? What are those metrics? Why would metrics not be defined for some?

(a) Phase space is comprised of two variables, $p$ and $q$, each of which represent different physical quantities, with incompatible units. For instance, if $p$ is momentum and $q$ is position, then $p^2 + q^2$ is non-physical.

(b) The metric for the interior of a circle in 2D Euclidean space would be the Euclidean norm in 2 dimensions. While this could be given by $(\Delta s)^2 = (\Delta x)^2 + (\Delta y)^2$, it would be more natural to express in units of $r$ and $\theta$.
%
\begin{align*}
  (\Delta s)^2 &=
  (\Delta x)^2 + (\Delta y)^2
  \\ &=
  (x - x_0)^2 + (y - y_0)^2
  \\ &=
  r^2 \qty[ (\cos\theta - \cos\theta_0)^2 + (\sin\theta - \sin\theta_0)^2 ]
  \\ &=
  r^2 \qty[
    \cos^2\theta + \cos^2\theta_0 - 2 \cos\theta \cos\theta_0 +
    \sin^2\theta + \sin^2\theta_0 - 2 \sin\theta \sin\theta_0
  ]
  \\ &=
  r^2 \qty[ 1 + 1 - 2 \cos(\theta - \theta_0) ] =
  2 r^2 \qty[ 1 - \cos(\Delta\theta) ]
  \\ &=
  4 r^2 \sin^2(\Delta\theta / 2)
\end{align*}

(c) This was not a manifold.

(d) Since this is again 2D Euclidean space, we could use the Euclidean norm in 2 dimensions. This time it would be more natural to express distances in $(x,y)$ coordinates, unless we restricted ourselves to the unit circle portion of this manifold.

\textbf{4}
Prove the following:

(a) The number of independent terms in $\pdv*{x^\alpha}{x^{\gamma'}}{x^{\mu'}}|_\mathcal{P}$ is $40$.

The total number of components is $4^3$, however, we do not want to consider duplicate terms. To find the number of duplicate terms in total, we find the number of duplicate terms for a fixed value of $\alpha$, and then multiply that by $4$. The number of terms for a fixed $\alpha$ is $4^2$, and of those, $4$ are completely independent (the diagonals), and the remainder exist in pairs. Since we only want one from each pair, we divide the total count by two, which means that the total number of duplicate components is $4 \qty[ (4^2 - 4) / 2 ]$, and so the total number of non-duplicate components is $4^3 - 4 \qty[ (4^2 - 4) / 2 ] = 40$.

In the next part, I cheat and use a formula. I will apply it to this part first, to show that it works. If you have a symmetric rank $k$ tensor with $n$ dimensions, then it has
%
\begin{displaymath}
  \qty(\!\!\binom{n}{k}\!\!) = \binom{n+k-1}{k}
\end{displaymath}
%
independent components. In the case of this problem, by fixing $\alpha$, we get $4$ rank $2$ tensors of $4$ dimensions, and so the total number of independent components is
%
\begin{displaymath}
  4 \binom{4+2-1}{2} = 40.
\end{displaymath}

(b) The number for $\pdv*{x^\alpha}{x^{\lambda'}}{x^{\mu'}}{x^{\nu'}}|_\mathcal{P}$ is $80$.

Here, if we fix $\alpha$, we have $4$ symmetric rank $3$ tensors of $4$ dimensions, and so there are
%
\begin{displaymath}
  4 \binom{4+3-1}{3} = 80
\end{displaymath}
%
independent components.

(c) The number for $g_{\alpha\beta,\gamma'\mu'}|_\mathcal{P}$ is $100$.

If we interchange $\alpha\beta$, but fix $\gamma'\mu'$, then we have a symmetric rank $2$ tensor of $4$ dimensions, which has
%
\begin{displaymath}
  \binom{4+2-1}{2} = 10
\end{displaymath}
%
independent components. Likewise, if we interchange $\gamma'\mu'$ but fix $\alpha\beta$, we get $10$ independent components. Multiply the two and we have $100$ independent components.

\textbf{7}

(a) Define $\det(A)$ in terms of cofactors of elements.

\begin{displaymath}
  \det(A) =
  \sum_{j=1}^n (-1)^{i+j} a_{i,j} M_{i,j} =
  \sum_{i=1}^n (-1)^{i+j} a_{i,j} M_{i,j}
\end{displaymath}

(b) Compute $\dv{x} \det(A)$, where $A$ is a $2\times2$ matrix. Show that this satisfies Equation 6.39.

First we note that, for $A_{1\times1}$, $\det(A) = a_{1,1}$. Thus, for $A_{2\times2}$, $M_{i,j} = a_{i',j'}$, where $i \neq i'$ and $j \neq j'$. Therefore we can rewrite the determinant of $A_{2\times2}$ as
%
\begin{align*}
  \det(A) &=
  \sum_{i=1}^2 (-1)^{i+j} a_{i,j} a_{i',j'}
  \\ &=
  (-1)^{j+1} a_{1,j} a_{2,j'} + (-1)^{j+2} a_{2,j} a_{1,j'}.
\end{align*}
%
If we assume $j = 1$ (it doesn't really matter if we choose $1$ or $2$), then this simplifies to
%
\begin{align*}
  \det(A) &=
  (-1)^2 a_{1,1} a_{2,2} + (-1)^3 a_{2,1} a_{1,2}
  \\ &=
  a_{1,1} a_{2,2} - a_{2,1} a_{1,2}.
\end{align*}
%
We can then see that the derivative is
%
\begin{align*}
  \pdv{x^\mu} \det(A) &=
  \pdv{x^\mu} (a_{11} a_{22} - a_{21} a_{12})
  \\ &=
  a_{11} a_{22,\mu} + a_{22} a_{11,\mu} - a_{21} a_{12,\mu} - a_{12} a_{21,\mu}
\end{align*}

Now to relate this to Equation 6.39, we let $A$ be the metric $g$. Then the derivative of its determinant is
%
\begin{align*}
  g_{,\mu} &=
  g_{11} g_{22,\mu} + g_{22} g_{11,\mu} -
  g_{21} g_{12,\mu} - g_{12} g_{21,\mu}
  \\ &=
  g_{11} g_{22,\mu} + g_{22} g_{11,\mu} - 2 g_{12} g_{12,\mu}.
\end{align*}
%
Now if we expand Equation 6.39, we see we have
%
\begin{align*}
  g &=
  g_{11} g_{22} - g_{12} g_{21} =
  g_{11} g_{22} - (g_{12})^2
  \\
  g^{\alpha\beta} g_{\alpha\beta,\mu} &=
  g^{11} g_{11,\mu} + g^{22} g_{22,\mu} + 2 g^{12} g_{12,\mu}
  \\
  g g^{\alpha\beta} g_{\alpha\beta,\mu} &=
  (g_{11} g_{22} - (g_{12})^2)
  (g^{11} g_{11,\mu} + g^{22} g_{22,\mu} + 2 g^{12} g_{12,\mu})
  \\ &=
  g_{22} g_{11,\mu} - g^{11} (g_{12})^2 g_{11,\mu} +
  g_{11} g_{22,\mu} - g^{22} (g_{12})^2 g_{22,\mu} +
  2 g_{11} g_{22} g^{12} g_{12,\mu} -
  2 g_{12} g_{12,\mu}
  \\ &=
  g_{11} g_{22,\mu} + g_{22} g_{11,\mu} - 2 g_{12} g_{12,\mu}
  + 2 g_{11} g_{22} g^{12} g_{12,\mu}
  - (g_{12})^2 (g^{11} g_{11,\mu} + g^{22} g_{22,\mu}).
\end{align*}
%
If it is the case that $2 g_{11} g_{22} g^{12} g_{12,\mu} - (g_{12})^2 (g^{11} g_{11,\mu} + g^{22} g_{22,\mu}) = 0$, then this is consistent with our previous expression for $g_{,\mu}$, but I'm not sure how to show that.

\textbf{10}
A ``straight line'' on a sphere forms a great circle. The sum of the interior angles of a triangle whose sides are formed by arcs of great circles is greater than $180^\circ$. Show that the rotation of a vector, parallel transported around such a triangle (Figure 6.3 in Schutz), is exactly equal to the excess of that $180^\circ$ sum.

\textbf{11}
What guarantees we can find a vector field $\vec{V}$ satisfying:
%
\begin{displaymath}
  \tensor{V}{^\alpha_{;\beta}} =
  \tensor{V}{^\alpha_{,\beta}} +
  \tensor{\Gamma}{^\alpha_{\mu\beta}}
  V^\mu =
  0
\end{displaymath}
%
\begin{enumerate}[(a)]
\item The integrability condition follows from the commuting of partial derivatives, $\comm{\partial_\nu}{\partial_\beta} V^\alpha = 0$. Show that this implies
%
\begin{displaymath}
  (\tensor{\Gamma}{^\alpha_{\mu\beta,\nu}} -
   \tensor{\Gamma}{^\alpha_{\mu\nu,\beta}}) V^\mu =
  (\tensor{\Gamma}{^\alpha_{\mu\beta}} \tensor{\Gamma}{^\mu_{\sigma\nu}} -
   \tensor{\Gamma}{^\alpha_{\mu\nu}} \tensor{\Gamma}{^\mu_{\sigma\beta}})
  V^\sigma =
  0
\end{displaymath}

Since we must satisfy $\tensor{V}{^\alpha_{,\beta}} + \tensor{\Gamma}{^\alpha_{\mu\beta}} V^\mu = 0$, then it must be the case that $\tensor{V}{^\alpha_{,\beta}} = -\tensor{\Gamma}{^\alpha_{\mu\beta}} V^\mu$. Differentiating both sides, we get
%
\begin{align*}
  \tensor{V}{^\alpha_{,\beta\nu}} &=
  -\tensor{\Gamma}{^\alpha_{\mu\beta,\nu}} V^\mu -
   \tensor{\Gamma}{^\alpha_{\mu\beta}} \tensor{V}{^\mu_{,\nu}}
  \\ &=
  -\tensor{\Gamma}{^\alpha_{\mu\beta,\nu}} V^\mu +
   \tensor{\Gamma}{^\alpha_{\mu\beta}}
   \tensor{\Gamma}{^\mu_{\lambda\nu}} V^\lambda
  \\
  \tensor{V}{^\alpha_{,\nu\beta}} &=
  -\tensor{\Gamma}{^\alpha_{\mu\nu,\beta}} V^\mu +
   \tensor{\Gamma}{^\alpha_{\mu\nu}}
   \tensor{\Gamma}{^\mu_{\sigma\beta}} V^\sigma
  \\
  \tensor{V}{^\alpha_{,\beta\nu}} &=
  \tensor{V}{^\alpha_{,\nu\beta}}
  \\ \implies
  -\tensor{\Gamma}{^\alpha_{\mu\beta,\nu}} V^\mu +
   \tensor{\Gamma}{^\alpha_{\mu\beta}}
   \tensor{\Gamma}{^\mu_{\sigma\nu}} V^\sigma &=
  -\tensor{\Gamma}{^\alpha_{\mu\nu,\beta}} V^\mu +
   \tensor{\Gamma}{^\alpha_{\mu\nu}}
   \tensor{\Gamma}{^\mu_{\sigma\beta}} V^\sigma
  \\
  (\tensor{\Gamma}{^\alpha_{\mu\beta,\nu}} -
   \tensor{\Gamma}{^\alpha_{\mu\nu,\beta}})
  V^\mu &=
  (\tensor{\Gamma}{^\alpha_{\mu\beta}} \tensor{\Gamma}{^\mu_{\sigma\nu}} -
   \tensor{\Gamma}{^\alpha_{\mu\nu}} \tensor{\Gamma}{^\mu_{\sigma\beta}})
  V^\sigma
\end{align*}

\item By relabeling indices, we can work this into another form:
%
\begin{align*}
  (\tensor{\Gamma}{^\alpha_{\mu\beta,\nu}} -
   \tensor{\Gamma}{^\alpha_{\mu\nu,\beta}})
  V^\mu &=
  (\tensor{\Gamma}{^\alpha_{\sigma\beta}} \tensor{\Gamma}{^\sigma_{\mu\nu}} -
   \tensor{\Gamma}{^\alpha_{\sigma\nu}} \tensor{\Gamma}{^\sigma_{\mu\beta}})
  V^\mu
  \\
  (\tensor{\Gamma}{^\alpha_{\mu\beta,\nu}} -
   \tensor{\Gamma}{^\alpha_{\mu\nu,\beta}} &+
   \tensor{\Gamma}{^\alpha_{\sigma\nu}} \tensor{\Gamma}{^\sigma_{\mu\beta}} -
   \tensor{\Gamma}{^\alpha_{\sigma\beta}} \tensor{\Gamma}{^\sigma_{\mu\nu}})
  V^\mu =
  0
\end{align*}

\end{enumerate}

\textbf{13}
\begin{enumerate}[(a)]
\item Show that if $\vec{A}$ and $\vec{B}$ are parallel transported along a curve, their dot product is constant along that curve.

The dot product being constant along the curve means that \emph{it} must be parallel transported along the curve, i.e. $\grad_{\vec{U}} (\vec{A} \cdot \vec{B}) = 0$. We will now show this.
%
\begin{align*}
  \grad_{\vec{U}} (\vec{A} \cdot \vec{B}) &=
  U^\lambda \grad_\lambda (g_{\alpha\beta} A^\alpha B^\beta)
  \\ &=
  U^\lambda (
    A^\alpha B^\beta \cancel{\grad_\lambda g_{\alpha\beta}} +
    g_{\alpha\beta} B^\beta \grad_\lambda A^\alpha +
    g_{\alpha\beta} A^\alpha \grad_\lambda B^\beta
  )
  \\ &=
  B^\beta U^\lambda \grad_\lambda A^\alpha +
  A^\alpha U^\lambda \grad_\lambda B^\beta.
\end{align*}

Notice that the terms $U^\lambda \grad_\lambda A^\alpha$ and $U^\lambda \grad_\lambda B^\beta$ are just the parallel transport equations, and so they come out to be zero, meaning $\grad_{\vec{U}} (\vec{A} \cdot \vec{B}) = 0$, i.e. the dot product is constant along the curve.

\item Show that if a geodesic is spacelike, timelike, or null \emph{somewhere}, then it remains that way \emph{everywhere}.

Since the dot product of two parallel transported vectors is constant, if we parallel transport a curve's tangent vector along itself (the geodesic), its magnitude ($\vec{U} \cdot \vec{U}$) should remain constant. Since its magnitude doesn't change, it will remain spacelike, timelike, or null.

\end{enumerate}

\textbf{14}
Show that if the curve in Equation 6.8 is a geodesic, the proper length is an affine parameter.

Equation 6.8 states
%
\begin{displaymath}
  \ell =
  \int_{\lambda_0}^{\lambda_1} \sqrt{\abs{\vec{V} \cdot \vec{V}}} \dd\lambda.
\end{displaymath}
%
If the curve is a geodesic, we have just shown that the dot product of any two vectors remains constant along the curve, and so we may pull it out of the integral.
%
\begin{displaymath}
  \ell =
  \sqrt{\abs{\vec{V} \cdot \vec{V}}}
  \int_{\lambda_0}^{\lambda_1} \dd\lambda =
  \sqrt{\abs{\vec{V} \cdot \vec{V}}} (\lambda_1 - \lambda_0),
\end{displaymath}
%
and so the proper length $\ell$ is indeed an affine parameter, as it can be obtained by a linear transformation of the parameter of the curve, $\lambda$.

\textbf{16}
\begin{enumerate}[(a)]
\item Derive Equations 6.59 and 6.60 from 6.68.

Somehow Schutz uses a Taylor expansion to get 6.59 from 6.68. I honestly have no idea how he does this, and Taylor expanding vectors and Christoffel symbols is black magic to me, so here's my (obviously wrong) attempt.
%
\begin{align*}
  \var{V^\alpha} &=
  \int_{x^1=a} \tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu \dd{x^2} -
  \int_{x^1=a+\var{a}} \tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu \dd{x^2}
  \\ &+
  \int_{x^2=b} \tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu \dd{x^1} -
  \int_{x^2=b+\var{b}} \tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu \dd{x^1}
  \\ &\approx
  \int_b^{b+\var{b}} \eval[
    \tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu +
    \var{a} \pdv{x^1} \qty(\tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu)
  |_a \dd{x^2}
  \\ &-
  \int_b^{b+\var{b}} \eval[
    \tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu +
    \var{a} \pdv{x^1} \qty(\tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu)
  |_a \dd{x^2}
  \\ &+
  \int_a^{a+\var{a}} \eval[
    \tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu +
    \var{b} \pdv{x^2} \qty(\tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu)
  |_b \dd{x^1}
  \\ &-
  \int_a^{a+\var{a}} \eval[
    \tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu +
    \var{b} \pdv{x^2} \qty(\tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu)
  |_b \dd{x^1}
  \\ &\approx
  0
  \\ &
  \text{but then a miracle occurred!!}
  \\ &\approx
 -\int_b^{b+\var{b}}
  \var{a} \pdv{x^1} \qty(\tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu) \dd{x^2}
  \\ &+
  \int_a^{a+\var{a}}
  \var{b} \pdv{x^2} \qty(\tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu) \dd{x^1}
\end{align*}

The next step actually \emph{does} make sense to me. Since we are integrating over such tiny areas ($\var{a}$ and $\var{b}$),
$\int_a^{a+\var{a}} f(x) \dd{x} \approx \var{a} f(a)$, so
%
\begin{align*}
  \int_b^{b+\var{b}}
  \var{a} \pdv{x^1} \qty(\tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu) \dd{x^2}
  &\approx
  \var{a} \var{b} \pdv{x^1} \qty(\tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu),
  \\
  \int_a^{a+\var{a}}
  \var{b} \pdv{x^2} \qty(\tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu) \dd{x^1}
  &\approx
  \var{a} \var{b} \pdv{x^2} \qty(\tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu).
\end{align*}
%
Subtracting the two gives us
%
\begin{displaymath}
  \var{V^\alpha} \approx
  \var{a} \var{b} \qty[
   -\pdv{x^1} \qty(\tensor{\Gamma}{^\alpha_{\mu 2}} V^\mu) +
    \pdv{x^2} \qty(\tensor{\Gamma}{^\alpha_{\mu 1}} V^\mu)
  ].
\end{displaymath}

\item Derive Equation 6.61 from this.

Using a generalized form of Equation 6.53:
%
\begin{displaymath}
  \tensor{V}{^\alpha_{,\beta}} =
  -\tensor{\Gamma}{^\alpha_{\mu\beta}} V^\mu,
\end{displaymath}
%
we arrive at the expression
%
\begin{displaymath}
  \qty(\tensor{\Gamma}{^\alpha_{\nu\lambda}} V^\nu)_{,\beta} =
  \tensor{\Gamma}{^\alpha_{\nu\lambda,\beta}} V^\nu +
  \tensor{\Gamma}{^\alpha_{\nu\lambda}} \tensor{V}{^\nu_{,\beta}} =
  \tensor{\Gamma}{^\alpha_{\nu\lambda,\beta}} V^\nu -
  \tensor{\Gamma}{^\alpha_{\nu\lambda}}
  \tensor{\Gamma}{^\nu_{\mu\beta}}
  V^\nu.
\end{displaymath}
%
Now we substitute $\mu \to \nu$ in Equation 6.60, and use this expression to find
%
\begin{align*}
  \var{V^\alpha} &\approx
  \var{a} \var{b} \qty[
   -\tensor{\Gamma}{^\alpha_{\nu2,1}} V^\nu +
    \tensor{\Gamma}{^\alpha_{\nu2}}
    \tensor{\Gamma}{^\nu_{\mu1}}
    V^\nu +
    \tensor{\Gamma}{^\alpha_{\nu1,2}} V^\nu -
    \tensor{\Gamma}{^\alpha_{\nu1}}
    \tensor{\Gamma}{^\nu_{\mu2}}
    V^\nu
  ]
  \\ &\approx
  \var{a} \var{b} \qty[
    \tensor{\Gamma}{^\alpha_{\nu1,2}} -
    \tensor{\Gamma}{^\alpha_{\nu2,1}} +
    \tensor{\Gamma}{^\alpha_{\nu2}}
    \tensor{\Gamma}{^\nu_{\mu1}} -
    \tensor{\Gamma}{^\alpha_{\nu1}}
    \tensor{\Gamma}{^\nu_{\mu2}}
  ]
  V^\nu.
\end{align*}

\end{enumerate}

\textbf{18}
\begin{enumerate}[(a)]
\item Derive Equations 6.69 and 6.70 from 6.68.

\begin{align*}
  R_{\alpha\beta\mu\nu} &=
  \frac{1}{2} (
    {\color{red}    g_{\alpha\nu,\beta\mu}} -
    {\color{green}  g_{\alpha\mu,\beta\nu}} +
    {\color{blue}   g_{\beta\mu,\alpha\nu}} -
    {\color{violet} g_{\beta\nu,\alpha\mu}}
  )
  \\
  R_{\beta\alpha\mu\nu} &=
  \frac{1}{2} (
    {\color{violet} g_{\beta\nu,\alpha\mu}} -
    {\color{blue}   g_{\beta\mu,\alpha\nu}} +
    {\color{green}  g_{\alpha\mu,\beta\nu}} -
    {\color{red}    g_{\alpha\nu,\beta\mu}}
  )
  \\ &=
  \frac{1}{2} (
   -{\color{red}    g_{\alpha\nu,\beta\mu}} +
    {\color{green}  g_{\alpha\mu,\beta\nu}} -
    {\color{blue}   g_{\beta\mu,\alpha\nu}} +
    {\color{violet} g_{\beta\nu,\alpha\mu}}
  )
  \\ &=
  -R_{\alpha\beta\mu\nu}
  \\
  R_{\alpha\beta\nu\mu} &=
  \frac{1}{2} (
    {\color{green}  g_{\alpha\mu,\beta\nu}} -
    {\color{red}    g_{\alpha\nu,\beta\mu}} +
    {\color{violet} g_{\beta\nu,\alpha\mu}} -
    {\color{blue}   g_{\beta\mu,\alpha\nu}}
  )
  \\ &=
  \frac{1}{2} (
   -{\color{red}    g_{\alpha\nu,\beta\mu}} +
    {\color{green}  g_{\alpha\mu,\beta\nu}} -
    {\color{blue}   g_{\beta\mu,\alpha\nu}} +
    {\color{violet} g_{\beta\nu,\alpha\mu}}
  )
  \\ &=
  -R_{\alpha\beta\mu\nu}
  \\
  R_{\mu\nu\alpha\beta} &=
  \frac{1}{2} (
    {\color{blue}   g_{\mu\beta,\nu\alpha}} -
    {\color{green}  g_{\mu\alpha,\nu\beta}} +
    {\color{red}    g_{\nu\alpha,\mu\beta}} -
    {\color{violet} g_{\nu\beta,\mu\alpha}}
  )
  \\ &=
  \frac{1}{2} (
    {\color{red}    g_{\alpha\nu,\beta\mu}} -
    {\color{green}  g_{\alpha\mu,\beta\nu}} +
    {\color{blue}   g_{\beta\mu,\alpha\nu}} -
    {\color{violet} g_{\beta\nu,\alpha\mu}}
  )
  \\ &=
  R_{\alpha\beta\mu\nu}
\end{align*}
%
\begin{align*}
  2 (R_{\alpha\beta\mu\nu} + R_{\alpha\nu\beta\mu} + R_{\alpha\mu\nu\beta}) &=
  {\color{red}    g_{\alpha\nu,\beta\mu}} -
  {\color{green}  g_{\alpha\mu,\beta\nu}} +
  {\color{blue}   g_{\beta\mu,\alpha\nu}} -
  {\color{violet} g_{\beta\nu,\alpha\mu}}
  \\ &+
  {\color{green}  g_{\alpha\mu,\nu\beta}} -
  {\color{brown}  g_{\alpha\beta,\nu\mu}} +
  {\color{violet} g_{\nu\beta,\alpha\mu}} -
  {\color{teal}   g_{\nu\mu,\alpha\beta}}
  \\ &+
  {\color{brown}  g_{\alpha\beta,\mu\nu}} -
  {\color{red}    g_{\alpha\nu,\mu\beta}} +
  {\color{teal}   g_{\mu\nu,\alpha\beta}} -
  {\color{blue}   g_{\mu\beta,\alpha\nu}}
  \\ &=
  0
\end{align*}

\item Show that Equation 6.69 reduces the number of independent components from $4\times4\times4\times4$ to $6 \times 7 / 2$.

For a rank-2 symmetric tensor, you have $(n/2) (n+1)$ independent components. For an anti-symmetric tensor you have $(n/2) (n-1)$ independent components. So for each of our pairs of anti-symmetric indices, there are $(n/2) (n-1)$ independent components. We can then treat the two pairs as a single pair of symmetric indices, with that many possible values. The number of indices is therefore:
%
\begin{displaymath}
  (1/2) [(n/2) (n-1)] [(n/2) (n-1) + 1] =
  (1/2) [(4/2) (4-1)] [(4/2) (4-1) + 1] =
  6 \times 7 / 2 = 21.
\end{displaymath}

\item Show that Equation 6.70 only imposes one additional relation, separate from Equation 6.69, reducing the total independent components to 20.

The addition of Equation 6.70 adds the condition that $R_{\alpha[\beta\mu\nu]} = 0$, and so the number of independent components becomes
%
\begin{displaymath}
  \qty(\!\!\binom{4}{3}\!\!) =
  \binom{4+3-1}{3} =
  \binom{6}{3} =
  20.
\end{displaymath}

\end{enumerate}

\textbf{19}
Prove that the components of the Riemann tensor are all zero for polar coordinates in the Euclidean plane. Recall that:
%
\begin{align*}
  \tensor{\Gamma}{^\theta_{(\theta r)}} &= 1/r; \quad
  \tensor{\Gamma}{^r_{\theta\theta}} = -r
  \\
  \tensor{R}{^\alpha_{\beta\mu\nu}} &=
  \tensor{\Gamma}{^\alpha_{\beta\nu,\mu}} -
  \tensor{\Gamma}{^\alpha_{\beta\mu,\nu}} +
  \tensor{\Gamma}{^\alpha_{\sigma\mu}} \tensor{\Gamma}{^\sigma_{\beta\nu}} -
  \tensor{\Gamma}{^\alpha_{\sigma\nu}} \tensor{\Gamma}{^\sigma_{\beta\mu}}.
\end{align*}

According to the computer algebra system, \texttt{Maxima}, the components are all zero.

\begin{verbatim}
(%i1) load(ctensor)$

(%i2) ct_coordsys(polar)$

(%i3) cmetric()$

(%i4) lg;
                                   [ 1  0  ]
(%o4)                              [       ]
                                   [     2 ]
                                   [ 0  r  ]
(%i5) riemann(mcs);
This spacetime is flat
(%o5)                                done
\end{verbatim}

% \begin{table}[ht]
%   \centering
%   \begin{tabular}{llll|l}
%     $\alpha$ & $\beta$ & $\mu$ & $\nu$ & $\tensor{R}{^\alpha_{\beta\mu\nu}}$ \\
%     \hline
%     $\theta$ & $\theta$ & $\theta$ & $\theta$ \\
%     $\theta$ & $\theta$ & $\theta$ & $r$ \\
%     $\theta$ & $\theta$ & $r$ & $\theta$ \\
%     $\theta$ & $\theta$ & $r$ & $r$ \\
%     $\theta$ & $r$ & $\theta$ & $\theta$ \\
%     $\theta$ & $r$ & $\theta$ & $r$ \\
%     $\theta$ & $r$ & $r$ & $\theta$ \\
%     $\theta$ & $r$ & $r$ & $r$ \\
%     $r$ & $\theta$ & $\theta$ & $\theta$ \\
%     $r$ & $\theta$ & $\theta$ & $r$ \\
%     $r$ & $\theta$ & $r$ & $\theta$ \\
%     $r$ & $\theta$ & $r$ & $r$ \\
%     $r$ & $r$ & $\theta$ & $\theta$ \\
%     $r$ & $r$ & $\theta$ & $r$ \\
%     $r$ & $r$ & $r$ & $\theta$ \\
%     $r$ & $r$ & $r$ & $r$ \\
%   \end{tabular}
%   \caption{Problem 19: Components on the Riemann tensor.}
%   \label{tab:ch6-problem19}
% \end{table}

\textbf{24}
Using Equation 6.88, derive Equation 6.89.

\begin{align*}
  R_{\alpha\beta\mu\nu,\lambda} &=
  \frac{1}{2} (
    g_{\alpha\nu,\beta\mu\lambda} -
    g_{\alpha\mu,\beta\nu\lambda} +
    g_{\beta\mu,\alpha\nu\lambda} -
    g_{\beta\nu,\alpha\mu\lambda}
  )
  \\
  R_{\alpha\beta\lambda\mu,\nu} &=
  \frac{1}{2} (
    g_{\alpha\mu,\beta\lambda\nu} -
    g_{\alpha\lambda,\beta\mu\nu} +
    g_{\beta\lambda,\alpha\mu\nu} -
    g_{\beta\mu,\alpha\lambda\nu}
  )
  \\
  R_{\alpha\beta\nu\lambda,\mu} &=
  \frac{1}{2} (
    g_{\alpha\lambda,\beta\nu\mu} -
    g_{\alpha\nu,\beta\lambda\mu} +
    g_{\beta\nu,\alpha\lambda\mu} -
    g_{\beta\lambda,\alpha\nu\mu}
  )
  \\
  2 (
    R_{\alpha\beta\mu\nu,\lambda} +
    R_{\alpha\beta\lambda\mu,\nu} +
    R_{\alpha\beta\nu\lambda,\mu}
  ) &=
  {\color{red} g_{\alpha\nu,\beta\mu\lambda}} -
  {\color{orange} g_{\alpha\mu,\beta\nu\lambda}} +
  {\color{brown} g_{\beta\mu,\alpha\nu\lambda}} -
  {\color{green} g_{\beta\nu,\alpha\mu\lambda}}
  \\* &+
  {\color{orange} g_{\alpha\mu,\beta\lambda\nu}} -
  {\color{blue} g_{\alpha\lambda,\beta\mu\nu}} +
  {\color{violet} g_{\beta\lambda,\alpha\mu\nu}} -
  {\color{brown} g_{\beta\mu,\alpha\lambda\nu}}
  \\* &+
  {\color{blue} g_{\alpha\lambda,\beta\nu\mu}} -
  {\color{red} g_{\alpha\nu,\beta\lambda\mu}} +
  {\color{green} g_{\beta\nu,\alpha\lambda\mu}} -
  {\color{violet} g_{\beta\lambda,\alpha\nu\mu}}
  \\* &=
  0
\end{align*}

\textbf{25}

\begin{enumerate}[(a)]
\item Prove the Ricci tensor is the only independent contraction of the Riemann tensor. All others are $\pm \tensor{R}{^\alpha_{\beta\mu\nu}}$ or $0$.

There are three possible ways to contract the Riemann tensor. If we contract on the second lower index, we have the definition of the Ricci tensor: $R_{\beta\nu} = \tensor{R}{^\alpha_{\beta\alpha\nu}}$.

The value of contracting the last index is the easiest to find, and can be found by manipulating the above expression and invoking the anti-symmetry properties of the Riemann tensor:
%
\begin{displaymath}
  R_{\beta\nu} =
  \tensor{R}{^\alpha_{\beta\alpha\nu}} =
 -\tensor{R}{^\alpha_{\beta\nu\alpha}}
  \implies
  \tensor{R}{^\alpha_{\beta\nu\alpha}} =
 -R_{\beta\nu}.
\end{displaymath}
%
Given this identity, finding the value of the remaining contraction is easy. Equation 6.70 states that
%
\begin{displaymath}
  R_{\alpha\beta\mu\nu} + R_{\alpha\nu\beta\mu} + R_{\alpha\mu\nu\beta} = 0.
\end{displaymath}
%
If we raise the $\alpha$'s with the metric, we get
%
\begin{align*}
  g^{\alpha\beta}
  (R_{\alpha\beta\mu\nu} + R_{\alpha\nu\beta\mu} + R_{\alpha\mu\nu\beta}) &=
  0
  \\
  \tensor{R}{^\beta_{\beta\mu\nu}} +
  \tensor{R}{^\beta_{\nu\beta\mu}} +
  \tensor{R}{^\beta_{\mu\nu\beta}} &=
  0
  \\
  \tensor{R}{^\beta_{\beta\mu\nu}} +
  \tensor{R}{^\beta_{\nu\beta\mu}} -
  \tensor{R}{^\beta_{\mu\beta\nu}} &=
  0
  \\
  \tensor{R}{^\beta_{\beta\mu\nu}} &=
  0
\end{align*}

\item Show that the Ricci tensor is symmetric.

\begin{align*}
  R_{\beta\nu} &=
  \tensor{R}{^\alpha_{\beta\alpha\nu}}
  \\
  g_{\alpha\lambda} R_{\beta\nu} &=
  \tensor{R}{_{\lambda\beta\alpha\nu}} =
  \tensor{R}{_{\alpha\nu\lambda\beta}}
  \\
  g^{\alpha\lambda} g_{\alpha\lambda} R_{\beta\nu} &=
  g^{\alpha\lambda} \tensor{R}{_{\alpha\nu\lambda\beta}} =
  \tensor{R}{^\lambda_{\nu\lambda\beta}} = R_{\nu\beta}
  \\ \implies
  R_{\beta\nu} &= R_{\nu\beta}
\end{align*}

\end{enumerate}

\textbf{28}
\begin{enumerate}[(a)]
\item Derive Equation 6.19 using the coordinate transformation
  $(x,y,z) \to (r,\theta,\phi)$

We begin by finding the basis vectors in $(r,\theta,\phi)$, using
%
\begin{align*}
  \vec{e}_r &=
  \pdv{x}{r} \vec{e}_x +
  \pdv{y}{r} \vec{e}_y +
  \pdv{z}{r} \vec{e}_z,
  \\
  \vec{e}_\theta &=
  \pdv{x}{\theta} \vec{e}_x +
  \pdv{y}{\theta} \vec{e}_y +
  \pdv{z}{\theta} \vec{e}_z,
  \\
  \vec{e}_\phi &=
  \pdv{x}{\phi} \vec{e}_x +
  \pdv{y}{\phi} \vec{e}_y +
  \pdv{z}{\phi} \vec{e}_z.
\end{align*}
%
The variables transform according to
%
\begin{align*}
  x &= r \sin\theta \cos\phi,
  \\
  y &= r \sin\theta \sin\phi,
  \\
  z &= r \cos\theta.
\end{align*}
%
Now we take the derivatives
%
\begin{align*}
  \pdv{x}{r}      &=    \sin\theta \cos\phi, &
  \pdv{x}{\theta} &=  r \cos\theta \cos\phi, &
  \pdv{x}{\phi}   &= -r \sin\theta \sin\phi,
  \\
  \pdv{y}{r}      &=    \sin\theta \sin\phi, &
  \pdv{y}{\theta} &=  r \cos\theta \sin\phi, &
  \pdv{y}{\phi}   &= -r \sin\theta \cos\phi,
  \\
  \pdv{z}{r}      &=    \cos\theta, &
  \pdv{z}{\theta} &= -r \sin\theta, &
  \pdv{z}{\phi}   &=  0.
\end{align*}
%
The basis vectors are therefore
%
\begin{align*}
  \vec{e}_r &=
    \sin\theta \cos\phi \vec{e}_x +
    \sin\theta \sin\phi \vec{e}_y +
    \cos\theta          \vec{e}_z
  \\
  \vec{e}_\theta &=
  r \cos\theta \cos\phi \vec{e}_x +
  r \cos\theta \sin\phi \vec{e}_y -
  r \sin\theta          \vec{e}_z
  \\
  \vec{e}_\phi &=
 -r \sin\theta \sin\phi \vec{e}_x +
  r \sin\theta \cos\phi \vec{e}_y
\end{align*}
%
Now we find the components of the metric tensor using the fact that
$g_{\alpha\beta} = \vec{e}_\alpha \cdot \vec{e}_\beta$.
%
\begin{align*}
  g_{rr} =
  \vec{e}_r \cdot \vec{e}_r &=
  (\sin\theta \cos\phi)^2 \delta_{xx} +
  (\sin\theta \sin\phi)^2 \delta_{yy} +
  (\cos^2\theta)^2 \delta_{zz} +
  \ldots
  \\ &=
  \sin^2\theta \cos^2\phi +
  \sin^2\theta \sin^2\phi +
  \cos^2\theta =
  \sin^2\theta + \cos^2\theta
  \\ &=
  1,
  \\
  g_{\theta\theta} =
  \vec{e}_\theta \cdot \vec{e}_\theta &=
  (r \cos\theta \cos\phi)^2 \delta_{xx} +
  (r \cos\theta \sin\phi)^2 \delta_{yy} +
  (-r \sin\theta)^2 \delta_{zz}
  \\ &=
  r^2 (\cos^2\theta \cos^2\phi + \cos^2\theta \sin^2\phi + \sin^2\theta)
  \\ &=
  r^2 (\cos^2\theta + \sin^2\theta)
  \\ &=
  r^2,
  \\
  g_{\phi\phi} =
  \vec{e}_\phi \cdot \vec{e}_\phi &=
  (-r \sin\theta \sin\phi)^2 \delta_{xx} +
  ( r \sin\theta \cos\phi)^2 \delta_{yy}
  \\ &=
  r^2 (\sin^2\theta \sin^2\phi + \sin^2\theta \cos^2 \phi)
  \\ &=
  r^2 \sin^2\theta.
\end{align*}
%
Now for the off-diagonal elements, we take advantage of the symmetry properties of the metric to reduce it from 6 terms to 3.
%
\begin{align*}
  g_{r \theta} = g_{\theta r} =
  \vec{e}_r \cdot \vec{e}_\theta &=
  (\sin\theta \cos\phi) ( r \cos\theta \cos\phi) \delta_{xx} +
  (\sin\theta \sin\phi) ( r \cos\theta \sin\phi) \delta_{yy} +
  (\cos\theta)          (-r \sin\theta)          \delta_{zz}
  \\ &=
  r \qty(
    \sin\theta \cos\theta \cos^2\phi +
    \sin\theta \cos\theta \sin^2\phi -
    \sin\theta \cos\theta
  )
  \\ &=
  0,
  \\
  g_{r \phi} = g_{\phi r} =
  \vec{e}_r \cdot \vec{e}_\phi &=
  (\sin\theta \cos\phi) (-r \sin\theta \sin\phi) \delta_{xx} +
  (\sin\theta \sin\phi) ( r \sin\theta \cos\phi) \delta_{yy} +
  (\cos\theta) (0) \delta_{zz}
  \\ &=
  r (-\sin^2\theta \sin\phi \cos\phi + \sin^2\theta \sin\phi \cos\phi)
  \\ &=
  0,
  \\
  g_{\theta \phi} = g_{\phi \theta} =
  \vec{e}_\theta \cdot \vec{e}_\phi &=
  (r \cos\theta \cos\phi) (-r \sin\theta \sin\phi) \delta_{xx} +
  (r \cos\theta \sin\phi) ( r \sin\theta \cos\phi) \delta_{yy}
  \\ &=
  r^2 (
   -\cos\theta \cos\phi \sin\theta \sin\phi +
    \cos\theta \cos\phi \sin\theta \sin\phi
  )
  \\ &=
  0.
\end{align*}
%
The metric tensor in spherical polar coordinates is therefore
%
\begin{displaymath}
  (g_{ij}) = \mqty(\dmat[0]{1,r^2,r^2\sin^2\theta}).
\end{displaymath}

\item Use Equation 6.19 to find the metric on the surface of a sphere.

On the surface of a sphere, $r$ is fixed, and therefore $\Delta r = 0$. As a result of this, we do not need to consider $g_{rr}$, and the only relevant components become $(\theta,\phi)$. So we can simplify the metric as:
%
\begin{displaymath}
  (g_{ij}) = \mqty(\dmat[0]{r^2,r^2\sin^2\theta}).
\end{displaymath}

\item Find the components of $g^{\alpha\beta}$ on the surface of a sphere.

Since $g_{\alpha\beta}$ is a diagonal matrix, the components of its inverse are simply equal to their multiplicative inverse. So the matrix is
%
\begin{displaymath}
  (g_{ij}) = \mqty(\dmat[0]{1/r^2,1/r^2\sin^2\theta}).
\end{displaymath}

\end{enumerate}

\textbf{29}
Calculate the Riemann tensor of the unit sphere in spherical polar coordinates.

The metric for a unit sphere in spherical polars is
%
\begin{displaymath}
  (g_{ij}) = \mqty(\dmat[0]{1,\sin^2\theta}),
\end{displaymath}
%
and so one component of the Riemann tensor is
%
\begin{align*}
  R_{\theta\phi\theta\phi} &=
  \frac{1}{2} \qty(
    g_{\theta\phi,\phi\theta} -
    g_{\theta\theta,\phi\phi} +
    g_{\phi\theta,\theta\phi} -
    g_{\phi\phi,\theta\theta}
  ) =
  \frac{1}{2} \qty(
    g_{\theta\theta,\phi\phi} -
    g_{\phi\phi,\theta\theta}
  )
  \\ &=
  \frac{1}{2} \qty(
    \pdv[2]{\phi}   1 -
    \pdv[2]{\theta} \sin^2\theta
  ) =
  \frac{1}{2} \sin^2\theta.
\end{align*}
%
Using the symmetry and anti-symmetry properties of the Riemann tensor, we find the remaining components:
%
\begin{align*}
  R_{\phi\theta\phi\theta} &=
  \sin^2\theta
  \\
  R_{\theta\phi\phi\theta} &=
  R_{\phi\theta\theta\phi} =
 -\sin^2\theta.
\end{align*}
%
All remaining components are zero, as they have indices $\theta\theta\theta\phi$ or $\phi\phi\phi\theta$, and the only non-zero second derivative of the metric is $g_{\phi\phi,\theta\theta}$, which requires two of each index, not three.

\textbf{30}
Calculate the Riemann tensor on a cylinder.

The metric in cylindrical polars, $(r,\theta,z)$, is given by
%
\begin{displaymath}
  (g_{ij}) = \mqty(\dmat[0]{1,r^2,1}).
\end{displaymath}
%
On the surface of a cylinder (excluding the top and bottom) the radius is unchanging, so $\Delta r = $, as was the case on the surface of a sphere. The metric can therefore be simplified in $(\theta,z)$ coordinates as:
%
\begin{displaymath}
  (g_{ij}) = \mqty(\dmat[0]{r^2,1}).
\end{displaymath}
%
From the metric alone, it is obvious that the components of the Riemann tensor must \emph{all} be zero. This is because the Riemann tensor depends on second derivatives of the components of the metric, and the only variable term is $g_{\theta\theta} = r^2$. Since we removed the dependence on the \emph{coordinate} $r$, \emph{none} of the terms in the Riemann tensor will involve differentiating with respect to $r$, and therefore they will \emph{all} be zero.

\textbf{32}
A $4$D manifold has coodinates $(u,v,w,p)$, and a metric
%
\begin{displaymath}
  (g_{\alpha\beta}) =
  \mqty( 0 & 1 & 0 & 0 \\
         1 & 0 & 0 & 0 \\
         0 & 0 & 1 & 0 \\
         0 & 0 & 0 & 1 ).
\end{displaymath}

\begin{enumerate}[(a)]
\item Show that the manifold is flat and has signature $+2$.

Since every element in the metric is a constant, $g_{\alpha\beta,\mu\nu} \equiv 0$, and therefore $R_{\alpha\beta\mu\nu} \equiv 0$, so the manifold is flat.

The signature is just the sum of the diagonal elements, which in this case is $1 + 1 = 2$.

\item Since this manifold is flat and has signature $+2$, it must be a Minkowski spacetime. Find a coordinate transformation to $(t,x,y,z)$.

\begin{align*}
  \Lambda g &= \eta
  \\
  \Lambda g g^{-1} &= \eta g^{-1}
  \\
  \Lambda &= \eta g^{-1} = \eta g
  \text{ (since $g$ is symmetric)}
  \\
  (\Lambda_{\alpha\beta}) &=
  \mqty(\dmat[0]{-1,1,1,1})
  \mqty( 0 & 1 & 0 & 0 \\
         1 & 0 & 0 & 0 \\
         0 & 0 & 1 & 0 \\
         0 & 0 & 0 & 1 ) =
  \mqty( 0 & -1 & 0 & 0 \\
         1 &  0 & 0 & 0 \\
         0 &  0 & 1 & 0 \\
         0 &  0 & 0 & 1 )
\end{align*}

\end{enumerate}

\textbf{33}
A three-sphere (or glome) is the 4D analog of a sphere, with cartesian coordinates $(x,y,z,w)$, described by the equation $x^2+y^2+z^2+w^2=r^2$, where $r$ is its radius.

\begin{enumerate}[(a)]
\item Define coordinates $(r,\theta,\phi,\chi)$, given by
%
\begin{align*}
  x &= r \sin\chi \sin\theta \cos\phi, &
  y &= r \sin\chi \sin\theta \sin\phi,
  \\
  z &= r \sin\chi \cos\theta, &
  w &= r \cos\chi,
\end{align*}
%
and show that $(\theta,\phi,\chi)$ form the coordinates of the surface of the sphere.

Per usual, we begin by finding the elements of the Jacobian
%
\begin{displaymath}
  \Lambda : (x,y,z,w) \to (r,\theta,\phi,\chi).
\end{displaymath}
%
\begin{align*}
  \pdv*{x}{r} &=
  \sin\chi \sin\theta \cos\phi, &
  \pdv*{y}{r} &=
  \sin\chi \sin\theta \sin\phi, &
  \pdv*{z}{r} &=
  \sin\chi \cos\theta, &
  \pdv*{w}{r} &=
  \cos\chi,
  \\
  \pdv*{x}{\theta} &=
  r \sin\chi \cos\theta \cos\phi, &
  \pdv*{y}{\theta} &=
  r \sin\chi \cos\theta \sin\phi, &
  \pdv*{z}{\theta} &=
  -r \sin\chi \sin\theta, &
  \pdv*{w}{\theta} &=
  0,
  \\
  \pdv*{x}{\phi} &=
  -r \sin\chi \sin\theta \sin\phi, &
  \pdv*{y}{\phi} &=
  r \sin\chi \sin\theta \cos\phi, &
  \pdv*{z}{\phi} &=
  0, &
  \pdv*{w}{\phi} &=
  0,
  \\
  \pdv*{x}{\chi} &=
  r \cos\chi \sin\theta \cos\phi, &
  \pdv*{y}{\chi} &=
  r \cos\chi \sin\theta \sin\phi, &
  \pdv*{z}{\chi} &=
  r \cos\chi \cos\theta, &
  \pdv*{w}{\chi} &=
  -r \sin\chi.
\end{align*}
%
the basis vectors are then
%
\begin{align*}
  \vec{e}_\xi &=
  \pdv{x^\alpha}{\xi} \vec{e}_\alpha &
  \\
  \vec{e}_r &=
  \sin\chi \sin\theta \cos\phi \vec{e}_x &
%
  \vec{e}_\theta &=
  r \sin\chi \cos\theta \cos\phi \vec{e}_x &
%
  \vec{e}_\phi &=
  -r \sin\chi \sin\theta \sin\phi \vec{e}_x &
  \vec{e}_\chi &=
  r \cos\chi \sin\theta \cos\phi \vec{e}_x
  \\ &+ %%%%
  \sin\chi \sin\theta \sin\phi \vec{e}_y &&+
%
  r \sin\chi \cos\theta \sin\phi \vec{e}_y &&+
%
  r \sin\chi \sin\theta \cos\phi \vec{e}_y &&+
%
  r \cos\chi \sin\theta \sin\phi \vec{e}_y
  \\ &+ %%%%
  \sin\chi \cos\theta \vec{e}_z &&-
%
  r \sin\chi \sin\theta \vec{e}_z &&
%
  &&+
%
  r \cos\chi \cos\theta
  \\ &+
  \cos\chi \vec{e}_w &&
%
  &&
%
  &&-
%
  r \sin\chi \vec{e}_w
\end{align*}
%
Notice that if we fix $\chi = \pi/2$, this reduces to the basis vectors for 2D spherical polars.

The components of the metric can be found using
$g_{\alpha\beta} = \vec{e}_\alpha \cdot \vec{e}_\beta$.
%
\begin{align*}
  g_{rr} &=
  \sin^2\chi \sin^2\theta \cos^2\phi \eta_{xx} +
  \sin^2\chi \sin^2\theta \sin^2\phi \eta_{yy} +
  \sin^2\chi \cos^2\theta \eta_{zz} +
  \cos^2\chi \eta_{ww}
  \\* &=
  \sin^2\chi (\sin^2\theta + \cos^2\theta) + \cos^2\chi =
  \sin^2\chi + \cos^2\chi =
  1
  \\
  g_{\theta\theta} &=
  r^2 \qty(
    \sin^2\chi \cos^2\chi \cos^2\phi \eta_{xx} +
    \sin^2\chi \cos^2\theta \sin^2\phi \eta_{yy} +
    \sin^2\chi \sin^2\theta \eta_{zz}
  )
  \\* &=
  r^2 \sin^2\chi (\cos^2\theta + \sin^2\theta) =
  r^2 \sin^2\chi
  \\
  g_{\phi\phi} &=
  r^2 \qty(
    \sin^2\chi \sin^2\theta \sin^2\phi \eta_{xx} +
    \sin^2\chi \sin^2\theta \cos^2\phi \eta_{yy}
  )
  \\* &=
  r^2 \sin^2\chi \sin^2\theta
  \\
  g_{\chi\chi} &=
  r^2 \qty(
    \cos^2\chi \sin^2\theta \cos^2\phi \eta_{xx} +
    \cos^2\chi \sin^2\theta \sin^2\phi \eta_{yy} +
    \cos^2\chi \cos^2\theta \eta_{zz} +
    \sin^2\chi \eta_{ww}
  )
  \\* &=
  r^2 \qty(
    \cos^2\chi \sin^2\theta +
    \cos^2\chi \cos^2\theta +
    \sin^2\chi
  ) =
  r^2 \qty( \cos^2\chi + \sin^2\chi ) =
  r^2
\end{align*}

To show that the off-diagonal terms are zero, I got lazy and used the Maxima computer algebra system. Its naming convention and ordering for these coordinates is different, but it still makes it clear that the metric is diagonal.

\begin{verbatim}
(%i1) load(ctensor)$            /* load the component tensor package */
(%i2) ct_coordsys(spherical4d)$ /* use the 3-sphere metric */
(%i3) lg;                       /* display the metric */
              [ 1  0         0                    0             ]
              [                                                 ]
              [     2                                           ]
              [ 0  r         0                    0             ]
(%o3)         [                                                 ]
              [         2    2                                  ]
              [ 0  0   r  sin (theta)             0             ]
              [                                                 ]
              [                           2       2    2        ]
              [ 0  0         0         sin (eta) r  sin (theta) ]
\end{verbatim}

So in our notation, the metric tensor is
%
\begin{displaymath}
  (g_{ij}) =
  \mqty(\dmat[0]{1, r^2\sin^2\chi, r^2\sin^2\chi\sin^2\theta, r^2}).
\end{displaymath}

\item Show that the metric on the \emph{surface} of the three-sphere only has non-zero components $g_{\theta\theta}$, $g_{\phi\phi}$, and $g_{\chi\chi}$.

On the surface of a three-sphere, $r$ is unchanging, so $\Delta r$ is always zero. Thus, we may reduce the dimensionality of the metric to 3: $(\theta,\phi,\chi)$.
%
\begin{displaymath}
  (g_{ij}) =
  \mqty(\dmat[0]{r^2\sin^2\chi, r^2\sin^2\chi\sin^2\theta, r^2}).
\end{displaymath}

\end{enumerate}

\textbf{34}
Prove the following identities for a general metric tensor in a general coordinate system. Equations 6.39 and 6.40 will be helpful.

\begin{enumerate}[(a)]
\item $\tensor{\Gamma}{^\mu_{\mu\nu}} = \frac{1}{2} (\ln\abs{g})_{,\nu}$
%
\begin{displaymath}
  \tensor{\Gamma}{^\mu_{\mu\nu}} =
  \frac{(\sqrt{-g})_{,\nu}}{\sqrt{-g}} =
  \frac{1}{2 \sqrt{-g}} \frac{(-g)_{,\nu}}{\sqrt{-g}} =
  \frac{(-g)_{,\nu}}{2 (-g)} =
  \frac{\abs{g}_{,\nu}}{2 \abs{g}} =
  \frac{1}{2} (\ln\abs{g})_{,\nu}
\end{displaymath}
%
\item $g^{\mu\nu} \tensor{\Gamma}{^\alpha_{\mu\nu}} =
       (-g^{\alpha\beta} \sqrt{-g})_{,\beta} / \sqrt{-g}$
%
\begin{align*}
  g^{\mu\nu} \tensor{\Gamma}{^\alpha_{\mu\nu}} &=
 -(g^{\alpha\beta} \sqrt{-g})_{,\beta} / \sqrt{-g}
  \\ &=
 -(g^{\alpha\beta} (\sqrt{-g})_{,\beta} +
   \tensor{g}{^{\alpha\beta}_{,\beta}} \sqrt{-g}) / \sqrt{-g}
  \\ &=
  -(g^{\alpha\beta} (\sqrt{-g})_{,\beta} / \sqrt{-g} +
    \tensor{g}{^{\alpha\beta}_{,\beta}})
  \\ &=
  -(g^{\alpha\beta} \tensor{\Gamma}{^\lambda_{\lambda\beta}} +
    \tensor{g}{^{\alpha\beta}_{,\beta}})
  \\
  \frac{1}{2} g^{\mu\nu} g^{\beta\alpha}
  (g_{\beta\mu,\nu} + g_{\beta\nu,\mu} - g_{\mu\nu,\beta}) &=
  -(g^{\alpha\beta} g^{\lambda\sigma} g_{\lambda\sigma,\beta} / 2 +
    \tensor{g}{^{\alpha\beta}_{,\beta}})
  \\
  \frac{1}{2} g^{\mu\nu} g^{\beta\alpha}
  (g_{\beta\mu,\nu} + g_{\beta\nu,\mu}) -
  g^{\mu\nu} g^{\beta\alpha} g_{\mu\nu,\beta} / 2 &=
  -(g^{\alpha\beta} g^{\lambda\sigma} g_{\lambda\sigma,\beta} / 2 +
    \tensor{g}{^{\alpha\beta}_{,\beta}})
  \\
  \frac{1}{2} g^{\mu\nu} g^{\beta\alpha}
  (g_{\beta\mu,\nu} + g_{\beta\nu,\mu}) &=
 -\tensor{g}{^{\alpha\beta}_{,\beta}}
  \\
 -\frac{1}{2} g^{\mu\nu}
  (\tensor{g}{^{\beta\alpha}_{,\nu}} g_{\beta\mu} +
   \tensor{g}{^{\beta\alpha}_{,\mu}} g_{\beta\nu}) &=
 -\tensor{g}{^{\alpha\beta}_{,\beta}}
  \\
 -\frac{1}{2}
  (\tensor{\delta}{_\beta^\nu} \tensor{g}{^{\beta\alpha}_{,\nu}} +
   \tensor{\delta}{_\beta^\mu} \tensor{g}{^{\beta\alpha}_{,\mu}}) &=
 -\tensor{g}{^{\alpha\beta}_{,\beta}}
  \\
 -\frac{1}{2}
  (2 \tensor{g}{^{\beta\alpha}_{,\beta}}) &=
 -\tensor{g}{^{\alpha\beta}_{,\beta}}
\end{align*}
%
\item
  $\tensor{F}{^{[\mu\nu]}_{;\nu}} =
   (\sqrt{-g} F^{[\mu\nu]})_{,\nu} / \sqrt{-g}$
%
\begin{displaymath}
  \tensor{F}{^{[\mu\nu]}_{;\nu}} =
  \tensor{F}{^{[\mu\nu]}_{,\nu}} +
  F^{[\mu\nu]} \tensor{\Gamma}{^\alpha_{\nu\alpha}} =
  (\tensor{F}{^{[\mu\nu]}_{,\nu}} \sqrt{-g} +
   F^{\mu\nu} (\sqrt{-g})_{,\nu}) / \sqrt{-g} =
  (\sqrt{-g} F^{\mu\nu})_{,\nu}
\end{displaymath}
%
\item $g^{\alpha\sigma} g_{\sigma\beta,\gamma} =
      -\tensor{g}{^{\alpha\sigma}_{,\gamma}} g_{\sigma\beta}$
%
We start with $g^{\alpha\sigma} g_{\sigma\beta} = \tensor{\delta}{^\alpha_\beta}$. Then we differentiate both sides to get
%
\begin{align*}
  \tensor{g}{^{\alpha\sigma}_{,\gamma}} g_{\sigma\beta} &+
  g^{\alpha\sigma} g_{\sigma\beta,\gamma} =
  0
  \\
  g^{\alpha\sigma} g_{\sigma\beta,\gamma} &=
 -\tensor{g}{^{\alpha\sigma}_{,\gamma}} g_{\sigma\beta}
\end{align*}

\item $\tensor{g}{^{\mu\nu}_{,\alpha}} =
      -\tensor{\Gamma}{^\mu_{\beta\alpha}} g^{\beta\nu} -
       \tensor{\Gamma}{^\nu_{\beta\alpha}} g^{\mu\beta}$

\begin{align*}
  \tensor{g}{^{\mu\nu}_{;\alpha}} = \tensor{g}{^{\mu\nu}_{,\alpha}} &+
  \tensor{\Gamma}{^\mu_{\beta\alpha}} g^{\beta\nu} +
  \tensor{\Gamma}{^\nu_{\beta\alpha}} g^{\mu\beta} =
  0
  \\
  \tensor{g}{^{\mu\nu}_{,\alpha}} &=
 -\tensor{\Gamma}{^\mu_{\beta\alpha}} g^{\beta\nu} -
  \tensor{\Gamma}{^\nu_{\beta\alpha}} g^{\mu\beta}
\end{align*}

\end{enumerate}

\textbf{35}
Compute the metric tensor, Christoffel symbols, and Riemann tensor for a spacetime with line element:
%
\begin{displaymath}
  \dd{s^2} =
 -e^{2\Phi} \dd{t^2} +
  e^{2\Lambda} \dd{r^2} +
  r^2 (\dd{\theta^2} + \sin^2\theta \dd{\phi^2}).
\end{displaymath}

Based on the line element, the metric must be
%
\begin{align*}
  (g_{\alpha\beta}) &=
  \mqty(\dmat[0]{-e^{2\Phi}, e^{2\Lambda}, r^2, r^2 \sin^2\theta}) &
  (g^{\alpha\beta}) &=
  \mqty(\dmat[0]{-e^{-2\Phi}, e^{-2\Lambda}, 1/r^2, 1/r^2 \sin^2\theta})
\end{align*}

For the rest of this problem, I took advantage of the \texttt{Maxima} computer algebra system. According to it, the non-zero, unique Christoffel symbols are
%
\begin{align*}
  \tensor{\Gamma}{^r_{tt}} &=
  \exp(2\Phi - 2\Lambda) \dv{\Phi}{r}
  &
  \tensor{\Gamma}{^t_{rt}} &=
  \dv{\Phi}{r}
  \\
  \tensor{\Gamma}{^r_{rr}} &=
  \dv{\Lambda}{r}
  &
  \tensor{\Gamma}{^\theta_{r \theta}} =
  \tensor{\Gamma}{^\phi_{r \phi}} &=
  \frac{1}{r}
  \\
  \tensor{\Gamma}{^r_{\theta\theta}} &=
  -\exp(-2 \Lambda) r
  &
  \tensor{\Gamma}{^\phi_{\theta\phi}} &=
  \cot\theta
  \\
  \tensor{\Gamma}{^r_{\phi\phi}} &=
  -\exp(-2 \Lambda) r \sin^2\theta
  &
  \tensor{\Gamma}{^\theta_{\phi\phi}} &=
  -\sin\theta \cos\theta
\end{align*}
%
The independent non-zero components of the Riemann tensor are
%
\begin{align*}
  R_{t \theta t \theta} &=
  \exp(2(\Phi-\Lambda)) \qty[
    \dv{\Phi}{r} \qty(\dv{\Lambda}{r} - \dv{\Phi}{r}) - \dv[2]{\Phi}{r}
  ]
  &
  R_{t \theta t \theta} = R_{t \phi t \phi} &=
  -\frac{1}{r} \exp(2(\Phi - \Lambda)) \dv{\Phi}{r}
  \\
  R_{r r t t} &=
  \dv{\Lambda}{r} \dv{\Phi}{r} -
  \dv[2]{\Phi}{r} -
  \qty(\dv{\Phi}{r})^2
  &
  R_{r \theta r \theta} = R_{r \phi r \phi} &=
  -\frac{1}{r} \dv{\Lambda}{r}
  \\
  R_{\theta \phi \theta \phi} &=
  \exp(-2\Lambda) - 1
  &
  R_{\phi \phi \theta \theta} &=
  \exp(-2\Lambda) \qty(\exp(2 \Lambda) - 1) \sin^2\theta
  \\
  R_{\theta \theta t t} &=
  -r \exp(-2 \Lambda) \dv{\Phi}{r}
  &
  R_{\theta \theta r r} &=
  r \exp(-2 \Lambda) \dv{L}{r}
\end{align*}

\textbf{36}
Consider a 4D manifold with coordinates $(t,x,y,z)$ and line element
%
\begin{displaymath}
  \dd{s}^2 =
 -(1 + 2\phi) \dd{t}^2 +
  (1 - 2\phi) (\dd{x}^2 + \dd{y}^2 + \dd{z}^2),
\end{displaymath}
%
with $\abs{\phi(t,x,y,z)} \ll 1$. At an arbitrary point $\mathcal{P}$ with coordinates $(t_0,x_0,y_0,z_0)$, find a coordinate transformation to LIF. How does this frame accelerate with respect to the original coordinates? Do all of this to first order in $\phi$.

By inspection of the line element, we can see that the metric has components
%
\begin{displaymath}
  (g_{\alpha\beta}) \underset{(t,x,y,z)}{\to}
  \mqty(\dmat[0]{-(1+2\phi),(1-2\phi),(1-2\phi),(1-2\phi)}).
\end{displaymath}
%
We want a transformation to a Minkowski spacetime, i.e.
%
\begin{displaymath}
  \tensor{\Lambda}{^{\alpha'}_\alpha}
  \tensor{\Lambda}{^{\beta'}_\beta}
  g_{\alpha'\beta'} =
  \eta_{\alpha\beta}.
\end{displaymath}
%
Now, there may be multiple transformations which satisfy this, so we need only find one. Since both $\boldsymbol{g}$ and $\boldsymbol{\eta}$ are diagonal, I assume that $\boldsymbol{\Lambda}$ is diagonal as well, and find its components.
%
\begin{align*}
  \eta_{00} &=
  \tensor{\Lambda}{^{0'}_0}
  \tensor{\Lambda}{^{0'}_0}
  g_{0'0'} &
%%%%
  \eta_{ii} &=
  \tensor{\Lambda}{^{i'}_i}
  \tensor{\Lambda}{^{i'}_i}
  g_{i'i'}
  \\
  -1 &=
  (\tensor{\Lambda}{^{0'}_0})^2 (-(1 + 2\phi)) &
%%%%
  1 &=
  (\tensor{\Lambda}{^{i'}_i})^2
  (1 - 2\phi)
  \\
  \tensor{\Lambda}{^{0'}_0} &=
  (1 + 2\phi)^{-1/2} &
%%%%
  \tensor{\Lambda}{^{i'}_i} &=
  (1 - 2\phi)^{-1/2}
\end{align*}
%
Since we know that $\phi$ is small, we can use the approximation
$(1 + x)^{-1/2} = (1 - x/2) + \order{x^2}$, to find
%
\begin{align*}
  \tensor{\Lambda}{^{0'}_0} &\approx
  (1 - \phi) &
%%%%
  \tensor{\Lambda}{^{i'}_i} &\approx
  (1 + \phi)
\end{align*}

\textbf{(39)}

\end{document}


\chapter{Quadratic functions}
\section{Defined on $\mdr$}
Let $f:\mdr \rightarrow \mdr, f(x) = a \cdot x^2 + b \cdot x + c$ with $a \in \mdr \setminus \Set{0}$ and
$b, c \in \mdr$ be a quadratic function.

\begin{figure}[htp]
    \centering
\begin{tikzpicture}
    \begin{axis}[
        legend pos=north west,
        axis x line=middle,
        axis y line=middle,
        grid = major,
        width=0.8\linewidth,
        height=8cm,
        grid style={dashed, gray!30},
        xmin=-3,    % start the diagram at this x-coordinate
        xmax= 3,    % end   the diagram at this x-coordinate
        ymin=-0.25, % start the diagram at this y-coordinate
        ymax= 9,    % end   the diagram at this y-coordinate
        axis background/.style={fill=white},
        xlabel=$x$,
        ylabel=$y$,
        tick align=outside,
        minor tick num=-3,
        enlargelimits=true,
        tension=0.08]
      \addplot[domain=-3:3, thick,samples=50, red]    {0.5*x*x};
      \addplot[domain=-3:3, thick,samples=50, green]  { x*x};
      \addplot[domain=-3:3, thick,samples=50, blue]   { x*x +   x};
      \addplot[domain=-3:3, thick,samples=50, orange,dotted] { x*x + 2*x};
      \addplot[domain=-3:3, thick,samples=50, black,dashed]  {-x*x + 6};
      \addlegendentry{$f_1(x)=\frac{1}{2}x^2$}
      \addlegendentry{$f_2(x)=x^2$}
      \addlegendentry{$f_3(x)=x^2+x$}
      \addlegendentry{$f_4(x)=x^2+2x$}
      \addlegendentry{$f_5(x)=-x^2+6$}
    \end{axis}
\end{tikzpicture}
    \caption{Quadratic functions}
\end{figure}

\subsection{Calculate points with minimal distance}
In this case, $d_{P,f}^2$ is polynomial of degree $n^2 = 4$.
We use Theorem~\ref{thm:fermats-theorem}:\nobreak
\begin{align}
    0     &\overset{!}{=} (d_{P,f}^2)'\\
          &= 2x -2 x_p -2y_p f'(x) + \left (f(x)^2 \right )'\\
          &= 2x -2 x_p -2y_p f'(x) + 2 f(x) \cdot f'(x) \rlap{\hspace*{3em}(chain rule)}\label{eq:minimizingFirstDerivative}\\
\Leftrightarrow 0 &\overset{!}{=} x -x_p -y_p f'(x) + f(x) \cdot f'(x) \rlap{\hspace*{3em}(divide by 2)}\label{eq:minimizingFirstDerivative}\\
          &= x -x_p -y_p (2ax+b) + (ax^2+bx+c)(2ax+b)\\
          &= x -x_p -y_p \cdot 2ax- y_p b + (2 a^2 x^3+2 a b x^2+2 a c x+ab x^2+b^2 x+bc)\\
          &= x -x_p -2y_p ax- y_p b + (2a^2 x^3 + 3 ab x^2 + 2acx + b^2 x + bc)\\
          &= 2a^2 x^3 + 3 ab x^2 + (1 -2y_p a+ 2ac + b^2)x +(bc-by_p-x_p)\label{eq:quadratic-derivative-eq-0}
\end{align}

This is an algebraic equation of degree 3.
There can be up to 3 solutions in such an equation. Those solutions
can be found with a closed formula. But not every solution of the
equation given by Theorem~\ref{thm:fermats-theorem}
has to be a solution to the given problem as you can see in
Example~\ref{ex:false-positive}.
\goodbreak
\begin{example}\label{ex:false-positive}
    Let $a = 1,  b = 0,  c=-1, x_p= 0, y_p = 1$.
    So $f(x) = x^2 - 1$ and $P(0, 1)$.
    \begin{align}
        \xRightarrow{\text{Equation}~\ref{eq:quadratic-derivative-eq-0}} 0 &\stackrel{!}{=} 2x^3 - 3x\\
        &= x(2x^2-3)\\
        \Rightarrow x_{1,2} &= \pm \sqrt{\frac{3}{2}} \text{ and } x_3 = 0\\
        d_{P,f}(x_3) &= \sqrt{0^2 + (-1-1)^2} = 2\\
        d_{P,f} \left (\pm \sqrt{\frac{3}{2}} \right ) &= \sqrt{\left (\sqrt{\frac{3}{2} - 0} \right )^2 + \left (\frac{1}{2}-1 \right )^2}\\
            &= \sqrt{\nicefrac{3}{2}+\nicefrac{1}{4}} \\
            &= \sqrt{\nicefrac{7}{4}}\\
    \end{align}
    This means $x_3$ is not a point of minimal distance, although
    $(d_{P,f}(x_3))' = 0$.
\end{example}

\subsection{Number of points with minimal distance}
\begin{theorem}
    A point $P$ has either one or two points on the graph of a
    quadratic function $f$ that are closest to $P$.
\end{theorem}

\begin{proof}
The number of closests points of $f$ cannot be bigger than 3, because
Equation~\ref{eq:quadratic-derivative-eq-0} is a polynomial function
of degree 3. Such a function can have at most 3 roots. As $f$ has
at least one point on its graph, there is at least one point with
minimal distance.

In the following, I will do some transformations with $f = f_0$ and
$P = P_0$. This will make it easier to calculate the minimal distance
points. Moving $f_0$ and $P_0$ simultaneously in $x$ or $y$ direction does
not change the minimum distance. Furthermore, we can find the
points with minimum distance on the moved situation and calculate
the minimum points in the original situation.

First of all, we move $f_0$ and $P_0$ by $\frac{b}{2a}$ in $x$ direction, so
\[f_1(x) = ax^2 - \frac{b^2}{4a} + c \;\;\;\text{ and }\;\;\; P_1 = \left (x_p+\frac{b}{2a},\;\; y_p \right )\]

Because:\footnote{The idea why you subtract $\frac{b}{2a}$ within
$f$ is that when you subtract something from $x$ before applying
$f$ it takes more time ($x$ needs to be bigger) to get to the same
situation. In consequence, if we want to move the whole graph by 1
to the left, we have to add $+1$.}
\begin{align}
    f(x-\nicefrac{b}{2a}) &= a (x-\nicefrac{b}{2a})^2 + b (x-\nicefrac{b}{2a}) + c\\
    &= a (x^2 - \nicefrac{b}{a} x + \nicefrac{b^2}{4a^2}) + bx - \nicefrac{b^2}{2a} + c\\
    &= ax^2 - bx + \nicefrac{b^2}{4a} + bx - \nicefrac{b^2}{2a} + c\\
    &= ax^2 -\nicefrac{b^2}{4a} + c
\end{align}

Then move $f_1$ and $P_1$ by $\frac{b^2}{4a}-c$ in $y$ direction. You get:
\[f_2(x) = ax^2\;\;\;\text{ and }\;\;\; P_2 = \Big (\underbrace{x_P+\frac{b}{2a}}_{=: z},\;\; \underbrace{y_P+\frac{b^2}{4a}-c}_{=: w} \Big )\]

As $f_2(x) = ax^2$ is symmetric to the $y$ axis, only points
$P = (0, w)$ could possilby have three minima.

Then compute:
\begin{align}
  d_{P,{f_2}}(x)  &= \sqrt{(x-0)^2 + (f_2(x)-w)^2}\\
    &= \sqrt{x^2 + (ax^2-w)^2}\\
    &= \sqrt{x^2 + a^2 x^4-2aw x^2+w^2}\\
    &= \sqrt{a^2 x^4 + (1-2aw) x^2 + w^2}\\
    &= \sqrt{\left (a x^2 + \frac{1-2 a w}{2a} \right )^2 + w^2 - \left (\frac{1-2 a w}{2a} \right )^2}\\
    &= \sqrt{\left (a x^2 + \nicefrac{1}{2a}- w \right )^2 + \left (w^2 - \left (\frac{1-2 a w}{2a} \right )^2 \right)}
\end{align}

This means, the term
\[a^2 x^2 + (\nicefrac{1}{2a}- w)\]
has to get as close to $0$ as possilbe when we want to minimize
$d_{P,{f_2}}$. For $w \leq \nicefrac{1}{2a}$ you only have $x = 0$ as a minimum.
For all other points $P = (0, w)$, there are exactly two minima $x_{1,2} = \pm \sqrt{\frac{\frac{1}{2a} - w}{a}}$.
$\qed$
\end{proof}

\subsection{Solution formula}
We start with the graph that was moved so that $f_2 = ax^2$.

\textbf{Case 1:} $P$ is on the symmetry axis, hence $x_P = - \frac{b}{2a}$.

In this case, we have already found the solution. If $w = y_P + \frac{b^2}{4a} - c > \frac{1}{2a}$,
then there are two solutions:
\[x_{1,2} = \pm \sqrt{\frac{\frac{1}{2a} - w}{a}}\]
Otherwise, there is only one solution $x_1 = 0$.

\textbf{Case 2:} $P = (z, w)$ is not on the symmetry axis, so $z \neq 0$. Then you compute:
\begin{align}
  d_{P,{f_2}}(x)  &= \sqrt{(x-z)^2 + (f_2(x)-w)^2}\\
    &= \sqrt{(x^2 - 2zx + z^2) + ((ax^2)^2 - 2 awx^2 + w^2)}\\
    &= \sqrt{a^2x^4 + (1- 2 aw)x^2 +(- 2z)x + z^2 + w^2}\\
  0 &\stackrel{!}{=} \Big(\big(d_{P, {f_2}}(x)\big)^2\Big)' \\
    &= 4a^2x^3 + 2(1- 2 aw)x +(- 2z)\\
    &= 2 \left (2a^2x^3 + (1- 2 aw)x \right ) - 2z\\
    \Leftrightarrow 0 &\stackrel{!}{=} 2a^2x^3  + (1- 2 aw) x - z\\
\stackrel{a \neq 0}{\Leftrightarrow} 0 &\stackrel{!}{=} x^3 + \underbrace{\frac{1- 2 aw}{2 a^2}}_{=: \alpha} x  + \underbrace{\frac{-z}{2 a^2}}_{=: \beta}\\
    &= x^3 + \alpha x + \beta\label{eq:simple-cubic-equation-for-quadratic-distance}
\end{align}

Let $t$ be defined as
\[t := \sqrt[3]{\sqrt{3 \cdot (4 \alpha^3 + 27 \beta^2)} -9\beta}\]

\subsubsection{Analyzing $t$}
\input{analyzing-t.tex}

\subsubsection{Solutions of $x^3 + \alpha x + \beta$}
I will make use of the following identities:
\begin{align*}
    (1-i \sqrt{3})^2     &= -2 (1+i \sqrt{3})\\
    (1+i \sqrt{3})^2     &= -2 (1-i \sqrt{3})\\
    (1 \pm i \sqrt{3})^3 &= -8\\
    (a-b)^3              &= a^3-3 a^2 b+3 a b^2-b^3
\end{align*}

\textbf{Case 2.1:}
\input{quadratic-case-2.1}
\goodbreak
\textbf{Case 2.2:}
\input{quadratic-case-2.2}

\textbf{Case 2.3:}
\input{quadratic-case-2.3}

\goodbreak
So the solution is given by
\todo[inline]{NO! Currently, there are erros in the solution.
Check $f(x) = x^2$ and $P=(-2,4)$. Solution should be $x_1 = -2$, but it isn't!}
\begin{align*}
x_S &:= - \frac{b}{2a} \;\;\;\;\; \text{(the symmetry axis)}\\
w &:= y_P+\frac{b^2}{4a}-c \;\;\; \text{ and } \;\;\; z := x_P+\frac{b}{2a}\\
\alpha &:= \frac{1- 2 aw}{2 a^2} \;\;\;\text{ and }\;\;\; \beta := \frac{-z}{2 a^2}\\
t &:= \sqrt[3]{\sqrt{3 \cdot (4 \alpha^3 + 27 \beta^2)} -9\beta}\\
\underset{x\in\mdr}{\arg \min d_{P,f}(x)} &= \begin{cases}
     x_1 = +\sqrt{a (y_p + \frac{b^2}{4a} - c) - \frac{1}{2}} + x_S \text{ and }   &\text{if } x_P = x_S \text{ and } y_p + \frac{b^2}{4a} - c >  \frac{1}{2a} \\
     x_2 = -\sqrt{a (y_p + \frac{b^2}{4a} - c) - \frac{1}{2}} + x_S\\
     x_1 = x_S   &\text{if } x_P = x_S \text{ and } y_p + \frac{b^2}{4a} - c \leq  \frac{1}{2a} \\
     x_1 = \frac{t}{\sqrt[3]{18}} - \frac{\sqrt[3]{\frac{2}{3}} \alpha }{t}   &\text{if } x_P \neq x_S
    \end{cases}
\end{align*}
\clearpage

\section{Defined on a closed interval $[a,b] \subseteq \mdr$}
Now the problem isn't as simple as with constant and linear
functions.

If one of the minima in $S_2(P,f)$ is in $[a,b]$, this will be the
shortest distance as there are no shorter distances.

\todo[inline]{
The following IS WRONG! Can I include it to help the reader understand the
problem?}

If the function (defined on $\mdr$) has only one shortest distance
point $x$ for the given $P$, it's also easy: The point in $[a,b]$ that
is closest to $x$ will have the sortest distance.

\[\underset{x\in[a,b]}{\arg \min d_{P,f}(x)} = \begin{cases}
 S_2(f, P) \cap [a,b] &\text{if } S_2(f, P) \cap [a,b] \neq \emptyset \\
              \Set{a} &\text{if } |S_2(f, P)| = 1 \text{ and } S_2(f, P) \ni x < a\\
              \Set{b} &\text{if } |S_2(f, P)| = 1 \text{ and } S_2(f, P) \ni x > b\\
                 todo &\text{if } |S_2(f, P)| = 2 \text{ and } S_2(f, P) \cap [a,b] = \emptyset
    \end{cases}\]


\section{Question 4}
In this problem we use masserati ghibli data. For cancelling oscillation we use derivative controller to make overshoot low and increase gain to be fast enough with low overshoot.
\begin{center}
    \begin{table}[H]\caption{Maserati ghibli data}
        \centering
        \begin{tabular}{ c c c }
            \hline
            Paramete & Unit & Value \\
            \hline
            M & kg & 1900 \\
            $C_d$ & 1 & 0.29\\
            \hline
           \end{tabular}
    \end{table}
\end{center}
In this problem we use
\newpage
\begin{itemize}
    \item system step responde
    \begin{figure}[H]
        \caption{system step responde}
        \centering
        \includegraphics[width=12cm]{../Figure/Q4/Q4_system_respond.png}
    \end{figure}
    \item system rlocus
    \begin{figure}[H]
        \caption{system rlocus plot}
        \centering
        \includegraphics[width=12cm]{../Figure/Q4/Q4_system_rlocus.png}
    \end{figure}
    \item system with controller step responde
    \begin{figure}[H]
        \caption{system with controller step responde}
        \centering
        \includegraphics[width=12cm]{../Figure/Q4/Q4_system_controller_respond.png}
    \end{figure}
    \item system with controller rlocus
    \begin{figure}[H]
        \caption{system with controller rlocus plot}
        \centering
        \includegraphics[width=12cm]{../Figure/Q4/Q4_system_controller_rlocus.png}
    \end{figure}
    \item system with and without controller step responde
    \begin{figure}[H]
        \caption{system with and without controller step responde}
        \centering
        \includegraphics[width=12cm]{../Figure/Q4/Q4_respond_all.png}
    \end{figure}
    \item system with and without controller rlocus
    \begin{figure}[H]
        \caption{system with and withou controller rlocus plot}
        \centering
        \includegraphics[width=12cm]{../Figure/Q4/Q4_rlocus.png}
    \end{figure}
\end{itemize}


\documentclass[../main.tex]{subfiles}
\begin{document}

\setcounter{footnote}{0}

\chapter{Appendices}

\section{ML Representations}
\subsection{SOAP} \label{section::soap_derivation}

A SOAP vector\cite{Bartok2013} $\boldsymbol{p}$ is given by concatenating elements,
\begin{equation}
	p_{nn'l}^{Z_1, Z_2} = \pi \sqrt{\frac{8}{2l + 1}} \sum_m \left(c_{nlm}^{Z_1}\right)^* c_{n'lm}^{Z_2}
\end{equation}
for every pair of atoms with atomic number $Z$ and the coefficients ($c_{nlm}$) are of radial and angular basis functions centred a particular atom given by,
\begin{equation}
	c_{nlm}^Z = \int_\mathcal{R} g_n(r) Y_{lm}(\phi,\theta) \rho^Z(\boldsymbol{r})\; \text{d}V
\end{equation}
where the atomic density is given as a sum over 3D Gaussian centred on each atom $i$,
\begin{equation}
	\rho^Z(\boldsymbol{r}) = \sum_{i \in \{Z\}} \exp\left(-\frac{|\boldsymbol{r} - \boldsymbol{R}_i|^2}{2\sigma_\text{at}^2}\right)
\end{equation}
A component of the neighbour density is then ($a := 1/2\sigma_\text{at}^2$),
% https://journals.aps.org/prb/pdf/10.1103/PhysRevB.87.184115
% https://iopscience.iop.org/article/10.1088/0953-4075/22/1/004/pdf
\begin{equation}
	\text{e}^{-a|\boldsymbol{r} - \boldsymbol{R}_i|^2} = 4\pi \text{e}^{-a(r^2+R_i^2)}i_l(2arR_i) \sum_{l'm'}Y_{l'm'}(\phi, \theta) Y_{l'm'}^*(\boldsymbol{R}_i)
\end{equation}
inserting and using the orthogonality of the spherical harmonics integrated over theta and phi,
\begin{equation}
	\begin{split}
		c_{nlm}^Z &= \int_\mathcal{R} g_n(r) Y_{lm}(\phi,\theta)  \sum_{i \in \{Z\}} \exp\left(-a|\boldsymbol{r} - \boldsymbol{R}_i|^2\right) \text{d}V \\
		&= \sum_{i \in \{Z\}} \int_\mathcal{R} g_n(r) Y_{lm}(\phi,\theta) \exp\left(-a|\boldsymbol{r} - \boldsymbol{R}_i|^2\right) \text{d}V \\
		&=  4\pi \sum_{i \in \{Z\}}\sum_{l'm'} \int_\mathcal{R} g_n(r) Y_{lm}(\phi,\theta) \text{e}^{-a(r^2+R_i^2)}i_l(2arR_i)Y_{l'm'}(\phi, \theta) Y_{l'm'}^*(\boldsymbol{R}_i)  \text{d}V \\
		&=4\pi \sum_{i \in \{Z\}}Y_{lm}^*(\boldsymbol{R}_i) \int_\mathcal{\tilde{R}} g_n(r) \text{e}^{-a(r^2+R_i^2)}i_l(2arR_i)r^2\; \text{d}r
	\end{split}
\end{equation}
where $i_l$ is a modified spherical Bessel function of the first kind. Inserting a orthonormal radial basis as $g_n(r)$,
\begin{equation}
	\begin{split}
		c_{nlm}^Z &=4\pi \sum_{i \in \{Z\}}Y_{lm}^*(\boldsymbol{R}_i) \int_\mathcal{\tilde{R}} \sum_{n'}^{n_\text{max}} \beta_{nn'l}r^l e^{-\alpha_{n'l}r^2}\text{e}^{-a(r^2+R_i^2)} i_l(2arR_i)r^2\; \text{d}r \\
		&= 4\pi \sum_{i \in \{Z\}}Y_{lm}^*(\boldsymbol{R}_i)\text{e}^{-aR_i^2} \sum_{n'}^{n_\text{max}} \beta_{nn'l}\int_\mathcal{\tilde{R}} r^{l + 2}  \text{e}^{-(\alpha_{n'l} + a)r^2} i_l(2arR_i)\; \text{d}r.
	\end{split}
\end{equation}

Evaluating the integral where $b  := \alpha_{n'l} + a$ and $c_i:= 2aR_i$,

\begin{equation}
	I_{iln'} = \int_0^\infty r^{l+2} \text{e}^{-br^2}i_l(c_i r)\; \text{d}r
\end{equation}

using $i_\lambda(z) = i^{-\lambda}j_\lambda(iz)$ where from Gradshteyn and Ryzhik,\cite{Gradshteyn2007}
% https://arxiv.org/pdf/1908.07374.pdf

\[\int_0^\infty x^{\lambda + 2}\text{e}^{-k_1x^2}j_\lambda(k_2x) \text{d}x =
\sqrt{\frac{\pi}{2}} \frac{k_2^\lambda}{(2k_1)^{\lambda + 3/2}}\exp\left(-\frac{k_2^2}{4k_1}\right)\]

so the required integral is with $\lambda = l, k_1 = b, k_2 = ic_i$,

\begin{equation}
	\begin{split}
		I_{iln'} &= \sqrt{\frac{\pi}{2}} \frac{c_i^l}{(2b)^{l+3/2}}\exp\left(\frac{c_i^2}{4b}\right) \\
		&=  \sqrt{\frac{\pi}{2}} \frac{(2aR_i)^l}{(2(\alpha_{n'l} + a))^{l+3/2}}\exp\left(\frac{(aR_i)^2}{\alpha_{n'l} + a}\right)
	\end{split}
\end{equation}
so then,

\begin{equation}
	\begin{split}
		c_{nlm}^Z &= \sqrt{8\pi^3} \sum_{i \in \{Z\}}Y_{lm}^*(\boldsymbol{R}_i)\,\text{e}^{-aR_i^2} \sum_{n'}^{n_\text{max}} \beta_{nn'l} \frac{(2aR_i)^l}{(2(\alpha_{n'l} + a))^{l+3/2}}\exp\left(\frac{(aR_i)^2}{\alpha_{n'l} + a}\right).
	\end{split}
\end{equation}

Using real spherical harmonic functions,

\begin{equation}
	Y_{l,m}(\theta, \phi) = \begin{cases}
		\sqrt{2}(-1)^m \,\text{Im}\{Y_l^{|m|}(\theta, \phi)\} &\quad \text{if } m < 0 \\
		1 &\quad \text{if } m = 0 \\
		\sqrt{2}(-1)^m\,\text{Re}\{Y_l^{m}(\theta, \phi)\} &\quad \text{if } m > 0 \\
	\end{cases}
\end{equation}
where,
\begin{equation}
	Y_l^m (\theta, \phi) = \sqrt{\frac{(2l+1)(l- m)!}{4\pi (l+m)!}} P_l^{m}(\cos\theta)e^{im\phi}.
\end{equation}

\section{Solution Phase Entropy}
\subsection{Partition Functions} \label{section::appendix_igm_partition_functions}

For completeness, the well-known integral approximation to the particle in a box PF is reproduced below. Provided the gaps between energy levels are small the sum can be replaced by a integral to give,
\begin{equation}
	q_\text{trans} \approx \iiint_0^\infty dn_x\;dn_y\;dn_z\; \exp{ {\Big \{} -{\beta}\cdot  \frac{\hbar^2 \pi^2}{2ml^2}(n_x^2 + n_y^2 + n_z^2)}{\Big \}}.
\end{equation}

Converting into spherical polar coordinates with $n_x^2 + n_y^2 + n_z^2 = n_r^2$ and integrating over $n_\theta$ and $n_\phi$ in the positive octant,
\begin{equation}
	\begin{aligned}
		q_\text{trans} &\approx \frac{1}{8} \cdot 4\pi \int_0^\infty dn_r\; n_r^2\exp{ {\Big \{} -{\beta}\cdot  \frac{\hbar^2 \pi^2}{2ml^2}n_r^2}{\Big \}} \\
		&\approx \frac{\pi}{2} \cdot \frac{\sqrt{\pi}}{4} {\Big (} \frac{\hbar^2 \pi^2\beta}{2ml^2} {\Big )}^{-3/2} \\
		&\approx \pi^{3/2} {\Big (} \frac{ml^2}{2\hbar^2 \pi^2\beta} {\Big )}^{3/2} \\
		&\approx {\Big (} \frac{2\pi m k_B T}{h^2} {\Big )}^{3/2} V
		\label{q_trans_pib}
	\end{aligned}
\end{equation}
where the standard integral $\int_{0}^{\infty} dx\; x^2 e^{-ax^2} = \sqrt{\pi}/4a^{3/2}$ and $V = l^3$ have been used. Interestingly, \eqref{q_trans_pib} is identical to that obtained classically \eqref{q_trans_pib_classical}.
\begin{equation}
	\begin{aligned}
		q_\text{trans, c} &= \frac{1}{h^{3}}\int\int e^{-\beta H(\boldsymbol{p}, \boldsymbol{x})} \; d\boldsymbol{p}^{3} d\boldsymbol{x}^{3} \\
		&= \frac{1}{h^{3}}\int_{-\infty}^\infty e^{-\beta \boldsymbol{p}^2/2m} \; d\boldsymbol{p}^{3} \int_0^l e^{-\beta \cdot 0} \;  d\boldsymbol{x}^{3} \\
		&= \frac{1}{h^{3}} {\Big \{}  \int_{-\infty}^\infty e^{-\beta {p_k}^2/2m} \; d{p_k} {\Big \}}^3 {\Big \{}  \int_0^l  \;  dx_k {\Big \}}^3 \\
		&= \frac{l^3}{h^{3}} {\Big \{}  \sqrt{\frac{\pi}{1/(2 k_B T)}} {\Big \}}^3 \\
		&={\Big (} \frac{2\pi m k_B T}{h^2} {\Big )}^{3/2} V.
		\label{q_trans_pib_classical}
	\end{aligned}
\end{equation}

\subsection{Classical Truncated Harmonic Oscillator}

The classical entropy of the truncated harmonic oscillator with potential energy,
\begin{equation}
	V(x) = \begin{cases}
		\frac{1}{2}m\omega^2x^2 &\text{if} \quad x > -r_e \\
		+\infty &\text{if} \quad x \le -r_e
	\end{cases}
\end{equation}
is derived as follows. First the classical partition function is,\footnote{Using $\int_{a}^{+\infty}  e^{-bx^2} dx = \sqrt{\pi/b}\;\text{erfc}(a\sqrt{b})/2$}
\begin{equation}
	\begin{aligned}
		Z_c &= \frac{1}{h}\int_{-\infty}^\infty \; dp\int_{-\infty}^{\infty} \; dx \; e^{-\beta E(x,p)} \\
		&= \frac{1}{h}\int_{-\infty}^\infty \; dp \; e^{-\beta p^2/2m} \int_{-\infty}^{\infty} \; dx \; e^{-\beta V(x)} \\
		&= \frac{1}{h}\int_{-r_e}^\infty \; dp \; e^{-\beta p^2/2m} \int_{-r_e}^{\infty} \; dx \; e^{-\beta m\omega^2x^2/2} \\
		&=\frac{1}{h}\cdot \frac{\sqrt{\pi}\;\text{erfc}(-r_e \sqrt{\beta/2m})}{2\sqrt{\beta/2m}}\cdot \frac{\sqrt{\pi}\;\text{erfc}(-r_e \sqrt{\beta m\omega^2/2})}{2\sqrt{\beta m\omega^2/2}} \\
		&=\frac{\pi k_B T}{2h\omega} \;\text{erfc}(-r_e \sqrt{\beta/2m})\;\text{erfc}(-r_e \sqrt{\beta m\omega^2/2})
	\end{aligned}
\end{equation}

where $\text{erfc}(x)$ is the complementary error function. The derivative with respect to temperature for $a := r_e^2/ 2k_B m$ and $b := r_e^2m\omega^2/2k_B$ is,
\begin{equation}
	\begin{aligned}
		\frac{d Z_c}{dT} &= \frac{d}{dT} {\Big \{} \frac{\pi k_B T}{2h\omega} \;\text{erfc}(- \sqrt{a/T})\;\text{erfc}(- \sqrt{b/T}) {\Big \}} \\
		&= \frac{ k_B}{4\hbar\omega} {\Bigg (} \text{erfc}(- \sqrt{a/T})\;\text{erfc}(- \sqrt{b/T}\,) - \frac{b e^{-b/T} \; \text{erfc}(-\sqrt{a/T})}{\sqrt{b\pi T}} - \frac{a e^{-a/T} \; \text{erfc}(-\sqrt{b/T})}{\sqrt{a\pi T}} {\Bigg )}
	\end{aligned}
\end{equation}

\subsection{Classical Morse Oscillator}

The classical entropy of a Morse oscillator as a model of a chemical bond requires an upper bound to the total energy to prevent the configurational integral becoming unbounded. For a total energy,
\begin{equation}
	E(p, x) = \frac{p^2}{2m} + D_e (1 - e^{-a(r-r_e)})^2
\end{equation}
where $r$ is the bond length and $r_e$ the equilibrium bond length. The maximum energy is the dissociation energy of the bond ($D_e$) such that the the momentum is bounded,
\begin{equation}
	E(x, p) < D_e \qquad \implies \qquad p_\pm = \pm \sqrt{2mD_e(1 - (1-e^{-ax})^2)}
\end{equation}
where $x$ is the displacement from equilibrium, with $x > -\frac{1}{a}\ln(2)$ to ensure the momentum is real.

The classical partition function is then,\footnote{Using $\int_{-a}^{+a}  e^{-bx^2} dx = \sqrt{\pi/b}\;\text{erf}(a\sqrt{b})$ and that $\text{erf}$ is an even function.}
\begin{equation}
	\begin{aligned}
		Z_c &= \frac{1}{h}\int_{-\infty}^\infty \; dp\int_{-\infty}^{\infty} \; dx \; e^{-\beta E(x,p)} \\
		&= \frac{1}{h}\int_{p_-}^{p_+} \int_{-\frac{1}{a}\ln(2)}^{\infty}\; e^{-\beta \{{p^2}/{2m} + D_e (1 - e^{-ax})^2\}}  \; dx  \; dp \\
		&= \frac{1}{h}\int_{p_-}^{p_+} \int_{-\frac{1}{a}\ln(2)}^{\infty}\; e^{-\beta {p^2}/{2m}} e^{-\beta D_e (1 - e^{-ax})^2}  \; dx  \; dp \\
		&= \frac{1}{h} \int_{-\frac{1}{a}\ln(2)}^{\infty}\;\int_{p_-}^{p_+}\; e^{-\beta {p^2}/{2m}} e^{-\beta D_e (1 - e^{-ax})^2}  \; dp  \; dx \\
		&= \frac{1}{h} \int_{-\infty}^{\infty}\; e^{-\beta D_e (1 - e^{-ax})^2}  \cdot \frac{\sqrt{\pi}\;\text{erf}(p\sqrt{\beta/2m})}{\sqrt{\beta/2m}} \Bigg|_{p_-}^{p_+} \; dx \\
		&= \frac{2}{h}\sqrt{\frac{2m\pi}{\beta}} \int_{-\frac{1}{a}\ln(2)}^{\infty}\; e^{-\beta D_e (1 - e^{-ax})^2}   \;\text{erf}(p_+\sqrt{\beta/2m}) \; dx \\
		&= \frac{2}{h}\sqrt{\frac{2m\pi}{\beta}} \int_{-\frac{1}{a}\ln(2)}^{\infty}\; e^{-\beta D_e (1 - e^{-ax})^2}   \;\text{erf}{\Big (} \sqrt{\beta D_e(1 - (1-e^{-ax})^2)}{\Big )} \; dx.
	\end{aligned}
	\label{morse_pf_integral}
\end{equation}

Although \eqref{morse_pf_integral} has no analytical solution, the integrand is smooth allowing for efficient numerical evaluation (\figurename{ \ref{morse_pf_integrand_vs_x}}).

\begin{figure}[h!]
	\centering
	\includegraphics[width=12cm]{8/figs/morse_pf_integrand_vs_x}
	\vspace{0.2cm}
	\hrule
	\caption{Integrand of $Z_c$ vs $x$. $D_e$ = 400 kJ mol$^{-1}$, $T$ = 298.15 K, $m = 1$ amu.}
	\label{morse_pf_integrand_vs_x}
\end{figure}

\subsection{Exponential Well}

To derive the entropy and internal energy due to translation of a molecule in an 3D exponential well the temperature derivative of the partition function ($Z_c^\text{exp}$) is required. For,
\begin{equation}
	Z_c^\text{exp} =\left(\frac{2m\pi k_B T}{h^2} \right)^{3/2} \int_0^\infty 4\pi r^2 e^{- k(e^{ar} - 1) / k_B T} \; \text{d}r :=  \Lambda(T) I(T)
\end{equation}
the derivative is,
\begin{equation}
	\begin{aligned}
		\left(\frac{\partial Z_c^\text{exp}}{\partial T}\right)_{N , V} &= \left(\frac{\partial \Lambda}{\partial T}\right)_{N , V} I(T) + \Lambda(T)\left(\frac{\partial I}{\partial T}\right)_{N , V} \\
		&= \Lambda(T) \frac{3}{2}T^{-1} I(T) + \Lambda(T) \int_0^\infty 4\pi r^2 \frac{k(e^{ar} - 1)}{k_B T^2}  e^{- k\beta (e^{ar} - 1)} \; \text{d}r \\
		&= \frac{3}{2T} Z_c^\text{exp} + \frac{\Lambda(T) k\beta}{T} \int_0^\infty 4\pi r^2 e^{ar}  e^{- k\beta(e^{ar} - 1)} \; \text{d}r \\
		&\qquad\qquad\qquad\qquad-  \frac{\Lambda(T) k\beta}{T}  \int_0^\infty 4\pi r^2 e^{- k\beta(e^{ar} - 1)} \; \text{d}r \\
		&= \frac{1}{T} \left(  \frac{3}{2} Z_c^\text{exp} + \Lambda(T) k\beta \int_0^\infty 4\pi r^2 e^{ar}  e^{- k\beta(e^{ar} - 1)} \; \text{d}r -  k\beta Z_c^\text{exp} \right) \\
		&= \frac{Z_c^\text{exp}}{T} \left( \frac{3}{2} - k\beta + \frac{\Lambda(T) k\beta}{Z_c^\text{exp}} \int_0^\infty 4\pi r^2 e^{ar}  e^{- k\beta(e^{ar} - 1)} \; \text{d}r
		\right)
	\end{aligned}
\end{equation}

\clearpage
\subsection{Test Sets} \label{section::appendix_entropy_test_cases}

Test set {\bfseries{A}} contains two reactions from the Morita Baylis--Hillman reaction for which experimental reaction $\Delta S$ values are available (\tablename{ \ref{setA_data}}, \figurename{ \ref{plata_mbh}}).\cite{Plata2015}

\begin{table}[h!]
	\renewcommand{\arraystretch}{1.5}
	\begin{center}
		\small
		\begin{tabularx}{\textwidth}{YYYY}
			\toprule
			Reaction & $T_\text{avg}$ / K & {$T\Delta S$} / \kcal & {$\Delta G$} / \kcal \\
			\hline
			% 4.184
			\bfseries{R-MBH1}       & 317.6  & -7.9 & -3.2\\
			\bfseries{R-MBH2}       & 328.4  & -10.2 & -3.9\\
			\bottomrule
		\end{tabularx}
	\end{center}

	\caption{Thermodynamic data for {\bfseries{A}}. No error is given. $T_\text{avg}$ values are averages over the temperature range used to calculate $\Delta S$.}
	\label{setA_data}
\end{table}

\begin{figure}[h!]
	\centering
	\includegraphics[width=13cm]{8/figs/plata_mbh}
	\vspace{0.2cm}
	\hrule
	\caption{Reactions in test set {\bfseries{A}}. }
	\label{plata_mbh}
\end{figure}

Test set {\bfseries{B}} comprise entropies of activation for 10 S$_\text{N}$2 reactions collated in ref. \cite{Vlasov2006} (\figurename{ \ref{vlasov_sn2}}).  These were chosen based on modest structural complexity, while spanning a wide range of $\Delta S^\ddagger$ values (\tablename{ \ref{setB_data}}).
\\
\begin{table}[h!]
	\renewcommand{\arraystretch}{1.5}
	\begin{center}
		\small
		\begin{tabularx}{\textwidth}{YYYYY}
			\toprule
			Reaction & $T$ / K & {$\Delta H^\ddagger$} / \kcal & {$T\Delta S^\ddagger$} / \kcal & {$\Delta G^\ddagger$} / \kcal\\
			\hline
			\bfseries{R1} & 369.1 & 22.3 & -3.9 & 26.0\\
			\bfseries{R2} & 369.1 & 18.6 & -6.1 & 24.4\\
			\bfseries{R3} & 322.4 & 21.5 & -1.9 & 23.4\\
			\bfseries{R4} & 303.1 & 15.9 & -3.7 & 19.6\\
			\bfseries{R5} & 303.1 & 16.5 & -2.1 & 18.6\\
			\bfseries{R6} & 303.1 & 16.4 & -4.9 & 21.3\\
			\bfseries{R7} & 303.1 & 18.5 & -2.0 & 20.5\\
			\bfseries{R8} & 252.2 & 11.9 & -3.1 & 15.0\\
			\bfseries{R9} & 303.1 & 18.6 & -2.4 & 20.9\\
			\bfseries{R10} & 303.1 & 20.2 & -1.3 & 21.5\\
			\bottomrule
		\end{tabularx}
	\end{center}

	\caption{Activation parameters for test set {\bfseries{B}}. Reactions are shown in \figurename{ \ref{vlasov_sn2}}. Where errors are quoted: ${\Delta S}_\text{err} < \pm2.5$ J K$^{-1}$ mol$^{-1}$, ${\Delta H}_\text{err} < \pm0.2$ \kcal.}
	\label{setB_data}
\end{table}

\begin{figure}[h!]
	\centering
	\includegraphics[width=14.5cm]{8/figs/vlasov_sn2}
	\vspace{0.2cm}
	\hrule
	\caption{Reactions in test set {\bfseries{B}}.}
	\label{vlasov_sn2}
\end{figure}

\clearpage
\end{document}


\section{\src{comp_caldyn_vert}}

\subsection{Description}

Kernel \src{comp_caldyn_vert} is taken from the original subroutine
\src{compute_caldyn_vert} in \DYNAMICO.
%
This subroutine is originally defined in module \src{caldyn_gcm_mod}.
%
This module defines subroutine \src{caldyn}, which is the main
subroutines for dynamics part of the model, and several sub-subroutines
for various terms in the governing equation, such as potential
vorticity, geopotential, etc.
%
This subroutine calculates vertical mass flux and vertical transport.

\subsection{Discretization and code}

\autoref{l:definition_comp_caldyn_vert} shows the definition part of this subroutine,
and \autoref{f:pad_comp_caldyn_vert} shows the PAD of this.

\begin{LstF90}[%
caption={Definition part of \src{compute_caldyn_vert}},%
label={l:definition_comp_caldyn_vert}%
]
SUBROUTINE compute_caldyn_vert(u,theta,rhodz,convm, wflux,wwuu, dps,dtheta_rhodz,du)
  USE icosa
  USE disvert_mod
  USE exner_mod
  USE trace
  USE omp_para
  IMPLICIT NONE
    REAL(rstd),INTENT(IN)  :: u(iim*3*jjm,llm)
    REAL(rstd),INTENT(IN)  :: theta(iim*jjm,llm)
    REAL(rstd),INTENT(IN)  :: rhodz(iim*jjm,llm)
    REAL(rstd),INTENT(INOUT)  :: convm(iim*jjm,llm)  ! mass flux convergence

    REAL(rstd),INTENT(INOUT) :: wflux(iim*jjm,llm+1) ! vertical mass flux (kg/m2/s)
    REAL(rstd),INTENT(INOUT) :: wwuu(iim*3*jjm,llm+1)
    REAL(rstd),INTENT(INOUT) :: du(iim*3*jjm,llm)
    REAL(rstd),INTENT(INOUT) :: dtheta_rhodz(iim*jjm,llm)
    REAL(rstd),INTENT(INOUT) :: dps(iim*jjm)

! temporary variable
    INTEGER :: i,j,ij,l
    REAL(rstd) :: p_ik, exner_ik
    INTEGER,SAVE ::ij_omp_begin, ij_omp_end
!$OMP THREADPRIVATE(ij_omp_begin, ij_omp_end)
    LOGICAL,SAVE :: first=.TRUE.
!$OMP THREADPRIVATE(first)
\end{LstF90}
%
Where \src{u}, \src{theta}, \src{rhodz} are wind velocity on the edge,
potential temperature, and mass, respectively.
\src{convm}, \src{wflux}, \src{wwuu} are mass flux convergence, vertical mass flux,
and \src{wflux*u} on the edge, respectively.
%
Last three variables are time derivatives.
\src{du}, \src{dtheta_rhodz}, \src{dps} are for wind velocity on the edge,
mass-weighted potential temperature, and surface pressure, respectively.
%
All of these except \src{dps} are two dimensional.
%
First dimension is for horizontal index, and the size depends on the
point where the variable is defined, since \DYNAMICO adopts C-grid.
%
Second dimension is for vertical index, and the size is \src{llm},
except \src{llm+1} for \src{wflux} and \src{wwuu}, these are defined on
the half level in vertical, while others are defined on the full level.

\begin{figure}[tbp]
 \centering
 \includegraphics[scale=.5]{figs/caldyn_vert.pdf}
 \caption{PAD of \src{compute_caldyn_vert}}
 \label{f:pad_comp_caldyn_vert}
\end{figure}

Main part of this subroutine is consist of several $l$- and $ij$- double loop.
%
The first double loop is to accumulate mass flux convergence from top to bottom,
then convert \src{convm} at the lowest level to \src{dps}.
%
The second double loop is to compute vertical mass flux \src{wflux}.
%
Note that the range of $l$-loop, because \src{wflux} is defined on half
vertical level and at the top and the bottom are already set by
subroutine \src{caldyn_BC} as a boundary condition.
%
Next two double loop is to calculate convergence of potential
temperature \src{dtheta_rhodz}.
%
Again note that the range of two $l$-loop, since \src{dtheta_rhodz} is
defined on full vertical level and needs to sum up both upper and lower
face of the level.
%
Next two double loop is to compute vertical transport \src{wwuu}, and to
add it to \src{du}.
%
Note the horizontal index here.
%
\src{wwuu} and \src{du} are defined on the edge
of control volume, there are three statement in each double loop.

\clearpage

\subsection{Inputdata and result}

Input data file is prepared and you can download from official server using
\file{data/download.sh} script.
%
This data file is created by original \DYNAMICO\footnotemark with
Held-Suarez case parameter set included in the original source archive.
%
\footnotetext{with slight modification by AICS.}
%
Max/min/sum of input/output data of the kernel subroutine are output as
a log.
%
Below is an example of \src{$IAB_SYS=Ubuntu-gnu-ompi} case.

\begin{LstLog}
 [KERNEL] comp_caldyn_vert
 *** Start  initialize
                iim, jjm, llm:    23    25    19
             ij_begin, ij_end:    48   528
     ij_begin_ext, ij_end_ext:    24   552
             ll_begin, ll_end:     1    19
         ll_beginp1, ll_endm1:     2    18
        t_right, t_rup, t_lup:     1    23    22
     t_left, t_ldown, t_rdown:    -1   -23   -22
        u_right, u_rup, u_lup:     0  1173   575
     u_left, u_ldown, u_rdown:    -1  1150   553
           z_rup, z_up, z_lup:   598     0   597
     z_ldown, z_down, z_rdown:   -23   575   -22
                       dbg: g:     9.80000000
 +check[bp              ] max=  1.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  6.9254510678414132E+00
 *** Finish initialize
 *** Start kernel
 ### check point iteration:        1000
 ### Input ###
 +check[u               ] max=  4.1278968179782127E-01,min= -4.1278968179782127E-01,sum=  1.6791131703073393E+01
 +check[theta           ] max=  8.0139914420291746E+02,min=  0.0000000000000000E+00,sum=  3.8582633571973117E+06
 +check[rhodz           ] max=  1.2306877011993038E+03,min=  0.0000000000000000E+00,sum=  5.3979591836733194E+06
 +check[convm_prev      ] max=  1.0361970643226587E-03,min= -1.0359249303947807E-04,sum= -1.5233533963107249E-01
 +check[wflux_prev      ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[wwuu_prev       ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[du_prev         ] max=  3.4404317002518906E-03,min= -3.0804630348046005E-03,sum=  5.5048589972605033E-01
 +check[dtheta_rhodz_pre] max=  3.2251351666935379E-01,min= -3.3676276308628725E-02,sum= -5.3720539414185993E+01
 +check[dps_prev        ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 ### Output ###
 +check[convm           ] max=  6.9593389571287302E-03,min= -7.9269107622801825E-04,sum= -1.5227927267389074E+00
 +check[wflux           ] max=  4.1171035230973149E-04,min= -3.6145630748324665E-03,sum=  5.8901163077820706E-01
 +check[wwuu            ] max=  1.7149300599654128E-04,min= -1.8768192515764522E-04,sum= -5.0377733672629036E-04
 +check[du              ] max=  3.4404317002518906E-03,min= -3.0804630348046005E-03,sum=  5.5048632410110032E-01
 +check[dtheta_rhodz    ] max=  3.5427038431326496E-01,min= -4.2032604085394595E-02,sum= -5.3720539414186263E+01
 +check[dps             ] max=  6.8201521779861565E-02,min= -7.7683725470345790E-03,sum= -1.3213658793877174E+00
 ### final iteration:        1000
 ### Validation : grid-by-grid diff ###
 +check[convm           ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[wflux           ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[wwuu            ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[du              ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[dtheta_rhodz    ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 +check[dps             ] max=  0.0000000000000000E+00,min=  0.0000000000000000E+00,sum=  0.0000000000000000E+00
 *** Finish kernel
\end{LstLog}

Check the lines below \src{``Validation : grid-by-grid diff''} line,
that shows difference between calculated output array and
pre-calculated reference array.
These should be zero or enough small to be acceptable.
%
There are sample output log files in \file{reference/}
in each kernel program directory, for reference purpose.

\subsection{Sample of performance result}

Here's an example of the performance result part of the log output.
Below is an example executed with the machine environment described in \autoref{s:measuring_env}.
%
Note that in this program kernel part is iterated 1000 times.

\begin{LstLog}
 *** Computational Time Report
 *** ID=001 : MAIN_comp_caldyn_vert            T=     0.156 N=   1000
\end{LstLog}


\documentclass{beamer}

\usepackage{beamerthemevictor,comment,verbatim,graphicx,amssymb}

\input{tutmacs}
\input{slidemacs}
\input idxmacs

\begin{document}

\title{Dynamic Programming}
\author{Victor Eijkhout}
\date{Notes for CS 594 -- Fall 2004}

\frame{\titlepage}

\section{Introduction}

\frame[containsverbatim]{
  \frametitle{What is dynamic programming?}
\begin{itemize}
\item Solution technique for minization problems
\item Often lower complexity than naive techniques
\item Sometimes equivalent to analytical techniques
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{What is it \emph{not}?}
\begin{itemize}
\item Black box that will solve your problem
\item Way of finding lowest complexity
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{When dynamic programming?}
\begin{itemize}
\item Minimization problems
\item constraints; especially integer
\item sequence of decisions
\end{itemize}
}

\section{Examples}
\subsectionframe{Decision timing}

\frame[containsverbatim]{
  \frametitle{Description}
\begin{itemize}
\item Occasions for deciding yes/no
\item items with attractiveness $\in[0,1]$
\item Finite set
\item no reconsidering
\item Question: at any given step, do you choose or pass?
\item Objective: maximize expectation
\end{itemize}
}

\frame{
  \frametitle{crucial idea}
\begin{itemize}
\item start from the end:
\item step $N$: no choice left
\item expected yield: $.5$
\item<2-> in step $N-1$: pick if better than $.5$
\end{itemize}
}

\frame{
  \frametitle{yield from $N-1$}
\begin{itemize}
\item pick if $>.5$: done in $.5$ of the cases
\item<2-> expected yield $.75$
\item<3-> go on in $.5$ of the cases
\item<4-> expected yield then $.5$
\item<5-> total expected yield: $.5\times.75+.5\times.5=.625$
\end{itemize}
}

\frame{
  \frametitle{at $N-2$}
\begin{itemize}
\item pick if better than $.625$
\item<2-> happens in $.375$ of the cases,
\item<3-> yield in that case $1.625/2$
\item<4-> otherwise, $.625$ yield from later choice
\item<4-> et cetera
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{Essential features}
\begin{itemize}
\item Stages: more or less independent decisions
\item Global minimization; solving by subproblems
\item Principle of optimality: sub part of total solution is optimal
  solution of sub problem
\end{itemize}
}

\subsectionframe{Manufacturing problem}
\frame{
  \frametitle{Statement}
\begin{itemize}
\item Total to be produced in given time, variable cost in each time
  period
\item wanted: scheduling
\item
\[ \min_{\sum p_k=S}\sum w_kp_k^2.\]
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{define concepts}
\begin{itemize}
\item amount of work to produce~$s$ in $n$~steps:
\[ v(s|n)=\min_{\sum_{k>N-n} p_k=s}\sum w_kp_k^2 \]
\item optimal amount $p(s|n)$ at $n$~months from the end
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{principle of optimality}
\begin{eqnarray*}
    v(s|n)&=&\min_{p_n\leq s}\left\{w_np_n^2
        +\sum_{{k>N-n+1\atop\sum p_k=s-p_n}}w_kp_k^2\right\} \\
        &=&\min_{p_n\leq s}\left\{ w_np_n^2+v(s-p_n|n-1)\right\}
\end{eqnarray*}
}

\frame{
  \frametitle{start from the end}
\begin{itemize}
\item In the last period: $p(s|1)=s$, and $v(s|1)=w_1s^2$
\item<2-> period before:
\[ v(s|2)=\min_{p_2}\{w_2p_2^2+v(s-p_2|1)\}=\min_{p_2}c(s,p_2) \]
where $c(s,p_2)=w_2p_2^2+w_1(s-p_2)^2$.
\item<3-> Minimize: $\delta c(s,p_2)/\delta p_2=0$,
\item<3-> then
$p(s|2)=w_1s/(w_1+w_2)$ and $v(s|2)=w_1w_2s^2/(w_1+w_2)$.
\end{itemize}
}

\frame{
  \frametitle{general form}
\begin{itemize}
\item Inductively
 \[ p(s|n)={1/w_n\over \sum_{i=1}^n 1/w_i}s,\qquad
    v(s|n)=s^2\sum_{i=1}^n1/w_i.\]
\item<2-> Variational approach:
\[ \sum_kw_kp_k^2+\lambda(\sum_kp_k-S) \]
Constrained minimization
\item<3-> Solve by setting derivatives to $p_n$ and~$\lambda$ to zero.
\end{itemize}
}

\frame{
  \frametitle{characteristics}
\begin{itemize}
\item Stages: time periods
\item State: amount of good left to be produced
\item Principle of optimality
\item<2-> Can be solved analytically
\item<3-> Analytical approach can not deal with integer constraints
\end{itemize}
}

\subsectionframe{Stagecoach problem}

\frame[containsverbatim]{
  \frametitle{Statement}
Several routes from beginning to end\\
Cost of travel insurance:

\convertMPtoPDF{stages.1}{1}{1}

Objective: minimize cost
}

\frame[containsverbatim]{
  \frametitle{data in python}
\begin{verbatim}
table = [ [0, 5, 4, 0, 0, 0, 0, 0, 0], # first stage: 0
          [0, 0, 0, 1, 3, 4, 0, 0, 0], # second: 1 & #2
          [0, 0, 0, 4, 2, 2, 0, 0, 0],
          [0, 0, 0, 0, 0, 0, 5, 1, 0], # third: 3, #4, #5
          [0, 0, 0, 0, 0, 0, 2, 4, 0],
          [0, 0, 0, 0, 0, 0, 4, 3, 0],
          [0, 0, 0, 0, 0, 0, 0, 0, 5], # fourth: 6 & #7
          [0, 0, 0, 0, 0, 0, 0, 0, 2]
          ]
final = len(table);
\end{verbatim}
}

\frame{
  \frametitle{recursive formulation}
\begin{itemize}
\item In the final city, the cost is zero;
\item Otherwise minimum over all cities reachable\\
  of the cost of the next leg plus the minimum cost from that city.\\
(principle of optimality)
\item<2-> wrong to code it recursively
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{recursive solution in python}
\footnotesize
\hypertarget{rec-coach}{}
\begin{verbatim}
def cost_from(n):
    # if you're at the end, it's free
    if n==final: return 0
    # otherwise range over cities you can reach
    # and keep minimum value
    val = 0
    for m in range(n+1,final+1):
        local_cost = table[n][m]
        if local_cost>0:
            # if there is a connection from here,
            # compute the minimum cost
            local_cost += cost_from(m)
            if val==0 or local_cost<val:
                val = local_cost
    return val
print "recursive minimum cost is",cost_from(0)
\end{verbatim}
\hyperlink{back-coach}{\beamerbutton{backward}}
}

\frame[containsverbatim]{
  \frametitle{characteristic}
\begin{itemize}
\item Overlapping subproblems\\
\convertMPtoPDF{123.1}{1}{1}
\item \n{cost_from(1)} computed twice
\item Cost: $N$~cities, $S$~stages of $L$~each: $O(L^S)$
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{dynamic programming}
\begin{itemize}
\item Compute minimum cost $f_n(x_n)$\\
of traveling from step~$n$, starting in $x_n$ (state variable)
\item
Formally, $f_k(s)$ minimum cost for traveling from stage~$k$\\
starting in city~$s$. Then
\[ f_{k-1}(s)=\min_t\{ c_{st}+f_k(t) \]
where $c_{st}$ cost of traveling from city~$s$ to~$t$.
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{backward dynamic solution in python}
\footnotesize
\hypertarget{back-coach}{}
\begin{verbatim}
cost = (final+1)*[0] # initialization
# compute cost backwards
for t in range(final-1,-1,-1):
    # computing cost from t
    for i in range(final+1):
        local_cost = table[t][i]
        if local_cost==0: continue
        local_cost += cost[i]
        if cost[t]==0 or local_cost<cost[t]:
            cost[t] = local_cost
print "minimum cost:",cost[0]
\end{verbatim}
\hyperlink{rec-coach}{\beamerbutton{recursive}}
\hyperlink{forw-coach}{\beamerbutton{forward}}
}

\frame[containsverbatim]{
  \frametitle{analysis}
\begin{itemize}
\item Running time $O(N\cdot L)$ or~$O(L^2S)$
\item compare $L^S$ for recursive
\end{itemize}
}

\frame{
  \frametitle{Forward solution}
\begin{itemize}
\item Backward: $f_n(x)$ cost from $x$ in $n$ steps to the end
\item Forward: $f_n(x)$ cost in $n$ steps to $x$
\[ f_n(t) =\min_{s<t}\{c_{st}+f_{n-1}(s)\} \]
\item sometimes more appropriate
\item same complexity
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{forward dynamic solution in python}
\footnotesize
\hypertarget{forw-coach}{}
\begin{verbatim}
cost = (final+1)*[0]
for t in range(final):
    for i in range(final+1):
        local_cost = table[t][i]
        if local_cost == 0: continue
        cost_to_here = cost[t]
        newcost = cost_to_here+local_cost
        if cost[i]==0 or newcost<cost[i]:
            cost[i] = newcost
print "cost",cost[final]
\end{verbatim}
\hyperlink{back-coach}{\beamerbutton{backward}}
}

\subsectionframe{Traveling salesman}

\frame{
  \frametitle{Problem statement}
\begin{itemize}
\item Cities as stages?
\item<2-> No ordering
\item<3-> Stage $n$ : having $n$ cities left
\item<4-> State: combination of cities to visit plus current city
\item<4-> Cost formula to~0 (both start/end)
\begin{eqnarray*}
C(\{\,\},f)&=&a_{f0}\quad\hbox{for $f=1,2,3,\ldots$}\\
C(S,f)&=&\min_{m\in S}a_{fm}+\left[C(S-m,m)]\right]
\end{eqnarray*}
\end{itemize}
}

\frame[containsverbatim]{
  \frametitle{backward implementation}
\footnotesize
\begin{verbatim}
def shortest_path(start,through,lev):
    if len(through)==0:
        return table[start][0]
    l = 0
    for dest in through:
        left = through[:]; left.remove(dest)
        ll = table[start][dest]+shortest_path(dest,left,lev+1)
        if l==0 or ll<l:
            l = ll
    return l
to_visit = range(1,ntowns);
s = shortest_path(0,to_visit,0)
\end{verbatim}
(recursive; need to be improved)
}

\sectionframe{Discussion}

\frame[containsverbatim]{
  \frametitle{Characteristics}
\begin{description}
\item[Stages] sequence of choices
\item[Stepwise solution] solution by successive subproblems
\item[State] cost function has a state parameter,\\
description of work left~\&c
\item[Overlapping subproblems]
\item[Principle of optimality] This is the property that the
  restriction of a global solution to a subset of the stages is also
  an optimal solution for that subproblem.
\end{description}
}

\frame[containsverbatim]{
  \frametitle{Principle of optimality}
\begin{quote}
An optimal policy has the property that whatever the initial state and
initial decision are, the remaining decisions must be an optimal
policy with regard to the state resulting from the first decision.
\end{quote}
}

\frame[containsverbatim]{
  \frametitle{derivation}
Maximize~$\sum^N_ig_i(x_i)$ under~$\sum_ix_i=\nobreak X$, $x_i\geq0$\\
Call this~$f_N(X)$, then
\begin{eqnarray*}
f_N(X)&=&\max_{\sum_i^Nx_i=X}\sum_i^Ng_i(x_i)\\
&=&\max_{x_N<X}\left\{g_N(x_N)+\max_{\sum_i^{N-1}x_i=X-x_N}\sum_i^{N-1}g_i(x_i)\right\}\\
&=&\max_{x_N<X}\left\{g_N(x_N)+f_{N-1}(X-x_N)\right\}
\end{eqnarray*}
}

\end{document}


\subsection{Sample mode}

The is the most common value in the sample.