\section{Static Analysis}

\subsection{Control Flow Graph}
\begin{itemize}
    \item Every node is an instruction
    \item If instruction $p$ is followed by $q$, there is an arc $p\rarr q$
\end{itemize}

True and false values in conditionals are not represented.
\begin{itemize}
    \item Assignment and reading is replaced with \emph{define}
    \item Variable in the right part is replaced with \emph{use}
\end{itemize}

Every instruction $p$ has $def(p)$ and $use(p)$ set.

\subsection{Liveness intervals of Variables}
A variable is live at some point if later its current value is used by an instruction.

For the final node (if it has only one exiting arc): $live_{out}(p) = \emptyset$. For the other nodes:
\begin{align*}
    live_{in}(p) &= use(p) \cup (live_{out}(p) \setminus def(p)) \\
    live_{out}(p) &= \bigcup_{q\in succ(p)} live_{in}(q)
\end{align*}

To solve the system of flow equations, start with $live_{out}(p) = \emptyset$, then iteratively find $live_{in}(p)$ and $live_{out}(p)$, until convergence.

\paragraph{Applications}
\begin{itemize}
    \item Memory allocation: if two variables are never simultaneously live, they do not interfere
    \item Useless definitions: instruction that defines a variable that is not live out of the instruction.
\end{itemize}

\subsection{Reaching Definitions}

A definition of $a$ in $q$ reaches the entrance of instruction $p$ if there exists a path from $q$ to $p$ that does not traverse any node where $a$ is defined.

If $p$ defines $a$, any other definition $a_q$ (with $q\ne p$) is suppressed by $p$: $sup(p) = \{a_q | a \in def(p) \land a \in def(q) \land q \ne q\}$

\begin{align*}
    in(1) &= \emptyset \\
    out(p) &= def(p) \cup (in(p) \setminus sup(p)) \\
    in(p) &= \bigcup_{q\in pred(p)} out(q)
\end{align*}

Note that $in(p)$ and $out(p)$ contain $a_q$ or $a_?$ (for usage of variable $a$ at the start of the program).

To solve the system of flow equations, start with $in(p) = \emptyset$, then iteratively find $out(p)$ and $in(p)$, until convergence.

Constant propagation: it's possible to replace variable $a$ in $p$ with $k$ if it exists $q: a = k$ such that $a_q$ reaches $p$ and no other definition $a_r$ ($r\ne q$) reaches the entrance of $p$.

\subsection{Availability}

A variable $a$ is available on the entrance of $p$ if every path from the initial node to $p$ includes a definition of $a$.


\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

%% Sets page size, margins, and layout properties
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}
\setlength{\parskip}{\baselineskip}

%% Useful packages
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{physics}
\usepackage{array}

%% Math Operations
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}

\title{LaTeX Equation Practice}
\author{Raymond Heberer\\
  \texttt{ray.heberer@gmail.com}}

\usepackage{datetime}
\newdate{date}{25}{05}{2018}
\date{\displaydate{date}}

\begin{document}
\maketitle

\section{Introduction}

\paragraph{} Ideas from mathematics underly virtually every technique and concept in Machine Learning (ML). While possessing a rigorous understanding of all these ideas is certainly not required, it can be beneficial. For the beginning practitioner, the scope of the math that forms the foundation of ML is intimidating, and many choose to reassure themselves by observing that modern programming frameworks mean that the ability to implement an algorithm is far removed from the ability to understand its mathematical underpinnings.

This "top-down" approach, emphasizing results over theory, is both effective and marketable. However, there are certain mathematical foundations of ML that are worth becoming familiar with.

In what follows, I state some of the most important equations a beginner should seek to understand when approaching ML. The contents of this document will lay the groundwork for at least one article on Medium.

\section{Functions and Derivatives}

\subsection{Variables and Function Notation}

$$ y = f(x) $$

\subsection{Equation of a Line}

$$ y = mx + b $$

\subsection{The Power Rule}

$$ \dv{}{x}\left(x^n\right)  = nx^{n-1} $$

\subsection{Finite Differences and Difference Quotients}

$$ \frac{\Delta f(x)}{\Delta x} = \frac{f\left(x+\Delta x\right) - f(x)}{\Delta x} $$
$$ \Delta f(x) = f\left(x+\Delta x\right) - f(x) $$
$$ \nabla f(x) = f(x) - f\left(x - \Delta x\right) $$
$$ \delta f(x) = f\left(x+\frac{1}{2}\Delta x\right) - f\left(x - \frac{1}{2}\Delta x\right) $$

\section{Vectors and Matrices}

$$ \vec{a}, \vec{b} \in \mathbb{R}^n $$

\subsection{Vector Arithmetic}

$$ \vec{a} + \vec{b} = (a_1+b_1, a_2+b_2, \ldots, a_n+b_n) $$
$$ \lambda\vec{a} = (\lambda a_1, \lambda a_2,\ldots, \lambda a_n) $$

\subsection{Vector Magnitude}

$$ |\vec{a}| = \sum_{i=1}^{n}\sqrt{a_i^2} = \sqrt{a_1 + a_2 + \ldots + a_n} $$

\subsection{L1 and L2 Norms}

$$ ||\vec{a}||_1 = \sum_{i=1}^{n} |a_i| $$
$$ ||\vec{a}||_1 = \sum_{i=1}^{n} \sqrt{a_i^2} $$

\subsection{Matrix Multiplication}

$$ \mathbf{A} \in \mathbb{R}^{m \times n}, \mathbf{B} \in \mathbb{R}^{n \times p} $$

$$ \mathbf{A} =
\begin{pmatrix}
a_{11} & a_{12} & \ldots & a_{1n} \\
a_{21} & a_{22} & \ldots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \ldots & a_{mn}
\end{pmatrix}
$$

$$ \mathbf{AB} \in \mathbb{R}^{m \times p} $$

$$ \mathbf{C} = \mathbf{AB} =
\begin{pmatrix}
c_{11} & c_{12} & \ldots & c_{1p} \\
c_{21} & c_{22} & \ldots & c_{2p} \\
\vdots & \vdots & \ddots & \vdots \\
c_{m1} & c_{m2} & \ldots & c_{mp}
\end{pmatrix}
$$

$$ c_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + \ldots + a_{im}b_{mj} = \sum_{k=1}^{m}a_{ik}b_{kj} $$

\subsection{Matrix Inversion}

$$ \mathbf{A} \in \mathbb{R}^{n \times n} $$

$$ \mathbf{A}^{-1}\mathbf{A} = \mathbf{AA}^{-1} = \mathbf{I}_n $$

$$ \mathbf{A}^{-1} \in \mathbb{R}^{n \times n} $$

$$ \mathbf{I} =
\begin{pmatrix}
1 & 0 & \ldots & 0 \\
0 & 1 & \ldots & 0 \\
\vdots & \vdots & \ddots & \vdots \\
0 & 0 & \ldots & 1
\end{pmatrix}
$$

\section{Statistical Relationships and Procedures}

\subsection{Correlation}

$$ \rho_{\mathbf{X}, \mathbf{Y}} = \frac{\mathbf{cov}(\mathbf{X}, \mathbf{Y})}{\sigma_{\mathbf{X}}\sigma_{\mathbf{Y}}} $$

$$ = \frac{E[(\mathbf{X}-\mu_{\mathbf{X}})(\mathbf{Y}-\mu_{\mathbf{Y}})]}{\sigma_{\mathbf{X}}\sigma_{\mathbf{Y}}} $$

$$ r_{xy} = \frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})}
{\sqrt{
\sum_{i=1}^{n}(x_i-\bar{x})^2
\sum_{i=1}^{n}(y_i-\bar{y})^2
}} $$

$$ \bar{x} = \frac{1}{n}\sum_{i=1}^{n}x_i $$

\subsection{Principal Components Analysis}

$$ \mathbf{w_{(1)}} = \argmax_{||\mathbf{w}||=1}\left\{ ||\mathbf{Xw}||^2 \right\} = \argmax_{||\mathbf{w}||=1}\left\{ ||\mathbf{w}^T\mathbf{X}^T\mathbf{Xw}||^2 \right\}$$

$$ \mathbf{w_{(1)}}=\argmax\left\{\frac{||\mathbf{w}^T\mathbf{X}^T\mathbf{Xw}||^2}{\mathbf{w}^T\mathbf{w}}\right\}$$

$$ \mathbf{W}_k = \argmax_{||\mathbf{w}||=1}\left\{ ||\mathbf{\hat{X}}_k\mathbf{w}||^2 \right\} $$

$$ \mathbf{\hat{X}}_k = \mathbf{X}-\sum_{s=1}^{k-1}\mathbf{Xw}_{(s)}\mathbf{w}_{(s)}^T $$

\subsubsection{Singular-Value Decomposition (SVD)}

$$ \mathbf{M} \in \mathbb{R}^{m \times n}$$

$$ \mathbf{M} = \mathbf{U\Sigma V}^* $$

\begin{itemize}
  \item The nonzero singular values are the square roots of the nonzero eigenvalues of $\mathbf{M}^*\mathbf{M}$ or $\mathbf{MM}^*$
  \item $\mathbf{\Sigma}$ is a diagonal $(m \times n)$ matrix of non-negative real numbers, known as the \textbf{singular values} of $\mathbf{M}$
  \item The columns of $\mathbf{V}$ (right singular vectors) are eigenvectors of $\mathbf{M}^*\mathbf{M}$
  \item The columns of $\mathbf{U}$ (left singular vectors) are eigenvectors of $\mathbf{MM}^*$
\end{itemize}

\end{document}


\documentclass{article}

\usepackage{amsmath}
\usepackage{numprint}

