\subsection{Riemann integration}\label{subsec:riemann_integration}

\begin{definition}\label{def:riemann_partition}\mcite[def. 1]{Gordon1991}
  The concept of a partition of a nonempty \hyperref[def:set_of_real_numbers]{real} \hyperref[def:partially_ordered_set_interval/closed]{closed interval} \( [a, b] \) is the base for defining Riemann-style integrals.

  \begin{thmenum}
    \thmitem{def:riemann_partition/partition} A \term{Riemann partition} of \( [a, b] \) is a set
    \begin{equation*}
      \Delta \coloneqq \{ x_0, \ldots, x_n \} \subseteq [a, b]
    \end{equation*}
    that satisfies
    \begin{equation*}
      a = x_0 < x_1 < \ldots < x_n = b.
    \end{equation*}

    For brevity, we write
    \begin{equation}\label{eq:def:riemann_partition/partition}
      \Delta: a = x_0 < x_1 < \ldots < x_n = b.
    \end{equation}

    We denote the set of all partitions of \( [a, b] \) by \( \op{part}([a, b]) \).

    \thmitem{def:riemann_partition/refinement} The partition
    \begin{equation*}
      \Gamma: a = y_0 < y_1 < \ldots < y_m = b
    \end{equation*}
    is called a \term{refinement} of the partition \eqref{eq:def:riemann_partition/partition} if we have the \hyperref[def:subset]{set inclusion}
    \begin{equation}\label{eq:def:riemann_partition/refinement/inclusion}
      \{ x_0, x_1, \ldots, x_n \} \subseteq \{ y_0, y_1, \ldots, y_m \}.
    \end{equation}

    In this case, we \enquote{split} \( \Gamma \) into chains such that, for each \( k = 1, 2, \ldots, n \),
    \begin{equation}\label{def:riemann_partition/refinement/splitting}
      y_{k,j} \coloneqq \begin{cases}
        x_{k-1},                                                                          &j = 0, \\
        x_k,                                                                              &j = p_k, \\
        j\text{-th point of } \{ y_0, \ldots, y_m \} \cap [x_{k-1}, x_k], &0 < j < p_k.
      \end{cases}
    \end{equation}

    \thmitem{def:riemann_partition/diameter} Finally, the \term{diameter} of the partition \eqref{eq:def:riemann_partition/partition} is defined as
    \begin{equation}\label{eq:def:riemann_partition/diameter}
      \diam(\Delta) \coloneqq \max_{1 \leq k \leq n} (x_k - x_{k-1}).
    \end{equation}

    \thmitem{def:riemann_partition/order} We can make the set \( \op{part}([a, b]) \) of all \hyperref[def:riemann_partition/partition]{Riemann partitions} of \( [a, b] \) into a \hyperref[def:directed_set]{directed set} using two common approaches:
    \begin{thmenum}
      \thmitem{def:riemann_partition/order/refinement} Put \( \Delta \preceq_R \Gamma \) if and only if \( \Gamma \) is a \hyperref[def:riemann_partition/refinement]{refinement} of \( \Delta \). This actually makes \( (\op{part}([a, b]), \preceq_R) \) a \hyperref[def:partially_ordered_set]{partially ordered set}.
      \thmitem{def:riemann_partition/order/diameter} Put \( \Delta \preceq_D \Gamma \) if and only if \( \diam(\Gamma) \leq \diam(\Delta) \).
    \end{thmenum}

    \thmitem{def:riemann_partition/tagged} A \term{tagged partition} of \( [a, b] \) is a partition \eqref{eq:def:riemann_partition/partition} of \( [a, b] \) along with a choice of a \term{tag} \( \xi_k \) for each closed interval \( [x_{k-1}, x_k], k = 1, \ldots, n \). By putting \( \Xi \coloneqq \{ \xi_k \}_{k=1}^n \), we can define a tagged partition as the tuple \( (\Delta, \Xi) \). For brevity, we write
    \begin{alignedeq}\label{eq:def:riemann_partition/tagged}
      &\Delta: a = x_0 < x_1 < \ldots < x_n = b \\
      &\Xi: \xi_k \in [x_{k-1}, x_k], k = 1, \ldots, n.
    \end{alignedeq}

    We denote the set of all tagged partitions of \( [a, b] \) by \( \op{tpart}([a, b]) \). We introduce an order on \( \op{tpart}([a, b]) \) by putting
    \begin{equation*}
      (\Delta, \Xi) \preceq_R (\Gamma, \Eta) \T{if and only if} \Delta \preceq_R \Eta
    \end{equation*}
    and analogously for \( \preceq_D \). Note that \( \preceq_R \) is not a partial order in \( \op{tpart}([a, b]) \) unlike in \( \op{part}([a, b]) \).
  \end{thmenum}
\end{definition}

\begin{remark}\label{rem:set_and_riemann_partitions}
  Note that \eqref{eq:def:riemann_partition/partition} is not a partition in the sense of \fullref{def:set_partition}, however the set of intervals
  \begin{equation*}
    \Big\{ [x_0, x_1), [x_1, x_2), \ldots, [x_{n-2}, x_{n-1}), [x_{n-1}, x_n] \Big\}
  \end{equation*}
  is a set-theoretic partition of \( [a, b] \). Conversely, every finite set-theoretic partition of \( [a, b] \) gives rise to a Riemann partition in the sense of \fullref{def:riemann_partition/partition}.
\end{remark}

\begin{definition}\label{def:riemann_integral}\mcite[def. 2]{Gordon1991}
  Let \( \mscrX \) be a real \hyperref[def:separation_axioms/T2]{Hausdorff} \hyperref[def:topological_vector_space]{topological vector space}. Fix a \hyperref[def:function]{function} \( f: [a, b] \to X \).

  The \term{Riemann sum} of \( f \) corresponding to the \hyperref[def:riemann_partition/tagged]{tagged partition} \eqref{eq:def:riemann_partition/tagged} is defined as
  \begin{equation*}
    S(f, \Delta, \Xi) \coloneqq \sum_{k=1}^n f(\xi_k) (x_k - x_{k-1}).
  \end{equation*}

  Consider the net
  \begin{equation}\label{eq:def:riemann_integral/net}
    \{ S(f, \Delta, \Xi) \}_{(\Delta, \Xi) \in \op{tpart}([a, b])}
  \end{equation}

  Both orders \fullref{def:riemann_partition/order/refinement} and \fullref{def:riemann_partition/order/diameter} on \( \op{tpart}([a, b]) \) provide equivalent convergence for Riemann sums. If the limit exists, \( f \) is said to be \term{Riemann integrable} in \( [a, b] \). We call the limit the \term{Riemann integral} of \( f \) and denote it by
  \begin{equation}\label{eq:def:riemann_integral}
    \int_a^b f(x) dx.
  \end{equation}
\end{definition}
\begin{proof}
  \ImplicationSubProof{def:riemann_partition/order/refinement}{def:riemann_partition/order/diameter} Let \( I \) be the limit \eqref{eq:def:riemann_integral} with respect to \( \preceq_R \). Fix a neighborhood \( U \) of \( 0 \). Since \eqref{eq:def:riemann_integral/net} is eventually in \( I + U \), there exists a tagged partition
  \begin{alignedeq}\label{eq:def:riemann_integral/tagged_zero}
    &\Delta_0: a = x_0^{(0)} < x_1^{(0)} < \ldots < x_n^{(0)} = b \\
    &\Xi_0: \xi_k^{(0)} \in [x_{k-1}^{(0)}, x_k^{(0)}], k = 1, \ldots, n_0.
  \end{alignedeq}
  such that \( S(f, \Gamma, \Eta) \in I + U \) if \( \Gamma \) is a refinement of \( \Delta_0 \).

  Note that \( f \) is \hyperref[def:bounded_function/bounded]{bounded}. Indeed, if it is unbounded on \( [a, b] \), then there exists a refinement \( (\Gamma, \Eta) \) of \( (\Delta_0, \Xi_0) \) such that
  \begin{equation*}
    S(f, \Gamma, \Eta) - I \not\in U.
  \end{equation*}

  But this contradicts our choice of \( \Delta_0 \). Therefore, \( f \) is bounded and there exists a bounded neighborhood \( V_0 \) of \( 0 \) such that \( f([a, b]) \subseteq V_0 \) and hence \( f(x) - f(y) \in V \coloneqq V_0 - V_0 \) for all \( x, y \in [a, b] \).

  Let  \( v > 0 \) be such that \( V \subseteq vU \).

  Let \( (\Delta, \Xi) \) be a tagged partition such that \( \diam(\Delta) \leq \diam(\Delta_0) \).

  We introduce another partition \( \Gamma \coloneqq \Delta \cup \Delta_0 \). Since \( \Gamma \) is a refinement of \( \Delta_0 \), we can use a splitting similar to \eqref{def:riemann_partition/refinement/splitting} such that
  \begin{equation}\label{def:riemann_partition/subdiameter_splitting}
    S(f, \Delta_0, \Xi_0) = \sum_{k=1}^{n_0} \sum_{j=1}^{p_k} f(\xi^{(0)}_k) (y_{k,j} - y_{k,j-1}).
  \end{equation}

  Denote by \( \xi_{k,j} \) the largest tag in \( \Xi \) such that \( \xi_{k,j} \leq y_{k,j} \). Thus,
  \begin{equation*}
    S(f, \Delta, \Xi) = \sum_{k=1}^{n_0} \sum_{j=1}^{p_k} f(\xi_{k,j}) (y_{k,j} - y_{k,j-1}).
  \end{equation*}

  For every \( k = 1, \ldots, n \) and every \( j = 0, \ldots, p_k \), choose an arbitrary tag
  \begin{equation*}
    \Eta: \eta_{k,j} \in [y_{k,j-1}, y_{k,j}].
  \end{equation*}

  Then we have
  \begin{balign*}
    S(f, \Delta, \Xi) - I
    &=
    S(f, \Delta, \Xi) - S(f, \Gamma, \Eta) + \underbrace{S(f, \Gamma, \Eta) - I}_{\in U}
    \in \\ &\in
    \sum_{k=1}^{n_0} \sum_{j=1}^{p_k} [ \underbrace{f(\xi_{k,j}) - f(\eta_{k,j})}_{\in V} ] (y_{k,j} - y_{k,j-1}) + U
    \subseteq \\ &\subseteq
    V \cdot \sum_{k=1}^{n_0} \underbrace{\sum_{j=1}^{p_k} (y_{k,j} - y_{k,j-1})}_{x_k - x_{k-1}} + U
    \subseteq \\ &\subseteq
    \diam(\Delta) \cdot n_0 \cdot V + U
    \subseteq \\ &\subseteq
    (\diam(\Delta) \cdot n_0 \cdot v + 1) U.
  \end{balign*}

  Let \( (\Delta_1, \Xi_1) \) be a tagged partition of \( [a, b] \) such that \( \diam(\Delta_1) \leq \min \left\{ \diam(\Delta_0), \frac 1 {v n_0} \right\} \). It follows that
  \begin{equation}\label{eq:def:riemann_integral/subdiameter_in_neighborhood}
    S(f, \Delta_1, \Xi_1) - I \subseteq 2U.
  \end{equation}

  Until now, \( U \) was fixed. Given any neighborhood \( W \) of \( 0 \), we need to choose a neighborhood \( U \) of \( 0 \) and a corresponding partition \( \Delta_1 \) such that \eqref{eq:def:riemann_integral/subdiameter_in_neighborhood} holds. Then, whenever \( \diam(\Delta) \leq \diam(\Delta_1) \), we have
  \begin{equation*}
    S(f, \Delta, \Xi) - I \subseteq 2U \subseteq W.
  \end{equation*}

  This finishes the proof.

  \ImplicationSubProof{def:riemann_partition/order/diameter}{def:riemann_partition/order/refinement} Note that if \( \Gamma \) is a refinement of \( \Delta \), clearly \( \diam(\Gamma) \leq \diam(\Delta) \). Therefore, if the net \eqref{eq:def:riemann_integral/net} with respect to \( \preceq_D \) is eventually in some open set \( U \), the corresponding net with respect to \( \preceq_R \) is also eventually in \( U \). This finishes the proof.
\end{proof}

\begin{corollary}\label{thm:riemann_integrable_implies_bounded}
  A Riemann-integrable function is bounded.
\end{corollary}
\begin{proof}
  Proven in \fullref{def:riemann_integral}.
\end{proof}

\begin{definition}\label{def:darboux_integrability}\mcite[def. 17]{Gordon1991}
  Let \( (\mscrX, \rho) \) be a \hyperref[def:frechet_space]{Frechet space}. Fix a function \( f: [a, b] \to X \). Similarly to \fullref{def:riemann_integral}, choose any of the orderings \fullref{def:riemann_partition/order/refinement} and \fullref{def:riemann_partition/order/diameter} on the set of all untagged \hyperref[def:riemann_partition/partition]{Riemann partitions} \( \op{part}([a, b]) \).

  For each partition \eqref{eq:def:riemann_partition/partition}, we define its \term{oscillation} via the \hyperref[def:function_oscillation]{function oscillation} of \( f \)
  \begin{equation}\label{eq:def:darboux_integrability/oscillation}
    \omega(f, \Delta) \coloneqq \sum_{k=1}^n \omega(f, [x_{k-1}, x_k]) (x_k - x_{k-1}).
  \end{equation}

  Consider the net
  \begin{equation}\label{eq:def:darboux_integrability/net}
    \{ \omega(f, \Delta) \}_{\Delta \in \op{part}([a, b])}
  \end{equation}

  If this net converges to zero, we say that \( f \) is \term{Darboux integrable}.
\end{definition}