\author{Daniel Fernandes Martins (danielfmt)}
\title{Question \#7 Solution}

\begin{document}

\maketitle

\section{Cross-Validation}

This question gives us 3 data points: $(-1,0)$, $(\rho,1)$, $(1,0)$, and a choice
of two models: constant $[h_0(x)=b]$ and linear $[h_1(x)=ax+b]$, and asks at
which $\rho \geq 0$ the two models give the same cross-validation error assuming
we use leave-one-out cross-validation and the squared error measure.

The cross-validation error for a model $m$ on these 3 points is

\begin{equation*}
E_{cv}^{(m)}=\frac{1}{3}(e_1^{(m)} + e_2^{(m)} + e_3^{(m)}),
\end{equation*}

where $e_n^{(m)}$ is the squared error measure for point $n$ and model $m$:

\begin{equation*}
e_n^{(m)}=(h_m(x_n)-y_n)^2
\end{equation*}

Now we need to compute the cross-validation error for all three permutations on
both models.

\subsection{The Constant Model}

In the constant model $h_0$, the best fit is found by averaging the values of
$y$ coordinate of all points.

Taking the points $(-1,0)$ and $(1,0)$ for training, and $(\rho,1)$ for validation,
the validation error is

\begin{equation*}
e_1^{(0)} = \left(\frac{0+0}{2} - 1\right)^2 = 1.
\end{equation*}

We get the same value for the last two permutations:

\begin{equation*}
e_2^{(0)} = e_3^{(0)} = \left(\frac{0+1}{2} - 0\right)^2 = \frac{1}{4}
\end{equation*}

Thus the cross-validation error $E_{cv}^{(0)}$ for the constant model $h_0$ is

\begin{equation*}
E_{cv}^{(0)} = \frac{1}{3} \left( 1 + \frac{1}{4} + \frac{1}{4} \right).
\end{equation*}

\subsection{The Linear Model}

We know that, given two points, the best fit for the linear model $h_1$ is a
line that passes through both of them.

The first permutation (training: $(-1,0)$ $(1,0)$, validation: $(\rho,1)$), is
easy to compute because this line has slope $m=0$:

\begin{equation*}
e_1^{(1)} = (1 - 0)^2 = 1
\end{equation*}

For the remaining two permutations, we need to find the equation for the line
order to compute the squared error for the validation point.

The slope of the line passing through the points $(-1,0)$ and $(\rho,1)$ is
given by

\begin{equation*}
m = \frac{1-0}{\rho-(-1)} = \frac{1}{\rho+1},
\end{equation*}

and in order to find the equation for that line, just pick any point $(x_1,y_1)$
and plug it on the formula $y-y_1 = m(x-x_1)$. For instance, if we pick
$(x_1,y_1)=(-1,0)$, we get

\begin{equation*}
y = \frac{x+1}{\rho+1}.
\end{equation*}

Finally, to compute the squared error for this permutation, plug the $x$
coordinate of the validation point $(1,0)$ in the line equation, subtract the
result by $y$ and square it, resulting in

\begin{equation*}
e_2^{(1)} = \left( \frac{2}{\rho+1} \right)^2.
\end{equation*}

If you do same thing in order to compute the validation error for the last
permutation, you will get

\begin{equation*}
e_3^{(1)} = \left( \frac{-2}{\rho-1} \right)^2.
\end{equation*}

So the cross-validation error $E_{cv}^{(1)}$ for the linear model $h_1$ is given
by

\begin{equation*}
E_{cv}^{(1)} = \frac{1}{3} \left( 1 + \left(\frac{2}{\rho+1}\right)^2 +
 \left(\frac{-2}{\rho-1}\right)^2 \right).
\end{equation*}

\subsection{Solving For $\rho$}

Now that we found $E_{cv}^{(m)}$ for both models, we can form a single equation

\begin{equation*}
\frac{1}{3} \left( 1 + \left(\frac{2}{\rho+1}\right)^2 + \left(\frac{-2}{\rho-1}\right)^2 \right) =
\frac{1}{3} \left( 1 + \frac{1}{4} + \frac{1}{4} \right),
\end{equation*}

and solve it for $\rho \geq 0$ in order to get the correct answer
$\rho=\sqrt{9+4\sqrt{6}}$.

\end{document}


\documentclass{article}
\usepackage{amsmath}
\usepackage[margin=1.0in]{geometry}
\usepackage{xcolor}

\begin{document}

\noindent
Does $\displaystyle \sum_{n=1}^\infty \frac{\cos \frac\pi3 n}{n^2}$
diverge, converge absolutely, or converge conditionally?

\subsection*{Note}

The series $\displaystyle \sum_{n=1}^\infty \frac{\cos \frac\pi3 n}{n^2}$ is NOT an alternating series.

\subsection*{Solution}

We consider
\[
\sum_{n=1}^\infty \left|\frac{\cos \frac\pi3 n}{n^2}\right|
= \sum_{n=1}^\infty \frac{|\cos \frac\pi3 n|}{n^2}
\]
Note that
\[ 0 \leq  |\cos \frac\pi3 n| \leq 1\]
so by dividing all three sides by $n^2$, we have
\[ 0 \leq  \frac{|\cos \frac\pi3 n|}{n^2} \leq \frac1{n^2}.\]
The series $\displaystyle \sum \frac1{n^2}$ converges by the $p$-test. Since, terms of the series $\displaystyle \sum_{n=1}^\infty \frac{|\cos \frac\pi3 n|}{n^2}$ are positive, by the Direct Comparison test, the series $\displaystyle \sum_{n=1}^\infty \frac{|\cos \frac\pi3 n|}{n^2}$ converges.

Therefore the series $\displaystyle \sum_{n=1}^\infty \frac{\cos \frac\pi3 n}{n^2}$ converges by the Absolute Convergence Test. In fact, the series $\displaystyle \sum_{n=1}^\infty \frac{\cos \frac\pi3 n}{n^2}$ is absolutely convergent.

\end{document}%%%%%%%%%%%%%%%%%

\begin{align*}
L&=\lim_{n \to \infty} \sqrt[n]{|a_n|}\\
&= \lim_{n \to \infty} \sqrt[n]{\left| \right|}\\
\end{align*}

Since $\sum |a_n| = \sum a_n$, the series $\displaystyle \sum_{n=1}^\infty AAAAAAAAAAAAAA$ converges absolutely.

Since $|r| < 1$, the series ...  converges by the Geometric Series Test.

Since $|r| \geq 1$, the series ...  diverges by the Geometric Series Test.

The function $f(x)=\frac{}{}$ is continuous, positive, and decreasing on $[1,\infty)$.

\subsection*{Solution}


\subsection{Hypergraphs}\label{subsec:hypergraphs}

\begin{definition}\label{def:hypergraph}
  Fix a \hyperref[def:set]{set} \( V \), whose members we will call \term{vertices} or \term{nodes}, and a disjoint from \( V \) set \( E \), whose members we will call \term{hyperedges}.

  A \term{hypergraph} is a tuple \( H = (V, E, \mscrE) \), where \( \mscrE: E \multto V \) is a \hyperref[def:multi_valued_function/total]{total multi-valued function} whose role is to give us a nonempty set of endpoints \( \mscrE(e) \) for each edge \( e \in E \).

  \begin{figure}[h]
    \begin{equation}\label{eq:fig:def:hypergraph}
      \begin{aligned}
        \includegraphics[page=1]{output/def__hypergraph.pdf}
      \end{aligned}
    \end{equation}
    \caption{A hypergraph containing four hyperedges of rank two and one of rank four.}\label{fig:def:hypergraph}
  \end{figure}

  \begin{thmenum}
    \thmitem{def:hypergraph/cardinality} The \term{cardinality} of a hyperedge \( e \) is the \hyperref[thm:cardinality_existence]{cardinality}
    \begin{equation*}
      \card(e) \coloneqq \card(\mscrE(e))
    \end{equation*}
    of the set of all vertices of \( e \).

    Hyperedges of rank \( 1 \) are called \term{loops} and hyperedges of rank \( 2 \) are called \term{edges}. Loops are often considered to be edges, especially in \hyperref[def:undirected_multigraph]{multigraphs}.

    \thmitem{def:hypergraph/parallel_hyperedges} We say that the hyperedges \( e \) and \( d \) are parallel if they have the same endpoints.

    \thmitem{def:hypergraph/incidence} We say that the vertex \( v \) and the hyperedge \( e \) are \term{incident} if \( v \) is an endpoint \( e \).

    \thmitem{def:hypergraph/adjacency} We say that \( v \) and \( w \) are \term{adjacent vertices} if there exists an hyperedge \( e \) such that both \( v \) and \( w \) are endpoints of \( e \).

    Similarly, we say that \( e \) and \( d \) are \term{adjacent hyperedges} if they have a common endpoint.

    \thmitem{def:hypergraph/order} The \term{order} \( \ord(H) \) of the hypergraph \( H \) is the \hyperref[thm:cardinality_existence]{cardinality} of \( V \).

    We say that the hypergraph is finite if both \( V \) and \( E \) are finite and infinite otherwise. If no parallel hyperedges are allowed, the hypergraph is finite if \( \ord(H) \) is finite.

    \thmitem{def:hypergraph/degree} The \term{degree} \( \deg(v) \) of a vertex \( v \in V \) is the cardinality of set
    \begin{equation*}
      \set{ e \in E \given v \T{is an endpoint of} e }.
    \end{equation*}

    If \( \deg(v) = 0 \), we say that \( v \) is an \term{isolated vertex}, especially in connection with \fullref{def:quiver_geometric_realization/undirected}.

    The degree \( \deg(H) \) of the hypergraph itself is the maximum of the degrees of all vertices. It is possible that the maximum in \( \deg(H) \) is not attained if \( H \) is infinite.

    We say that the graph is \term{locally finite} if the degree of every vertex is finite.

    This is not to be confused with \hyperref[def:category_size]{locally finite categories}.

    \thmitem{def:hypergraph/submodel} The hypergraph \( H' = (V', E', \mscrE') \) is a is a sub-hypergraph of \( H = (V, E, \mscrE) \) if \( V' \subseteq V \), \( E' \subseteq E \) and \( \mscrE' \) is a \hyperref[def:multi_valued_function/restriction]{restriction} of \( \mscrE \) to \( E' \).

    We say that sub-hypergraph \( H' \) is \term{full} if
    \begin{equation}\label{eq:def:hypergraph/submodel/full}
      E' = \set{ e \in E \given \mscrE(e) \subseteq V' }.
    \end{equation}

    In this case, we also say that \( V' \) \term{induces} the sub-hypergraph \( H' \).

    \thmitem{def:hypergraph/trivial} Unlike the \hyperref[def:group/trivial]{trivial group} \( \set{ e } \) or \hyperref[def:partially_ordered_set/trivial]{empty ordered set}, which are unique up to an isomorphism, there is no single agreed upon graph called the \enquote{trivial hypergraph}.

    An unambiguous concept is that of an \term{edgeless hypergraph}, in which the set of hyperedges is empty, but the set of vertices may or may not be empty. Every hypergraph \( H: E \to V \) has \( 2^{\ord(V)} \) edgeless sub-hypergraphs (one for each subset of \( V \)).

    The \term{order-zero hypergraph} \( H: \varnothing \multto \varnothing \) is the unique hypergraph that is a sub-hypergraph of all others.

    The terms \term{empty hypergraph}, \term{null hypergraph} and \term{trivial hypergraph} may refer to either edgeless graphs or the order-zero graph, depending on the author and the situation.
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:family_of_sets_induces_hypergraph}
  Every \hyperref[rem:family_of_sets]{family} of nonempty sets \( \mscrA \) induces a \hyperref[def:hypergraph]{hypergraph} as follows:
  \begin{itemize}
    \item The set of vertices is \( \bigcup \mscrA \).
    \item The set of hyperedges is \( \mscrA \) itself.
  \end{itemize}