\begin{proposition}\label{thm:darboux_integrable_implies_riemann_integrable}
  In a \hyperref[def:banach_space]{Banach space}, \hyperref[def:darboux_integrability]{Darboux integrability} implies \hyperref[def:riemann_integral]{Riemann integrability}.
\end{proposition}
\begin{proof}
  We will show that the net \eqref{eq:def:riemann_integral/net} is fundamental. Fix \( \varepsilon > 0 \). Since \( f \) is Darboux integrable, there exists an untagged partition \( \Delta_0 \) such that, if \( \Delta \) is a refinement of \( \Delta_0 \), we have
  \begin{equation*}
    \omega(f, \Delta) < \varepsilon.
  \end{equation*}

  Let \( \Delta \) be a refinement of \( \Delta_0 \) and \( \Gamma \) be a refinement of \( \Delta \). Assume that the points of \( \Gamma \) are split as in \eqref{def:riemann_partition/refinement/splitting}. Choose arbitrary tags \( \Xi = \{ \xi_k \}_{k=1}^n \) for \( \Delta \) and \( \Eta = \{ \eta_{k,j} \}_{k=1,j=1}^{n,p_k} \) for \( \Gamma \). For the corresponding Riemann sums, we have
  \begin{balign*}
    &\phantom{{}={}}
    \norm{S(f, \Delta, \Xi) - S(f, \Gamma, \Eta)}
    = \\ &=
    \norm{\sum_{k=1}^n f(\xi_k) (x_k - x_{k-1}) - \sum_{k=1}^n \sum_{j=1}^{p_k} f(\eta_{k,j}) (y_{k,j} - y_{k,j-1}) }
    \leq \\ &\leq
    \sum_{k=1}^n \sum_{j=1}^{p_k} \norm{f(\xi_k) - f(\eta_{k,j})} (y_{k,j} - y_{k,j-1})
    \leq \\ &\leq
    \sum_{k=1}^n \sum_{j=1}^{p_k} (y_{k,j} - y_{k,j-1}) \sup \{ \norm{f(\xi) - f(\eta)} \colon \xi, \eta \in [y_{k,j-1}, y_{k,j}] \}
    \leq \\ &\leq
    \sum_{k=1}^n \sup \{ f(\xi) - f(\eta) \colon \xi, \eta \in [x_{k-1}, x_k] \} \underbrace{\sum_{j=1}^{p_k} (y_{k,j} - y_{k,j-1})}_{x_{k-1} - x_k}
    = \\ &=
    \omega(f, \Delta)
    <
    \varepsilon.
  \end{balign*}

  Therefore, the net \eqref{eq:def:riemann_integral/net} is fundamental and, since \( \mscrX \) is complete, the net converges to a limit.
\end{proof}

\begin{definition}\label{def:darboux_integral}
  Fix a real-valued function \( f: [a, b] \to \BbbR \). The \term{upper Darboux sum} corresponding to the partition \eqref{eq:def:riemann_partition/partition} is defined as
  \begin{equation*}
    \overline{S}(f, \Delta) \coloneqq \sum_{k=1}^n (x_{k-1} - x_k) \sup_{\xi \in [x_{k-1}, x_k]} f(\xi).
  \end{equation*}

  The \term{lower Darboux sum} is defined as
  \begin{equation*}
    \underline{S}(f, \Delta) \coloneqq \sum_{k=1}^n (x_{k-1} - x_k) \inf_{\xi \in [x_{k-1}, x_k]} f(\xi).
  \end{equation*}

  If the nets
  \begin{align}\label{eq:def:darboux_integral/nets}
    \{ \overline{S}(f, \Delta) \}_{\Delta \in \op{part}([a, b])}
    &&
    \{ \underline{S}(f, \Delta) \}_{\Delta \in \op{part}([a, b])}
  \end{align}
  have a common limit, we call this limit the \term{Darboux integral} of \( f \) and, analogously to \fullref{def:riemann_integral}, we denote it by
  \begin{equation*}
    \int_a^b f(x) dx.
  \end{equation*}

  This notation is justified by \fullref{thm:darboux_integral_iff_riemann_integral}.
\end{definition}

\begin{proposition}\label{thm:darboux_integrable_iff_has_darboux_integral}
  A real-valued function \( f: [a, b] \to \BbbR \) is \hyperref[def:darboux_integrability]{Darboux integrable} if and only if it has a \hyperref[def:darboux_integral]{Darboux integral}.
\end{proposition}
\begin{proof}
  Note that, given the partition \eqref{eq:def:riemann_partition/partition}, we have
  \begin{align*}
    \overline{S}(f, \Delta) - \underline{S}(f, \Delta)
    &=
    \sum_{k=1}^n (x_k - x_{k-1}) \left[ \sup_{\xi \in [x_{k-1}, x_k]} f(\xi) - \inf_{\eta \in [x_{k-1}, x_k]} f(\eta) \right]
    = \\ &=
    \sum_{k=1}^n (x_k - x_{k-1}) \left[ \sup_{\xi \in [x_{k-1}, x_k]} f(\xi) + \sup_{\eta \in [x_{k-1}, x_k]} -f(\eta) \right]
    = \\ &=
    \sum_{k=1}^n (x_k - x_{k-1}) \sup \{ f(\xi) - f(\eta) \colon \xi, \eta \in [x_{k-1}, x_k] \}
    = \\ &=
    \sum_{k=1}^n (x_k - x_{k-1}) \sup \{ \abs{f(\xi) - f(\eta)} \colon \xi, \eta \in [x_{k-1}, x_k] \}
    = \\ &=
    \omega(f, \Delta).
  \end{align*}

  Therefore, the nets \eqref{eq:def:darboux_integral/nets} converge to a common limit if and only if \( \omega(f, \Delta) \xrightarrow[\Delta]{} 0 \). This finishes the proof.
\end{proof}

\begin{proposition}\label{thm:darboux_integral_iff_riemann_integral}
  A real-valued function \( f: [a, b] \to \BbbR \) has a \hyperref[def:darboux_integral]{Darboux integral} if and only if it has a \hyperref[def:riemann_integral]{Riemann integral}. Furthermore, the two integrals are equal.
\end{proposition}
\begin{proof}
  Fix \( \varepsilon > 0 \).

  \ImplicationSubProof{def:darboux_integral}{def:riemann_integral} Denote by \( I_D \) the Darboux integral of \( f \). Then there exists a partition \( \Delta_0 \) of \( [a, b] \) such that for any refinement \eqref{eq:def:riemann_partition/partition} of \( \Delta_0 \) we have
  \begin{equation*}
    \overline{S}(f, \Delta) - \underline{S}(f, \Delta) < \frac \varepsilon 2.
  \end{equation*}

  In particular, \( I_D - \underline{S}(f, \Delta) < \tfrac \varepsilon 2 \).

  Let \( \Xi \coloneqq \{ \xi_k \}_{k=1}^n \) be tags for \( \Delta \). Then
  \begin{align*}
    \abs{S(f, \Delta, \Xi) - I_D}
    &\leq
    \abs{S(f, \Delta, \Xi) - \underline{S}(f, \Delta)} - \abs{\underline{S}(f, \Delta) - I}
    \leq \\ &\leq
    \abs{\overline{S}(f, \Delta) - \underline{S}(f, \Delta)} - \abs{\underline{S}(f, \Delta) - I}
    < \\ &<
    \frac \varepsilon 2 + \frac \varepsilon 2
    = \\ &=
    \varepsilon.
  \end{align*}

  Therefore, \( I_D \) is also a Riemann integral for \( f \).

  \ImplicationSubProof{def:riemann_integral}{def:darboux_integral} Denote by \( I_R \) the Riemann integral of \( f \). Then there exists a partition \eqref{eq:def:riemann_integral/tagged_zero} such that for any partition \eqref{eq:def:riemann_partition/tagged} with \( \diam(\Delta) \leq \diam(\Delta_0) \), we have
  \begin{equation*}
    \abs{S(f, \Delta, \Xi) - I_R} < \frac \varepsilon 2.
  \end{equation*}

  Since \eqref{thm:riemann_integrable_implies_bounded} is bounded, there exists a constant \( M > 0 \) such that \( \abs{f(\xi) - f(\eta)} < M \) for any \( \xi, \eta \in [a, b] \).

  Using an analogous to \eqref{def:riemann_partition/subdiameter_splitting} splitting for the refinement \( \Gamma \coloneqq \Delta \cup \Delta_0 \) of \( \Delta_0 \), we obtain
  \begin{align*}
    \overline{S}(f, \Gamma) - S(f, \Gamma, \Eta)
    &=
    \sum_{k=1}^{n_0} \sum_{k=1}^{p_k} [ \sup_{\xi \in [y_{k,j-1}, y_{k,j}]} f(\eta) - f(\eta_{k,j}) ] (y_{k,j} - y_{k,j-1})
    \leq \\ &\leq
    M \sum_{k=1}^{n_0} \sum_{k=1}^{p_k} (y_{k,j} - y_{k,j-1})
    \leq \\ &\leq
    M \cdot n_0 \cdot \diam(\Gamma).
  \end{align*}

  By choosing a tagged partition \( (\Delta_1, \Xi_1) \) with \( \diam(\Delta_1) < \min \left\{ \diam(\Delta_0), \frac \varepsilon {2 M n_0} \right\} \), we obtain
  \begin{equation*}
    \overline{S}(f, \Delta_1) - S(f, \Delta_1, \Xi) < \frac \varepsilon 2.
  \end{equation*}

  Therefore, whenever \( \diam(\Delta) \leq \diam(\Delta_1) \),
  \begin{equation*}
    \overline{S}(f, \Delta) - I_R
    =
    \overline{S}(f, \Delta) - S(f, \Delta, \Xi) + S(f, \Delta, \Xi) - I_R
    <
    \frac \varepsilon 2 + \frac \varepsilon 2
    =
    \varepsilon.
  \end{equation*}

  Thus, the net \( \{ \overline{S}(f, \Delta) \}_{\Delta \in \op{part}([a, b])} \) of upper Darboux sums converges to \( I \). We can analogously show that the lower Darboux sums also converge to \( I_R \). Hence, \( I_R \) is the Darboux integral of \( f \).
\end{proof}

\begin{proposition}\label{thm:countinuous_functions_integrable}
  In a \hyperref[def:frechet_space]{Frechet space} \( (\mscrX, \rho) \), \hyperref[def:global_continuity]{continuous functions} \( f: [a, b] \to X \) are \hyperref[def:darboux_integrability]{Darboux integrable}.
\end{proposition}
\begin{proof}
  Fix \( \delta > 0 \). Let \eqref{eq:def:riemann_partition/partition} be a partition of \( [a, b] \) such that \( \diam(\Delta) < \delta \). We have
  \begin{equation*}
    \omega(f, \Delta)
    =
    \sum_{k=1}^n \omega(f, [x_{k-1}, x_k]) (x_k - x_{k-1})
    \leq
    \sum_{k=1}^n \omega(f, \diam(\Delta)) \diam(\Delta)
    <
    n \omega(f, \delta) \delta.
  \end{equation*}

  Now fix \( \varepsilon > 0 \). A continuous function on a compact interval is \hyperref[def:uniform_continuity]{uniformly continuous}. By \fullref{thm:def:function_oscillation/properties/continuity_condition}, there exists \( \delta_0 > 0 \) such that \( \omega(f, \delta_0) < \varepsilon \). It is then enough to choose
  \begin{equation*}
    \delta \coloneqq \frac {\delta_0} {n \varepsilon}
  \end{equation*}
  to obtain
  \begin{equation*}
    \omega(f, \Delta)
    <
    n \delta \omega(f, \delta)
    =
    \delta_0 \frac {\omega(f, \delta)} {\varepsilon}
    \reloset {\ref{thm:def:function_oscillation/properties/monotone}} \leq
    \delta_0 \frac {\omega(f, \delta_0)} {\varepsilon}
    <
    \varepsilon.
  \end{equation*}

  Therefore, the same inequality holds for all partitions with diameters smaller than \( \delta \), which implies that \( f \) is Darboux integrable.
\end{proof}

\begin{proposition}\label{thm:componentwise_integration}
  Let \( f: [a, b] \to \BbbR^n \) be a function and let \( f_k, k = 1, \ldots, n \) be its components. We have that \( f \) is integrable if and only if \( f_k \) is integrable for \( k = 1, \ldots, n \). Furthermore,
  \begin{equation}\label{eq:thm:componentwise_integration}
    \bigintss_a^b \begin{pmatrix} f_1(x) \\ \vdots \\ f_n(x) \end{pmatrix} dx
    =
    \begin{pmatrix} {\displaystyle \int_a^b f_1(x)} dx \\ \vdots \\ {\displaystyle \int_a^b f_n(x) dx} \end{pmatrix}.
  \end{equation}