\end{proposition}
\begin{proof}
  The hypergraph is given by the function
  \begin{equation*}
    \begin{aligned}
      &H: \mscrA \multto \bigcup \mscrA \\
      &\mscrE(A) \coloneqq A,
    \end{aligned}
  \end{equation*}
  which is better represented as the binary relation
  \begin{equation*}
    \set{ (A, x) \given A \in \mscrA \T{and} x \in A }.
  \end{equation*}
\end{proof}

\begin{example}\label{ex:hypergraphs_not_induced_by_family}
  The hypergraph \eqref{eq:fig:def:hypergraph} is a counterexample to the converse of \fullref{thm:family_of_sets_induces_hypergraph}. It cannot be represented as a family of sets because the edges \( e_2 \) and \( \widehat{e_2} \) are \hyperref[def:hypergraph/parallel_hyperedges]{parallel} and would be represented by the same set.

  Another counterexample is a hypergraph with a nonempty vertex set and no hyperedges. The union of the endpoints of all hyperedges is empty and is thus only a strict subset of the vertices.
\end{example}

\begin{definition}\label{def:category_of_small_hypergraphs}
  Suppose that we are given a \hyperref[def:grothendieck_universe]{Grothendieck universe} \( \mscrU \), which is safe to assume to be the smallest suitable one as explained in \fullref{def:large_and_small_sets}.

  We denote the \hyperref[def:category]{category} of \( \mscrU \)-small \hyperref[def:hypergraph]{hypergraphs} by \( \ucat{HypGph} \) or, if the universe is clear from the context, simply by \( \cat{HypGph} \). See \fullref{def:category_size} for a further discussion of universes and categories.

  \begin{itemize}
    \item The \hyperref[def:category/objects]{set of objects} \( \obj(\cat{HypGph}) \) is the set of all \( \mscrU \)-small hypergraphs, i.e. the hypergraphs \( H = (V, E, \mscrE) \) such that \( V \) and \( E \) are both members of \( \mscrU \).

    \item The \hyperref[def:category/morphisms]{set of morphisms} \( \cat{HypGph}(H, G) \) from \( H \) to \( G \) is the set hypergraph homomorphisms. Given two hypergraphs \( H: E_H \multto V_H \) and \( G: E_G \multto V_G \), a \term{hypergraph homomorphism} is a pair of functions
    \begin{equation}\label{eq:def:category_of_small_hypergraphs/homomorphism}
      \begin{cases}
        f_V: V_H \to V_G \\
        f_E: E_H \to E_G
      \end{cases}
    \end{equation}
    such that, for every hyperedge \( e \in E_H \), if \( v \in V_H \) is an endpoint of \( e \), then \( f_V(v) \) is an endpoint of \( f_E(e) \).

    Note that \enquote{graph embedding} commonly refers to an embedding of its \hyperref[def:quiver_geometric_realization/undirected]{geometric realization}, hence we will avoid the term when referring to injective hypergraph homomorphisms. Furthermore, it should be clarified whether we mean \enquote{injective on vertices} or \enquote{injective on edges}, which is an important distinction in category theory --- see \fullref{def:functor_invertibility}.

    \item The \hyperref[def:category/composition]{composition of the morphisms}
    \begin{align*}
      &(f_V, f_E) \in \cat{HypGph}(A, B),
      &(g_V, g_E) \in \cat{HypGph}(B, C)
    \end{align*}
    is the morphism
    \begin{equation*}
      (g_V \bincirc f_V, g_E \bincirc f_E) \in \cat{HypGph}(A, C).
    \end{equation*}

    \item The \hyperref[def:category/identity]{identity morphism} on the hypergraph \( H = (V, E, \mscrE) \) is the pair of \hyperref[def:multi_valued_function/identity]{identity functions} \( (\id_V, \id_H) \).
  \end{itemize}
\end{definition}

\begin{definition}\label{def:hypergraph_incidence_matrix}
  Let \( H = (V, E, \mscrE) \) be a finite hypergraph. Its \term{incidence matrix}
  \begin{equation*}
    M = \seq{ M_{ve} }_{v \in V, e \in E}
  \end{equation*}
  has elements
  \begin{equation*}
    M_{ve} \coloneqq \begin{cases}
      1,  &v \T{is \hyperref[def:hypergraph/incidence]{incident} to} e \\
      0,  &\T{otherwise.}
    \end{cases}
  \end{equation*}

  Compare this definition to \fullref{def:quiver_incidence_matrix}.
\end{definition}

\begin{example}\label{ex:def:hypergraph_incidence_matrix}
  The \hyperref[def:hypergraph_incidence_matrix]{incidence matrix} of the hypergraph \eqref{eq:fig:def:hypergraph} is
  \begin{equation}\label{eq:ex:def:hypergraph_incidence_matrix}
    \begin{blockarray}{cccccc}
        & e_1 & e_2 & \widehat{e_2} & e_3 & e_4 \\
      \begin{block}{c(ccccc)}
      a & 1   & 1   & 1             &     &     \\
      b & 1   &     &               & 1   &     \\
      c &     & 1   & 1             &     & 1   \\
      d &     &     &               & 1   & 1   \\
      e &     &     &               &     & 1   \\
      f &     &     &               &     & 1   \\
      \end{block}
    \end{blockarray}
  \end{equation}

  Every column corresponds to a hyperedge and its nonzero elements are the endpoints of the hyperedge.
\end{example}

\begin{definition}\label{def:hypergraph_vector_spaces}
  Let \( H = (V, E, \mscrE) \) be a \hyperref[def:hypergraph]{hypergraph}. We introduce several \hyperref[def:vector_space]{vector spaces} that allow us to study hypergraphs using linear algebra.

  \begin{thmenum}
    \thmitem{def:hypergraph_vector_spaces/vertex} The \term{vertex space} \( \BbbF_2^V \) is the \hyperref[thm:functions_over_ring_form_algebra]{function space} \( \BbbF_2^V \), where \( \BbbF_2 \) is the \hyperref[thm:f2_is_boolean_algebra]{two-element field}.

    Every subset \( U \subseteq V \) of vertices induces a unique vector \( \vect{U} = \seq{ \vect{U}_u }_{u \in U} \) in the \hyperref[def:hypergraph_vector_spaces/vertex]{vertex space} \( \BbbF_2^V \) such that
    \begin{equation*}
      \vect{U}_u \coloneqq \begin{cases}
        1, &u \in A \\
        0, &u \not\in A
      \end{cases}
    \end{equation*}

    This vector is called the \term{characteristic vector} of \( U \). Conversely, every vector in \( \BbbF_2^V \) induces a set of vertices. If \( U \) consists of a single vertex \( u \), we write \( \vect{u} \) rather than \( \vect{\set{u}} \).

    Without a choice of ordering of \( V \), there is no canonical basis in \( \BbbF_2^V \). Thus, even for finite graphs, we cannot in general regard the vectors of \( \BbbF_2^V \) as ordered tuple.

    \thmitem{def:hypergraph_vector_spaces/edge} Analogously, the \term{hyperedge space} \( \BbbF_2^E \) is the \hyperref[thm:functions_over_ring_form_algebra]{function space} \( \BbbF_2^E \). Every subset of \( E \) induces a unique characteristic vector in \( \BbbF_2^E \) and vice versa.

    The space is motivated by \hyperref[def:undirected_multigraph_path]{undirected paths} and their \hyperref[def:undirected_multigraph_path/characteristic_vector]{characteristic vectors}.
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:graphs_as_linear_transformations}
  Let \( V = \set{ 1, \ldots, m } \) and \( E = \set{ 1, \ldots, n } \). Then there is a bijection between the \( m \times n \) \hyperref[def:array/matrix]{matrices} over \( \BbbF_2 \) and the \hyperref[def:hypergraph]{hypergraphs} \( H = (V, E, \mscrE) \).
\end{proposition}
\begin{proof}
  The \hyperref[def:hypergraph_incidence_matrix]{incidence matrix} of every hypergraph is a matrix in \( \BbbF_2^{m \times n} \).

  Conversely, let \( M = \seq{ M_{ve} } \in \BbbF_2^{m \times n} \) and define the hypergraph \( H \coloneqq (V, E, \mscrE) \), where
  \begin{equation*}
    \begin{aligned}
      &\mscrE: E \multto V \\
      &\mscrE(e) \coloneqq \set{ v \in 1, \ldots, n \given M_{ve} = 1 }.
    \end{aligned}
  \end{equation*}

  Then the adjacency matrix of \( H \) is \( M \).
\end{proof}

\begin{definition}\label{def:hypergraph_transversal}\mcite[32]{GondranMinoux1984Graphs}
  Let \( H = (V, E, \mscrE) \) be a \hyperref[def:hypergraph]{hypergraph}. We say that a set \( T \subseteq V \) of vertices is a \term{transversal} of \( H \) if it is incident to every edge of \( H \).
\end{definition}

\begin{example}\label{ex:hypergraph_vertex_set_is_transversal}
  Every hypergraph has at least one transversal since the vertex set it itself a transversal.
\end{example}

\begin{definition}\label{def:hypergraph_minimal_transversal}
  A transversal \( T \) of the hypergraph \( H = (V, E, \mscrE) \) is said to be \term{minimal} if any of the following equivalent conditions hold:
  \begin{thmenum}
    \thmitem{def:hypergraph_minimal_transversal/order} \( T \) is a minimal \hyperref[def:partially_ordered_set_extremal_points/maximal_and_minimal_element]{element} under \hyperref[def:subset]{set inclusion} in the set of all transversals of \( H \).

    \thmitem{def:hypergraph_minimal_transversal/singleton} For every vertex \( v \) in \( T \) there exists a hyperedge \( e_v \in E \) such that
    \begin{equation*}
      T \cap \mscrE(e_v) = \set{ v }.
    \end{equation*}
  \end{thmenum}