\end{proposition}
\begin{proof}
  \SufficiencySubProof Let \( f \) be integrable and let \( I = (I_1, \ldots, I_n)^T \) be the value of the integral. Fix \( \varepsilon > 0 \) and let \( (\Delta, \Xi) \) be a tagged partition such that
  \begin{equation*}
    \norm{I - S(f, \Delta, \Xi)} < \varepsilon.
  \end{equation*}

  Then for any \( k = 1, \ldots, n \) we have
  \begin{equation*}
    \norm{I - S(f, \Delta, \Xi)}^2
    =
    \sum_{m=1}^n \abs{I_m - S(f_m, \Delta, \Xi)}^2
    \geq
    \abs{I_k - S(f_k, \Delta, \Xi)}^2,
  \end{equation*}
  hence
  \begin{equation*}
    \abs{I_k - S(f_k, \Delta, \Xi)} < \varepsilon.
  \end{equation*}

  Therefore, \( f_k \) is integrable and
  \begin{equation*}
    \int_a^b f_k(x) dx = I_k.
  \end{equation*}

  \NecessitySubProof Let \( f_k \) be integrable for \( k = 1, \ldots, n \) with value \( I_k \). Put \( I \coloneqq (I_1, \ldots, I_n)^T \). Fix \( \delta > 0 \) and let \( (\Delta_k, \Xi_k) \) be a parition such that
  \begin{equation*}
    \abs{I_k - S(f_k, \Delta_k, \Xi_k)} < \delta
  \end{equation*}

  Let \( \Gamma \coloneqq \bigcup_{k=1}^n \Delta_k \) and let \( \Eta \) be tags for \( \Gamma \). Since \( \diam(\Gamma) \leq \diam(\Delta_k) \) and since \( f_k \) is integrable, we have
  \begin{equation*}
    \abs{I_k - S(f_k, \Gamma, \Eta)} < \delta \quad\forall k = 1, \ldots, n.
  \end{equation*}

  We have
  \begin{equation*}
    \norm{I - S(f, \Gamma, \Eta)}
    =
    \sqrt{\sum_{m=1}^n \abs{I_m - S(f_m, \Gamma, \Eta)}^2}
    <
    \delta \sqrt{n}.
  \end{equation*}

  Therefore, given \( \varepsilon > 0 \), it is enough to choose \( \delta \coloneqq \frac {\varepsilon} {\sqrt n} \) to obtain a tagged partition \( (\Gamma_0, \Eta_0) \), so that for \( (\Gamma, \Eta) \) with \( \diam(\Gamma) < \diam(\Gamma_0) \) we have
  \begin{equation*}
    \norm{I - S(f, \Gamma, \Eta)} < \varepsilon.
  \end{equation*}

  This proves integrability of \( f \) and \eqref{eq:thm:componentwise_integration}.
\end{proof}


\title{KL(p||q) Minimization}

\subsection{$\text{KL}(p\|q)$ Minimization}

One form of variational inference minimizes the Kullback-Leibler divergence
\textbf{from} $p(\mathbf{z} \mid \mathbf{x})$ \textbf{to} $q(\mathbf{z}\;;\;\lambda)$,
\begin{align*}
  \lambda^*
  &=
  \arg\min_\lambda \text{KL}(
  p(\mathbf{z} \mid \mathbf{x})
  \;\|\;
  q(\mathbf{z}\;;\;\lambda)
  )\\
  &=
  \arg\min_\lambda\;
  \mathbb{E}_{p(\mathbf{z} \mid \mathbf{x})}
  \big[
  \log p(\mathbf{z} \mid \mathbf{x})
  -
  \log q(\mathbf{z}\;;\;\lambda)
  \big].
\end{align*}
The KL divergence is a non-symmetric, information theoretic measure of
similarity between two probability distributions.

\subsubsection{Minimizing an intractable objective function}

The $\text{KL}(p\|q)$ objective we seek to minimize is intractable; it directly
involves the posterior $p(\mathbf{z} \mid \mathbf{x})$. Ignoring this for the moment, consider its
gradient
\begin{align*}
  \nabla_\lambda\;
  \text{KL}(
  p(\mathbf{z} \mid \mathbf{x})
  \;\|\;
  q(\mathbf{z}\;;\;\lambda)
  )
  &=
  -
  \mathbb{E}_{p(\mathbf{z} \mid \mathbf{x})}
  \big[
  \nabla_\lambda\;
  \log q(\mathbf{z}\;;\;\lambda)
  \big].
\end{align*}
Both $\text{KL}(p\|q)$ and its gradient are intractable
because of the posterior expectation.
We can use importance sampling to both
estimate the objective and calculate stochastic gradients
\citep{oh1992adaptive}.

\subsubsection{Adaptive Importance sampling}

First rewrite the expectation to be with respect to the variational
distribution,
\begin{align*}
  -
  \mathbb{E}_{p(\mathbf{z} \mid \mathbf{x})}
  \big[
  \nabla_\lambda\;
  \log q(\mathbf{z}\;;\;\lambda)
  \big]
  &=
  -
  \mathbb{E}_{q(\mathbf{z}\;;\;\lambda)}
  \Bigg[
  \frac{p(\mathbf{z} \mid \mathbf{x})}{q(\mathbf{z}\;;\;\lambda)}
  \nabla_\lambda\;
  \log q(\mathbf{z}\;;\;\lambda)
  \Bigg].
\end{align*}

We then use importance sampling to obtain a noisy estimate of this gradient.
The basic procedure follows these steps:
\begin{enumerate}
  \item draw $S$ samples $\{\mathbf{z}_s\}_1^S \sim q(\mathbf{z}\;;\;\lambda)$,
  \item evaluate $\nabla_\lambda\; \log q(\mathbf{z}_s\;;\;\lambda)$,
  \item compute the normalized importance weights
  \begin{align*}
    w_s
    &=
    \frac{p(\mathbf{z}_s \mid \mathbf{x})}{q(\mathbf{z}_s\;;\;\lambda)}
    \Bigg/
    \sum_{s=1}^{S}
    \frac{p(\mathbf{z}_s \mid \mathbf{x})}{q(\mathbf{z}_s\;;\;\lambda)}
  \end{align*}
  \item compute the weighted mean.
\end{enumerate}
The key insight is that we can use the joint $p(\mathbf{x},\mathbf{z})$ instead of the posterior
when estimating the normalized importance weights
\begin{align*}
  w_s
  &=
  \frac{p(\mathbf{z}_s \mid \mathbf{x})}{q(\mathbf{z}_s\;;\;\lambda)}
  \Bigg/
  \sum_{s=1}^{S}
  \frac{p(\mathbf{z}_s \mid \mathbf{x})}{q(\mathbf{z}_s\;;\;\lambda)} \\
  &=
  \frac{p(\mathbf{x}, \mathbf{z}_s)}{q(\mathbf{z}_s\;;\;\lambda)}
  \Bigg/
  \sum_{s=1}^{S}
  \frac{p(\mathbf{x}, \mathbf{z}_s)}{q(\mathbf{z}_s\;;\;\lambda)}.
\end{align*}
This follows from Bayes' rule
\begin{align*}
  p(\mathbf{z} \mid \mathbf{x})
  &=
  p(\mathbf{x}, \mathbf{z}) / p(\mathbf{x})\\
  &=
  p(\mathbf{x}, \mathbf{z}) / \text{a constant function of }\mathbf{z}.
\end{align*}

Importance sampling thus gives the following biased yet consistent gradient
estimate
\begin{align*}
\nabla_\lambda\;
  \text{KL}(
  p(\mathbf{z} \mid \mathbf{x})
  \;\|\;
  q(\mathbf{z}\;;\;\lambda)
  )
  &=
  -
  \frac{1}{S}
  \sum_{s=1}^S
  w_s
  \nabla_\lambda\; \log q(\mathbf{z}_s\;;\;\lambda).
\end{align*}
The objective $\text{KL}(p\|q)$ can be calculated in a similar fashion.
The only new ingredient for its gradient is the score function
$\nabla_\lambda \log q(\mathbf{z}\;;\;\lambda)$.  Edward uses automatic
differentiation, specifically with TensorFlow's computational graphs,
making this gradient computation both simple and efficient to
distribute.

Adaptive importance sampling follows this gradient to a local optimum using
stochastic optimization. It is adaptive because the variational distribution
$q(\mathbf{z}\;;\;\lambda)$ iteratively gets closer to the posterior $p(\mathbf{z} \mid \mathbf{x})$.

For more details, see the \href{/api/}{API} as well as its
implementation in Edward's code base.

\subsubsection{References}\label{references}


\subsection{The AK model}

\subsubsection{Recap of growth models}

As with the Harrod-Domar model we have output as a function of capital:

\(Y=f(K)\)

Capital dynamics:

\(\dot K=I-\delta K\)

\(I=S=sY\)

This gives us:

\(\dot K = sY-\delta K\)

\subsubsection{Recap of the Harrod-Domar and Solow-Swan models}

In the Solow-Swan model the production function was:

\(Y=K^\alpha (AL)^{1-\alpha }\)

In the Harrod-Domar model the production function was:

\(Y=cK\)

In the Solow-Swan model we also added population and technology growth

\subsubsection{The AK model}

In the AK model the production function is:

\(Y=AK\)

We keep population growth from the Solow-Swan model.

\subsubsection{Per-capita income}

\(\dot K = sAK-\delta K\)

\(\dot K = (sA-\delta )K\)

\(k=\dfrac{K}{L}\)

\(\dot k =\dfrac{\dot K}{L}-\dot L\dfrac{K}{L^2}\)

\(\dot k =\dfrac{(sA-\delta )K}{L}-\dot L\dfrac{K}{L^2}\)

\(\dot k =(sA-\delta )k-k\dfrac{\dot L}{L}\)

\(\dot k =(sA-\delta -n)k\)

\(\dfrac{\dot k}{k} =sA-\delta -n\)


\section{An alternative approach}

To complete our analysis, we thought to seek alternative models to compare with the ones described above. Our idea was to consider different approaches to see if they lead to same results. After some research we found a new process, discussed in \cite{7520324}, that proposed a linear proceedings to determine the error. \\
% During the analysis discussed above, we encountered some problems: few of them were caused by misunderstandings of parts of the model itself, some others by calculation or implementation errors. All these errors prevented us to reach meaningful result during the test phase. Thus, we decided to look for alternative solutions in order to place them side by side with our model and, if possible, to correct it and compare final results. After some research we found a new process, discussed in \cite{7520324}, and proposed to fully understand the propagation error in laser triangulation-based systems. \\

This new model is based on \cite{576335}, that proposed a way to propagate approximately additive random perturbations through vision algorithms in which the appropriate random perturbation model for the estimated quantity (produced by the vision step) is also an additive random perturbation. We have considered this aspect very interesting because if we are able to find a linear description $f(\nu, \theta)$ of our problem, we can theoretically evaluate the error propagation over the experimental parameters $\hat{\theta}$ when they are not derived by an experimental observation of the noise $\nu$, but through a minimization such as:
  \begin{equation*}
    \hat{\theta} = argmin_{\theta} \, f(\nu, \theta)
  \end{equation*}
In this case, the propagation error we are interested in, is given by the covariance matrix $\Sigma_{\hat{\theta}}$ of each parameter involved by the system. A general for of this matrix is given by:
  \begin{equation*}
    \Sigma_{\hat{\theta}} =
      \left( \frac{\partial g}{\partial \theta} \right)^{-1}
      \frac{\partial g}{\partial \nu}^T
      \Sigma_\nu
      \frac{\partial g}{\partial \nu}
      \left(\left( \frac{\partial g}{\partial \theta} \right)^{-1}\right)^T
  \end{equation*}
where $\Sigma_\nu$ is the covariance matrix of the observed noise. To make a complete and robust description of the problem, we have to build this last matrix properly.

From a geometrical point of view, a 3D point in the world reference system must satisfy both the camera perspective projection model (Equation \ref{eq:perspective_projection}) as well as the laser plane equation $x^T\boldsymbol{n} = d$, where $\boldsymbol{n}$ is the plane normal vector, and $d = 0$ accordingly with the coplanar version of Tsai \cite{TsaiTvLenses}. This allows to build a system of equation, described by:
  \begin{equation}
    \begin{bmatrix}
      \boldsymbol{r}^T - \boldsymbol{v}^T \frac{(x_p - c_x)}{f_x} \\
      \boldsymbol{u}^T - \boldsymbol{v}^T \frac{(y_p - c_y)}{f_y} \\
      \boldsymbol{n}^T
    \end{bmatrix}
    \begin{bmatrix}
      x_w \\ y_w \\ z_w
    \end{bmatrix}
    =
    \begin{bmatrix}
      \frac{(x_p - c_x)}{f_x} t_3 - t_1 \\
      \frac{(y_p - c_y)}{f_y} t_2 - t_1 \\
      d
    \end{bmatrix}
    \label{eq:app2-model}
  \end{equation}
The vectors $\boldsymbol{r}$, $\boldsymbol{u}$ and $\boldsymbol{v}$ are the row vectors of the rotation matrix $R^T = \begin{bmatrix} \boldsymbol{r} & \boldsymbol{u} & \boldsymbol{v} \end{bmatrix}$, while $t_i$ is the element of the translation vector $T^T = \begin{bmatrix} t_1 & t_2 & t_3 \end{bmatrix}$. We can rewrite the system of equation as:
  \begin{equation*}
    A\boldsymbol{x} = \boldsymbol{b}
  \end{equation*}
and we obtain a linear equation that can be used to determine $\hat{\theta}$. Furthermore, if we perturb this last equation, we obtain something like:
  \begin{equation*}
    (\boldsymbol{x} + \delta \boldsymbol{x}) = (A + \delta A)^{-1}(\boldsymbol{b} + \delta \boldsymbol{b})
  \end{equation*}
At this point it is simple to identify all the parameters from Equation \ref{eq:app2-model} that are included in $\Sigma_{\nu}$. \\