\end{definition}
\begin{proof}
  \ImplicationSubProof{def:hypergraph_minimal_transversal/order}{def:hypergraph_minimal_transversal/singleton} Let \( T \) be minimal under inclusion among all transversals.

  Fix a vertex \( v \in T \). Since \( T \) is minimal, the set \( T \setminus \set{ v } \) is not a transversal. So there exists a hyperedge \( e_v \in E \) such that \( (T \setminus \set{ v }) \cap \mscrE(e_v) = \varnothing \).

  Now since \( T \) is a transversal for \( H \), the set \( T \cap \mscrE(e_v) \) is nonempty and thus
  \begin{align*}
    T \cap \mscrE(e_x)
    &=
    \parens[\Big]{ (T \setminus \set{ v }) \cup \set{ v } } \cap \mscrE(e_v)
    \reloset {\eqref{eq:def:semilattice/distributive_lattice/finite/meet_over_join}} = \\ &=
    \underbrace{\parens[\Big]{ (T \setminus \set{ v }) \cap \mscrE(e_v) }}_{\varnothing} \cup \parens[\Big]{ \set{ v } \cap \mscrE(e_v) }
    = \\ &=
    \set{ v }.
  \end{align*}

  \ImplicationSubProof{def:hypergraph_minimal_transversal/singleton}{def:hypergraph_minimal_transversal/order} Now suppose that for every vertex \( v \in T \) there exists a hyperedge \( e_v \in E \) such that \( T \cap \mscrE(e_v) = \set{ v } \).

  Suppose that \( T \) is not minimal. Then there exists some vertex \( w \in T \) be such that \( T \setminus \set{ w } \) is a transversal. But our assertion gives us an edge \( e_u \in E \) such that \( T \cap \mscrE(e_u) = \set{ w } \). Clearly the set \( T \setminus \set{ w } \) cannot be a transversal of \( H \) since
  \begin{equation*}
    (T \setminus \set{ w }) \cap \mscrE(e_u) = \varnothing.
  \end{equation*}

  This contradiction proves that \( T \) is minimal under set inclusion.
\end{proof}

\begin{example}\label{ex:hypergraph_with_no_minimal_transversal}
  We will give an example of a hypergraph without a minimal transversal.

  For every nonnegative integer \( n \) define the set
  \begin{equation*}
    e_n \coloneqq \set{ n, n + 1, n + 2, \ldots }.
  \end{equation*}

  Let \( H \) be the hypergraph whose hyperedges are \( e_1, e_2, \cdots \). The set of vertices is \( e_1 \), hence \( e_1 \) is also a transversal.

  Now assume that \( T \) is a minimal transversal for \( H \). Since, by \fullref{thm:natural_numbers_are_well_ordered}, the natural numbers are well-ordered, \( T \) has a minimum. Let \( n_0 \coloneqq \min T \).

  But \( T \setminus \set{ n_0 } \) is also a transversal because each hyperedge \( e_n \) intersects \( T \) at infinitely many points besides \( n_0 \).

  The obtained contradiction shows that \( H \) has no minimal transversal.
\end{example}

\begin{theorem}[Hypergraph minimal transversal existence]\label{thm:hypergraphs_have_minimal_transversal}
  Every \hyperref[def:hypergraph]{hypergraph} has a \hyperref[def:hypergraph_minimal_transversal]{minimal transversal}.

  In \hyperref[def:zfc]{\logic{ZF}} this theorem is equivalent to the \hyperref[def:zfc/choice]{axiom of choice} --- see \fullref{thm:axiom_of_choice_equivalences/hypergraph}.
\end{theorem}
\begin{proof}
  The proof is merely a translation of the axiom of choice into the language of hypergraphs.

  \ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:hypergraphs_have_minimal_transversal]{minimal transversal existence} Let \( H = (V, E, \mscrE) \) be a hypergraph. Then
  \begin{equation*}
    \set{ \mscrE(e) \given e \in E }
  \end{equation*}
  is a family of nonempty sets and thus there exists a set \( B \subseteq V \) such that \( B \cap \mscrE(e) \) for every hyperedge \( e \in E \). This is a minimal transversal by \fullref{def:hypergraph_minimal_transversal/singleton}.

  \ImplicationSubProof[thm:hypergraphs_have_minimal_transversal]{minimal transversal existence}[def:zfc/choice]{axiom of choice} Let \( \mscrA \) be an arbitrary family of nonempty sets. Let \( H \) be the hypergraph \hyperref[thm:family_of_sets_induces_hypergraph]{induced by} \( \mscrA \). Let \( T \) be a minimal transversal of \( H \). Then, by definition, for every hyperedge \( e \in \mscrA \), the intersection \( T \cap \mscrE(e) \) is a singleton set. Hence, \( T \) is the image of a \hyperref[def:choice_function]{choice function} for \( \mscrA \).
\end{proof}


%================================
\section{Continuity}
%================================

% https://en.wikipedia.org/wiki/Base_(topology)#Theorems

%--------------------------------
\begin{definition}
	[continuous maps]
	\label{def: continuous maps}
	Let $(X, \mathcal T_X)$ and $(Y, \mathcal T_Y)$ be topological spaces. A map $f: X \to Y$ is said to be \textit{continuous} iff for any open set $U$ in $Y$, its preimage in $X$ under $f$ is open.
\end{definition}
%--------------------------------

%--------------------------------
\begin{note}
	In Definition \ref{def: continuous maps}, note that even if for any open set $U$ in $X$, $f[X]$ is open in $Y$, $f$ is not necessarily continuous. For example, let $X = (\mathbb R, \mathcal T_X)$ with $\mathcal T_X$ induced by standard Euclidean metric, let $Y=(\mathbb R, \mathcal T_Y)$ with $\mathcal T_Y$ as a indiscrete topology, and define
	$$
	f(x) = [x],
	$$
	where $[x]$ denotes the integer part of $x$. Then for all $U \subseteq X$, $f[U]$ is open in $Y$, but by Definition \ref{def: continuous maps}, $f$ is not continuous.
\end{note}
%--------------------------------

%--------------------------------
\begin{note}
	Let $(X, \mathcal T_X)$ and $(Y, \mathcal T_Y)$ be topological spaces, if $\mathcal T_X$ is the discrete topology on $X$, then any function with domain $X$ is continuous. If $\mathcal T_Y$ is the indiscrete topology on $Y$, then any function with codomain $Y$ is continuous.
\end{note}
%--------------------------------

%--------------------------------
\begin{note}
	A function is continuous bijection does not implies that its inverse is continuous. For example, let $X$ be any set and let $\mathcal T$ and $\mathcal T'$ be its topologies. If $\mathcal T$ is finer than $\mathcal T'$, then any bijection $f: (X, \mathcal T) \to (X, \mathcal T')$ is continuous. In this case, however, if $\mathcal T \ne \mathcal T'$, then $f^{-1}$ is not continuous.
\end{note}
%--------------------------------

%--------------------------------
\begin{theorem}
	\label{prop: alt-def of continuous maps by neighbourhoods}
	Let $(X, \mathcal T_X)$ and $(Y, \mathcal T_Y)$ be topological spaces. A map $f: X \to Y$ is continuous at $x \in X$ iff for any neighbourhood $N_y$ of $f(x)$, there is a neighbourhood $N_x$ of $x$, such that $f[N_x] \subseteq N_y$.

	\begin{proof}
		Let $N_y$ be a neighbourhood of $f(x)$. Clearly, there exists an open set $U_y$ contains $y$.

		By Definition \ref{def: continuous maps}, $f$ is continuous at $x$ iff $x \in f^{-1}[U_y] \in \mathcal T_X$. Clearly, $f^{-1}[U_y]$ is a neighbourhood of $x$. We have $f[f^{-1}[U_y]] = U_y \subseteq N_y$.

		By Proposition \ref{prop: alt-def of open sets by neighbourhoods}, there $U_x$ must contains at least one neighbourhood $N_x$ of $x$, thus, $f[N_x] \subseteq U_y$.
	\end{proof}
\end{theorem}
%--------------------------------

%--------------------------------
\begin{proposition}
	Let $(X, \mathcal T_X)$ and $(Y, \mathcal T_{Y})$ be metrizable spaces. A map $f: X \to Y$ is continuous at $p \in X$ iff for any $\varepsilon > 0$, there is a $\delta > 0$, such that for all $x \in B_X(p, \delta)$, $f(x) \in B_Y(f(p), \varepsilon)$, where $B_X$ is defined by any metrics $\rho_X$ induces $\mathcal T_X$, and $B_Y$ is defined by any metrics $\rho_Y$ induces $\mathcal T_Y$.

	\begin{proof}
		Clearly, for all $\varepsilon > 0$, $B_Y(f(x,), \varepsilon)$ is an open neighbourhood of $f(x)$.

		$f$ is not necessarily be injective, so $f^{-1}[B_Y(f(x), \varepsilon)] = U \in x$. By Definition \ref{def: continuous maps}, $U$ is open, so for some $\delta > 0$, $B_X(x, \delta) \subseteq U$. Thus, By Proposition \ref{prop: alt-def of continuous maps by neighbourhoods}, $f$ is continuous iff $f[B_X(x, \delta)] \subseteq B_Y(f(x), \varepsilon)$. This satisfies the conditions we have.
	\end{proof}
\end{proposition}
%--------------------------------

%--------------------------------
\begin{proposition}
	Let $(X, \mathcal T_X)$ and $(Y, \mathcal T_Y)$ be topological spaces. A function $f: X \to Y$ is said to be continuous iff for any closed set $V$ in $Y$, its preimage in $X$ under $f$ is closed.

	\begin{proof}
		Let $U_Y$ be any open set in $Y$, let $U_X$ be the preimage of $U_Y$ under $f$. By Definition \ref{def: continuous maps}, $U_X$ is open in $X$. Let
		$$
		V_X = f^{-1}[Y \setminus U_Y] = X \setminus U_X,
		$$
		Then $V_X$ is closed.
	\end{proof}
\end{proposition}
%--------------------------------

%--------------------------------
\begin{definition}
	[convergence of sequences]
	\label{def: convergence of sequences}
	Let $(X, \mathcal T)$ be a topological space, and let $\{x_n\}$ be a sequence in $X$. Then $\{x_n\}$ is said to be \textit{converges} in $X$ iff there is an $x \in X$, such that for any open neighbourhood $U_x$ of $x$, it contains a cofinite subset $A \subseteq \{x_n\}$. That is, there exists $N$ in the domain of $\{x_n\}$, for any natural numbers $n \ge N$, $x_n \in U_x$.
\end{definition}
%--------------------------------

%--------------------------------
\begin{example}
	\
	\begin{enumerate}
		\item
		In a discrete topological space, a sequence $\{x_n\}$ converges iff there is an $N$ in the domain of $\{x_n\}$, for any natural numbers $m > N$, $x_N = x_m$.

		\item
		In a indiscrete topological space, any sequence $\{x_n\}$ in $X$ converges in $X$. And
		$$
		\lim_{n \to \infty} \{x_n\} = X.
		$$
	\end{enumerate}
\end{example}
%--------------------------------

%--------------------------------
\begin{proposition}
	In a Hausdorff space, any convergent sequence converges to a unique point in the space.

	\begin{proof}
		Let $(X, \mathcal T)$ be a Hausdorff space, and let $\{x_n\}$ be a sequence in $X$. Suppose $\{x_n\}$ converges to more than one point, say to $x, y \in X$ with $x \ne y$, then, for all neighbourhoods $N_x$ of $x$ and $N_y$ of $y$, $N_x$ contains a cofinite subset $A \subseteq \{x_n\}$ and $N_y$ contains a cofinite subset $B \subseteq \{x_n\}$. If this were true, $N_x \cap N_y$ should be non-empty, otherwise $N_x$ or $N_y$ should be finite.

		Then, $x$ and $y$ are not separated by neighbourhoods, thus $(X, \mathcal T)$ is not Hausdorff. This is a contradiction.

		But, as $(X, \mathcal T)$ is Hausdorff, there must be mutually disjoint $N_x$ and $N_y$. Thus, the assumption cause a contradiction.
	\end{proof}
\end{proposition}
%--------------------------------

%--------------------------------
\begin{note}
	As all metrizable spaces are Hausdorff, so any convergent sequence in a metrizable space converges to at most one point.
\end{note}
%--------------------------------

%--------------------------------
\begin{proposition}
	Let $(X, \mathcal T_X)$ and $(Y, \mathcal T_Y)$ be topological space, let $f: X \to Y$ be a map, and let $\{x_n\}$ be a convergent sequence in $X$. If $f$ is continuous, then $f[\{x_n\}]$ is a sequence convergent in $Y$.

	\begin{proof}
		Let $U_y$ be any open neighbourhood of $f(x)$. By Definition \ref{def: continuous maps}, $f^{-1}[U_y]$ is also an open neighbourhood of $x$. By Definition \ref{def: convergence of sequences}, $f^{-1}[U_y]$ contains a cofinite subset $A \subseteq \{x_n\}$. Then $f[A]$ is a cofinite subset of $f[\{x_n\}]$. As $f[f^{-1}[U_y]] \supseteq f^{-1}[A]$, $f[\{x_n\}]$ converges in $f[f^{-1}[U_y]] \supseteq f^{-1}[A]$.
	\end{proof}
\end{proposition}
%--------------------------------

%--------------------------------
\begin{note}
	In this proposition, even if $f[\{x_n\}]$ converges in $Y$, $f$ might be discontinuous. For example, let $X$ any set, let $\mathcal T$ be the indiscrete topology on $X$, let $U$ be another cofinite subset of $X$ with $X \ne U$, and let $\mathcal T' = \{ \emptyset, X, U\}$. Let $f: (X, \mathcal T) \to (X, \mathcal T')$ be defined by
	$$
	f(x) = x.
	$$

	By Definition \ref{def: continuous maps}, $f$ is not continuous. But, for any convergent sequence $\{x_n\}$ in $(X, \mathcal T)$, $f[\{x_n\}]$ also convergent in $(X, \mathcal T)$.