To simplify the determination of significant factor, the authors suggest to group the parameters of interest in a few set:
  \begin{enumerate}
    \item \textit{Camera Intrinsic Calibration Uncertainty} \\
    We have already discussed extensively in the Section \ref{sec:calib-model} the issues that arise when we try to consider the propagation error in the calibration phase. The same conclusions are still valid in this case.

  \item \textit{Positioning Uncertainty} \\
  In this set are grouped both the position of the camera as well as the one of the laser. Concerning the position of the camera, we can consider its position deviations as negligible. From our point of view, if we move camera with respect of its ideal position, we will see some changes about its \acs{DOF} or resolution, that can be fixed by correcting lens focus, but not a substantial degradation of the ability to correctly detect the sub-pixel position of the laser spot.  \\
  About the laser, instead, we are strongly interested in determining as precisely as possible its pitch and roll rotations. If on the one hand laser rotations could be manufacture errors, on the other many system like \acs{WPMS}s acquire the laser when the target is not perpendicular to the laser itself. Thus, it is of primary importance to be able to determine the right laser orientation. In \cite{7520324} the authors proposed to use the rotation matrix \ref{eq:second-app-laser-rot} to determine the error in laser positioning.
  \begin{equation}
      \begin{bmatrix}
          \sin(e_\theta)\cos(e_\phi) \\ \sin(e_\theta)\sin(e_\phi) \\ \cos(e_\theta)
      \end{bmatrix}
      \label{eq:second-app-laser-rot}
   \end{equation}

    \item \textit{Laser detection} \\
    Following the idea as the one used in our model, it is natural to underline that errors of interest are the ones made by determining the position of the spot laser at sub-pixel accuracy, i.e. $\sigma_{x}$ and $\sigma_{y}$ (with $x$ and $y$ taken accordingly to the laser reference system), and $Cov_{xy}$ for the spot, under the hypothesis that the two coordinates are i.i.d. random variables. \\
    However, accordingly with \cite{7520324}, this seems not to be correct. In fact the authors suggest to perform some test on a known system, and to use the variations of the spot position between couples of acquisitions to make a statistics on the committed errors.

    \item \textit{Lens distortions and the point discretization} \\
    As we done in the previous model, also in this case we considered the contributions due by lens distortions and the point discretization on the 2D sensor plane. To do that, we consider the same analysis done in the Sections \ref{sec:model-lens-distortion} and \ref{sec:laser-peaks}.
  \end{enumerate}

Once all the parameters of interest have been defined, we tried to build the covariance matrix $\Sigma_\nu$: removing all the parameters that we considered negligible, we obtained a $6\times6$ matrix. We notice that many dependency relationships were not trivial to determine, sometimes because we couldn't understand what type of relations existed between the couple of parameters. Furthermore, the conclusion reached talking about laser detection (point 3 of the list above) does not convince us. Our goal is to develop a mathematical model that can be used without any information on the performance of a possible real system: the necessity to make an error statistic using real data is out of our requirements. \\
All these difficulties in creating the matrix $\Sigma_\nu$, and the bad results obtained using this second model, discouraged us to continue along this way.


\chapter{Weights and forces}

Pretend that the concept of \emph{mass} has not been invented.

\emph{Weight} is what a weight balance measures.

A weight balance has two arms.

Put a weight on an end of a weight balance.
Push the other end with your hand until the balance comes to rest.
When they reach equilibrium,
both of them exerts the same amount of \emph{force}.

\section{Law of the lever}

% https://en.wikipedia.org/wiki/Virtual_work#Law_of_the_lever
% https://en.wikipedia.org/wiki/Lever

\index{definitions!lever}%
\index{lever!definition}%
\index{simple machine!lever|see{lever}}%
A \emph{lever} has a fulcrum and two ends.

Let \(r_1\) be the distance between the first end to the fulcrum.

Let \(r_2\) be the distance between the second end to the fulcrum.

Let \(F_1\) be the weight placed at the first end.

Let \(F_2\) be the weight placed at the second end.

\index{Archimedes!law of the lever}%
\index{laws named after people!Archimedes's law of the lever}%
\index{laws!lever}%
\index{lever!law of the lever}%
\index{statics!Archimedes's law of the lever}%
\emph{Law of the lever}:
Such lever at equilibrium satisfies \(F_1 \cdot r_1 = F_2 \cdot r_2\).

We take this law as evident.
Doubt can be removed by a simple experiment.

Thus, a weight balance is a lever whose arms have equal length.


\subsection{Great-circle distance}
The shortest distance between two points $A$ and $B$ on a sphere $(O,r)$ is given by travelling along plane $OAB$. It is called the \emph{great-circle distance} because it follows the circumference of one of the big circles of radius $r$ that split the sphere in two.

\centerFig{sph-4}

So computing the distance between $A$ and $B$ amounts to finding the length of the circle arc joining them. This arc is subtended by angle $\theta$, the angle between $\vv{OA}$ and $\vv{OB}$, so its length is simply $r\theta$.
\begin{lstlisting}
double greatCircleDist(p3 o, double r, p3 a, p3 b) {
    return r * angle(a-o, b-o);
}
\end{lstlisting}

This code also works if $A$ and $B$ are not actually on the sphere, in which case it will give the distance between their projections on the sphere:

\centerFig{sph-5}

Note that in most 2D projections this great-circle path is not a straight line, and it tends to bend northward in the Northern Hemisphere, and southward in the Southern Hemisphere. This is why, for example, flights going from London to Los Angeles fly over Greenland, although it is much further North than both cities.

\centerFig{sph-6}

\subsection{Spherical segment intersection}
For points $A$ and $B$ on a sphere, we define spherical segment $[AB]$ as the path drawn by the great-circle distance between $A$ and $B$ on the sphere. This is not well-defined if $A$ and $B$ are directly opposite each other on the sphere, because there would be many possible shortest paths.

From simplicity, we assume that the sphere is centered at the origin.
We will call a segment $[AB]$ \emph{valid} if $A$ and $B$ are not opposite each other on the sphere, or in other words, if their directions as vectors are not directly opposite each other. Note that this definition accepts segments where $A=B$.
\begin{lstlisting}
bool validSegment(p3 a, p3 b) {
    return a*b != zero || (a|b) > 0;
}
\end{lstlisting}

Given two spherical segments $[AB]$ and $[CD]$, we would like to figure out if they intersect, and what their intersection is. This is part of a more general problem: given two segments $[AB]$ and $[CD]$ in space, if we view them from an observation point $O$, does one of them hide part of the other, that is, is there a ray from $O$ that touches them both?

\begin{center}
    \begin{tabu} to .9\linewidth {X[c]X[c]}
        \includeFig{sph-7} & \includeFig{sph-8} \\
        common point on sphere & common ray from $O$ \\
    \end{tabu}
\end{center}

We will solve the general problem, and make sure that our answer is always exact when points $A,B,C,D$ are integer points. To do this, we will separate cases just like we did for 2D segment intersection in section~\ref{ss:seg-seg-inter}:
\begin{enumerate}
\item Segments $[AB]$ and $[CD]$ intersect \term{properly}, that is, their intersection is one single point which is not an endpoint of either segment. For the general problem this means that there is a single ray from $O$ that touches both $[AB]$ and $[CD]$, and it doesn't touch any of $A,B,C,D$.
\item In all other cases, the intersection, if it exists, is determined by the endpoints. If it is a single point, it must be one of $A,B,C,D$, and if it is a whole segment, it will necessarily start and end with points in $A,B,C,D$.
\end{enumerate}

For the rest of explanation, we will consider the case of spherical segment intersection, because it's easier to visualize, but it should be easy to verify that this also applise to the general problem.

\subsubsection{Proper intersection}
Let's deal with the first case: there is a single proper intersection point $I$. For this to be the case, $A$ and $B$ must be on either side of plane $OCD$, and $C$ and $D$ must be on either side of plane $OAB$. Put another way, $A$ and $B$ must be on either side of the great circle containing $C$ and $D$, and vice versa.

\centerFig{sph-9}

We can check this with mixed product. We have to verify that
\begin{itemize}
\item $o_A = (C \times D) \cdot A$ and $o_B = (C \times D) \cdot B$ have opposite signs;
\item $o_C = (A \times B) \cdot C$ and $o_D = (A \times B) \cdot D$ have opposite signs.
\end{itemize}

However, this time it's not enough. Sometimes, even though the conditions above are verified, there is no intersection, because the segments are on opposite sides of the sphere:

\begin{center}
    \includeFig{sph-10}

    $C$ and $D$ are on the other side of the sphere
\end{center}

To eliminate this kind of case, we also have to check that $o_A$ and $o_C$ have opposite signs (this is clearly not the case here).

\exo{Consider a few more examples and verify that these criteria correctly detect proper intersections in all cases.}

The intersection point $I$ must be in the intersection of planes $OAB$ and $OCD$.
So direction $\vv{OI}$ must be perpendicular to their normals $A \times B$ and $C \times D$, that is, parallel to $(A \times B) \times (C \times D)$.
Multiplying this by the sign of $o_D$ gives the correct direction.

This is implemented by the code below. Note that the result, \lstinline|out|, only gives the direction of the intersection. If we want to find the intersection on the sphere, we need to scale it to have length $r$.
\begin{lstlisting}
bool properInter(p3 a, p3 b, p3 c, p3 d, p3 &out) {
    p3 ab = a*b, cd = c*d; // normals of planes OAB and OCD
    int oa = sgn(cd|a),
        ob = sgn(cd|b),
        oc = sgn(ab|c),
        od = sgn(ab|d);
    out = ab*cd*od; // four multiplications => careful with overflow!
    return (oa != ob && oc != od && oa != oc);
}
\end{lstlisting}

\subsubsection{Improper intersections}
To deal with the second case, we will do as for 2D segments and test for every point among $A,B,C,D$ if it is on the other segment. If it is, we add it to a set $S$. $S$ will contain 0, 1, or 2 distinct points, describing an empty intersection, a single intersection point or an intersection segment.

\centerFig{sph-11}

To check whether a point $P$ is on spherical segment $[AB]$, we need to check that $P$ is on plane $OAB$, but also that $P$ is is ``between`` rays $[OA)$ and $[OB)$ on that plane.

Let $\vv{n} = A \times B$, a normal of plane $OAB$. Checking that $P$ is on plane $OAB$ is easy: $\vv{n}\cdot P$ should be 0. If $P$ is indeed on plane $OAB$, then we can check if it is to the ``right'' of $[OA)$ by looking at cross product $A \times P$. It should be perpendicular to plane $OAB$. If it is in the same direction as $\vv{n}$, then $P$ is to the right of $OA$, and if it is in the opposite direction, then $P$ is to the left of $OA$. So we need to check $\vv{n} \cdot (A \times P) \geq 0$.
Similarly, to check that $P$ is to the left of $OB$, we should check $\vv{n} \dot (B \times X) \leq 0$.

\centerFig{sph-12}

There remains only one special case: if $A$ and $B$ are the same point on the sphere, then $\vv{n}=\vv{0}$, and then we should just check that $P$ is also that same point.

We arrive at the following implementation. To handle the general problem, instead of directly checking for equality between $P$ and $A$ or $B$, we check that they are in the same direction with the cross product.
\begin{lstlisting}
bool onSphSegment(p3 a, p3 b, p3 p) {
    p3 n = a*b;
    if (n == zero)
        return a*p == zero && (a|p) > 0;
    return (n|p) == 0 && (n|a*p) >= 0 && (n|b*p) <= 0;
}
\end{lstlisting}

Now we just have to put all of this together in one function. First we check for a proper intersection, then if there is none we check segment by segment and add the points to set $S$. Since (as mentioned) we can't check for equality directly, we use a custom set structure that checks if the cross product is zero for every point already in the set.
\begin{lstlisting}
struct directionSet : vector<p3> {
    using vector::vector; // import constructors
    void insert(p3 p) {
        for (p3 q : *this) if (p*q == zero) return;
        push_back(p);
    }
};
directionSet intersSph(p3 a, p3 b, p3 c, p3 d) {
    assert(validSegment(a, b) && validSegment(c, d));
    p3 out;
    if (properInter(a, b, c, d, out)) return {out};
    directionSet s;
    if (onSphSegment(c, d, a)) s.insert(a);
    if (onSphSegment(c, d, b)) s.insert(b);
    if (onSphSegment(a, b, c)) s.insert(c);
    if (onSphSegment(a, b, d)) s.insert(d);
    return s;
}
\end{lstlisting}


\chapter{Random}
A game will rarely stay interesting when it is completely predictable. To avoid predictability, developers use random values provided by the \eeClass{Random} class.

\section{Whole Numbers}
The function \eeFunc{Random()} returns a random number between 0 and 4.294.967.295. Check this yourself with the next example:

\begin{code}
uint number = 0;

bool Update() {
  if(Kb.bp(KB_SPACE)) number = Random();
	return true;
}

void Draw() {
	D.clear(BLACK);
	D.text(0, 0, S + number);
}
\end{code}

You will rarely need a number this big. Which is why you can use the \eeClass{Random()} function with one or more arguments. When used with one argument, the function will return a number in the range 0 to the argument minus one. In other words, \eeClass{Random(5)}  will return one of the values 0, 1, 2, 3 or 4. Count them, that's 5 different values. A common beginners mistake is to expect the number five as a result. That will never, ever happen!

It is also possible to pass two arguments. \eeClass{Random(-2, 4)} returns one of these values: -2, -1, 0, 1, 2, 3 or 4. The important thing to remember that with this version, the arguments are inclusive.

\begin{exercise}
Create the basics of a lottery application. Show a new number from 1 to 42 (inclusive) on the screen every time you press the space bar.
\end{exercise}

\begin{note}
How to get a random color? The RGB values which make up a color have a value between 0 and 255. To randomize a color, try this:

\begin{code}
Color myColor;
myColor.set(Random(256), Random(256), Random(256));
\end{code}
\end{note}

\section{Random Float}
So far we've discussed random whole numbers. But you will often need floating point values. These are provided by the function \eeFunc{RandomF()}. This function will return a value between 0 and 1 by default, but it will also accept arguments. \eeFunc{RandomF(3)} will return a value between 0 and 3. \eeFunc{RandomF(-1.3, 2.5)} returns one between -1.3 and 2.5.

These functions are often used to show an object on a random position. Like so:

\begin{code}
Circle c;

c.pos.x = RandomF(-D.w(), D.w());
c.pos.y = RandomF(-D.h(), D.h());
\end{code}

In the example above, we won't even pass actual numbers to the function \eeFunc{RandomF()}. Instead, we let our application decide. The width and height of the screen are not the same on every device. By asking the engine about it, we will always end up with the correct values.

\begin{exercise}
Create an application which shows a circle on the screen. Every time the space bar is pressed, you change the circle's position.
\end{exercise}
\begin{exercise}
Create an application with a small rectangle on the screen. Assign a new position every second.
\end{exercise}
\begin{exercise}
Starting from the previous exercise, add an int `score' equal to zero. Draw this score somewhere on the screen. When the left mouse button is pressed, check if the mouse pointer is on top of the rectangle. If it is, increase the score by one.
\end{exercise}
\begin{exercise}
\textit{(A bit harder)} With every score increase, the position of the rectangle should change a bit faster.
\end{exercise}


\begin{intro}
  The following results can be found in any book on linear
  algeba. Thus, we will just keep the arguments short. There will be a
  focus on normal matrices justified by results on conditioning of
  eigenvalue problems later on.

  Thus, spectral theory based on module theory will not be needed in
  this class. The spectral theorem for normal matrices on the other
  hand is fairly simple and can be proved without too much overhead.
\end{intro}

\begin{Definition}{eigenvalue}
  An \define{eigenvalue} of a matrix $\mata\in \C^{n\times n}$ is a
  complex number $\lambda$ such that the matrix
  \begin{gather}
   \mata-\lambda\id
  \end{gather}
  is singular.

  The set of all eigenvalues of $\mata$ is called the
  \define{spectrum} $\sigma(\mata)$.

  The \define{eigenspace} for $\lambda$ is the kernel of
  $A-\lambda\id$, that is, the set
\begin{gather}
    \esp{\lambda} = \bigl\{
    \vv \in \C^n \;\big\vert\;
    \mata\vv = \lambda\vv \bigr\}.
\end{gather}
The \define{geometric multiplicity} of $\lambda$ is the dimension of
$\esp{\lambda}$.

An \define{eigenvector} for $\lambda$ is a (normed) vector in
$\esp\lambda$. We refer to an eigenvector $\lambda$ and a
corresponding eigenvector $\vv$ as \define{eigenpair}.
\end{Definition}

\begin{Definition}{eigenvalue-algebraic}
  An \define{eigenvalue} of a matrix $\mata\in \C^{n\times n}$ is a root of the characteristic polynomial $\chi(\lambda) = \det(\mata-\lambda\id)$.

  The \define{algebraic multiplicity} of an eigenvalue is the multiplicity of the corresponding root of the characteristic polynomial.
\end{Definition}

\begin{Lemma}{eigenvalue-equivalent}
  The two definitions of an eigenvalue are consistent.
\end{Lemma}

\begin{Theorem}{eigenvalue-count}
  Every matrix in $\C^{n\times n}$ has at most $n$ eigenvalues. The algebraic multiplicities of all eigenvalues add up to $n$.
\end{Theorem}

\begin{proof}
  The ``at most'' follows from the fact that a polynomial contains
  linear factors $x-\lambda_i$ for each of its roots
  $\lambda_i$. Thus, if the characteristic polynomial has $k$ roots it
  has at least degree $k$. On the other hand, the characteristic
  polynomial has degree $n$, such that $k\le n$.

  The second statement is due to the fact that every polynomial over
  $\C$ is a product of linear factors.
\end{proof}

\begin{remark}
  The last theorem is not true in $\R$, as it is not algebraically
  closed. Thus, even a real matrix may have complex eigenvalues and
  eigenvectors. Therefore, all results in this chapter will be on
  complex matrices, but some simplifications for real matrices will be
  pointed out.
\end{remark}

\begin{Definition}{eigenvalue-simple}
  An eigenvalue is \define{simple}, if its algebraic and geometric multiplicity are one. It is \define{semi-simple}, if its algebraic and geometric multiplicities are equal.
\end{Definition}

\begin{remark}
  It is possible to refine the concept of eigenvalues and eigenvectors by distinguishing between right eigenvalues and vectors solving
  \begin{gather}
      \mata \vv = \lambda \vv,
  \end{gather}
  and left eigenvalues and vectors solving
  \begin{gather}
    \vu \mata = \lambda \vu,
  \end{gather}
  where $\vu$ is now a row vector. By taking the transpose of this equation\footnote{Here, we refer to the real transpose obtained by simply exchanging indices, not the complex conjugate transpose.},
  \begin{gather}
    \label{eq:evp:1}
    \mata^T \vu^T = \lambda \vu^T,
  \end{gather}
  we see that $\vu$ is a left eigenvector of $\mata$ if and only if
  $\vu^T$ is a right eigenvector of $\mata^T$.
\end{remark}

\begin{Lemma}{eigenvalues-conjugate}
  Every eigenvalue $\lambda$ of $\mata\in\C^{n\times n}$ is also an eigenvalue of $\mata^T$.
\end{Lemma}

\begin{proof}
  The determinant does not change when the matrix is transposed, therefore
  \begin{gather}
    \chi(\mata^T)
    = \det(\mata^T-\lambda \id)
    = \det(\mata-\lambda \id)
    = \chi(\mata).
  \end{gather}
  Thus, the eigenvalues of $\mata$ and of $\mata^T$ coincide.
\end{proof}

\subsection{Normal and Hermitian matrices}

\begin{Definition}{normal-Hermitian}
  A matrix $\mata\in\C^{n\times n}$ is called \define{normal} if there holds
  \begin{gather}
      A^*A = AA^*.
  \end{gather}
  It is called \define{Hermitian} or \define{complex symmetric}, if there holds
  \begin{gather}
      A=A^*.
  \end{gather}
\end{Definition}

\begin{Lemma}{Hermitian-eigenvalues-real}
  All eigenvalues of a Hermitian matrix are real.
\end{Lemma}

\begin{Theorem*}{Hermitian-diagonalizable}{Spectral theorem for Hermitian matrices}
  A Hermitian matrix $\mata\in\C^{n\times n}$ is diagonalizable with
  an orthogonal basis of eigenvectors and real eigenvalues. That is,
  there is a real, diagonal matrix $\matlambda$ and a unitary matrix
  $\matq$ such that
  \begin{gather}
    \mata = \matq^T \matlambda\matq.
  \end{gather}
\end{Theorem*}

%\begin{proof}
%\end{proof}

\begin{Corollary}{symmetric-diagonalizable}
  A symmetric matrix $\mata\in\R^{n\times n}$ is diagonalizable with
  an orthogonal basis of eigenvectors and real eigenvalues.
\end{Corollary}

\begin{Theorem*}{normal-diagonalizable}{Spectral theorem for normal matrices}
  A matrix $\mata\in\C^{n\times n}$ is normal if and only if it is diagonalizable by a unitary matrix.

  It is normal if and only if there exists an orthonormal basis of eigenvectors.
\end{Theorem*}

\begin{proof}

\end{proof}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


\lab{Mayavi}{Mayavi}

\section*{3-D Plotting with Mayavi} % =========================================

Although Matplotlib is capable of creating 3-D plots, Mayavi\footnote{If Mayavi is not installed on your machine, run \li{conda install mayavi} from the command line. See Appendix \ref{updateinstall} for more info.} does it much faster and with better visuals.
Here we introduce methods for plotting space curves, scatter plots, and surfaces in 3-D.
The \li{mlab} submodule within the \li{mayavi} package contains the functions for creating these plots.
% We will use Mayavi for all 3-D plots in these labs. % O RLY?

\begin{warn}
Mayavi must be imported before Matplotlib.
\begin{lstlisting}
from mayavi import mlab
from matplotlib import pyplot as plt
\end{lstlisting}
\end{warn}

\begin{comment}
\begin{info} % Installation note. Make into a footnote?
If you do not have the \li{Mayavi} package installed on your system, you may download it by running the following commands from the command line:
\begin{lstlisting}
$ conda install conda               # Download the most recent installer.
$ conda install anaconda            # Update all packages.
$ conda install mayavi              # Installs mayavi.
\end{lstlisting}

% For more information regarding installing Python packages, see Appendix \ref{updateinstall}.
\end{info}

\begin{table} % Mayavi plotting functions. Probably should put this back in.
\begin{center}
\begin{tabular}
{|c|l|}
\hline
Function & Description \\
\hline
\li{barchart} & Produces 3D histogram-like plots\\
\li{contour3d} & Plots level surfaces of functions of three variables\\
\li{flow} & Creates a trajectory of particles following the flow of a vector field\\
\li{imshow} & Use a colormap to view a 2D array as an image\\
\li{mesh} & Plot a surface using \li{(x,y,z)} coordinates supplied as three 2D arrays\\
\li{plot3d} & Draws lines between points\\
\li{points3d} & Plots glyphs (like points) at the coordinates supplied\\
\li{quiver3d} & Generate 3D vector fields\\
\li{surf} & Plot a surface with a 2D array as elevation data\\
\hline
\end{tabular}
\end{center}
\caption{Some plotting functions in \li{mlab}.}
\label{table:mlab_functions}
\end{table}
\end{comment}

\subsection*{Lines} % ---------------------------------------------------------

The function \li{mlab.plot3d()} is the 3-D Mayavi equivalent for Matplotlib's \li{plt.plot()}.
Because the plot is 3-D, we must provide $x$, $y$, and $z$ coordinates, each contained in 1-D arrays of the same length.
The points \li{(x[i], y[i], z[i])} are graphed in $\mathbb{R}^3$ and connected with straight lines.

Consider the following curve, parametrized by time:
\begin{align*}
x(t) &= \cos(t)(1+\cos(6t))\\
y(t) &= \sin(t)(1+\sin(6t)\\
z(t) &= \sin\left(\frac{6}{11}t\right)
\end{align*}
The following code plots the curve over the time domain $t \in [0,2\pi]$.
The resulting plot is shown in Figure \ref{fig:plot3d}.

\begin{lstlisting}
>>> from mayavi import mlab

# Calculate the coordinates of a curve parametrized by time.
>>> t = np.linspace(0, 2*np.pi, 100)
>>> x = np.cos(t) * (1 + np.cos(t*6))
>>> y = np.sin(t) * (1 + np.cos(t*6))
>>> z = np.sin(t*6/11.)

# Plot and show the figure.
>>> mlab.plot3d(x, y, z)
>>> mlab.show()
\end{lstlisting}

\begin{figure} % Mayavi line and point plots.
\captionsetup[subfigure]{justification=centering}
\centering
\begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[width=\linewidth]{plot3d.png}
    \caption{A 3-D curve generated by \li{mlab.plot3d()}.}
    \label{fig:plot3d}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[width=\linewidth]{points3d.png}
    \caption{A 3-D scatter plot generated by \li{mlab.points3d()}.}
    \label{fig:points3d}
\end{subfigure}
\end{figure}

\subsection*{Points} % --------------------------------------------------------

The function \li{mlab.points3d()} is the 3-D Mayavi equivalent for Matplotlib's \li{plt.scatter()}.
Each point is plotted, but not connected with lines.
In the code below, the optional input array \li{s} defines a scalar for each point that modifies the color and size of the point.
The output is in Figure \ref{fig:points3d}.

\begin{lstlisting}
>>> t = np.linspace(0, 4*np.pi, 30)
>>> x = np.sin(2*t)
>>> y = np.cos(t)
>>> z = np.cos(2*t)
>>> s = 2 + np.sin(t)

# Adjust the keyword argument 'scale_factor' so all points are visible.
>>> mlab.points3d(x, y, z, s, scale_factor=.15)
>>> mlab.show()
\end{lstlisting}

\subsection*{Surfaces} % ------------------------------------------------------

The function \li{mlab.surf()} renders a 3-D surface.
Because the surface is over a 2-D domain, we create a coordinate grid with \li{np.mgrid()} (similar to \li{np.meshgrid()}).
This function uses the slicing syntax \li{[start:stop:step]}, similar to \li{range()} and \li{np.arange()}, but is accessed with brackets instead of parentheses.

The following code produces the hyperbolic paraboloid $f(x,y) = \frac{x^2}{4} - \frac{y^2}{4}$ over the domain $[-4,4]\times[-4,4]$.
The result is displayed in Figure \ref{fig:surf_example}.

\begin{lstlisting}
>>> X, Y = np.mgrid[-4:4:.025, -4:4:.025]
>>> Z = (X**2)/4. - (Y**2)/4.
>>> mlab.surf(X, Y, Z, colormap='RdYlGn')
>>> mlab.show()
\end{lstlisting}

\begin{figure}
\includegraphics[width=.7\textwidth]{mesh_example.png}
\caption{Sample output of \li{mlab.surf()}.}
\label{fig:surf_example}
\end{figure}

Like Matplotlib, Mayavi supports various color schemes, either as a solid color or with a varying colormap.
For example, the plot in Figure \ref{fig:surf_example} uses the colormap \li{'RdYlGn'}.
For a list of all colormaps in Mayavi, see \url{http://docs.enthought.com/mayavi/mayavi/mlab_changing_object_looks.html}.

% TODO: More exercises with Mayavi!!! Don't have to be too hard either...
\begin{problem}
Plot the function $z = \frac{1}{10}\sin(10(x^2+y^2))$ on $[-1,1] \times [-1,1]$ using Mayavi.
\end{problem}


\section{Introduction}

The key to convolutional neural networks (CNNs) lies in the way they employ convolution as a local and shift-invariant operation on Euclidean spaces, e.g.\ $\RR$ for audio or $\RR^2$ for images.
Recently, the concept of CNNs has been extended to more general spaces to exploit different structures that may underlie the data:
This includes spherical convolutions for rotationally invariant data~\cite{cohen2018sphericalcnn,esteves2018sphericalcnn,defferrard2020deepsphere}, more general convolutions on homogeneous spaces~\cite{cohen2016groupnn,kondor2018groupnn,worrall2017harmonicnn}, or convolutions on graphs~\cite{bruna2014graphnn,defferrard2016convolutional}.

Graph neural networks (GNNs) have proven to be an effective tool that can take into account irregular graphs to better learn interactions in the data~\cite{bronstein2017geometric,wu2020survey}.
Although graphs are useful in describing complex systems of irregular relations in a variety of settings, they are intrinsically limited to modeling pairwise relationships. The advance of topological methods in machine learning~\cite{Gabrielsson2020topological, Hofer2019LearningRO, rieck2018neural}, and the earlier establishment of \emph{topological data analysis (TDA)}~\cite{carlsson2008,chazal2017,edelsbrunner2010computational,ghrist2008barcodes} as a field in its own right, have confirmed the usefulness of viewing data as topological spaces in general, or in particular as simplicial complexes. The latter can be thought of as a higher-dimensional analog of graphs~\cite{moore2012,patania2017}. We here take the view that structure is encoded in \emph{simplicial complexes}, and that these represent $n$-fold interactions. In this setting, we present \emph{simplicial neural networks (SNNs)}, a neural network framework that take into account locality of data living over a simplicial complex in the same way a GNN does for graphs or a conventional CNN does for grids.

Higher-order relational learning methods, of which hypergraph neural networks~\cite{feng2018hypergraphs} and motif-based GNNs~\cite{monti2018motif} are examples, have already proven useful in some applications, e.g.\ protein interactions~\cite{ze2020graph}. However the mathematical theory underneath the notion of convolution in these approaches does not have clear connections with the global topological structure of the space in question. This leads us to believe that our method, motivated by Hodge--de Rham theory, is far better suited for situations where topological structure is relevant, such as perhaps in the processing of data that exists naturally as vector fields or data that is sensitive to the space's global structure.


\chapter{Bernoulli-Euler Beam equation}\label{Bernoulli-Euler Beam equation}

Assumptions used to derive the Bernoulli-Euler beam equation are (Complete derivation in \cite{craig2006fundamentals}):
\begin{enumerate}
	\item Beam is bending in a plane, in this case in the y-direction, where the x-direction is along the length of the beam.
	\item The  neutral axis undergoes no deformation in the longitudinal direction.
	\item Cross sections remain plane and perpendicular to the nuetral axis.
	\item The material is linear-elastic.
	\item Stresses in the y and z direction are negligible compared to those in the x direction.
	\item Rotary inertial effects are not considered.
	\item Mass density is constant at each cross section, so that each mass center is coincident with the centroid of that section.
\end{enumerate}
Using kinematics and assumptions 2 \& 3, the strain in the x direction may be related to the curvature of the beam, $\mu(x,t)$, and the distance from the neutral axis by
\begin{equation} \label{eq:curvature}
\epsilon=-\dfrac{y}{\mu}
\end{equation}
then, with assumption 4 \& 7 the relation from curvature to moment is
\begin{equation} \label{eq:curv_moment}
M(x,t)=\dfrac{EI}{\mu}
\end{equation}
\begin{figure}
	\centering
	\def\svgwidth{300pt}
	\import{figures/}{BeamFBD.pdf_tex}
	\caption{Free body diagram of a beam section in planar bending.}
	\label{fig:BeamFBD}
\end{figure}
where $ E $, Young's modulus, and $ I $, area moment of inertia are constant in cross sections. By using Newton's laws and the free body diagram of a single beam element, see Figure \ref{fig:BeamFBD}, the equations of motion are summarized as:
\begin{equation} \label{eq:Newton}
\sum{F_y}=\Delta m \ddot{v} \quad \textrm{\&} \quad \sum{M_G}=0
\end{equation}
Moment equation is represented as moments summarized at the center of mass, $ G $. The right hand side of moment equation of EOM \eqref{eq:Newton} is know to be null due to assumption 6. Applying Newton's equations \eqref{eq:Newton} to the FBD of Figure \ref{fig:BeamFBD} results in the force equation
\begin{equation} \label{eq:force_EOM}
F(x,t)-F(x+\Delta x,t)=\rho A\Delta x \frac{\partial^2 v}{\partial t^2}
\end{equation}
and moment equation
\begin{equation} \label{eq:moment_EOM}
-M(x,t) + M(x+\Delta x,t) + F(x,t)\left( \frac{-\Delta x}{2}\right)  + \left[-F(x+\Delta x,t)\right] \left(\frac{\Delta x}{2}\right) = 0
\end{equation}
Taking the limit of equations \eqref{eq:force_EOM} \& \eqref{eq:moment_EOM} as $ \Delta x \rightarrow 0 $ results in equations \eqref{eq:force_EOM_partial} \& \eqref{eq:moment_EOM_partial} respectively.
\begin{equation} \label{eq:force_EOM_partial}
\frac{\partial F}{\partial x}=-\rho A \frac{\partial^2 v}{\partial t^2}
\end{equation}
\begin{equation} \label{eq:moment_EOM_partial}
\frac{\partial M}{\partial x} - F=0
\end{equation}
Assuming the beam slope, $ \frac{\partial v}{\partial x} $, remains relatively small, then linearized curvature of the beam is inversely related to $ \frac{\partial^2 v}{\partial x^2} $. Substituting this linearized curvature in \eqref{eq:curv_moment} produces
\begin{equation} \label{eq:moment_curvature_partial}
M(x,t)=EI\frac{\partial^2 v}{\partial x^2}
\end{equation}
Using linearized moment equation \eqref{eq:moment_curvature_partial}, combined with \eqref{eq:force_EOM_partial} \&  \eqref{eq:moment_EOM_partial} lends the Euler beam equation
\begin{equation} \label{eq:euler_beam_equation}
\frac{\partial^2}{\partial x^2} \left(EI\frac{\partial^2 v}{\partial x^2}\right) = -\rho A\frac{\partial^2 v}{\partial t^2}
\end{equation}
This is the governing differential equation for transverse motion of a slender beam. This equation is not suitable for an application involving lengths that are not much greater than the width of the beam \cite{genta2007dynamics}.


\documentclass{article}

\usepackage{style/conference}
\usepackage{opensans}
\usepackage{graphicx}
\usepackage{biblatex}
\usepackage{fontawesome}
\usepackage[hidelinks]{hyperref}

\addbibresource{references.bib}
\input{style/math_commands.tex}

\title{Winged Horses with a Deep Convolutional Generative Adversarial Network}

\begin{document}
\maketitle
\begin{abstract}
    This paper proposes using a deep convolutional generative adversarial network (DCGAN) to generate images that look like a Pegasus. We give an overview of the underpinning mathematical theory behind GANs, display the architecture that was applied for the task, suited for use with the CIFAR-10 dataset, and describe and explain our pre-processing and implementation steps. The best result obtained is shown, a Pegasus with a dark body colour, alongside the unique batch, and limitations of the approach as well as improvements unaccomplished due to time constraints are discussed.
\end{abstract}

\section{Methodology}
\subsection{Underpinning mathematical theory}
The method is to train a deep convolutional generative adversarial network (DCGAN) \cite{article}, by having two networks, $D$ and $G$, play the following two-player minimax game with value function $V(D, G)$:
\begin{equation}
    \underset{G}{\text{min}} \ \underset{D}{\text{max}} \ V(D,G) = \mathbb{E}_{x\sim p_{data}(x)}\big[logD(x)\big] + \mathbb{E}_{z\sim p_{z}(z)}\big[log(1-D(G(z)))\big].
\end{equation}
The discriminator network, $D$, discriminates between real and fake images. $D$ takes as input an image, $x$, and outputs the scalar probability, $D(x)$, that $x$ came from training data (real) rather than the generator (fake).

The generator network, $G$, generates fake images. $G$ takes as input a latent space vector, $z$, sampled from a standard normal distribution, $p_z$, and outputs the mapped vector, $D(z)$, in data space (e.g. a space of dimension $3 \times 32 \times 32$, which corresponds to the number of channels, height, and width of an image).

GANs proceed by simultaneously training both $G$ and $D$. We train $D$ to maximise $logD(x)$, the probability of $D$ assigning the correct label to both real and fake images. At the same time, we train $G$ to minimise $log(1-D(G(z)))$, the probability of $D$ assigning the correct label to a fake image. Alternatively, we can train $G$ to maximise $logD(G(z))$, the probability of $D$ assigning the incorrect label to a fake image (i.e. making a mistake), which results in the same dynamics of $G$ and $D$. We decide to train $G$ with the latter objective function, since it is supposed to provide much stronger gradients early in learning \cite{NIPS2014_5ca3e9b1}.

There exists a unique solution (global optimum) to the minimax game. This is achieved when $G$'s estimate of the training data distribution, $p_g$, matches exactly the true training data distribution, $p_{data}$. When $p_g = p_{data}$, the fake images $G$ generates (by sampling from $p_g$) are indistinguishable from the real images (sampled from $p_{data}$), so $D(x)$ equals $\frac{1}{2}$ for all $x$, since the discriminator can do no better than guess whether $x$ is real or fake.

\subsection{Architecture}
An architectural diagram of the method is included in Figure \ref{fig:architecture}. More detailed architectural diagrams of the generator and discriminator networks are also included, in Figure \ref{fig:generator} and Figure \ref{fig:discriminator} respectively. Figures \ref{fig:generator} and \ref{fig:discriminator} were made using the online tool `\textit{NN-SVG}' \footnote{https://github.com/alexlenail/NN-SVG}.

\begin{figure}[h]
    \begin{center}
        \includegraphics[width=0.75\textwidth]{figures/architecture.pdf}
    \end{center}
    \caption{Method architectural diagram. Both generator and discriminator networks process data with a batch size of 64. The image data used to train the discriminator is a manually identified subset of the CIFAR-10 dataset. The motivation and method for doing this is explained in Section \ref{implementation}.}
    \label{fig:architecture}
\end{figure}

\begin{figure}[h]
    \begin{center}
        \includegraphics[width=0.75\textwidth]{figures/generator.png}
    \end{center}
    \caption{Generator architectural diagram. Transformations happen from left to right.}
    \label{fig:generator}
\end{figure}

The generator architecture consists of four layers. The first layer takes as input a $100 \times 1 \times 1$ vector of noise (random numbers) sampled from the standard normal distribution, and consists of a convolutional transpose layer, with a $4 \times 4$ kernel, stride 1, and 0 padding, paired with a batch normalisation layer and ReLU activation function. The second and third layers are like the first, except with stride 2 and 1 padding. The fourth and final layer consists of a convolutional transpose layer, with a $4 \times 4$ kernel, stride 2, and 1 padding, with $tanh$ activation function, and outputs a $3 \times 32 \times 32$ image.

\begin{figure}[h]
    \begin{center}
        \includegraphics[width=0.75\textwidth]{figures/discriminator.png}
    \end{center}
    \caption{Discriminator architectural diagram. Transformations happen from right to left.}
    \label{fig:discriminator}
\end{figure}

The discriminator architecture also consists of four layers. The first layer takes as input a $3 \times 32 \times 32$ image, and consists of a convolutional transpose layer, with a $4 \times 4$ kernel, stride 2, and 1 padding, with Leaky ReLU activation function. The second and third layers are like the first, each paired with an additional batch normalisation layer. The fourth and final layer consists of a convolutional transpose layer, with a $4 \times 4$ kernel, stride 1, and 0 padding, with Sigmoid activation function, and outputs a probability.

\subsection{Implementation} \label{implementation}
Our goal was to create unique and diverse images of winged horses that all looked like a Pegasus. We chose to use the CIFAR-10 dataset to train our DCGAN model.

In order to create an image that looked like a Pegasus, we had to combine a horse's body with a bird's wings. The first step would be to identify good examples of images that exhibited these features clearly. Therefore, we manually identified birds and horses using the annotated class labels available for the CIFAR-10 images. However, upon inspecting the subset, it was noted that the required features were not often displayed clearly: not all horse images showed the horse's body --- instead, showing just the head --- and not all bird images showed birds with their wings outstretched --- instead, showing their beak or neck. (See Appendix \ref{appendix:A}.)

To get around this issue, we trained a convolutional neural network classifier by Chris Willcocks\footnote{https://colab.research.google.com/gist/cwkx/3a6eba039aa9f68d0b9d37a02216d385/convnet.ipynb} for 20 epochs, and used it to choose our model training data. By selecting only horse images that the classifier predicted correctly and with over 80\% confidence, it was almost guaranteed that the resulting horse images would be of the horse's entire body. Similarly, by selecting only bird images that the classifier misclassified as airplanes with over 80\% confidence, the resulting bird images would be of birds in mid-flight with outstretched wings. (See Appendix \ref{appendix:B}.)

From this, we made 10 batches of bird images and 10 batches of horse images, with a batch size of 64. Using a weighted random sampler, we trained the DCGAN on this data, and varied the number of epochs the model trained for (from 100 to 1000), as well as the probability of the discriminator training on horse data versus bird data (from odds of 1:1 to 1:20). Our best results were when the odds of the discriminator being given a batch of horses versus a batch of birds to train on was 1:5.

\section{Results}
The generated images are low resolution, but they are not blurry since there are clear-defined edges which outline the objects in them. The objects have realistic shapes because one can easily identify the body of a horse and distinguish between its features, including the torso, head, legs, and, in some cases, tail. The objects in them also have some texture, in particular where the shading highlights the mane and musculature. Although there is some noise, the generated images look real enough to classify as horse-like.

The images are not that different to their nearest neighbours in the dataset, indicating that the network has learned well the data distribution of horse images. Although the objects in the generated images all hold the same side-view pose, there is diversity between the samples within the batch of 64 provided, in the orientation of pose (left-facing and right-facing), colour (various shades of brown, black, and white), as well as stance (standing and moving). Unfortunately, few clearly identifiable winged horses were made --- the closest were horses with humps instead of wings. There is definitely mode collapse, since we observed the generator rotate through outputting horse-like objects against a green, grassy backdrop and outputting bird-like objects against a blue, cloudless backdrop. (See Appendix \ref{appendix:C}.)

The best batch of images looks like this:
\begin{center}
    \includegraphics[width=0.5\textwidth]{figures/best-batch.png}
\end{center}

From this batch, the most Pegasus-like image is:
\begin{center}
    \includegraphics[width=0.075\textwidth]{figures/best-pegasus.png}
\end{center}

\section{Limitations}
It's very difficult to see anything that looks like a Pegasus. This was anticipated since GANs are notoriously difficult to train due to lacking convergence, having diminishing gradients, and being susceptible to mode collapse. We demonstrate this by plotting the running average of generator and discriminator loss over the previous 100 iterations during a training run, shown below:
\begin{center}
    \includegraphics[width=0.6\textwidth]{figures/avgloss.png}
\end{center}

In the future, mode collapse in the GAN could be reduced by lowering the Lipschitz constant for the discriminator function, as was achieve by Wasserstein GANs \cite{arjovsky2017wasserstein} or by spectral normalisation \cite{DBLP:journals/corr/abs-1802-05957}, which normalises the weights for each layer using the spectral norm $\sigma(\mathbf{W}$). Furthermore the diversity and quantity of training data could have been improved by incorporating data from the STL-10 dataset. Training with STL-10 at the full 96x96 pixels would also have improved issues regarding resolution and realism. Regrettably, these steps could not be accomplished due to the time constraints.

\section*{Bonuses}
This submission has a total bonus of -8 marks (a penalty), as it used an adversarial training method, is trained only on CIFAR-10, and the Pegasus has a dark body colour.

\appendix
\section{Images with the `horse' and `bird' labels} \label{appendix:A}
\begin{center}
    \includegraphics[width=0.5\textwidth]{figures/birds.png}
\end{center}
\begin{center}
    \includegraphics[width=0.5\textwidth]{figures/horses.png}
\end{center}

\section{Images filtered by the classifier} \label{appendix:B}
\begin{center}
    \includegraphics[width=1\textwidth]{figures/c-birds.png}
\end{center}
\begin{center}
    \includegraphics[width=1\textwidth]{figures/c-horses.png}
\end{center}

\section{Demonstrating mode collapse} \label{appendix:C}
\begin{center}
    \includegraphics[width=0.5\textwidth]{figures/best-batch-0.png}
\end{center}
\begin{center}
    \includegraphics[width=0.5\textwidth]{figures/best-batch-2.png}
\end{center}

% you can have an unlimited number of references (they can go on the 5th page and span many additional pages without any penalty)
\printbibliography
\end{document}


\documentclass{article}
\usepackage{amssymb}
\begin{document}
\section{Filters}
Source: Daniel Ch. von Grueningen, "Digitale Signalverarbeitung", Carl Hanser Verlag 2014, page 251.\\

Apparently, the filter coefficients can be calculted like so
\begin{eqnarray*}
h_{lowpass}[n]&=& \frac{\Omega_u}{\pi}sinc \left(\frac{n\Omega_u}{pi}\right)\\
h_{highpass}[n]&=&-\frac{\Omega_l}{\pi}sinc \left(\frac{n\Omega_l}{pi}\right) \\
h_{bandpass}[n]&=& \frac{\Omega_u}{\pi}sinc \left(\frac{n\Omega_u}{pi}\right)-\frac{\Omega_l}{\pi}sinc \left(\frac{n\Omega_l}{\pi}\right){pi}\\
h_{bandstop}[n]&=& \frac{\Omega_l}{\pi}sinc \left(\frac{n\Omega_l}{pi}\right)-\frac{\Omega_u}{\pi}sinc \left(\frac{n\Omega_u}{\pi}\right){pi}\\
\end{eqnarray*}
With
\begin{eqnarray*}
h_{lowpass}[0]&=&\frac{\Omega_u}{\pi}\\
h_{highpass}[0]&=&1-\frac{\Omega_u}{\pi}\\
h_{bandpass}[0]&=&\frac{\Omega_u-\Omega_l}{\pi}\\
h_{bandstop}[0]&=&1-\frac{\Omega_u-\Omega_l}{\pi}\\
\end{eqnarray*}
\section{Windows}
\begin{tabular}{l|c}
Hamming&$w_{Hamm}[n]=\left\{\begin{array}{l@{:}l}c\cdot\left( 0.54+0.46\cos\left(\frac{2\pi n}{N+1}\right)\right)&|n|\leqslant N/2\\0&otherwise\\\end{array}\right.$\\\hline  %% }
\end{tabular}
\end{document}


\section{Matrix Element Analysis Technique}

\subsection{Introduction}
\label{me_intro}
The matrix element analysis uses leading order matrix elements to separate single top quark events from W+jets and $\ttbar$ background events. The matrix element analysis calculates a probability for an event to be a signal top event, either s-channel or t-channel, and a probability for one of several W+jets backgrounds. This probability is defined in equation ~\ref{prob}.

\begin{equation}
\label{prob}
P(\vec{x}) = \frac{1}{\sigma} \sum_{i,j} \int f_{i}(x_{1}, Q^{2})dx_{1}
\times
f_{j}(x_{2}, Q^{2})dx_{2} \times \pderiv{\sigma_{hs,ij}(\vec{y})}{\vec{y}} \times W(\vec{x},\vec{y})d\vec{y}
\end{equation}

where $f(x_{i},Q^{2})$ is the parton distribution function for parton i,  $\pderiv{\sigma_{hs,ij}(\vec{y})}{\vec{y}}$ is the differential cross section for the hard scatter interaction, and $W(\vec{x},\vec{y})$ is the probability that final state $\vec{y}$ is reconstructed as $\vec{x}$ in the detector, and finally, $\sigma$ is an overall normalization constant defined as the integral of the differential cross section over the entire detector phase space, $d\vec{x}$ as shown in equation ~\ref{prob2}.
\begin{equation}
\label{prob2}
\sigma = \sum_{i,j} \int f_{i}(x_{1}, Q^{2})dx_{1}
\times
f_{j}(x_{2}, Q^{2})dx_{2} \times \pderiv{\sigma_{hs,ij}(\vec{y})}{\vec{y}} \times W(\vec{x},\vec{y})d\vec{y}d\vec{x}
\end{equation}

This analysis uses CTEQ 6.1 LO parton distribution functions accessed via
LHAPDF C++ wrapper~\footnote{http://hepforge.cedar.ac.uk/lhapdf/}. The matrix elements are calculated using the MadGraph leading order
matrix element generator.

\subsection{Jet-Parton Assignment}
The event probabilities calculated in section ~\ref{me_intro} assume a particle assignment of a jet to a parton in the final state. In practice, this assignment is not known and we must sum over all possible assignments to ensure the correct one is chosen.
For two jet events, the event probability is then re-written as a sum over assignment possibilities as shown in equation ~\ref{assign}

\begin{eqnarray}
\label{assign}
\nonumber
P(\ell, \nu, \vec{\rm{jets}}) = \alpha_{1 \rightarrow 1;2 \rightarrow 2} \times P(\ell, \nu, \rm{j}_{1} \rightarrow p_{1}, j_{2} \rightarrow p_{2}) + \\
\alpha_{1 \rightarrow 2; 2 \rightarrow 1} \times P(\ell, \nu, \rm{j}_{1} \rightarrow p_{2}, j_{2} \rightarrow p_{1})
\end{eqnarray}

where the coefficients, $\alpha$, are free parameters that depend on the jet-parton assignment probability. Determination of these parameters is described in appendix ~\ref{jpassign}. For three jet events, the event probability is defined as

\begin{eqnarray}
\label{assign}
\nonumber
P(\ell, \nu, \vec{\rm{jets}}) =
\alpha_{1 \rightarrow 1;2 \rightarrow 2; 3 \rightarrow 3} \times P(\ell, \nu, \rm{j}_{1} \rightarrow p_{1}, j_{2} \rightarrow p_{2}, j_{3} \rightarrow p_{3}) + \\
\nonumber
\alpha_{1 \rightarrow 1;2 \rightarrow 3; 3 \rightarrow 2} \times P(\ell, \nu, \rm{j}_{1} \rightarrow p_{1}, j_{2} \rightarrow p_{3}, j_{3} \rightarrow p_{2}) + \\
\nonumber
\alpha_{1 \rightarrow 2;2 \rightarrow 1; 3 \rightarrow 3} \times P(\ell, \nu, \rm{j}_{1} \rightarrow p_{2}, j_{2} \rightarrow p_{1}, j_{3} \rightarrow p_{3}) + \\
\nonumber
\alpha_{1 \rightarrow 2;2 \rightarrow 3; 3 \rightarrow 1} \times P(\ell, \nu, \rm{j}_{1} \rightarrow p_{2}, j_{2} \rightarrow p_{3}, j_{3} \rightarrow p_{1}) + \\
\nonumber
\alpha_{1 \rightarrow 3;2 \rightarrow 2; 3 \rightarrow 1} \times P(\ell, \nu, \rm{j}_{1} \rightarrow p_{3}, j_{2} \rightarrow p_{2}, j_{3} \rightarrow p_{1}) + \\
\alpha_{1 \rightarrow 3;2 \rightarrow 1; 3 \rightarrow 2} \times P(\ell, \nu, \rm{j}_{1} \rightarrow p_{3}, j_{2} \rightarrow p_{1}, j_{3} \rightarrow p_{2})
\end{eqnarray}

\subsection{Matrix Element Analysis Output}
The matrix element analysis is named so because the differential cross section for the hard scatter interaction is proportional to the leading order matrix element as shown in equation ~\ref{me}

\begin{equation}
\label{me}
d\sigma_{hs} = \frac{(2\pi)^4}{4} \frac{{|\cal M|}^{2}}{\sqrt{(q_{1}q_{2})^2 - m_{1}^2
m_{2}^2}} d\Phi_{n}(y)
\end{equation}

For this analysis, we consider four probabilities for two jet events and and three probabilities for three jet events. For two jet events events, we calculate the probability for s-channel single top ($u\bar{d}$ $\rightarrow$ $t\bar{b}$), t-channel single top ($ub$ $\rightarrow$ $td$), Wbb production ($u\bar{d}$ $\rightarrow$ $Wb\bar{b}$), and Wcg production ($sg$ $\rightarrow$ $W\bar{c}g$). The leading order diagrams for these channels are shown in figure ~\ref{2jets}.

\vspace{0.1in}
\begin{figure}[!h!tbp]
\begin{center}
\subfigure[]{
	\includegraphics[width=0.22\textwidth]{figures/tb.eps}
}
\subfigure[]{
	\includegraphics[width=0.22\textwidth]{figures/tq.eps}
}
\subfigure[]{
	\includegraphics[width=0.22\textwidth]{figures/wbb.eps}
}
\subfigure[]{
	\includegraphics[width=0.22\textwidth]{figures/wcg.eps}
}
\end{center}
\vspace{-0.1in}
\caption[2jets]{The leading order matrix elements used for event probability calculation for events with two jets. (a) $u\bar{d}$ $\rightarrow$ $t\bar{b}$, (b) $ub$ $\rightarrow$ $td$, (c) $u\bar{d}$ $\rightarrow$ $Wb\bar{b}$, (d) $sg$ $\rightarrow$ $W\bar{c}g$}
\label{2jets}
\end{figure}

For events with three jets, we use three matrix elements, s-channel with gluon radiation ($u\bar{d}$ $\rightarrow$ $t\bar{b}g$), t-channel with associated b quark ($ug$ $\rightarrow$ $t\bar{b}d$), and Wbbg ($u\bar{d}$ $\rightarrow$ $Wb\bar{b}g$). The leading order Feynman diagrams are shown in figure ~\ref{3jets}.

\vspace{0.1in}
\begin{figure}[!h!tbp]
\begin{center}
\subfigure[]{
	\includegraphics[width=0.22\textwidth]{figures/tbg.eps}
}
\subfigure[]{
	\includegraphics[width=0.22\textwidth]{figures/tqb.eps}
}
\subfigure[]{
	\includegraphics[width=0.22\textwidth]{figures/wbbg.eps}
}
\end{center}
\vspace{-0.1in}
\caption[3jets]{The leading order matrix elements used for event probability calculation for events with two jets.  (a) $u\bar{d}$ $\rightarrow$ $t\bar{b}g$, (b) $ug$ $\rightarrow$ $t\bar{b}d$, (c) $u\bar{d}$ $\rightarrow$ $Wb\bar{b}g$}
\label{3jets}
\end{figure}

After calculating event probabilities we combine them into a discriminant output variable, D, defined in equation ~\ref{disc}

\begin{equation}
\label{disc}
D(\vec{x}) = \frac{P_{\rm{signal}}(\vec{x})}{P_{\rm{signal}}(\vec{x}) + P_{\rm{background}}(\vec{x})}
\end{equation}

where $c_{wbb}$ and $c_{wcg}$ are, in principle, the relative background fractions for each background in the data; however, these background fractions are optimizable for the analysis.

For events with two jets the discriminant for either s-channel or t-channel as signal is defined as

\begin{equation}
D(\vec{x})_{\rm{s|t}} = \frac{P_{\rm{s|t}}(\vec{x})}{P_{\rm{st}}(\vec{x}) + c_{wbb}P_{\rm{wbb}}(\vec{x}) + c_{wcg}P_{\rm{wcg}}(\vec{x})}
\end{equation}

and events with three jets the discriminant for s-channel and t-channel is defined as

\begin{equation}
D(\vec{x})_{\rm{s|t}} = \frac{P_{\rm{s|t}}(\vec{x})}{P_{\rm{st}}(\vec{x}) + P_{\rm{wbbg}}(\vec{x})}
\end{equation}


\section{The long exact sequence of homotopy groups}
\sectionmark{The long exact sequence}

\subsection{The long exact sequence}

\begin{defn}
A fiber sequence $F\hookrightarrow E \twoheadrightarrow B$ consists of:
\begin{enumerate}
\item Pointed types $F$, $E$, and $B$, with base points $x_0$, $y_0$, and $b_0$ respectively,
\item Base point preserving maps $i:F\to_\ast E$ and $p:E\to_\ast B$, with $\alpha:i(x_0)=y_0$ and $\beta:p(y_0)=b_0$,
\item A pointed homotopy $H:\mathsf{const}_{b_0}\htpy_\ast p\circ_\ast i$ witnessing that the square
\begin{equation*}
\begin{tikzcd}
F \arrow[r,"i"] \arrow[d] & E \arrow[d,"p"] \\
\unit \arrow[r,swap,"\mathsf{const}_{b_0}"] & B,
\end{tikzcd}
\end{equation*}
commutes and is a pullback square.
\end{enumerate}
\end{defn}

\begin{lem}
Any fiber sequence $F\hookrightarrow E\twoheadrightarrow B$ induces a sequence of pointed maps
\begin{equation*}
\begin{tikzcd}
\loopspace{F} \arrow[r,"\loopspace{i}"] & \loopspace{E} \arrow[r,"\loopspace{p}"] & \loopspace{B} \arrow[r,"\partial"] & F \arrow[r,"i"] & E \arrow[r,"p"] & B,
\end{tikzcd}
\end{equation*}
in which every two consecutive maps form a fiber sequence.
\end{lem}

\begin{proof}
By taking pullback squares repeatedly, we obtain the diagram
\begin{equation*}
\begin{gathered}[b]
\begin{tikzcd}[column sep=large]
\loopspace{F} \arrow[d,swap,"\loopspace{i}"] \arrow[r] & \unit \arrow[d,"\mathsf{const}_{\refl{b_0}}"] \\
\loopspace{E} \arrow[r,"\loopspace{p}"] \arrow[d] & \loopspace{B} \arrow[r] \arrow[d,swap,"\partial"] & \unit \arrow[d,"\mathsf{const}_{y_0}"] \\
\unit \arrow[r,swap,"\mathsf{const}_{x_0}"] & F \arrow[r,"i"] \arrow[d] & E \arrow[d,"p"] \\
& \unit \arrow[r,swap,"\mathsf{const}_{b_0}"] & B.
\end{tikzcd}\\[-\dp\strutbox]
\end{gathered}\qedhere
\end{equation*}
\end{proof}

\begin{defn}
We say that a consecutive pair of pointed maps between pointed sets
\begin{equation*}
\begin{tikzcd}
A \arrow[r,"f"] & B \arrow[r,"g"] & C
\end{tikzcd}
\end{equation*}
is \define{exact} at $B$ if we have
\begin{equation*}
\Big(\exis{a:A}f(a)=b\Big)\leftrightarrow (g(b)=c)
\end{equation*}
for any $b:B$.
\end{defn}

\begin{rmk}
If a pair of consecutive pointed maps between pointed sets
\begin{equation*}
\begin{tikzcd}
A \arrow[r,"f"] & B \arrow[r,"g"] & C
\end{tikzcd}
\end{equation*}
is exact at $B$, it directly that $\im(f)=\fib{g}{c}$. Indeed, such a pair of pointed maps is exact at $B$ if and only if there is an equivalence $e:\im(f)\eqvsym \fib{g}{c}$ such that the triangle
\begin{equation*}
\begin{tikzcd}[column sep=tiny]
\im(f) \arrow[dr] \arrow[rr,"e"] & & \fib{g}{c} \arrow[dl] \\
& B
\end{tikzcd}
\end{equation*}
commutes. In other words, $\im(f)$ and $\fib{g}{c}$ are equal \emph{as subsets of $B$}.
\end{rmk}

\begin{lem}
Suppose $F\hookrightarrow E \twoheadrightarrow B$ is a fiber sequence. Then the sequence
\begin{equation*}
\begin{tikzcd}
\trunc{0}{F} \arrow[r,"\trunc{0}{i}"] & \trunc{0}{E} \arrow[r,"\trunc{0}{p}"] & \trunc{0}{B}
\end{tikzcd}
\end{equation*}
is exact at $\trunc{0}{E}$.
\end{lem}

\begin{proof}
To show that the image $\im\trunc{0}{i}$ is the fiber $\fib{\trunc{0}{p}}{\tproj{0}{b_0}}$, it suffices to construct a fiberwise equivalence
\begin{equation*}
\prd{x:\trunc{0}{E}} \trunc{-1}{\fib{\trunc{0}{i}}{x}} \eqvsym \trunc{0}{p}(x)=\tproj{0}{b_0}.
\end{equation*}
By the universal property of $0$-truncation it suffices to show that
\begin{equation*}
\prd{x:E} \trunc{-1}{\fib{\trunc{0}{i}}{\tproj{0}{x}}} \eqvsym \trunc{0}{p}(\tproj{0}{x})=\tproj{0}{b_0}.
\end{equation*}
First we note that
\begin{align*}
\trunc{0}{p}(\tproj{0}{x})=\tproj{0}{b_0} & \eqvsym \tproj{0}{p(x)} = \tproj{0}{b_0} \\
& \eqvsym \trunc{-1}{p(x)=b_0}.
\end{align*}
Next, we note that
\begin{align*}
\fib{\trunc{0}{i}}{\tproj{0}{x}} & \eqvsym \sm{y:\trunc{0}{F}}\trunc{0}{i}(y)=\tproj{0}{x} \\
& \eqvsym \trunc{0}{\sm{y:F}\trunc{0}{i}(\tproj{0}{y})=\tproj{0}{x}} \\
& \eqvsym \trunc{0}{\sm{y:F}\tproj{0}{i(y)}=\tproj{0}{x}} \\
& \eqvsym \trunc{0}{\sm{y:F}\trunc{-1}{i(y)=x}}.
\end{align*}
Therefore it follows that
\begin{align*}
\trunc{-1}{\fib{\trunc{0}{i}}{\tproj{0}{x}}} & \eqvsym \trunc{-1}{\sm{y:F}\trunc{-1}{i(y)=x}} \\
& \eqvsym \trunc{-1}{\sm{y:F}i(y)=x} \\
\end{align*}
Now it suffices to show that $\eqv{\big(\sm{y:F}i(y)=x\big)}{p(x)=b_0}$. This follows by the pasting lemma of pullbacks
\begin{equation*}
\begin{tikzcd}
(p(x)=b_0) \arrow[r] \arrow[d] & \unit \arrow[d] \\
F \arrow[r] \arrow[d] & E \arrow[d] \\
\unit \arrow[r] & B
\end{tikzcd}
\end{equation*}
\end{proof}

\begin{thm}
Any fiber sequence $F\hookrightarrow E\twoheadrightarrow B$ induces a long exact sequence on homotopy groups
\begin{equation*}
\begin{tikzcd}
& & \cdots \arrow[out=355,in=175,dll] \\
\pi_n(F) \arrow[r,"\pi_n(i)"] & \pi_n(E) \arrow[r,"\pi_n(p)"] & \pi_n(B) \arrow[out=355,in=175,dll,densely dotted] \\
\pi_1(F) \arrow[r,"\pi_1(i)"] & \pi_1(E) \arrow[r,"\pi_1(p)"] & \pi_1(B) \arrow[out=355,in=175,dll] \\
\pi_0(F) \arrow[r,"\pi_0(i)"] & \pi_0(E) \arrow[r,"\pi_0(p)"] & \pi_0(B)
\end{tikzcd}
\end{equation*}
\end{thm}

\subsection{The Hopf fibration}
Our goal in this section is to construct the Hopf fibration, i.e.~a fiber sequence
\begin{equation*}
\sphere{1}\hookrightarrow\sphere{3}\twoheadrightarrow\sphere{2}.
\end{equation*}
This fiber sequence involves the complex multiplication of the unit sphere in the complex number, which is a circle. Viewing the circle as a subspace of the complex numbers, we write $1$ for the base point of the circle.

\begin{defn}
We define the \define{complex multiplication} operation
\begin{equation*}
\mu_{\mathbb{C}}:\sphere{1}\to(\sphere{1}\to\sphere{1}).
\end{equation*}
\end{defn}

\begin{constr}
By the universal property of the circle, it is equivalent to define
\begin{align*}
\mu_{\mathbb{C}}(1) & : \sphere{1}\to\sphere{1} \\
\ap{\mu_{\mathbb{C}}}{\lloop} & : \mu_{\mathbb{C}}(1)=\mu_{\mathbb{C}}(1).
\end{align*}
The function $\mu_{\mathbb{C}}(1)$ is multiplication by $1$, which is the identity function. The type of $\ap{\mu_{\mathbb{C}}}{\lloop}$ is equivalent to the type of homotopies
\begin{equation*}
\idfunc[\sphere{1}] \htpy \idfunc[\sphere{1}].
\end{equation*}
We construct this homotopy by induction on $\sphere{1}$. Therefore it suffices to construct
\begin{align*}
p & : 1=1 \\
q & : \mathsf{tr}_{L}(\lloop,p)=p
\end{align*}
\end{constr}

\begin{lem}
The complex multiplication operation $\mu_{\mathbb{C}}$ on the circle satisfies the unit laws
\begin{align*}
\mathsf{left\usc{}unit}_{\mathbb{C}}(x) & : \mu_{\mathbb{C}}(1,x) = x \\
\mathsf{right\usc{}unit}_{\mathbb{C}}(x) & : \mu_{\mathbb{C}}(x,1) = x \\
\mathsf{coh\usc{}unit}_{\mathbb{C}} & : \mathsf{left\usc{}unit}_{\mathbb{C}}(1)=\mathsf{right\usc{}unit}_{\mathbb{C}}(1),
\end{align*}
and the functions $\mu_{\mathbb{C}}(x,\blank)$ and $\mu_{\mathbb{C}}(\blank,y)$ are equivalences for each $x:\sphere{1}$ and $y:\sphere{1}$, respectively.
\end{lem}

\begin{lem}
Both commuting squares in the diagram
\begin{equation*}
\begin{tikzcd}
\sphere{1} \arrow[d] & \sphere{1}\times\sphere{1} \arrow[d,swap,"\mu_{\mathbb{C}}"] \arrow[l,swap,"\proj 1"] \arrow[r,"\proj 2"] & \sphere{1} \arrow[d] \\
\unit & \sphere{1} \arrow[l] \arrow[r] & \unit
\end{tikzcd}
\end{equation*}
are pullback squares.
\end{lem}

\begin{cor}
There is a fiber sequence
\begin{equation*}
\sphere{1}\hookrightarrow \join{\sphere{1}}{\sphere{1}} \twoheadrightarrow \sphere{2}.
\end{equation*}
\end{cor}

\begin{lem}
The join operation is associative
\end{lem}

\begin{proof}
\begin{equation*}
\begin{tikzcd}
A & A\times C \arrow[l] \arrow[r] & A\times C \\
A\times B \arrow[u] \arrow[d] & A\times B \times C \arrow[r] \arrow[d] \arrow[l] \arrow[u] & A\times C \arrow[u] \arrow[d] \\
B & B\times C \arrow[l] \arrow[r] & C
\end{tikzcd}
\end{equation*}
\end{proof}

\begin{cor}
There is an equivalence $\eqv{\join{\sphere{1}}{\sphere{1}}}{\sphere{3}}$.
\end{cor}

\begin{thm}
There is a fiber sequence $\sphere{1}\hookrightarrow\sphere{3}\twoheadrightarrow\sphere{2}$.
\end{thm}

\begin{lem}
Suppose $f:G\to H$ is a group homomorphism, such that the sequence
\begin{equation*}
\begin{tikzcd}
0 \arrow[r] & G \arrow[r,"f"] & H \arrow[r] & 0
\end{tikzcd}
\end{equation*}
is exact at $G$ and $H$, where we write $0$ for the trivial group consisting of just the unit element. Then $f$ is a group isomorphism.
\end{lem}

\begin{cor}
We have $\pi_2(\sphere{2})=\Z$, and for $k>2$ we have $\pi_k(\sphere{2})=\pi_k(\sphere{3})$.
\end{cor}

\begin{exercises}
\item Give the $0$-sphere $\sphere{0}$ the structure of an H-space.
\item For any pointed type $A$, give $\loopspace{A}$ the structure of an H-space.
\item Show that the type of (small) fiber sequences is equivalent to the type of quadruples $(B,P,b_0,x_0)$, consisting of
\begin{align*}
B & : \UU \\
P & : B \to \UU \\
b_0 & : B \\
x_0 & : P(b_0).
\end{align*}
\end{exercises}


%---------------------------Edge Ratio-----------------------------
\section{Edge Ratio}

The edge ratio of a quadrilateral is the ratio of its longest and shortest edge lengths:
\[
  q = \frac{L_{\max}}{L_{\min}}.
\]

\quadmetrictable{edge ratio}%
{$1$}%                                      Dimension
{$[1,1.3]$}%                                Acceptable range
{$[1,DBL\_MAX]$}%                           Normal range
{$[1,DBL\_MAX]$}%                           Full range
{$1$}%                                      Square
{\cite{pebay:04}}%                          Citation
{v\_quad\_edge\_ratio}%                     Verdict function name