\end{note}
%--------------------------------

%


\chapter{Cycles in the Collatz Graph}
\label{ch:cycles}

\section{A remark about cycles}
\label{sec:cycles}
In graph theory, a path of length $n\geq 1$ that starts and ends at the same vertex is called a circuit. A circuit, in which no vertex is repeated with the sole exception that the initial vertex is the terminal vertex, is called a cycle. A cycle of length $n$ is referred to as an $n$-cycle. For these definitions, we rely on \cite[p.~599]{Ref_Rosen}, \cite[p.~35]{Ref_Benjamin_Chartrand_Zhang} and \cite[p.~445]{Ref_Chartrand_Zhang}. Furthermore, we call a cycle originating from the root a trivial cycle.

\begin{remark}
In order for the cycles to become graphically visible, we now require that in a graph $H$ two vertices $v_1$ and $v_2$ are one and the same if the label of both nodes are identical: $l_{V(H)}(v_1)=l_{V(H)}(v_2)\rightarrow v_1=v_2$. As a consequence, there is no guarantee that the graph precisely refers to the algebraic structure of a free monoid anymore. A free monoid requires that each of its elements can be written in one and only one way.
\end{remark}

When different nodes collapse on one, the graph is no longer necessarily a tree. Let us point to the monoid $S^\ast$, which we introduced in section \ref{sec:groups_graphs}. Take for example four of its elements, the empty string $e$, the strings $qqr$, $qqrqqr$, and $qqrqqrqqr$. These elements lie as well within the subset $U\subset T\subset S^\ast$, and they are represented by nodes of the tree $H_U$ that all have the same label $1=ev_{S^\ast}(qqr,1)=ev_{S^\ast}(qqrqqr,1)=ev_{S^\ast}(qqrqqrqqr,1)$. These nodes are one and the same, the root of $H_U$. Visually, then in $H_U$ a directed edge goes from the vertex labeled with $4$ back to the root node. Analogically, in $H_{C,3}$ a loop connects the root to itself, since due to the path contraction even labeled nodes do not exist in $H_{C,3}$. The  aforementioned example reflects the trivial cycle of the Collatz sequence.

Figure~\ref{fig:5} depicts a section of $H_{C,5}$, which includes the $3$-cycle $43,17,27$. Because of the two non-trivial cycles $(43,17,27)$ and $(83,33,13)$, in $H_{C,5}$ there does not exist a path between the root and the vertex $43$ and between the root and the vertex $83$. Hence, $H_{C,5}$ is said to be a disconnected graph. Generally, a graph is called a disconnected graph if it is impossible to walk (along its edges) from any vertex to any other \cite[pp.~46-47]{Ref_Benjamin_Chartrand_Zhang}.

\begin{figure}
	\includegraphics[width=1.00\textwidth]{figures/h_c5a.png}
	\caption{Section of $H_{C,5}$ including the $3$-cycle $43,17,27$}
	\label{fig:5}
\end{figure}

The following considerations focus on non-trivial cycles, and therefore on cycles that do not originate from the root, but cause the graph to be a disconnected graph. Utilizing the example of the graph $H_{C,5}$ we are able to deduct from the cycle $(43,17,27)$ the simple and self-evident equality $\textit{left-child}^3(43)=43$:
\begin{equation*}
\begin{array}{l}
\textit{left-child}(43)=\frac{1}{5}*\left(43*2^1-1\right)=17
\\[\medskipamount]
\textit{left-child}(17)=\frac{1}{5}*\left(17*2^3-1\right)=27
\\[\medskipamount]
\textit{left-child}(27)=\frac{1}{5}*\left(27*2^3-1\right)=43
\end{array}
\end{equation*}

Obviously, the authors note, it would be interesting to find out what circumstances enable a graph to have non-trivial cycles, whether it be the $5x+1$ variant, the $7x+1$ variant of $H_C$ or any variant $H_{C,k}$ with $k\geq 1$.

\section{\texorpdfstring{Which variants of $H_C$ have non-trivial cycles?}{Which variants of HC have non-trivial cycles?}}
\label{sec:non_trivial_cycles}
The generalization of the relationship between successive nodes, given by equation~\ref{eq:generalized_reachability} leads to the condition for an existence of an $n$-cycle in any $kx+1$ variant of $H_C$, which looks analogous to the condition given by equation~\ref{eq:func_cycle} that specifies $H_{C,3}$ has a cycle:
\begin{equation}
\label{eq:generalized_cycle}
2^\alpha=\prod_{i=1}^{n}\left(k+\frac{1}{v_i}\right)
\end{equation}

The natural number $\alpha$ is the sum of edges that have been contracted between the vertices $v_i$ forming the cycle, in other words $\alpha$ is the number of divisions by $2$ within the sequence. The natural number $n$ is the cycle length and $k$ obviously specifies the variant of $H_C$. Since between each vertex at least one edge has been contracted (at least one division by $2$ took place), we know that our exponent alpha is greater than or equal to the sequence length:
\begin{equation}
\label{eq:n_alpha}
\alpha\ge n
\end{equation}

In their 2020 publication Koch et al. \cite{Ref_Koch_2020} provide a list of cycles for different values of $k$, identified with a linear search performed by a Python script \cite{Ref_Koch_Github}. Table~\ref{table:known_cycles} lists all these discovered cycles (refer to \cite{Ref_Koch_2020} for details on the discovery procedure and search intervals). Note that the cycles in table~\ref{table:known_cycles} are written in reverse order, i.e. in the order which corresponds to the Collatz sequence. To obtain the cycles in terms of graph theory referring to the graph $H_C$, read them from right to left.

\begin{table}[H]
	\centering
	\begin{tabular}{|L|R|R|C|}
		\hline
		\thead{\boldsymbol{k}} &
		\thead{\textbf{cycle}} &
		\thead{\boldsymbol{\alpha}} &
		\thead{\textbf{non-trivial}} \\
		\hline
		1 &
		1 &
		1 &
		\\
		\hline
		3 &
		1 &
		2 &
		\\
		\hline
		5 &
		1,3 &
		5 &
		\\
		\hline
		5 &
		13,33,83 &
		7 &
		\checkmark \\
		\hline
		5 &
		27,17,43 &
		7 &
		\checkmark \\
		\hline
		7 &
		1 &
		3 &
		\\
		\hline
		15 &
		1 &
		4 &
		\\
		\hline
		31 &
		1 &
		5 &
		\\
		\hline
		63 &
		1 &
		6 &
		\\
		\hline
		127 &
		1 &
		7 &
		\\
		\hline
		181 &
		27,611 &
		15 &
		\checkmark \\
		\hline
		181 &
		35,99 &
		15 &
		\checkmark \\
		\hline
		255 &
		1 &
		8 &
		\\
		\hline
		511 &
		1 &
		9 &
		\\
		\hline
	\end{tabular}
	\caption{Known $n$-cycles in $kx+1$ variants of $H_C$ for $k\leq1000$, $n\leq 100$}
	\label{table:known_cycles}
\end{table}

Based on the results shown in table~\ref{table:known_cycles} we state the following theorem~\ref{theo:2} that renders more precisely the prerequisite for cycles that may occur in any variants of $H_C$.

\begin{theorem}
	\label{theo:2}
	An $n$-cycle can only exist in a graph $H_{C,k}$, if the following equation holds:
	\begin{equation*}
	2^{\bar\alpha}=2^{\lfloor n\log_2k\rfloor+1}=\prod_{i=1}^{n}\left(k+\frac{1}{v_i}\right)
	\end{equation*}
\end{theorem}

The statement behind theorem~\ref{theo:2} consists in the claim that, in order for an $n$-cycle to occur, the exponent $\alpha$ has to be $\bar\alpha=\lfloor n\log_2k\rfloor+1$. This statement is true if the following general condition for the validity of the cycle-alpha's upper limit always holds (see \cite{Ref_Koch_2020}):
\begin{equation}
\label{eq:condition_max}
n\log_2k-\lfloor n\log_2k\rfloor<2-\log_2\left(\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)\right)
\end{equation}

A product $\prod(1+a_n)$ with positive terms $a_n$ is convergent if the series $\sum a_n$ converges, see Knopp \cite[p.~220]{Ref_Knopp}. A similar statement provides Murphy \cite{Ref_Murphy}, who write the factors in the form $c_n=1+a_n$ and explains that if $\prod c_n$ is convergent then $c_n\rightarrow1$ and therefore if $\prod (1+a_n)$ is convergent then $a_n\rightarrow0$. Thus, to verify whether the product in condition~\ref{eq:condition_max} is converging towards a limiting value, it is sufficient to examine the following sum:
\begin{equation*}
\sum_{i=1}^{n}\frac{1}{kv_{i}}
\end{equation*}

The sum of reciprocal vertices depending only from $v_1$ is given in appendix~\ref{appx:sum_reciprocal_vertices}.

\section{Cycles and the product in the condition for cycle-alpha's upper limit}
Let us start with the following product equality, which will give us insights into the relationship between cycles and the product in the condition for alpha's upper limit. The variables $V_1,\ldots,V_m$ and $W_1,\ldots,W_n$ are all odd positive integers:
\begin{equation}
	\label{eq:product_equality}
	(V_1+1)\cdots(V_m+1)\cdot W_1\cdots W_n=V_1\cdots V_m\cdot(W_1+1)\cdots(W_n+1)
\end{equation}

Every natural odd number $V$ can be expressed in the form of $V=v\cdot2^{\alpha}-1$ whereby $v$ is an positive odd integer and $\alpha>0$ is any natural number. This allows us to perform the following substitution (we use $\alpha_V$ for denoting the divisions by two between successive nodes $v_i$ and $\alpha_W$ for divisions by two between successive nodes $w_i$):

\begin{equation}
	\label{eq:product_equality_substitution}
	\begin{array}{lll}
		V_1&=v_22^{\alpha_{V,1}}-1&=kv_1\\
		V_2&=v_32^{\alpha_{V,2}}-1&=kv_2\\
		\vdots&\vdots&\vdots\\
		V_{m-1}&=v_m2^{\alpha_{V,m-1}}-1&=kv_{m-1}\\
		V_m&=v_12^{\alpha_{V,m}}-1&=kv_m
	\end{array}\qquad
	\begin{array}{lll}
		W_1&=w_22^{\alpha_{W,1}}-1&=kw_1\\
		W_2&=w_32^{\alpha_{W,2}}-1&=kw_2\\
		\vdots&\vdots&\vdots\\
		W_{n-1}&=w_n2^{\alpha_{W,n-1}}-1&=kw_{n-1}\\
		W_n&=w_12^{\alpha_{W,n}}-1&=kw_n
	\end{array}
\end{equation}

The substitution rotating from $v_2=(kv_1+1)\cdot2^{-\alpha_{V,1}}$ to $v_m=(kv_{m-1}+1)\cdot2^{-\alpha_{V,m-1}}$ and finally back to $v_1=(kv_m+1)\cdot2^{-\alpha_{V,m}}$ describes a cycle. The result of these substitutions into equation~\ref{eq:product_equality} is the following equality:
\begin{flalign*}
	v_22^{\alpha_{V,1}}\cdots v_m2^{\alpha_{V,m-1}}v_12^{\alpha_{V,m}}\cdot W_1\cdots W_n&=V_1\cdots V_m\cdot w_22^{\alpha_{W,1}}\cdots w_n2^{\alpha_{W,n-1}}w_12^{\alpha_{W,n}}\\
	v_22^{\alpha_{V,1}}\cdots v_m2^{\alpha_{V,m-1}}v_12^{\alpha_{V,m}}\cdot kw_1\cdots kw_n&=kv_1\cdots kv_m\cdot w_22^{\alpha_{W,1}}\cdots w_n2^{\alpha_{W,n-1}}w_12^{\alpha_{W,n}}
\end{flalign*}

The trivial case where $n=m$ and the sum of exponents are equal $\sum_{i=1}^{m}\alpha_{V,i}=\sum_{i=1}^{n}\alpha_{W,i}$ simplifies the product equality as follows:
\begin{flalign*}
	(V_1+1)\cdots(V_n+1)\cdot W_1\cdots W_n&=V_1\cdots V_n\cdot(W_1+1)\cdots(W_n+1)\\
	v_1\cdots v_n\cdot\cancel{2^{\alpha_{V,1}+\ldots+\alpha_{V,n}}}\cdot W_1\cdots W_n&=V_1\cdots V_m\cdot w_1\cdots w_n\cdot\cancel{2^{\alpha_{W,1}+\ldots+\alpha_{W,n}}}
\end{flalign*}
This equality becomes immediatly true if $V_1\cdots V_n=W_1\cdots W_n$ which is the less spectacular case. The more interesting case arises from setting $V_i=kv_i$ and $W_i=kw_i$ as given by substitution~\ref{eq:product_equality_substitution} wich turns the product equality into an always true statement as well:
\begin{flalign*}
	v_1\cdots v_n\cdot W_1\cdots W_n&=V_1\cdots V_m\cdot w_1\cdots w_n\\
	v_1\cdots v_n\cdot k^n\cdot w_1\cdots w_n&=k^n\cdot v_1\cdots v_n\cdot w_1\cdots w_n
\end{flalign*}

\begin{example}
	The following exemplarly product equality fullfills equation~\ref{eq:product_equality}, whereby $V_1=65$, $V_2=165$, $V_3=415$ and $W_1=135$, $W_2=85$, $W_3=215$:
	\[
	(65+1)(165+1)(415+1)\cdot135\cdot85\cdot215=65\cdot165\cdot415\cdot(135+1)(85+1)(215+1)
	\]
	We perform the following substitutions:
	\[
	\arraycolsep=0.2em\begin{array}{ll}
		V_1=65&=v_22^{\alpha_{V,1}}-1=33\cdot2^1-1=5v_1\\
		V_2=165&=v_32^{\alpha_{V,2}}-1=83\cdot2^1-1=5v_2\\
		V_3=415&=v_12^{\alpha_{V,3}}-1=13\cdot2^5-1=5v_3
	\end{array}\hspace{1em}
	\begin{array}{ll}
		W_1=135&=w_22^{\alpha_{W,1}}-1=17\cdot2^3-1=5w_1\\
		W_2=85&=w_32^{\alpha_{W,2}}-1=43\cdot2^1-1=5w_2\\
		W_3=215&=w_12^{\alpha_{W,3}}-1=27\cdot2^3-1=5w_3
	\end{array}
	\]
	The result of these substitutions is:
	\[
	33\cdot\cancel{2^1}\cdot83\cdot\cancel{2^1}\cdot13\cdot\cancel{2^5}\cdot135\cdot85\cdot215=65\cdot165\cdot415\cdot17\cdot\cancel{2^3}\cdot43\cdot\cancel{2^1}\cdot27\cdot\cancel{2^3}
	\]
	Since the sum of exponents $\alpha_{V,i}$ and $\alpha_{W,i}$ are equal, we can cancel out all powers of two and obtain:
	\[
	v_2v_3v_1W_1W_2W_3=33\cdot83\cdot13\cdot135\cdot85\cdot215=65\cdot165\cdot415\cdot17\cdot43\cdot27=V_1V_2V_3w_2w_3w_1
	\]
	This product equality becomes true $v_2v_3v_1\cdot k^3\cdot w_1w_2w_3=k^3\cdot v_1v_2v_3\cdot w_2w_3w_1$ when we set $V_i=kv_i$ and $W_i=kw_i$ (for $i=1,2,3$) which inevitably leads to the two corresponding cycles for $k=5$ that are already presented by table~\ref{table:known_cycles}.
\end{example}

Let us define the difference $\Delta=(1+\nicefrac{1}{V_1})(1+\nicefrac{1}{V_2})\cdots(1+\nicefrac{1}{V_m})-(1+\nicefrac{1}{W_1})(1+\nicefrac{1}{W_2})\cdots(1+\nicefrac{1}{W_n})$.
We know that if this difference is zero, then we have found two cycles, as for example $0=(1+\nicefrac{1}{65})(1+\nicefrac{1}{165})(1+\nicefrac{1}{415})-(1+\nicefrac{1}{135})(1+\nicefrac{1}{85})(1+\nicefrac{1}{215})$.
Can you identify empirically some set pairs $\{V_1,V_2,\ldots,V_m\}$ and $\{W_1,W_2,\ldots,W_n\}$, where the difference is not necessarly zero but a whole number, e.g. $\Delta=1,2,3,\ldots$?


\subsection{HDBSCAN}
\label{sec:ctm-hdb}

The third and last clustering algorithm we experimented with was HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) \cite{McInnes2017}. Similar to the previous two algorithms, it tries to group unlabeled data points with its own set of criteria. As its name implies, it tries to group points based on spatial density to ensure the resulting groups meet some density parameter.

The advantage of HDBSCAN is that it does not require us to specify the number of clusters we want to find. Instead, we specify the minimum number of points in each cluster $P$ and the algorithm will dynamically group points such that the resulting clusters have at least $P$ points. This gives us more flexibility in our parameters because choosing the number of clusters is harder than choosing the minimum number of points per cluster. We do not know the proper the number of clusters and thus must estimate it through an ad-hoc procedure. However, we do have a stronger conceptual understanding of the number of points per cluster: since we know there are only a limited number of approaches to solve an assignment and we know the majority of the students will follow similar approaches, either through collaboration or coincidence due to limited unique approaches, we know the $P$ value must be a significant fraction of the total number of students.

However, the disadvantage of this algorithm is that it is not guaranteed to be able to label every point; outlier points that cannot satisfy the group's density criteria are discarded as noise. The higher the minimum cluster size parameter $P$, the more points will be unlabeled. Ideally we want our groups to be as dense as possible so that we know the grouped points are extremely similar to each other. Ultimately, it is a balance between how many points we can label (automation rate) and how dense the resulting groups are.

Figure~\ref{fig:ctm-hdb} shows how the algorithm labels our data set based on varying minimum cluster sizes. A cluster size of 5 is able to achieve 3 groups, which is close to the 4 groups set for the previous two algorithms. However as we can see from the graph, the 3 groups are slightly sparse. As a result, we chose $P=10$ because it is able to label most of the points without sacrificing too much density; at higher cluster sizes, we do not seem to significantly increase our groups' densities.

Once we were satisfied with our parameters, we ran the HDBSCAN algorithm and designated each student's score to be equal to the \textquote{strength} of the student's corresponding group prediction returned from the algorithm.

\begin{figure}
\includegraphics[width=\textwidth]{conversion-to-mark/marking_paster_nbio_ece459-a1-w2017_hdb}
\caption[HDBSCAN Clustering]{These graphs show our data points clustered with HDBSCAN using different minimum cluster size parameters. The higher the minimum size, the denser the resulting clusters. Furthermore, higher cluster sizes also result in more outlier points marked as noise (dark blue) as well as fewer total clusters. Cluster size of 5 has three different groups whereas cluster sizes of 10 and higher only have two different groups.}
\label{fig:ctm-hdb}
\end{figure}


\chapter{Cycles in the Collatz Graph}
\label{ch:cycles}

\section{A remark about cycles}
\label{sec:cycles}
In graph theory, a path of length $n\geq 1$ that starts and ends at the same vertex is called a circuit. A circuit, in which no vertex is repeated with the sole exception that the initial vertex is the terminal vertex, is called a cycle. A cycle of length $n$ is referred to as an $n$-cycle. For these definitions, we rely on \cite[p.~599]{Ref_Rosen}, \cite[p.~35]{Ref_Benjamin_Chartrand_Zhang} and \cite[p.~445]{Ref_Chartrand_Zhang}. Furthermore, we call a cycle originating from the root a trivial cycle.

\begin{remark}
In order for the cycles to become graphically visible, we now require that in a graph $H$ two vertices $v_1$ and $v_2$ are one and the same if the label of both nodes are identical: $l_{V(H)}(v_1)=l_{V(H)}(v_2)\rightarrow v_1=v_2$. As a consequence, there is no guarantee that the graph precisely refers to the algebraic structure of a free monoid anymore. A free monoid requires that each of its elements can be written in one and only one way.
\end{remark}

When different nodes collapse on one, the graph is no longer necessarily a tree. Let us point to the monoid $S^\ast$, which we introduced in section \ref{sec:groups_graphs}. Take for example four of its elements, the empty string $e$, the strings $qqr$, $qqrqqr$, and $qqrqqrqqr$. These elements lie as well within the subset $U\subset T\subset S^\ast$, and they are represented by nodes of the tree $H_U$ that all have the same label $1=ev_{S^\ast}(qqr,1)=ev_{S^\ast}(qqrqqr,1)=ev_{S^\ast}(qqrqqrqqr,1)$. These nodes are one and the same, the root of $H_U$. Visually, then in $H_U$ a directed edge goes from the vertex labeled with $4$ back to the root node. Analogically, in $H_{C,3}$ a loop connects the root to itself, since due to the path contraction even labeled nodes do not exist in $H_{C,3}$. The  aforementioned example reflects the trivial cycle of the Collatz sequence.

Figure~\ref{fig:5} depicts a section of $H_{C,5}$, which includes the $3$-cycle $43,17,27$. Because of the two non-trivial cycles $(43,17,27)$ and $(83,33,13)$, in $H_{C,5}$ there does not exist a path between the root and the vertex $43$ and between the root and the vertex $83$. Hence, $H_{C,5}$ is said to be a disconnected graph. Generally, a graph is called a disconnected graph if it is impossible to walk (along its edges) from any vertex to any other \cite[pp.~46-47]{Ref_Benjamin_Chartrand_Zhang}.

\begin{figure}
	\includegraphics[width=1.00\textwidth]{figures/h_c5a.png}
	\caption{Section of $H_{C,5}$ including the $3$-cycle $43,17,27$}
	\label{fig:5}
\end{figure}

The following considerations focus on non-trivial cycles, and therefore on cycles that do not originate from the root, but cause the graph to be a disconnected graph. Utilizing the example of the graph $H_{C,5}$ we are able to deduct from the cycle $(43,17,27)$ the simple and self-evident equality $\textit{left-child}^3(43)=43$:
\begin{equation*}
\begin{array}{l}
\textit{left-child}(43)=\frac{1}{5}*\left(43*2^1-1\right)=17
\\[\medskipamount]
\textit{left-child}(17)=\frac{1}{5}*\left(17*2^3-1\right)=27
\\[\medskipamount]
\textit{left-child}(27)=\frac{1}{5}*\left(27*2^3-1\right)=43
\end{array}
\end{equation*}

Obviously, the authors note, it would be interesting to find out what circumstances enable a graph to have non-trivial cycles, whether it be the $5x+1$ variant, the $7x+1$ variant of $H_C$ or any variant $H_{C,k}$ with $k\geq 1$.

\section{\texorpdfstring{Which variants of $H_C$ have non-trivial cycles?}{Which variants of HC have non-trivial cycles?}}
\label{sec:non_trivial_cycles}
The generalization of the relationship between successive nodes, given by equation~\ref{eq:generalized_reachability} leads to the condition for an existence of an $n$-cycle in any $kx+1$ variant of $H_C$, which looks analogous to the condition given by equation~\ref{eq:func_cycle} that specifies $H_{C,3}$ has a cycle:
\begin{equation}
\label{eq:generalized_cycle}
2^\alpha=\prod_{i=1}^{n}\left(k+\frac{1}{v_i}\right)
\end{equation}

The natural number $\alpha$ is the sum of edges that have been contracted between the vertices $v_i$ forming the cycle, in other words $\alpha$ is the number of divisions by $2$ within the sequence. The natural number $n$ is the cycle length and $k$ obviously specifies the variant of $H_C$. Since between each vertex at least one edge has been contracted (at least one division by $2$ took place), we know that our exponent alpha is greater than or equal to the sequence length:
\begin{equation}
\label{eq:n_alpha}
\alpha\ge n
\end{equation}

In their 2020 publication Koch et al. \cite{Ref_Koch_2020} provide a list of cycles for different values of $k$, identified with a linear search performed by a Python script \cite{Ref_Koch_Github}. Table~\ref{table:known_cycles} lists all these discovered cycles (refer to \cite{Ref_Koch_2020} for details on the discovery procedure and search intervals). Note that the cycles in table~\ref{table:known_cycles} are written in reverse order, i.e. in the order which corresponds to the Collatz sequence. To obtain the cycles in terms of graph theory referring to the graph $H_C$, read them from right to left.

\begin{table}[H]
	\centering
	\begin{tabular}{|L|R|R|C|}
		\hline
		\thead{\boldsymbol{k}} &
		\thead{\textbf{cycle}} &
		\thead{\boldsymbol{\alpha}} &
		\thead{\textbf{non-trivial}} \\
		\hline
		1 &
		1 &
		1 &
		\\
		\hline
		3 &
		1 &
		2 &
		\\
		\hline
		5 &
		1,3 &
		5 &
		\\
		\hline
		5 &
		13,33,83 &
		7 &
		\checkmark \\
		\hline
		5 &
		27,17,43 &
		7 &
		\checkmark \\
		\hline
		7 &
		1 &
		3 &
		\\
		\hline
		15 &
		1 &
		4 &
		\\
		\hline
		31 &
		1 &
		5 &
		\\
		\hline
		63 &
		1 &
		6 &
		\\
		\hline
		127 &
		1 &
		7 &
		\\
		\hline
		181 &
		27,611 &
		15 &
		\checkmark \\
		\hline
		181 &
		35,99 &
		15 &
		\checkmark \\
		\hline
		255 &
		1 &
		8 &
		\\
		\hline
		511 &
		1 &
		9 &
		\\
		\hline
	\end{tabular}
	\caption{Known $n$-cycles in $kx+1$ variants of $H_C$ for $k\leq1000$, $n\leq 100$}
	\label{table:known_cycles}
\end{table}

Based on the results shown in table~\ref{table:known_cycles} we state the following theorem~\ref{theo:2} that renders more precisely the prerequisite for cycles that may occur in any variants of $H_C$.

\begin{theorem}
	\label{theo:2}
	An $n$-cycle can only exist in a graph $H_{C,k}$, if the following equation holds:
	\begin{equation*}
	2^{\bar\alpha}=2^{\lfloor n\log_2k\rfloor+1}=\prod_{i=1}^{n}\left(k+\frac{1}{v_i}\right)
	\end{equation*}
\end{theorem}

The statement behind theorem~\ref{theo:2} consists in the claim that, in order for an $n$-cycle to occur, the exponent $\alpha$ has to be $\bar\alpha=\lfloor n\log_2k\rfloor+1$. This statement is true if the following general condition for the validity of the cycle-alpha's upper limit always holds (see \cite{Ref_Koch_2020}):
\begin{equation}
\label{eq:condition_max}
n\log_2k-\lfloor n\log_2k\rfloor<2-\log_2\left(\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)\right)
\end{equation}

A product $\prod(1+a_n)$ with positive terms $a_n$ is convergent if the series $\sum a_n$ converges, see Knopp \cite[p.~220]{Ref_Knopp}. A similar statement provides Murphy \cite{Ref_Murphy}, who write the factors in the form $c_n=1+a_n$ and explains that if $\prod c_n$ is convergent then $c_n\rightarrow1$ and therefore if $\prod (1+a_n)$ is convergent then $a_n\rightarrow0$. Thus, to verify whether the product in condition~\ref{eq:condition_max} is converging towards a limiting value, it is sufficient to examine the following sum:
\begin{equation*}
\sum_{i=1}^{n}\frac{1}{kv_{i}}
\end{equation*}

The sum of reciprocal vertices depending only from $v_1$ is given in appendix~\ref{appx:sum_reciprocal_vertices}.


\chapter{Matrix Calculations} \index{Matrix calculations}
A very powerful feature of {\REDUCE} is the ease with which matrix
calculations can be performed. To extend our syntax to this class of
calculations we need to add another prefix operator, {\tt MAT},
\ttindex{MAT} and a further
variable and expression type as follows:

\section{MAT Operator}\ttindex{MAT}
This prefix operator is used to represent $n\times m$ matrices. {\tt
MAT} has {\em n} arguments interpreted as rows of the matrix, each of
which is a list of {\em m} expressions representing elements in that row.
For example, the matrix
\[ \left( \begin{array}{lcr} a & b & c \\ d & e & f \end{array} \right) \]
would be written as {\tt mat((a,b,c),(d,e,f))}.

Note that the single column matrix
\[ \left( \begin{array}{c} x \\ y \end{array} \right) \]
becomes {\tt mat((x),(y))}.  The inside parentheses are required to
distinguish it from the single row matrix
\[ \left( \begin{array}{lr} x & y \end{array} \right) \]
that would be written as {\tt mat((x,y))}.

\section{Matrix Variables}

An identifier may be declared a matrix variable by the declaration {\tt
MATRIX}.\ttindex{MATRIX}
The size of the matrix may be declared explicitly in the matrix
declaration, or by default in assigning such a variable to a matrix
expression. For example,
\begin{verbatim}
        matrix x(2,1),y(3,4),z;
\end{verbatim}
declares {\tt X} to be a 2 x 1 (column) matrix, {\tt Y} to be a 3 x 4
matrix and {\tt Z} a matrix whose size is to be declared later.

Matrix declarations can appear anywhere in a program. Once a symbol is
declared to name a matrix, it can not also be used to name an array,
operator or a procedure, or used as an ordinary variable. It can however
be redeclared to be a matrix, and its size may be changed at that time.
Note however that matrices once declared are {\em global\/} in scope, and so
can then be referenced anywhere in the program.  In other words, a
declaration within a block (or a procedure) does not limit the scope of
the matrix to that block, nor does the matrix go away on exiting the block
(use {\tt CLEAR} instead for this purpose).  An element of a matrix is
referred to in the expected manner; thus {\tt x(1,1)} gives the first
element of the matrix {\tt X} defined above.  References to elements of a
matrix whose size has not yet been declared leads to an error.  All
elements of a matrix whose size is declared are initialized to 0.  As a
result, a matrix element has an {\em instant evaluation\/}\index{Instant
evaluation} property and cannot stand for itself.  If this is required,
then an operator should be used to name the matrix elements as in:
\begin{verbatim}
        matrix m; operator x;  m := mat((x(1,1),x(1,2));
\end{verbatim}

\section{Matrix Expressions}

These follow the normal rules of matrix algebra as defined by the
following syntax:\ttindex{MAT}
\begin{verbatim}
        <matrix expression> ::=
                  MAT<matrix description>|<matrix variable>|
                  <scalar expression>*<matrix expression>|
                  <matrix expression>*<matrix expression>
                  <matrix expression>+<matrix expression>|
                  <matrix expression>^<integer>|
                  <matrix expression>/<matrix expression>
\end{verbatim}
Sums and products of matrix expressions must be of compatible size;
otherwise an error will result during their evaluation.  Similarly, only
square matrices may be raised to a power.  A negative power is computed as
the inverse of the matrix raised to the corresponding positive power.
{\tt a/b} is interpreted as {\tt a*b\verb|^|(-1)}.

{\it Examples:}

Assuming {\tt X} and {\tt Y} have been declared as matrices, the following
are matrix expressions
\begin{verbatim}
        y
        y^2*x-3*y^(-2)*x
        y + mat((1,a),(b,c))/2
\end{verbatim}
The computation of the quotient of two matrices normally uses a two-step
elimination method due to Bareiss.  An alternative method using Cramer's
method is also available.  This is usually less efficient than the Bareiss
method unless the matrices are large and dense, although we have no solid
statistics on this as yet.  To use Cramer's method instead, the switch
{\tt CRAMER}\ttindex{CRAMER} should be turned on.

\section{Operators with Matrix Arguments}

The operator {\tt LENGTH}\ttindex{LENGTH} applied to a matrix returns a
list of the number of rows and columns in the matrix.  Other operators
useful in matrix calculations are defined in the following subsections.
Attention is also drawn to the LINALG
\extendedmanual{(chapter~\ref{LINALG})} and NORMFORM
\extendedmanual{(chapter~\ref{NORMFORM})} packages.

\subsection{DET Operator}\ttindex{DET}
Syntax:
\begin{verbatim}
        DET(EXPRN:matrix_expression):algebraic.
\end{verbatim}

The operator {\tt DET} is used to represent the determinant of a square
matrix expression.  E.g.,
\begin{verbatim}
        det(y^2)
\end{verbatim}
is a scalar expression whose value is the determinant of the square of the
matrix {\tt Y}, and
\begin{verbatim}
        det mat((a,b,c),(d,e,f),(g,h,j));
\end{verbatim}
is a scalar expression whose value is the determinant of the matrix
\[ \left( \begin{array}{lcr} a & b & c \\ d & e & f \\ g & h & j
\end{array} \right) \]

Determinant expressions have the {\em instant evaluation\/} property.
\index{Instant evaluation}  In other words, the statement
\begin{verbatim}
        let det mat((a,b),(c,d)) = 2;
\end{verbatim}
sets the {\em value\/} of the determinant to 2, and does not set up a rule
for the determinant itself.

\subsection{MATEIGEN Operator}\ttindex{MATEIGEN}
Syntax:
\begin{verbatim}
        MATEIGEN(EXPRN:matrix_expression,ID):list.
\end{verbatim}

{\tt MATEIGEN} calculates the eigenvalue equation and the corresponding
eigenvectors of a matrix, using the variable {\tt ID} to denote the
eigenvalue.  A square free decomposition of the characteristic polynomial
is carried out.  The result is a list of lists of 3 elements, where the
first element is a square free factor of the characteristic polynomial,
the second its multiplicity and the third the corresponding eigenvector
(as an {\em n} by 1 matrix).  If the square free decomposition was
successful, the product of the first elements in the lists is the minimal
polynomial.  In the case of degeneracy, several eigenvectors can exist for
the same eigenvalue, which manifests itself in the appearance of more than
one arbitrary variable in the eigenvector.  To extract the various parts
of the result use the operations defined on lists.

{\it Example:}
 The command
\begin{verbatim}
        mateigen(mat((2,-1,1),(0,1,1),(-1,1,1)),eta);
\end{verbatim}
gives the output
\begin{verbatim}
        {{ETA - 1,2,

          [ARBCOMPLEX(1)]
          [             ]
          [ARBCOMPLEX(1)]
          [             ]
          [      0      ]

          },

         {ETA - 2,1,

          [      0      ]
          [             ]
          [ARBCOMPLEX(2)]
          [             ]
          [ARBCOMPLEX(2)]

          }}
\end{verbatim}

\subsection{TP Operator}\ttindex{TP}
Syntax:
\begin{verbatim}
        TP(EXPRN:matrix_expression):matrix.
\end{verbatim}

This operator takes a single matrix argument and returns its transpose.

\subsection{Trace Operator}\ttindex{TRACE}
Syntax:
\begin{verbatim}
        TRACE(EXPRN:matrix_expression):algebraic.
\end{verbatim}
The operator {\tt TRACE} is used to represent the trace of a square matrix.

\subsection{Matrix Cofactors}\ttindex{COFACTOR}
Syntax:
\begin{verbatim}
  COFACTOR(EXPRN:matrix_expression,ROW:integer,COLUMN:integer):
	   algebraic
\end{verbatim}

The operator {\tt COFACTOR} returns the cofactor of the element in row
{\tt ROW} and column {\tt COLUMN} of the matrix {\tt MATRIX}.  Errors occur
if {\tt ROW} or {\tt COLUMN} do not simplify to integer expressions or if
{\tt MATRIX} is not square.

\subsection{NULLSPACE Operator}\ttindex{NULLSPACE}
Syntax:
\begin{verbatim}
        NULLSPACE(EXPRN:matrix_expression):list
\end{verbatim}
{\tt NULLSPACE} calculates for a matrix {\tt A} a list of linear
independent vectors (a basis) whose linear combinations satisfy the
equation $A x = 0$.  The basis is provided in a form such that as many
upper components as possible are isolated.

Note that with {\tt b := nullspace a} the expression {\tt length b} is the
{\em nullity\/} of A, and that {\tt second length a - length b} calculates the
{\em rank\/} of A.  The rank of a matrix expression can also be found more
directly by the {\tt RANK} operator described below.

{\it Example:} The command
\begin{verbatim}
        nullspace mat((1,2,3,4),(5,6,7,8));
\end{verbatim}
   gives the output

\begin{verbatim}
        {
         [ 1  ]
         [    ]
         [ 0  ]
         [    ]
         [ - 3]
         [    ]
         [ 2  ]
         ,
         [ 0  ]
         [    ]
         [ 1  ]
         [    ]
         [ - 2]
         [    ]
         [ 1  ]
         }
\end{verbatim}

In addition to the {\REDUCE} matrix form, {\tt NULLSPACE} accepts as input a
matrix given as a list of lists, that is interpreted as a row matrix.  If
that form of input is chosen, the vectors in the result will be
represented by lists as well.  This additional input syntax facilitates
the use of {\tt NULLSPACE} in applications different from classical linear
algebra.

\subsection{RANK Operator}\ttindex{RANK}

Syntax:
\begin{verbatim}
        RANK(EXPRN:matrix_expression):integer
\end{verbatim}
{\tt RANK} calculates the rank of its argument, that, like {\tt NULLSPACE}
can either be a standard matrix expression, or a list of lists, that can
be interpreted either as a row matrix or a set of equations.

{\tt Example:}

\begin{verbatim}
        rank mat((a,b,c),(d,e,f));
\end{verbatim}
returns the value 2.

\section{Matrix Assignments} \index{Matrix assignment}

Matrix expressions may appear in the right-hand side of assignment
statements. If the left-hand side of the assignment, which must be a
variable, has not already been declared a matrix, it is declared by default
to the size of the right-hand side. The variable is then set to the value
of the right-hand side.

Such an assignment may be used very conveniently to find the solution of a
set of linear equations. For example, to find the solution of the
following set of equations
\begin{verbatim}
        a11*x(1) + a12*x(2) = y1
        a21*x(1) + a22*x(2) = y2
\end{verbatim}
we simply write
\begin{verbatim}
        x := 1/mat((a11,a12),(a21,a22))*mat((y1),(y2));
\end{verbatim}

\section{Evaluating Matrix Elements}

Once an element of a matrix has been assigned, it may be referred to in
standard array element notation.  Thus {\tt y(2,1)} refers to the element
in the second row and first column of the matrix {\tt Y}.


%---------------------------Aspect Beta----------------------------------
\section{Aspect Beta}

This metric measures the radius ratio (\emph{cf.}
\S\ref{s:tet-radius-ratio}) of a positively-oriented tetrahedron. Note
that it is equal to the tetrahedral radius ratio.

For a positively-oriented tetrahedron, the aspect $\beta$ is the
quotient of these two radii normalized by $\frac{1}{3}$ so
that an equilateral tetrahedron has quality of~$1$:
\begin{eqnarray*}
q & = & \frac{R}{3 r} \nonumber \\
  & = & \frac { \left|
   \normvec{L_3}^2 \left( \vec L_2 \times \vec L_0 \right) +
   \normvec{L_2}^2 \left( \vec L_3 \times \vec L_0 \right) +
   \normvec{L_0}^2 \left( \vec L_3 \times \vec L_2 \right)
   \right| A}{108 V^2}.
\end{eqnarray*}

Note that if the tetrahedron has negative orientation, we set $q = DBL\_MAX$.

\tetmetrictable{aspect $\beta$}%
{$1$}%                  Dimension
{$[1,3]$}%              Acceptable range
{$[1,DBL\_MAX]$}%       Normal range
{$[1,DBL\_MAX]$}%       Full range
{$1$}%                  Equilateral tet
{\cite{par:93}}%        Citation
{v\_tet\_aspect\_beta}% Verdict function name