\chapter{ELEC 360 CheatSheet}
Some keywords used can be found in the glossary section including:
\begin{itemize}
	\item  \gls{partFrac}, \gls{openLoop}, \gls{SISO}, \gls{MIMO}, and \gls{LTI}
	\item  \gls{conSys}, \gls{closedLoop}, \gls{DC Motors}, and \gls{Op Amps}
\end{itemize}

\begin{multicols}{3}

%\includegraphics[width=1.77165in,height=0.95669in]{media/image1.png}

\section{LAPLACE TRANSFORMS}

Final Value Theorem

In Control Engineering, the Final Value Theorem is used most frequently to determine the steady-state value of a system. The real part of the poles of the function must be < 0.
\begin{align}
& \lim\limits_{t \rightarrow \infty} x(t) = \lim\limits_{t \rightarrow 0} sX(s)
\end{align}
%\includegraphics[width=1.77165in,height=0.92126in]{media/image2.png}

%\includegraphics[width=1.77165in,height=1.14961in]{media/image3.png}

Initial Value Theorem

\begin{align}
& \lim\limits_{t \rightarrow 0} x(t) = \lim\limits_{t \rightarrow \infty} sX(s)
\end{align}
%\includegraphics[width=1.77165in,height=0.90551in]{media/image4.png}

%\includegraphics[width=1.77165in,height=0.77953in]{media/image5.png}

\section{SOLUTION OF LINEAR DIFFERENTIAL EQUATION}

\[A\ddot{y} + B\dot{y} + Cy = u\left( t \right)\]

\[\text{with initial conditions }\dot{y}\left( 0 \right)\ and \ y(0)\]

\[\text{is solved by constructing the equation}\]

%\[A\left\lbrack s^{2}Y\left( s \right) - sy\left( 0 \right) - \dot{y}\left( 0 \right) \right\rbrack + B\left\lbrack \text{sY}\left( s \right) - y\left( 0 \right) \right\rbrack + CY(s)\]

\begin{align*}
 &A\left\lbrack s^{2}Y\left( s \right) - sy\left( 0 \right) - \dot{y}\left( 0 \right) \right\rbrack + B\left\lbrack \text{sY}\left( s \right) - y\left( 0 \right) \right\rbrack \\
 & + CY(s)
\end{align*}
\[that\ is\ to\ say:\]

\[\mathcal{L}\left\{ \ddot{y} \right\} = s^{2}Y\left( s \right) - sy\left( 0 \right) - \dot{y}(0)\]

\[\text{and}\]

\[\mathcal{L}\left\{ \dot{y} \right\} = sY\left( s \right) - y\left( 0 \right)\]

\section{STATESPACE REPRESENTATIONS}

To generate from a differential equation:

Use the \textbf{closed loop transfer function}

\[\frac{Y\left( s \right)}{U\left( s \right)} = \frac{s + A}{s^{3} + \text{Bs}^{2} + s + A}\]

Separate and take the inverse Laplace transform

\begin{align*} &s^{3}Y\left( s \right) + \text{Bs}^{2}Y\left( s \right) + sY\left( s \right) + AY\left( s \right) \\
 &= sU\left( s \right) + AU\left( s \right)
 \end{align*}

\[= \dddot{y} + B\ddot{y} + \dot{y} + Ay = \dot{u} + Au\]

Then define state variables:

\(x_{1} = y\) \(\dot{x_{1}} = \dot{y} = x_{2}\)

\(x_{2} = \dot{y}\) \(\dot{x_{2}} = \ddot{y} = x_{3}\)

\(x_{3} = \ddot{y}\)
\(\dot{x_{3}} = \dddot{y} = \dot{u} + Au - B\ddot{y} - \dot{y} - Ay\)

Then construct the state space matrix

\[\begin{bmatrix}
\dot{x_{1}} \\
\dot{x_{2}} \\
\dot{x_{3}} \\
\end{bmatrix} = \begin{bmatrix}
0 & 1 & 0 \\
0 & 0 & 1 \\
 - A & - 1 & - B \\
\end{bmatrix}\begin{bmatrix}
x_{1} \\
x_{2} \\
x_{3} \\
\end{bmatrix} + \begin{bmatrix}
\beta_{1} \\
\beta_{2} \\
\beta_{3} \\
\end{bmatrix}u\]

and

\[y = \begin{bmatrix}
1 & 0 & 0 \\
\end{bmatrix}\begin{bmatrix}
x_{1} \\
x_{2} \\
x_{3} \\
\end{bmatrix} + \beta_{0}u\]

\(\beta\) values can be calculated as follows:

\[\beta_{0} = b_{0}\]

\[\beta_{1} = b_{1} - a_{1}\beta_{0}\]

\[\beta_{2} = b_{2} - a_{1}\beta_{1} - a_{2}\beta_{0}\]

\[\beta_{3} = b_{3} - a_{1}\beta_{2} - a_{2}\beta_{1} - a_{3}\beta_{0}\]

Where the values for \(a_{x}\text{\ and\ }b_{x}\)come from:

\[\dddot{y} + a_{1}\ddot{y} + a_{2}\dot{y} + a_{3}y = b_{0}\dddot{u} + b_{1}\ddot{u} + b_{2}\dot{u} + b_{3}u\]

\[\ddot{x}=(F-c\dot{x_{1}}-kx)/m\]
where
	x=position,$\dot{x}$=speed/velocity,$\ddot{x}$=acceleration
	c = damping constant,
	m = mass,
	F = force
	k = spring constant,

To perform inverse (find transfer function from statespace model)

\[G\left( s \right) = d + c{(sI - A)}^{- 1}b\]

where

\[\begin{bmatrix}
\dot{x_{1}} \\
\dot{x_{2}} \\
\dot{x_{3}} \\
\end{bmatrix} = \begin{bmatrix}
A_{11} & A_{12} & A_{13} \\
A_{21} & A_{22} & A_{23} \\
A_{31} & A_{32} & A_{33} \\
\end{bmatrix}\begin{bmatrix}
x_{1} \\
x_{2} \\
x_{3} \\
\end{bmatrix} + \begin{bmatrix}
b_{1} \\
b_{2} \\
b_{3} \\
\end{bmatrix}u\]

And

\[y = \begin{bmatrix}
c_{1} & c_{2} & c_{3} \\
\end{bmatrix}\begin{bmatrix}
x_{1} \\
x_{2} \\
x_{3} \\
\end{bmatrix} + \lbrack d\rbrack u\]

The inverse of a square 2x2 matrix is found by:

\[\begin{bmatrix}
a & b \\
c & d \\
\end{bmatrix}^{- 1} = \frac{1}{ad - bc}\begin{bmatrix}
d & - b \\
 - c & a \\
\end{bmatrix}\]

The inverse of a square 3x3 matrix is found by:
%\includegraphics[width=2.52147in,height=1.02367in]{media/image8.png}

For a 3×3 matrix
$$A=\begin{bmatrix}
	a_{11} & a_{12}  & a_{13} \\
	a_{21} & a_{22}  & a_{23}\\
	a_{31} & a_{32}  &  a_{33}
\end{bmatrix}$$
the matrix inverse is:

$$A^{-1}= \frac{1}{|A|}\begin{bmatrix}
\begin{bmatrix} a_{22} & a_{23} \\ a_{32} & a_{33}\end{bmatrix} & \begin{bmatrix} a_{13} & a_{12} \\ a_{33} & a_{32}\end{bmatrix} & \begin{bmatrix} a_{12} & a_{13} \\ a_{22} & a_{23}\end{bmatrix} \\
\begin{bmatrix} a_{23} & a_{21} \\ a_{33} & a_{31}\end{bmatrix}& \begin{bmatrix} a_{11} & a_{13} \\ a_{31} & a_{33}\end{bmatrix} & \begin{bmatrix} a_{13} & a_{11} \\ a_{23} & a_{21}\end{bmatrix} \\
\begin{bmatrix} a_{21} & a_{22} \\ a_{31} & a_{32}\end{bmatrix} & \begin{bmatrix} a_{12} & a_{11} \\ a_{32} & a_{31}\end{bmatrix} & \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22}\end{bmatrix}
\end{bmatrix}$$
Solving a three order polynomial, without a fancy calculator
\begin{align*}
& x = \left[q + \left[ q^2 + (r-p^2)^3\right ]^{1/2} \right]^{1 /3} \\
& \left[q - \left[ q^2 + (r-p^2)^3\right ]^{1/2} \right]^{1 /3} + p
\end{align*}
Where
\begin{align*}
& p = \frac{-b}{3a}, \ \ q =p^3 + \frac{bc-3ad}{3a^2}, \ \ r =\frac{c}{3a}
\end{align*}
\section{SECOND ORDER SYSTEMS}

\[G\left( s \right) = \frac{C(s)}{R(s)} = \frac{\omega_{n}^{2}}{s^{2} + 2\zeta\omega_{n}s + \omega_{n}^{2}}\]

\[K = \omega_{n}^{2};\ \ \ \ T = 2\zeta\omega_{n} = 2\sigma;\ \ \ \ \ \zeta = \frac{T}{2\sqrt{K}};\ \ \ \ \omega_{d} = \omega_{n}\sqrt{1 - \zeta^{2}}\]

\[\zeta = damping\ ratio; \sigma = real\ part\ of\ root;\]

\(\ \ \ \omega_{d} = damped\ natural\ frequency\)

\( omega_{n} = undamped\ natural\ frequency \)
%\includegraphics[width=1.96736in,height=1.37361in]{media/image9.png}

\[ Undamped:\ \zeta = 0;\]
\[ Critically\ Damped: \zeta = 1 \]
\[ Over\ Damped:\ \zeta > 1\]

Imaginary axis:

Frequency of oscillations

Real axis:

Decay time

\textbf{UNIT STEP RESPONSE OF A 2\textsuperscript{ND} ORDER UNDAMPED
SYSTEM}

$ t_{d}$ = delay time - to reach 50\% of $c\left( \infty \right) $\text{for the first time}.
$ t_{r}$ = rise time - time to reach 100 \% of $c\left( \infty \right)$ \text{for first time} .
$ t_{p}$ = peak time - time to reach first peak.
$ t_{s}$ = settling time - time to reach \& stay within 2\% or 5\%
$ M_{p}$ = maximum overshoot.
%\[{t_{d} = delay\ time - to\ reach\ 50\%\ of\ c\left( \infty \right)\text{for\ the\ first\ time}\backslash n}{t_{r} = rise\ time - time\ to\ reach\ 100\%\ of\ c\left( \infty \right)\text{for\ first\ time}\backslash n}{t_{p} = peak\ time - time\ to\ reach\ first\ peak\backslash n}{t_{s} = settling\ time - time\ to\ reach\ \&\ stay\ within\ 2\%\ or\ 5\%\backslash n}{M_{p} = maximum\ overshoot\ \left( \% \right)\backslash n}\]
\[{t_{r} = \frac{1}{\omega_{d}}\operatorname{}\left( - \frac{\omega_{d}}{\sigma} \right);\ \ \ \ t_{p} = \frac{\pi}{\omega_{d}}\backslash n}\]

\[{M_{p} = e^{- \frac{\zeta\omega_{n}\pi}{\omega_{d}}} = e^{- \frac{\eta \pi}{\sqrt{1 - \zeta^{2}}}} = e^{- \frac{\sigma \pi}{\omega_{d}}}}\]

\[t_{s} = \frac{4}{\sigma} = \frac{4}{\zeta\omega_{n}}\ \left( 2\%\ band \right)\]
\[t_{s} = \frac{3}{\sigma} = \frac{3}{\zeta\omega_{n}}\ \left( 5\%\ band \right)\]

Dominant poles are the ones closest to the imaginary axis

\section{ROUTH-HURWITZ STABILITY TEST}
\[a_0s^n + a_1s^{n-1}+ \cdots + a{n-1} s + a_n = 0\]
\[ \begin{array}{lllll}
\mbox{row n}   & a_0 & a_2 & a_4 & \cdots \\
\mbox{row n-1} & a_1 & a_3 & a_5 & \cdots \\
\mbox{row n-2} & b_1 & b_2 & b_3 & \cdots \\
\mbox{row n-3} & c_1 & c_2 & c_3 & \cdots \\
\cdots & \cdots & \cdots & \cdots & \cdots \\
\mbox{row 2} & * & * &  & \cdots \\
\mbox{row 1} & * &   &  & \cdots \\
\mbox{row 0} & * &   &  & \cdots \end{array} \]

\[ b_1=-\frac{det\left[\begin{array}{cc}a_0&a_2\\a_1&a_3\end{array}\right]}{a_1}
=\frac{a_1a_2-a_0a_3}{a_1} \]
\[ b_2=-\frac{det\left[\begin{array}{cc}a_0&a_4\\a_1&a_5\end{array}\right]}{a_1}
=\frac{a_1a_4-a_0a_5}{a_1} \]
\[ b_3=-\frac{det\left[\begin{array}{cc}a_0&a_6\\a_1&a_7\end{array}\right]}{a_1}
=\frac{a_1a_6-a_0a_7}{a_1} \]

\[ c_1=-\frac{det\left[\begin{array}{cc}a_1&a_3\\b_1&b_2\end{array}\right]}{b_1}
=\frac{b_1a_3-a_1b_2}{b_1} \]
\[ c_2=-\frac{det\left[\begin{array}{cc}a_1&a_5\\b_1&b_3\end{array}\right]}{b_1}
=\frac{b_1a_5-a_1b_3}{b_1} \]
\[ c_3=-\frac{det\left[\begin{array}{cc}a_1&a_7\\b_1&b_4\end{array}\right]}{b_1}
=\frac{b_1a_7-a_1b_4}{b_1} \]
\section{STEADY STATE ERROR ANALYSIS}

\[K_{p} = \operatorname{}{G\left( s \right)H(s)}\]

\[K_{v} = \operatorname{}{\text{sG}\left( s \right);\ \ \ \ K_{v} = \operatorname{}{s\left( \text{KG}\left( s \right) \right)}}\]

\[K_{a} = \operatorname{}{s^{2}G\left( s \right);\ \ \ \ K_{a} = \operatorname{}{s^{2}\left( \text{KG}\left( s \right) \right)}}\]

The type of system is determined by the number of poles at the origin.
For example:

%\includegraphics[width=2.60736in,height=0.52328in]{media/image10.png}

\section{ROOT LOCUS}

Root Locus presents the poles of the closed loop system when the gain K
changes from zero to infinity.

\textbf{Construction of the Root Locus}

Open loop transfer function

\[\text{KH}\left( s \right)G\left( s \right) = K\frac{B(s)}{A(s)}\]

m: the order of the \textbf{open-loop} numerator polynomial

n: the order of the \textbf{open-loop} denominator polynomial

\textbf{Rule 1:} number of branches equals the number of poles of the
open-loop transfer function

\textbf{Rule 2:} If the total number of poles and zeros of the open-loop
system to the right of the s-point on the real axis is odd, then this
point lies on the locus.

\textbf{Rule 3:} The locus starting point (K=0) are at the open-loop
poles and the locus ending points (K=$\infty$) are at the open loop zeros and
n-m branches terminate at infinity.

\textbf{Rule 4:} Slope of asymptotes of root locus as `s' approaches
infinity

\textbf{Rule 5:} Abscissa of the intersection between asymptotes of root
locus and real-axis.

%\includegraphics[width=2.13497in,height=0.89069in]{media/image11.png}

\textbf{Rule 6:} Break-away and break-in points. From the characteristic
equation

\[f\left( s \right) = A\left( s \right) + KB\left( s \right) = 0\ \ \ \ and\ \ \ \ K = - \frac{A\left( s \right)}{B\left( s \right)}\]

The break-away and break-in points can be found from

\[\frac{\text{dK}}{\text{ds}} = - \frac{A^{'}\left( s \right)B\left( s \right) - A\left( s \right)B^{'}\left( s \right)}{B^{2}\left( s \right)} = 0\]

\textbf{Rule 7:} Angle of departure from complex poles or zeros.
Subtract from 180° the sum of all angles from all other zeros and poles
of the open-loop system to the complex pole (or zero) with appropriate
signs.

\textbf{Rule 8:} Imaginary-axis crossing points. Use Ruth-Hurwitz table
to find value of K where system becomes unstable.

\section{BODE DIAGRAMS}

%\includegraphics[width=2.08800in,height=1.27279in]{media/image12.png}

\subsection{1. Gain Factor K:} Horizontal straight line at magnitude:
\(20\log{(K)}\text{dB}\)

Phase is zero.

\subsection{2. Integral or derivative factors}
\(\mathbf{(j\omega)}^{\mathbf{\pm 1}}\)

\[\left( \text{j}\omega \right)^{- 1}\  \rightarrow 20\log{\left| \frac{1}{\text{j}\omega} \right| = - 20\log\omega}\]

Magnitude: strait line with slope -20 dB/decade

Phase: -90°

\[\left( \text{j}\omega \right) \rightarrow 20\log\left| \text{j}\omega \right| = 20\log\omega\]

Magnitude: straight line with slope 20dB/decade

Phase: +90°

\subsection{3. First Order Factors}
\(\left( \mathbf{1 + j\omega T} \right)^{\mathbf{\pm 1}}\)

\begin{align}
& \left( 1 + j\omega T \right)^{- 1} \rightarrow 20\log\left| \frac{1}{1 + j\omega T} \right| \\ \notag
&= - 20\log\sqrt{1 + \omega^{2}T^{2}}\ \lbrack dB\rbrack
\end{align}

Approximation for Magnitude:

\[For\ \omega\ between\ 0\ and\ \frac{1}{T}\  \rightarrow 0dB\]
\[For\ \omega\  \gg \frac{1}{T} \  \rightarrow - 20dB/decade\]

Phase:

\[\omega = 0\  \rightarrow \varphi = 0\]
\[\omega = \frac{1}{T} \rightarrow \varphi = - 45\]
\[\omega = \infty \rightarrow \varphi = - 90 \]

\[\left( \mathbf{1 + j\omega T} \right)^{\mathbf{+ 1}}\]

\subsection{4. Quadratic Factors}

\[G\left( \text{j}\omega \right) = \frac{1}{1 + 2\zeta\left( \frac{\omega}{\omega_{n}} \right) + \left( \frac{\text{j}\omega}{\omega_{n}} \right)^{2}}\ \ ;\ \ 0 < \zeta < 1\]

Approximation for magnitude:

\[\omega \ll \omega_{n} \rightarrow 0dB\]

\[\omega \gg \omega_{n} \rightarrow - 20\log\left( \frac{\omega^{2}}{\omega_{n}^{2}} \right) = - 40\log{\left( \frac{\omega}{\omega_{n}} \right)\text{dB}}\]

\[Phase:\]

\[\omega = 0\  \rightarrow \varphi = 0\]
\[\frac{\omega}{\omega_{n}} = 1 \rightarrow \varphi = - 90\backslash \]
\[\omega = \infty \rightarrow \varphi = - 180 \]

\[Resonant\ Frequency:\]
	\[\omega_{r} = \omega_{n}\sqrt{1 - 2\zeta^{2}}\ \ for\ 0 < \zeta < 0.707\]

\[Resonant\ Peak\ Value:\]
\[M_{r} = \left| G\left( \text{j}\omega \right) \right|_{\max} = \frac{1}{2\zeta\sqrt{1 - \zeta^{2}}} \ for\ 0 < \zeta < 0.707 \]

Consider

\[ G_{1}\left( s \right) = \frac{1}{1 + Ts} \ G_{2}\left( s \right) = \frac{1}{1 - Ts} \ G_{3}\left( s \right) = \frac{1}{Ts - 1} \]

Then\ldots{}

\[\left| G_{1}(j\omega) \right| = \left| G_{2}(j\omega) \right| = \left| G_{3}(j\omega) \right|\]

And\ldots{}

\[\angle G_{2}\left( \text{j}\omega \right) = - \angle G_{1}\left( \text{j}\omega \right) and \]
\[ \angle G_{3}\left( \text{j}\omega \right) = 180 - \angle G_{1}\left( \text{j}\omega \right)\]

\[+ 90\ and\ \angle G_{3}\left( \text{j}\omega \right)\ goes\ from - 180\ to - 90\]

Generate based on the Bode Plot.

\textbf{The Nyquist Stability Criterion:} relates the stability of the
closed loop system to the frequency response of the open loop system.

\[Z = N + P\]

\textbf{Z:} Number of zeros of $(1+H(S)G(s))$ in the right half plane =
number of unstable poles of the closed-loop system.

\textbf{N:} Number of clockwise encirclements of the point $-1+j0$.

\textbf{P:} Number of poles of $G(s)H(s)$ in the right half plane.

If the plot makes a counter-clockwise encirclement of the $-1+j0$ point
then N becomes -1.

If Z = 0 the closed loop system is stable. If Z \textgreater{} 0 the
closed loop system has Z unstable poles. If Z \textless{} 0 a mistake
has been made and the calculations need to be rechecked.

\section{PHASE AND GAIN MARGINS}

A measure for relative stability of the closed-loop system is how close
\(G(j\omega)\), the frequency response of the open-loop system, comes to
the point $-1+j0$. This is represented by the phase and gain margins.

\textbf{Phase Margin:} The amount of additional phase lag at the Gain
Crossover Frequency \(\omega_{0}\) required to bring the system to the
verge of instability.

Gain crossover frequency:
\(\omega_{0}\text{\ for\ which\ }\left| G\left( j\omega_{0} \right) \right| = 1\)

Phase margin:
\(\gamma = 180 + \angle G\left( j\omega_{0} \right) = 180 + \phi\)

\textbf{Gain Margin:} The reciprocal of the magnitude
\(\left| G(j\omega_{1}) \right|\) at the Phase crossover frequency
\(\omega_{1}\) required to bring the system to the verge of instability.

Phase crossover frequency:
\(\omega_{1}\ where\ \angle G\left( j\omega_{1} \right) = - 180\)

Gain margin:

\[K_{g} = \frac{1}{\left| G(j\omega_{1}) \right|}\]

\[K_{g} = - 20\log\left| G\left( j\omega_{1} \right) \right|\]

\[K_{g}\ in\ dB > 0 = stable\] for minimum phase systems.
	\[K_{g}in\ dB < 0\] = unstable for minimum phase systems.

\textbf{Minimum phase systems:} all poles and zeros are in the left half
plane.

If the open-loop system is minimum phase and has both phase and gain
margins positive then the closed-loop system is stable.

For good relative stability both margins are required to be positive.

Good values for minimum phase system are:

Phase Margin: 30°-60°

Gain Margin: above 6dB

\end{multicols}


\iffalse
It's unfair to say that mathematicians aren't real doctors, we perform surgeries all the time. In this class we'll introduce the notion of a topological manifold via simplicial (delta) complexes. Spend a day or two doing examples and go over several notions like orientation, cobordism and of course surgery.

Keywords: simplicial complex, manifold, orientation, cobordism, surgery

Type: Lecture
Homework: Recommended
Prereqs: None
\fi

\input{../preamble}

\rhead{\scshape Mathcamp 2017 : All things Manifoldy}

\begin{document}
\title{Surfaces}
\author{Apurva Nakade}
\thispagestyle{fancy}
\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Real projective space $\R\P^2$}
One way to define the projective plane is by gluing the antipodal points on the disc. In this section we'll see how this corresponds to lines in $\R^3$.

Consider the upper hemisphere
\begin{align*}
	S^2_+ = \{ (x,y,z) : x^2 + y^2 + z^2 = 1 , z\ge 0\}
\end{align*}
Every line in $\R^3$ intersects $S^2_+$ in exactly one point, unless the line is along the $x-y$ plane in which case it intersects $S^2_+$ boundary in antipodal points. Thus the set of lines in $\R^3$ is in 1-1 correspondence with the points on $S^2_+$ but with the antipodal points on the boundary circle glued, but this is precisely $\R\P^2$!

\begin{figure}[H]
	\centering
	\includegraphics[width=0.25\linewidth]{images/ProjectivePlane}
	\caption{Real projective plane}
\end{figure}

\begin{exercise}
	Describe the space $\R\P^1$, the space of lines in $\R^2$.
\end{exercise}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Poincar\'e conjecture}

Poincar\'e conjecture is perhaps the most celebrated conjecture in the theory of manifolds. It's solution(s) led to creation of a lot of amazing mathematics. For 3 dimensional manifolds the conjecture is as follows.

\begin{thm}[Poincar\'e conjecture]
	Let $M$ be a compact connected 3 dimensional manifold (without boundary). Suppose every loop on $M$ can be shrunk to a point then $M$ is homeomorphic to the 3 dimensional sphere $S^3$.
\end{thm}

There is a generalization of this conjecture to higher dimensions which requires a little more language to state. Surprisingly the conjecture was first proven to be true for dimensions $\ge 5$ by Smale, next for dimension 4 by Freedman and finally for dimension 3 by Perelman. The conjecture is \textbf{false} in the `category' of smooth manifolds i.e. if we replace homeomorphism by something stronger like diffeomorphism. The fact that the conjecture is true in the topological `category' but false in the smooth `category' implies the existence of \textbf{exotic manifolds}. Exotic spheres were first discovered by Milnor and only exist in dimensions 7 and higher. Freedman proved that $\R^4$ is the only Euclidean space which supports an exotic structure.

The Poincar\'e conjecture in dimension 2 follows from the classification theorem for surfaces.

\begin{thm}[Classification of surfaces]
	Every compact connected 2-dimensional manifold (without boundary) is homeomorphic to one of the following:
	\begin{enumerate}
		\item $S^2$
		\item $T^{\#k}$ for some $k$
		\item $(\R\P^2)^{\#k}$ for some $k$
	\end{enumerate}
\end{thm}

The Poincare conjecture for 2 dimensions is an easy consequence of this theorem.

\begin{exercise}
	Find a loop on each of the following spaces $T$, $\R\P^2$ and $K$ which cannot be shrunk to a point.
\end{exercise}

\begin{exercise}
	Show that for any compact connected manifold $M$ there is a loop in each of the spaces $M \# T$ and $M \# \R\P^2$ which cannot be shrunk to a point.
\end{exercise}

\begin{exercise}
	For a compact connected 2 dimensional manifold $M$ (without boundary) show that if every loop on $M$ can be shrunk to a point then $M$ is homeomorphic to $S^2$.
\end{exercise}

\iffalse
A two dimensional manifold is called a surface. The surface of the earth is an example of a two dimensional manifold. By the above definition a surface is set $S$ such every point $s \in S$ has a neighborhood homeomorphism to a 2 dimensional disk.

\begin{figure}[H]
	\centering \includegraphics[width=0.85\linewidth]{images/GegusGSurfaces}
	\caption{Surfaces}
\end{figure}

\subsection{Connected sums}
It is not hard to see that we can make sense of `addition' of two surfaces, after all when we think of a genus $g$ surface we think of $g$ tori glued to each other.

If $M_1$ and $M_2$ are two surfaces of genus $g_1$ and $g_2$ then we can `add' $M_1$ and $M_2$ to get a surface of genus $g_1+ g_2$. This is done by removing a small disc from $M_1$ and $M_2$ each and gluing $M_1$ and $M_2$ along the holes. The resulting manifold is denoted by $M_1 \# M_2$ and is called their \textbf{connected sum}.

We will denote a torus by $T$ and a genus $g$ surface by $T \# \cdots \# T$, $g$ times or simply as $T^{\#g}$.

\begin{figure}[h]
	\centering \includegraphics[width=0.40\linewidth]{images/ConnectedSum}
	\caption{Connected sum}
\end{figure}

Thus it is possible to add two surfaces but not subtract them. There is also an \emph{identity element} for this connected sum operation (what is it?). This is more formally expressed by saying that the set of surfaces (up to homeomorphism) is a \textbf{monoid}.

\begin{exercise}
	Define connected sum for arbitrary manifolds.
\end{exercise}

\begin{exercise}
	In the definition of connected sum we removed arbitrary discs from the manifolds $M_1$ and $M_2$. Draw pictures to show that if any two such choices can be deformed into each other and hence up to homeomorphism the manifold $M_1 \# M_2$ is well defined. Can you come up with a rigorous proof for this?
\end{exercise}

\begin{ques}
	Is every surface a genus $g$ surface for some integer $g$?
\end{ques}
The answer is no. The most famous example is perhaps the Klein bottle. The Klein bottle is an example of a non-orientable surface (a surface with only 1 side) and it cannot be embedded in $\R^3$.
\begin{figure}[H]
	\centering
	\includegraphics[width=0.15\linewidth]{images/KleinBottle}
	\caption{Klein bottle}
\end{figure}

There is an amazing theorem that holds for 2 dimensional manifold but which does not hold in any higher dimension.

\begin{thm}[Classification of surfaces]
	Every compact connected 2 dimensional manifold is homeomorphic to one of the following
	\begin{enumerate}
		\item $S^2$
		\item $T^{\#g}$
		\item $(\R\P^2)^{\#g}$
	\end{enumerate}
\end{thm}
We'll define the surface $\R\P^2$, called the \textbf{real projective plane} below. If we think of a 2 dimensional manifold sitting inside some $\R^n$ then \textbf{compact connected} means that as a set the manifold is \textbf{closed} and \textbf{bounded}. If you do not know what these words mean then intuitively compact connected means that the manifold has no punctures in it and it does not extend to infinity.

How might one try to prove such a theorem? We'll use a technique very popular in topology called cutting and pasting!

\subsection{Gluing diagrams}
\begin{ques}
	What does a connected sum of a Klein bottle and a torus give us? What is the connected sum of two Klein bottles?
\end{ques}

To answer the above question we try to covert the problem into combinatorics by cutting open the surface. If cut a torus once we get a cylinder and we cut the cylinder again we get a square. On the square we label the sides to remember which side should be glued to which to get back the torus. Such a diagram is called a \textbf{gluing diagram}.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.20\linewidth]{images/GluingDiagramTorus}
	\caption{Gluing diagram for a torus}
\end{figure}

Can we find gluing diagrams for other surfaces? The connected sum comes to the rescue. We can use connected sums to construct gluing diagrams using $2g$ sided polygons to construct $g$ genus surfaces, as in figure \eqref{ConnectedSumGluingDiagram}.

\begin{figure}[h]
	\centering
	\includegraphics[width=0.50\linewidth]{images/GluingDiagramConnectedSum1}
	\includegraphics[width=0.60\linewidth]{images/GluingDiagramConnectedSum2}
	\caption{Connected sum and gluing diagrams}
	\label{ConnectedSumGluingDiagram}
\end{figure}

This is an interesting development. Perhaps we can even find a gluing diagram for the Klein bottle. What happens when you cut open the Klein bottle?

\begin{figure}[H]
	\centering
	\includegraphics[width=0.20\linewidth]{images/GluingDiagramKleinBottle}
	\caption{Gluing diagram for a Klein bottle}
\end{figure}

\begin{ques}
	What happens if we do not put arrows on all the edges?
\end{ques}

\begin{ques}
	What do open sets and line segments look like on the gluing diagrams?
\end{ques}

\begin{ques}
	When does the gluing diagram give us a manifold?
\end{ques}

\begin{ques}
	Can you come up with a gluing diagram for a sphere?
\end{ques}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Classifying surfaces}
Notice that if we flip the directions of both the arrows labelled $a$ on the gluing diagram for a torus we get the torus back, but if we flip only one of the $a$ while keeping the other fixed we get a Klein bottle. This begs the question,

\begin{ques}
	What happens when we flip both the arrows on the torus gluing diagram?
\end{ques}
This gives us the \textbf{Projective plane} denoted by $\R\P^2$. This is the space that we encountered in the classification theorem.
\begin{figure}[H]
	\centering
	\includegraphics[width=0.20\linewidth]{images/GluingDiagramProjectivePlane}
	\caption{Gluing diagram for the Projective Plane $\R\P^2$}
\end{figure}

The proof of the classification theorem has two main steps. First comes from point set topology. First we show that any compact connected surface gives rise to a gluing diagram. This is a highly non-trivial fact that we will assume. The proof of this requires some knowledge of the fundamental group.

The second step is the showing that any gluing diagram is of one of three types listed in the classification theorem.

\subsection{The algebra of gluing diagrams}
We saw how connected sums allowed us to construct gluing diagrams for genus $g$ surfaces. A connected sum is a cutting and pasting operation. We can do more interesting cutting and pasting operations and produce some non-trivial results about gluing diagrams.

\begin{figure}[h]
	\centering
	\includegraphics[width=0.75\linewidth]{images/GluingDiagramKleinBottleMobiusStrip}
	\caption{Klein bottle is the connected sum of two Mobius strips}
\end{figure}
\fi
\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Modular origami}

\subsection{Orientation of surfaces}
Let us start with surfaces. Roughly speaking a surface is called orientable if has two sides. A sphere or a torus are easily seen to be orientable. In fact any surface that can be \textit{embedded} in $\R^3$ is orientable. A Mobius strip on the other hand (which is not a surface as it has a boundary) is not orientable. With a little more mental effort one might be able to see that a Klein bottle or a Projective space are not orientable. We want an equivalent definition which can be used on gluing diagrams.

We begin by defining orientation of a polygon. An \textbf{orientation of a polygon} is simply a cyclic ordering of it's vertices. For example this is one of the two possible ways to orient a triangle with vertices $(0,1,2)$.

\begin{center}
	\begin{tabular}{c}
		\centering \includegraphics[height=3cm]{../noImageAvailable}
	\end{tabular}
\end{center}

\begin{exercise}
	This is related to the fact that the polygon has two sides via the right hand rule in physics. Do you see the connection?
\end{exercise}

An \textbf{orientation} of (a gluing diagram of) a surface is a compatible choice of orientation for each triangle, where the orientations of two adjacent triangles need to be compatible in the following way,
\begin{center}
	\begin{tabular}{c c c}
		\centering \includegraphics[height=3cm]{../noImageAvailable} & \: & \centering \includegraphics[height=3cm]{../noImageAvailable}
	\end{tabular}
\end{center}
This forces an edge to be directed in two different directions in adjacent triangles.

\begin{exercise}
	Add the diagonals to the standard gluing diagrams to obtain triangulations and try to find orientations for them. Conclude that $S^2,T$ are orientable and $\R\P^2,K$ are not.
\end{exercise}

\begin{exercise}
	Use gluing diagrams to show that $T\#T$ is orientable. Generalize this to argue that $T ^{\# n}$ are orientable.
\end{exercise}

This same method also allows us to understand manifolds in higher dimensions as well.

\subsection{Simplices}
As we go to higher dimensions polygons (or is it polytopes?) become whacky are themselves quite hard to understand. So instead of looking at arbitrary polygons we look at the simplest polygons: triangles. We'll upgrade the definition of a triangle to a simplex which can live in arbitrary dimensions.

\begin{definition}
	An $n$ dimensional \textbf{simplex} $\Delta^n$ is any set which is homeomorphic to the following region in $\R^{n}$.
	\begin{align}
		\{ (x_0, x_1, \cdots, x_n) : x_0 + \cdots + x_n \le 1 \mbox{ and each } x_i \ge 0  \}
	\end{align}
\end{definition}
A 1 dimensional simplex is a segment and a 2 dimensional simplex is a triangle.
Simplices are topologists best friend.

Note that by adding extra diagonal lines we could have made the gluing diagrams entirely out of triangles.
We represent a simplex by its set of vertices.

\begin{figure}[h]
	\centering \includegraphics{../noImageAvailable}
	\caption{Gluing diagram with labeled simplices}
	\label{}
\end{figure}

As with origami you can glue these simplices any way you want and get relaly interesting objects. We're going to glue them to create manifolds.

\subsection{Manifolds from simplices}
A delta complex is a collection of simplices glued along the faces.

\begin{definition}
	Faces of a simplex followed by examples.
\end{definition}

\begin{definition}
	Definition of a delta complex followed by several examples.
\end{definition}

Talk about spheres, tori and projective spaces in 3 dimensions.

\begin{ques}
	When is a delta complex a manifold?
\end{ques}

Examples of manifolds and non-manifolds.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{More on manifolds}
The last day is a little more on the expository side.

We saw how a Dehn surgery can be used to simplify a knot on a torus. We also saw how a connected sum can be used to build higher genus surfaces out of simpler ones.

Is it possible to simply go the other way? Can one reverse the connected sum operation and go from a more complicated manifold to a simple one?

\subsection{Orientation of manifolds}

Show that $\R\P^1$ and $\R \P^3$ are orientable but $\R\P^2$ is not using Delta complexes.

\subsection{Cutting $S^3$ into tori}

\subsection{Using Dehn twists to create 3 manifolds}

\end{document}

01 All things manifoldy/03 - Surfaces.tex


\section{Properties of a Random Sample}

\begin{definition}[Random Sample]
    A collection of random variables $X_1, \dots, X_n$ is a \emph{random sample of size n from population $f(x)$} if they are iid with pdf/pmf f(x).
\end{definition}

\begin{definition}[Statistic]
    $Y = T(X_1, \dots, X_n)$ is a \emph{statistic} if the domain of $T$ contains the sample space of $(X_1, \dots, X_n)$. The distribution of $Y$ is the \emph{sampling distribution of $Y$}.
\end{definition}

\begin{remark}
    A statistic is any function of the data. The only restriction is that the statistic is not also a function of some other parameters.
\end{remark}

\begin{definition}[Sample Mean and Sample Variance]
    The \emph{sample mean} $\bar{X}$ and \emph{sample variance} $S^2$ of a random sample $X_1, \dots, X_n$ are, respectively,
    \begin{itemize}
        \item $\bar{X} = \frac1n \sum_{i=1}^n X_i$
        \item $S^2 = \frac{1}{n-1}\sum_{i=1}^n (X_i - \bar{X})^2$.
    \end{itemize}
    The \emph{sample standard deviation} is $S = \sqrt{S^2}$.
\end{definition}

\begin{theorem}[Some facts]
    Let $X_1, \dots, X_n$ be a random sample from a population with mean $\mu$ and finite variance $\sigma^2$, then
    \begin{enumerate}[a.]
        \item $\E{}[\bar{X}] = \mu$
        \item $\Var{}[\bar{X}] = \frac{\sigma^2}{n}$
        \item $\E{}[S^2] = \sigma ^2$.
    \end{enumerate}
\end{theorem}

\begin{theorem}
    Take $x_1, \dots, x_n \in \R{}$ and let $\bar{x}$ be their mean. Then,
    \begin{enumerate}[a.]
        \item $\min_a \sum_{i=1}^n (x_i - a)^2 = \sum_{i=1}^n (x_i - \bar{x})^2$
        \item $(n-1)s^2 = \sum_{i=1}^n(x_i - \bar{x})^2 = \sum_{i=1}^n x_i^2 - n\bar{x}^2$.
    \end{enumerate}
\end{theorem}

\begin{theorem}
    Let $X_1, \dots, X_n$ be a random sample from population $f(x\vert{}\vec{\theta})$ belonging to an exponential family
    \[
        f(x \vert{} \vec{\theta}) = h(x)c(\vec{\theta}) \exp\left(\sum_{i=1}^k w_i(\vec{\theta})t_i(x)\right).
    \]
    Define the statistics
    \[
        T_i(X_1, \dots, X_n) = \sum_{j=1}^n t_i(X_j), \quad i=1, \dots, k.
    \]
    Then if the set $\{(w_1(\vec{\theta}), \dots, w_n(\vec{\theta}), \, \theta \in \Theta\}$ contains and open subset of $\R{}^k$ then the distribution of $(X_1, \dots, X_n)$ is an exponential family of the form
    \[
        f(u_1, \dots, u_n \vert{} \vec{\theta}) = H(u_1, \dots, u_n) c(\vec{\theta})^n \exp\left(\sum_{i=1}^kw_i(\vec{\theta})u_i\right).
    \]
\end{theorem}

\begin{remark}
    The open condition eliminates curved exponential families from this result.
\end{remark}

\subsection{Sampling from the Normal Distribution}

\begin{theorem}
    Let $X_1, \dots, X_n$ be a random sample from a $\n(\mu, \sigma)$ distribution. Then,
    \begin{itemize}
        \item $\bar{X}$ and $S^2$ are independent
        \item $\bar{X} \sim \n(\mu, \sigma^2/n)$
        \item $(n-1)S^2/\sigma^2 \sim \chi^2_{n-1}$.
    \end{itemize}
\end{theorem}

\begin{lemma}[Covariance and independence]
    In the case of samples from a multivariate normal
    \begin{itemize}
        \item Independence $\iff$ vanishing covariance
        \item Pairwise independence $\iff$ independence
    \end{itemize}
\end{lemma}

\subsection{Convergence Concepts}

\subsubsection{Convergence in Probability}
\begin{definition}
    A sequence of random variables $\{X_i: i \in \N \}$ \emph{converges in probability} to a random variable $X$ if $ \forall \epsilon > 0$
    \[
        \lim_{n\to\infty}\P{}(\abs{X_n - X} \geq \epsilon) = 0
    \]
    (or equivalently if $\lim_{n\to\infty}\P{}(\abs{X_n - X} < \epsilon) = 1$).
\end{definition}

\begin{theorem}[Weak Law of Large Numbers]
    Let $X_1, X_2, \dots$ be iid RVs with mean $\mu$ and $\E{}[\abs{X_i}] < \infty$. Define $\bar{X}_n = \frac1n \sum_{i=1}^n$. Then the sequence $\bar{X}_n$ converges in probability to $\mu$. That is, $\forall \epsilon > 0$
    \[
        \lim_{n\to\infty} \P{}(\abs{X_n - \mu} < \epsilon) = 1
    \]
\end{theorem}

Proof is using Chebychev's inequality.

\begin{theorem}
    If $X_1, X_2, \dots$ converges in probability to $X$ and $h$ is a continuous function, then $h(X_1), h(X_2), \dots$ converges in probability to $h(X)$.
\end{theorem}

\subsubsection{Almost Sure Convergence}

\begin{definition}
    A sequence of random variables $X_1, X_2, \dots$ \emph{converges almost surely} to a random variable $X$ if $ \forall \epsilon > 0$
    \[
        \P{}\left(\lim_{n\to\infty} \abs{\bar{X}_n - X} < \epsilon\right) = 1.
    \]
\end{definition}

\begin{comments}
    \mbox{}
    \begin{itemize}[+]
        \item Almost sure convergence is much stronger than convergence in probability. Convergence in probability states that the sequence of measures of the sets on which the sequence has finite difference from its the limit converges to 0. Almost sure convergence states that any place where the sequence has finite difference from its limit must have measure 0. It's like a sequence of integrals converging vs. whether the integrands converge.
        \item Almost sure convergence implies convergence in probability but not the other way around.
    \end{itemize}
\end{comments}

\begin{theorem}
    If a sequence converges in probability then it is possible to find a subsequence that converges almost surely.
\end{theorem}

\begin{theorem}[Strong Law of Large Numbers]
    Let $X_1, X_2, \dots$ be iid RVs with mean $\mu$ and $\E{}[\abs{X_i}] < \infty$. Define $\bar{X}_n = \frac1n \sum_{i=1}^n$. Then the sequence $\bar{X}_n$ converges almost surely to $\mu$. That is, $\forall \epsilon > 0$
    \[
         \P{}\left(\lim_{n\to\infty}\abs{\bar{X}_n - \mu} < \epsilon\right) = 1.
    \]
\end{theorem}

\subsubsection{Convergence in Distribution}

\begin{definition}
    A sequence of random variables $X_1, X_2, \dots$ \emph{converges in distribution} to a random variable $X$ if
    \[
        \lim_{n \to \infty} F_{X_n}(x) = F_X(x)
    \]
    at all points where $F_X$ is continuous.
\end{definition}

\begin{remark}
    Here it is really the cdfs that converge, rather than the random variables. In this way convergence in distribution differs from the previous two concepts.
\end{remark}

\begin{theorem}
    Convergence in probability implies convergence in distribution
\end{theorem}

\begin{theorem}[Central Limit Theorem]
    Let $X_1, X_2, \dots$ be a sequence of iid random variables with $\E{}[X_i] = \mu$ and finite variance $\Var{}[X_i] = \sigma^2 < \infty$. Define $\bar{X}_n = \frac1n \sum_{i=1}^n X_i$. Let $G_n(x)$ denote the cdf of $\sqrt{n}(\bar{X}_n - \mu)/\sigma$. Then $\forall x \in \R$,
    \[
        \lim_{n\to\infty} G_n(x) = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^x e^{-y^2/2}\d{}y.
    \]
    That is, $\sqrt{n}(\bar{X}_n - \mu)/\sigma$ converges in distribution to the standard normal.
\end{theorem}

\begin{theorem}[Slutsky's Theorem]
    If $X_n \to X$ in distribution and $Y_n \to a$ in probability with $a$ constant, then
    \begin{enumerate}[a.]
        \item $Y_nX_n \to aX$ in distribution
        \item $X_n + Y_n \to X + a$ in distribution
    \end{enumerate}
\end{theorem}

\begin{remark}
    This tells us, for instance, that
    \[
        \frac{\sqrt{n}(\bar{X}_n - \mu)}{S_n} \to \n(0, 1)
    \]
    in distribution, since we know that $S_n \to \sigma$ in probability.
\end{remark}

\subsubsection{The Delta Method}
If we are interested in the convergence of some function of a sequence of RVs, rather than the RVs themselves, then we can use the Delta Method (follows from an application of Taylor's theorem and Slutsky's theorem).

\begin{theorem}[Delta Method]
    Let $Y_n$ be a sequence of random variables that satisfies $\sqrt{n}(Y_n - \theta) \to \n(0, \sigma^2)$ in distribution. For a given function $g$ and a specific value of $\theta$, suppose that $g'(\theta)$ exists and is non-zero. Then
    \[
        \sqrt{n}[g(Y_n) - g(\theta)] \to \n(0, \sigma^2g'(\theta)^2)
    \]
    in distribution.
\end{theorem}

\begin{remark}
    There exists a corresponding multivariate result.
\end{remark}

If $g'(\theta) = 0$ then we take the next term in the Taylor series.

\begin{theorem}[Second Order Delta Method]
    Let $Y_n$ be a sequence of random variables that satisfies $\sqrt{n}(Y_n - \theta) \to \n(0, \sigma^2)$ in distribution. For a given function $g$ and a specific value of $\theta$, suppose that $g'(\theta) = 0$ and $g''(\theta)$ exists and is non-zero. Then
    \[
        \sqrt{n}[g(Y_n) - g(\theta)] \to \n(0, \sigma^2g'(\theta)^2)
    \]
    in distribution.
\end{theorem}

\subsection{Generating A Random Sample}

\begin{definition}[Direct Method]
    A \emph{Direct Method} of generating a random sample uses the probability integral transform to map draws from a $\text{uniform}(0, 1)$ random variable to draws from the distribution of interest.\\

    The Probability Integral Transform states that if $X$ has continuous cdf $F_X(x)$ then
    \[
        F_X(X) \sim \text{uniform}(0, 1).
    \]
\end{definition}

\begin{definition}[Accept-Reject Algorithm]
    Let $Y \sim f_Y(y)$ and $V \sim f_V(v)$ where $f_Y$ and $f_V$ have common support with
    \[
        M = \sup_y f_Y(y) / f_V(y) < \infty.
    \]
    To generate a random variable $Y \sim f_Y$:
    \begin{enumerate}[a.]
        \item Generate $U \sim \text{uniform}(0, 1)$, $V \sim f_V$ independent.
        \item If $U < \frac 1M f_Y(V)/f_V(V)$, return $V$ as a sample of $Y$; otherwise go back to (a.).
    \end{enumerate}
\end{definition}

\begin{remark}
    \mbox{}
    \begin{itemize}
        \item It is typical to call $V$ the \emph{candidate density} and $Y$ the \emph{target density}.
        \item One would normally try to choose a candidate density with heavier tails than the target density (e.g. Cauchy and normal) to ensure that the tails of the target are well represented. If the target has heavy tails, however, it can be hard to find a candidate that results in finite $M$. In this case people turn to MCMC methods.
        \item Note that $\P{}(\texttt{terminate}) = 1/M$. The number of trials to generate one sample of $Y$ is therefore $\text{geometric}(1/M)$, with $M$ the expected number of trials.
        \item The intuition behind this algorithm is that if we consider placing the density of a random variable $Y$ in a box (2d for simplicity) with coordinates $(v,u)$, we express the cdf of $Y$ using $V, U \sim \text{uniform}(0, 1)$
        \[
            \P{}(Y \leq y) = \P{}(V \leq y \vert{} U \leq \frac1c f_Y(V))
        \]
        where $c = \sup_y f_Y(y)$. In the actual algorithm we take $U \sim \text{uniform}(0,1)$ and $V$ to be an RV that has common support with $Y$.
    \end{itemize}
\end{remark}


%!TEX root =  ../../master.tex

\subsection{Results of the dispersion method in three dimensions}

\begin{figure}[!htb]
	\centering
    \scalebox{0.8}{\input{figure/ere-contact-fitted_a-inv_+0.0_zeta_dispersion_projector_a1g_n-eigs_200.pgf}}
    \caption{The same as \Figref{unimproved spherical}, but tuned and subsequently analyzed using the appropriate latticized \Luscher function, matching the cutoff on the sum to the lattice scale and accounting for the dispersion relation.
    We emphasize the results are on a log scale, and the tuning was to $-1/a_3 = 0$.
    }
    \label{fig:unimproved dispersion}
\end{figure}

In this section, we again attempt to tune our contact interaction to unitarity by matching the first zero of the zeta function.
However, the difference is that at each lattice spacing we tune to that spacing's respective $S^{\dispersion}_3$, leveraging the dispersion relation for that derivative.
Then, when we extract finite-volume and finite-spacing energy levels, we put them through the dispersion equation \eqref{dispersion-zeta-contact} using the same $S^{\dispersion}$ function.
The numerical results of said procedure are shown in \Figref{unimproved dispersion}.
Note that the results for $p\cot\delta$ are now flat across the spectrum, matching the known result for a contact interaction.
Moreover, comparing the scale to that in, for example, \Figref{unimproved spherical}, there the deviations were of order~1, while here the results remain within $10^{-8}$ of zero, with the value entirely reflecting how well the contact interaction was tuned.
Put another way, we have verified that the dispersion zeta function provides exact finite-spacing energy levels for our contact interaction \eqref{p space hamiltonian}, just as one would hope for a contact interaction in the continuum.

\begin{figure}[!hbt]
	\centering
    \scalebox{0.7}{\input{figure/contact-scaling-contact-fitted_a-inv_+0.0_zeta_dispersion_projector_a1g_n-eigs_200.pgf}}
    \caption{
        Scaling of the contact interaction strength $C_R^{(n_s)}(\epsilon)$ fitted using the dispersion method at unitarity.
        Data points are values of the contact interaction fitted to the first intersection of the phase shifts with the dispersion zeta function.
        The solid lines are analytic scaling predictions following \eqref{dispersion-renormalization} and the dashed line corresponds to the spherical counter term $ \mathcal{L}^{\spherical}_3 = 2 \pi$.
        Bar diagrams below present the absolute error between prediction and extracted value.
    }
    \label{fig:dispersion running of strength}
\end{figure}

In \Figref{dispersion running of strength} we show how the strength of the contact interaction runs with the lattice scale according to the analytic expectation \eqref{dispersion-renormalization}.
Note that the lines are not fits to the data; though the difference is down at $10^{-12}$ or better.
Again, this difference depends on the accuracy of the tuning.

We note that
\begin{enumerate}
	\item when matching the contact interaction parameter using spherical \Luscher data and finite spacing eigenvalues, the data points did not exactly match the analytic spherical contact scaling.
	The error at the smallest lattice spacing had a relative error on the percent scale and it got worse for larger lattice spacings.
	\item even in the limit of $n_s \to \infty$ the dispersion counter term $\mathcal{L}^\dispersion_3$ will not match the spherical counter term $\mathcal{L}^{\spherical}_3$.
At any finite $N$ the spherical integral and cartesian integrals differ---if the radius of the sphere is $N/2$, the corners of the lattice's Brillouin zone are absent; the cartesian integral matches the Brillouin zone correctly, critical for any finite-$N$ result.
\end{enumerate}

\subsection{Momentum-induced terms of  \texorpdfstring{$S^\bigcirc_3(x^\dispersion)$}{S3-spherical} due to discretization\label{sec:3d induced momenta}}
The zeta function in L\"uscher's formula, $S^\bigcirc_3(x)$, is derived in the continuum.
As such, it requires continuum energies $x$ for its argument.
If one instead feeds discretized energies $x^\dispersion$ through $S^\bigcirc_3(x)$ then momentum-dependent terms are subsequently induced.

\begin{figure}[htb]
    \scalebox{0.8}{\input{figure/3dtuned.pgf}}
    \caption{
        Here we show a contact interaction in three dimensions with the ground state tuned to the first zero of the spherical zeta function $S^{\spherical}_3$ on cubic lattices with $N=10,$ 20, 40, 80 (squares, diamonds, hexagons, and circles, respectively), with the resulting spectrum analyzed with $S^{\spherical}_3$ (colored points) and the $N$-appropriate $S^{\dispersion}_3$ (black points).
        The gray dashed line is $S^\spherical_3$ and the thin vertical lines are at the non-interacting $x$s where it diverges.
        The colored lines are the second-order analytic prediction for the difference between the dispersion and spherical analysis as a function of $x$.
        For clarity of the continuum limit we show, in the bottom panel, a limited range in $x$ and $pL\cot\delta_{30}$, where it is clear that each $N$ hits the zero of $S^\spherical_3$ but that the flat behavior at any finite $N$ is away from an infinite scattering length when analyzed with $S^\dispersion_3$.
    }
    \label{fig:3d-corrections}
\end{figure}

This is particularly evident for the contact interaction as was observed, for example, in \Ref{Endres:2012cw}.
To understand the source of these terms, consider
\begin{multline}
\frac{1}{\pi L}S^\bigcirc_3(x^\dispersion)=\frac{1}{\pi L}\left(S^{\dispersion}_3(x^\dispersion)+\left(S^\bigcirc_3(x^\dispersion)-S^{\dispersion}_3(x^\dispersion)\right)\right)=\frac{-1}{a_3}+\frac{1}{\pi L}\left(S^\bigcirc_3(x^\dispersion)-S^{\dispersion}_3(x^\dispersion)\right)\\
=\frac{-1}{a_3}+\lim_{\eta \to\infty}\frac{1}{\pi L}\left(\sum_{\bm n\notin \mathrm{B.Z.}}^{|\bm n|<\eta / 2} \frac{1}{\bm n^{2}-x^\dispersion}-\mathcal{L}^\bigcirc_3\frac{\eta}{2}+\mathcal{L}^\dispersion_3\frac{N}{2}\right)\ .
\end{multline}
In the first line we added and subtracted $S^\dispersion_3$ and used the dispersion results~\eqref{dispersion-zeta-form} and~\eqref{dispersion-zeta-contact} to introduce the scattering length in the case of a contact interaction.
For convenience we assume $n_s=\infty$\footnote{
The logic of the following derivation remains them same also for $n_s < \infty$, but, in this case, the expressions $\bm n^2$ must be replaced with the proper dispersion $\tilde K^{(n_s)}_{\bm n \bm n}$ \eqref{normalized-kinetic-hamitlonian}, which makes it difficult to obtained closed expressions.  Also, within the Brillouin zone the different dispersion relations cause the two sums differ by \order{x/N^2} term-by-term.}.
In the second line, since $\bm n$ is now restricted to be \emph{outside} the Brillouin zone, we can assume that $\bm n^2\gg x^\dispersion$ and expand in small $x^\dispersion$ under the summation,
\begin{align}
	\label{eqn:observable}
	S^\bigcirc_3(x^\dispersion)
	&=
	\frac{-\pi L}{a_3}
	+\mathcal{L}^\dispersion_3\frac{N}{2}
	+\lim_{\eta \to\infty}\left(\sum_{\bm n\notin \mathrm{B.Z.}}^{|\bm n|<\eta / 2} \frac{1}{\bm n^{2}}
	-\mathcal{L}^\bigcirc_3\frac{\eta}{2}\right)
	+x^\dispersion\lim_{\eta \to\infty}\sum_{\bm n\notin \mathrm{B.Z.}}^{|\bm n|<\eta / 2} \frac{1}{\bm n^{4}}
	+(x^\dispersion)^2\lim_{\eta \to\infty}\sum_{\bm n\notin \mathrm{B.Z.}}^{|\bm n|<\eta / 2} \frac{1}{\bm n^{6}}
	+ \ldots
	\\
	\label{eq:small x}
	&\equiv \frac{-\pi L}{a_3}+\alpha_1(N)+\alpha_2(N)x^\dispersion+\alpha_3(N)(x^\dispersion)^2
	+\ldots
\end{align}
The last line above shows explicitly the induced momentum-dependence in $x^\dispersion$ and defines the coefficients $\alpha_i(N)$ in terms of particular lattice summations similar to those of the three-dimensional zeta function.  The dependence of these coefficients on $N$ comes from the \emph{exclusion} of momentum modes within the Brillouin zone in the summation.   The fact that these coefficients do \emph{not} depend on $L$ is a unique feature of the contact interaction.  The numerical values of the coefficients $\alpha_i(N)$ can be determined using standard acceleration techniques (see, for example, Appendix B of~\Ref{Luu:2011ep}).  We provide values for select cases of $N$ in \Tabref{slopes}.
\begin{table}
\caption{Coefficients $\alpha_i(N)$ as a function of $N$ in 3-D.\label{tab:slopes}}
\center
\begin{tabular}{S[table-format=1.0]S[table-format=-1.15,table-auto-round=false]S[table-format=-1.15,table-auto-round=false]S[table-format=-1.15,table-auto-round=false]}
{$N$} & {$\alpha_1$} & {$\alpha_2$} & {$\alpha_3$} \\ \midrule
10 & 0.34622847019345 &2.1088361299026 &0.02096728133239\\
20 & 0.17384029798483 &1.0470052482673 &0.00253774588732\\
40 & 0.08701147975728 &0.5225652776531 &0.00031456311910\\
50 & 0.06961796407968 &0.4179620004936 &0.00016089237674\\
80 & 0.04351717442702 &0.2611651268184 &0.00003923695720\\
100 &0.03481483765136 &0.2089208128674 &0.00002008418957
\end{tabular}
\end{table}

In \Figref{3d-corrections} we show the result of tuning a finite-spacing contact interaction to the first zero of the continuum zeta function $S^\spherical_3$.
At each spacing the spectrum is fed through the continuum zeta for analysis, resulting in an apparent spacing-dependent momentum dependence that matches the small-$x$ expansion~\eqref{small x} discussed in the next section.
The same spectrum is also fed through the spacing-appropriate dispersion zeta $S^\dispersion$, resulting in the flat black lines.
Shown in detail in the bottom panel, it's clear that the continuum limit taken this way results in any finite spacing having a nonzero scattering length that vanishes with the continuum limit.
In contrast, tuning to the dispersion function directly, as in \Figref{unimproved dispersion}, is flat and nearly zero at each individual lattice spacing.
We expect that this difference explains the induced momentum dependence of, for example, \Refs{Endres:2011er,Endres:2012cw}.


\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb,wasysym}
\usepackage[margin=2cm]{geometry}

\usepackage{comment}
\usepackage{longtable}
\usepackage{tabularx,booktabs}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{hyperref}
\lstset{basicstyle=\ttfamily}
\newcommand{\py}{\lstinline}

% Math notations
\newcommand{\Z}{{\mathbb{Z}}}                     % set of integers

% MoA notations
\newcommand{\minus}{{}^{\boldsymbol{\mbox{-}}\!}} % scalar negation operator
\newcommand{\rop}[1]{\,\mathrm{#1}^*\,}           % relational operation
\newcommand{\op}[1]{\,\mathrm{#1}\,}              % binary operation
\newcommand{\uop}[1]{\mathrm{#1}\,}               % unary operation
\newcommand{\hop}[2]{{{}_{#1}\!\Omega_{#2}}\,}      % higher order operation
\newcommand{\id}[1]{\mathrm{id}(\op{#1})}         % identity of operations
\newcommand{\dims}{\delta\,}                      % array dimension operator
\newcommand{\shape}{\rho\,}                       % array shape operator
\newcommand{\size}{\tau\,}                        % array size operator
\newcommand{\reshape}{\,\widehat{\rho}\,}         % reshape operator
\newcommand{\drop}{\,\nabla\,}                    % drop operator
\newcommand{\take}{\,\Delta\,}                    % take operator
\newcommand{\product}{\pi\,}                      % product operator
\DeclareMathOperator{\rav}{rav}
\newcommand{\ravel}{\rav\,}                       % ravel operator
\newcommand{\range}{\iota\,}                      % range operator
\newcommand{\transpose}{\bigcirc\!\!\!\!\!\backslash\;} % transpose operator, need a better symbol
\newcommand{\vc}[1]{<#1>}                         % vector with one component
\newcommand{\vcc}[2]{<#1\;#2>}                    % vector with two components
\newcommand{\vccc}[3]{<#1\;#2\;#3>}               % vector with four components
\newcommand{\outerprod}[1]{\,\bullet_{#1}\,}              % outer product opetation
\newcommand{\innerprod}[2]{\,{}_{#1}\!\!\bullet_{#2}\,}   % inner product opetation
\DeclareMathOperator{\red}{red}
\newcommand{\reduce}[1]{{}_{#1}\!\red\,}          % reduce operator
\newcommand{\getitem}[2]{{#2}\,\psi\,{#1}}        % psi operator

\newcommand{\scan}[1]{{}_{\op{#1}\!}\mathrm{scan}\,}
\newcommand{\kron}{\bigcirc\,\!\!\!\!\!\!\times\;}
\newcommand{\cat}{+\!\!\!+}
\newcommand{\gu}{\mathrm{gu}\,}
\newcommand{\gd}{\mathrm{gd}\,}
\newcommand{\compress}{\,\notslash\,}
\newcommand{\expand}{\,\notbackslash\,}
\newcommand{\reverse}{\phi\,}
\newcommand{\rotate}[1]{{#1}\theta\,}

\title{MoA formalism and arrays in software}
\author{Pearu Peterson and Hameer and Saul and Lenore and Travis\\
Quansight, Labs}

\begin{document}
\maketitle
\section{Introduction}

MoA - Mathematics of Arrays - defines a formalism (based on APL) to
describe multidimensional arrays and operations on these. On the other
hand, contemporary array processing software (NumPy, Xnd, Apache
Arrow, etc) implement multidimensional array container objects and
define UI to interact with the array objects. The aim of this document
is to provide a mapping between MoA formalism and UI-s of widely used
array processing software.

\section{Basic definitions}

The MoA formalism is originally defined in ``A Mathematics of Arrays''
by Lenore Mullin, PhD thesis, 1988\cite{mul00}.  We use NumPy UI as a
representative of a software implementing UI for multidimensional
arrays. For brevity, we assume \verb+from numpy import *+.

\noindent
In general, \emph{an array is an object that has a mapping to get
  array items} \footnote{A mapping $f$ is a set of argument and value
  pairs,$(i,v)$, and is represented as $f(i)=v$. We consider only
  single-valued mappings.} . The arguments to the mapping are called
\emph{indices}, all valid indices define the so-called \emph{index
  set} of an array. The items can be arbitrary objects.
Two arrays are \emph{equal} iff their get items mappings are equal: their shapes and components are equivalent.
\emph{Element-wise operations} of two arrays are defined iff the index
sets of the two arrays are equal.
Arrays can be classified according to how the mappings are defined:
\begin{description}
\item[Multidimensional arrays:] The index set of
  an $N$-dimensional array is an $N$-dimensional hyperrectangle in
  $\Z^N$: $[0,\ldots,s_0-1]\times\cdots\times[0,\ldots,s_{N-1}-1]$
  where non-negative integers $(s_0,\ldots,s_{N-1})$ define the shape
  of an array.
\item[Ragged arrays:] The index set of an
  $N$-dimensional ragged array is a connected subset of an
  $N$-dimensional hyperrectangle in $\Z^N$. The concrete
  representation of the index set may have different forms.
\item[Sparse arrays:] The index set of an sparse array is a possibly
  disconnected subset of $N$-dimensional hyperrectangle in $\Z^N$ and
  is extended to the full hyperrectangle by defining the default
  value.
\end{description}

The MoA deals with multidimensional arrays only.  The NumPy implements
array object for multidimensional arrays only. There is one-to-one
relation between MoA formalism and NumPy UI. Xnd implements a more
general container object than NumPy ndarray.

The goal is to extend MoA formalism to ragged arrays and then use this
to define an UI as well as optimized algorithms to the array object
implementation software such as Xnd.

The current working hypothesis is that the ragged arrays can be
represented as arrays of arrays where the subarrays are
multidimensional arrays.

\section{Optimization of Arrays in NumPy: Dense to Start}
We show how the inclusion of MoA and the Psi Calculus for dense arrays
reduces to a normal form. This is a powerful concept in that programmers may design an algorithm differently, one may be efficient, another may not, even if the answer is the same.
\noindent
We show that there will not be performance issues for that choice because all algorithms using the MoA algebra will reduce to the same normal form. Another important concept is that all intermediate arrays are eliminated. Performance analysis and graphs will show this.

\subsection{An example}

In the following we demonstrate how to reduce a NumPy array expression
to its normal form using MoA.

Consider the following NumPy arrays
\begin{verbatim}
>>> A = np.arange(30).reshape((2,3,5))
>>> B = 2 + A
>>> A
array([[[ 0,  1,  2,  3,  4],
        [ 5,  6,  7,  8,  9],
        [10, 11, 12, 13, 14]],

       [[15, 16, 17, 18, 19],
        [20, 21, 22, 23, 24],
        [25, 26, 27, 28, 29]]])
>>> B
array([[[ 2,  3,  4,  5,  6],
        [ 7,  8,  9, 10, 11],
        [12, 13, 14, 15, 16]],

       [[17, 18, 19, 20, 21],
        [22, 23, 24, 25, 26],
        [27, 28, 29, 30, 31]]])
\end{verbatim}
that in MoA formalism are represented as
\begin{align}
  A^3 &\equiv \vccc235\reshape(\range30), \\
  B^3 &\equiv 2+A^3,
\end{align}
and the following array expression as an example case
\begin{verbatim}
>>> r = np.inner(A[1,0,:], np.outer(A[1,0,:], B[0,1,:])[2,:])
>>> r
13175
\end{verbatim}
that in MoA formalism reads
\begin{equation}
r \equiv (\vcc10\psi A^3) \innerprod+\times (\vc2\psi((\vcc10\psi A^3) \outerprod\times (\vcc01\psi B^3))).
\end{equation}
Note that when evaluating the array expression directly, the
computation involves 30 multiplication and 4 addition
operations. Using MoA, we reduce the above array expression to its
normal form where the number of operations is minimal.

First, the items of the left operand of the inner product are
\begin{align*}
  \getitem{(\vcc10\psi A^3)}{\vc i} = \getitem{A^3}{\vccc10i}
\end{align*}
The items of the right operand of the inner product are
\begin{align}
&\getitem{
  (\getitem{((\getitem{A^3}{\vcc10}) \outerprod\times (\getitem{B^3}{\vcc01}))}{\vc2})
}{\vc i} \\
&\equiv \getitem{((\getitem{A^3}{\vcc10}) \outerprod\times (\getitem{B^3}{\vcc01})))}{\vcc2i} \\
&\equiv \getitem{(\getitem{A^3}{\vcc10})}{\vc2} \times \getitem{(\getitem{B^3}{\vcc01})}{\vc i}\\
&\equiv \getitem{A^3}{\vccc102} \times \getitem{B^3}{\vccc01i}
\end{align}
As a result, we have
\begin{align*}
  r &\equiv ((\vcc10\psi A^3) \innerprod+\times  \getitem{B^3}{\vcc01})\times\getitem{A^3}{\vccc102}
\end{align*}
that in NumPy syntax reads
\begin{verbatim}
>>> r_nf = np.inner(A[1,0,:], B[0,1,:]) * A[1,0,2]
\end{verbatim}
which contains 6 multiplications and 4 additions.

\subsection{Performance analysis}

Now let us benchmark the original form of this expression against it's reduced normal form.
For $n$ in ${\{1, 10, 20, ..., 200\}}$ where $\shape A \equiv \vccc2 3 5 \times n$ we measured the
execution of the original expression and the reduced expression.

\begin{figure}[h]
  \includegraphics[width=1\textwidth]{benchmarks/visualization-ratio.png}
  \caption{The ratio of the mean execution time of evaluating the reduced and the original expression comparing decreases as the shape increases.}
  \label{fig:plot}
\end{figure}

\begin{figure}[h]
  \includegraphics[width=1\textwidth]{benchmarks/visualization-ratio.png}
  \caption{The ratio of the mean execution time of evaluating the reduced and the original expression comparing decreases as the shape increases.}
  \label{fig:plot2}
\end{figure}

As seen in Figure \ref{fig:plot}, the reduced normal form version is takes a third of the time when $n=1$ and a hundredth of the time when
~$n=80$. So as $n$ increases, so does the proportional time saving from reducing the expression.

To reproduce the benchmarks and for all the benchmark data as well as machine information, please go to \href{https://github.com/Quansight-Labs/uarray-docs/tree/fcb6baf8bb7284ac7223de73a70cf47063df9e4b/benchmarks}{github.com/Quansight-Labs/uarray-docs}.

\section*{Appendix}

\subsection*{Multidimensional arrays: MoA and NumPy}

\begin{comment}
\newcommand{\MoADefinition}[1]{
  \begin{itemize}
  #1
  \end{itemize}
}
\newcommand{\MoAItem}[3]{\item {#1}
  \begin{description}
  \item[MoA:] {#2}
  \item[NumPy:] {#3}
  \end{description}
}
\end{comment}
%\begin{comment}
\newcommand{\MoADefinition}[1]{
\renewcommand{\arraystretch}{2}
\begin{longtable}{| p{.5\textwidth} | p{.5\textwidth} |}
#1
\end{longtable}
\renewcommand{\arraystretch}{1}
}
\newcommand{\MoAItem}[3]{
\multicolumn2{l}{
  \begin{minipage}[l]{0.9\linewidth} \vspace{2ex}
  $\bullet$ #1\\[0.1ex]
  \end{minipage}
}\\\hline
\begin{minipage}[l]{0.95\linewidth}
{#2}
\end{minipage}
&
\begin{minipage}[l]{0.95\linewidth}
{#3}
\end{minipage}\\\hline
}
%\end{comment}

We have the following correspondence table for basic notions:
\MoADefinition{
  \MoAItem{a multidimensional array}{$\xi$}{\py'x=array(...)'}
  \MoAItem{a one dimensional array, a vector}{$\vec v\equiv<v_0\, v_1\, \ldots>$}{\py'v=array([v_0, v_1, ...])'}
  \MoAItem{total number of array items}{$\size\xi$}{\py'x.size'}
  \MoAItem{the shape of an array is a vector of non-negative integers}{$\shape\xi\equiv<s_0\, \ldots\, s_{n-1}>$}{\py`x.shape==(s_0,...,s_n1)`}
  \MoAItem{the dimensionality of an array is non-negative integer}{$\dims\xi\equiv n\equiv\size\shape\xi$}{\py'x.ndim==n==len(x.shape)'}
  \MoAItem{an array item}{$\getitem\xi{\vec i}\equiv\xi[i_0;\ldots;i_{n-1}]$}{\py'x[i_0,...,i_n1]'}
  \MoAItem{negative of $k$}{$\minus k$}{\py'-k'}
  \MoAItem{$\gamma$ function is used to define the mapping between the indices of an array and its ravelled version}{
  \begin{eqnarray*}
\gamma(<>;<>)&\equiv&0\\
\gamma(\vec a;\vec b)&\equiv&a_{-1} + b_{-1}\gamma({\minus1}\drop{\vec a}; {\minus1}\drop{\vec b})
  \end{eqnarray*}
}{}
  \MoAItem{inverse of $\gamma$ with respect to the first argument}{$\gamma'\ldots \gamma(\gamma'(n;\vec x); \vec x)=n$}{}
}

MoA defines a number of operators on multidimensional arrays:
\MoADefinition{
  \MoAItem{collapse an array to one dimension (row ordering is assumed)}{$\ravel \xi$}{\py'x.ravel()'}
  \MoAItem{product of vector items}{$\product\vec v$}{\py'v.prod()'}

}

MoA defines array construction operators:
\MoADefinition{
  \MoAItem{join a sequences of vectors}{$\vec v,\vec w,\ldots$}{\py'concatenate((v, w, ...))'}
  \MoAItem{a range of integers}{$\range n\equiv 0,1+\range(n-1)$}{\py'arange(n)'}
  \MoAItem{compress}{${\vec v}_l\compress{\vec v}_r$}{\py''}
  \MoAItem{}{${\vec v}_l\expand{\vec v}_r$}{\py''}
  % \MoAItem{}{$$}{\py''}
  % \MoAItem{}{$$}{\py''}
}

MoA defines various slicing operations:
\MoADefinition{
  \MoAItem{take first $k$ items; take last $k$ items}{$k\take{\vec v}\,;\,{\minus k}\take{\vec v} $}{\py'v[:k] ; v[-k:]'}
  \MoAItem{drop first $k$ items; drop last $k$ items}{$k\drop{\vec v}\,;\,{\minus k}\drop{\vec v} $}{\py'v[k:] ; v[:-k]'}
  \MoAItem{}{$\sigma\take\xi$}{\py''}
  \MoAItem{}{$\sigma\drop\xi$}{\py''}
  \MoAItem{}{${\vec v}\take\xi$}{\py''}
  \MoAItem{}{${\vec v}\drop\xi$}{\py''}
}

MoA defines the following relational operators,$(\rop{R}, \text{\py'rop'}) \in \{(\rop{>}, \text{\py'gt'}), (\rop{<}, \text{\py'lt'}), (\rop{=}, \text{\py'eq'}), \ldots\}$ :
\MoADefinition{
  \MoAItem{element-wise relational operators}{$\xi_l\rop{R}\xi_r$}{\py'x_l.__<rop>__(x_r).all()'}
  \MoAItem{scalar extension of relational operators}{$\xi\rop{R}a$}{\py'x.__<rop>__(a*ones(x.shape)).all()'}
  \MoAItem{}{$a\,R^{*}\xi$}{\py''}
}

MoA defines the following binary and unary operators, $(\op{op},\text{\py'op'})\in\{
(\op+, \text{\py'add'}), (\op-, \text{\py'sub'}), (\op\times, \text{\py'mul'}), \ldots
\}$:
\MoADefinition{
  \MoAItem{element-wise binary operators}{$\xi_l\op{op}\xi_r$}{\py'x_l.__<op>__(x_r)'}
  \MoAItem{scalar extension of binary operators}{$\xi\op{op}a\quad;\quad a\op{op}\xi$}{\py'x.__op__(a*ones(x.shape))'}
  \MoAItem{scalar extension of unary operators}{$\uop{uop}\xi$}{\py'x.__<uop>__()'}
}

MoA defines various array transformation operators:
\MoADefinition{
  \MoAItem{reshape a vector}{$\vec s\reshape\vec v$}{\py'v.reshape(s)'}
  \MoAItem{reverse vector items}{$\reverse \vec v$}{\py'v[::-1]'}
  \MoAItem{}{$\rotate{\sigma}\xi$}{\py''}
  \MoAItem{transpose of an array}{$\transpose{\vec v}\xi$}{\py''}
  \MoAItem{reduction}{$\red{op}\xi\equiv(\getitem\xi{<0>})\op{op}\red{op}(1\drop\xi)$}{}
}

Operations with arrays
\MoADefinition{
  \MoAItem{higher order operation}{
    $\getitem{\hop{f}{\vec d}}{\vec i} \equiv f(\getitem\xi{\vec i})$
  }{}
  \MoAItem{outer product $\xi_l\outerprod{\op{op}}\xi_r$}{
    \begin{align*}
      \getitem{\xi_l\outerprod{\op{op}}\xi_r}{(\vec i\cat\vec j)} \equiv
      (\getitem{\xi_l}{\vec i}) \op{op} (\getitem{\xi_r}{\vec j})
    \end{align*}
  }
  {\py|outer(x_l, x_r) FIXME|}
  \MoAItem{inner product $\xi_l\innerprod{\op{op_0}}{\op{op_1}}\xi_r$}{
    \begin{align*}
      \getitem{\xi_l\innerprod{\op{op_0}}{\op{op_1}}\xi_r}{(\vec i\cat \vec j)}
      \equiv\\
      \reduce{\op{op_0}} (\getitem{\xi_l}{\vec i}) \op{op_1} (\getitem{\xi_r}{(\range q\hop{\cat}{\vcc01}\vec j)})
    \end{align*}
}{\py|inner(x_l, x_r) FIXME|}
}

TODO:\\
\begin{tabularx}{\textwidth}{lX}
\begin{tabular}[m]{m{0.2\linewidth}|l|m{0.45\linewidth}|}
  MoA & Python & Description \\\hline
$\vec i\psi\xi;\qquad \size\vec i <\size\shape\xi$ & \verb|x[i+(Ellipsis,)]| & slice of an array\\
$\xi_l\psi\xi_r$ &&\\
\multicolumn2{l|}{$\id{op}\ldots \sigma\op{op}\id{op}\equiv\sigma$}& identity of an operator $\op{op}$\\
$\scan{op}$ && \\
$\xi_l,\xi_r$ & & \\
$\xi,\sigma\equiv \xi, (1,(1\drop{\shape\xi}))\shape\sigma$ &&\\
$\vec v[\vec x]$ &&\\
$\gu\vec v\,;\,\gd\vec v$ &&\\
$\hop{f}{\vec a}\xi$&&\\
$\xi_l(\hop{f}{\vec a})\xi_r$&&\\
\end{tabular}
\end{tabularx}

Referencing Travis \cite{travis0}, and Mullin \cite{mul00}.
\bibliography{paper}
\bibliographystyle{plain}
\end{document}


\subsection{Greedy search}

Find absolute distance from goal for each node. choose node with shortest distance.

Cost of each is \(f(n)=h(n)\), where \(h(n)\) is the heuristic cost of node \(n\).


\section{Mixture Models for Jet Tagging}
\label{sec:tagging}

\subsection{Gaussian Mixture Models}

As a first step we pick the boosted top tagging problem. From Figure \ref{fig:efp-histogram}, it is apparent that the jets are points N-dimentional space (here 1000 dimentional, we have limited to EFPs of degree <= 7) which originate from several multivariate distributions. The obvious choice to model this data is to fit a Bayesian Gaussian Mixture Model, each distribution being a multivariate Gaussian:
\begin{equation}
    f_{pdf}(X) = \frac{1}{\sqrt{(2\pi)^k \vert \Sigma \vert}} e^{-\frac{1}{2} (x - \mu)^T \Sigma^{-1} (x - \mu)}
\end{equation}
We train the model using Expectation Maximization algorithm.
The performance of the algorithm is at par with that of LDA (89.2\% on the top tagging dataset).

\subsection{Maxwellian Mixture Models}

The performance of the GMM is marred by the fact that the distributions of EFPs are actually maxwellian. The skew of the distributions is high for the top quarks even at low degrees and increases as the degree of the EFP increases. Therefore it behooves us to model the data using the Maxwellian distribution, which follows.

We model the multivariate form of the Maxwell-Boltzmann Distribution as follows ~\cite{maxwellian_multivariate}.
\begin{equation}
    f_{pdf}(X) = \frac{b^{1 + \frac{n}{2}} \vert B \vert^\frac{n}{2} \Gamma(\frac{n}{2})}{\pi^{\frac{n}{2}} \Gamma(1 + \frac{n}{2})} [XBX^T] e^{-b(XBX^T)}
\end{equation}
The parameters being learnt will be the $n \times n$ sized matrix $B$. $X$ is the input vector to the model of shape $n \times 1$ and the the constant $b$ is the determinant of the matrix $B$, which together with the Gamma functions serves the task of normalization.

\textcolor{red}{This distribution will be trained on using the Expectation Maximization algorithm, details of the E- step and M- step will be added here, together with any improvements in performance. ~\cite{maxwellian_plasma}}

\subsection{Performance of the Models}

Following is the performance of the algorithms on the Top Tagging dataset \cite{data_toptagging}.
\begin{table}
    \caption{Performance on Top Tagging \cite{tagging_review}}
    \label{tab:1}
    \begin{tabular}{lll}
        \hline\noalign{\smallskip}
        Model Name                                           & Accuracy & ROC AUC \\
        \noalign{\smallskip}\hline\noalign{\smallskip}
        \textbf{Bayessian Maxwellian Mixture Model with EFP} & UNK      & UNK     \\
        \textbf{Bayesian Gaussian Mixture Model with EFP}    & 89.224\% & UNK     \\
        Latent Dirichlet Allocation                          & 89.2\%   & 0.955   \\
        \noalign{\smallskip}\hline
        Linear Discriminant Analysis with EFP                & 93.2\%   & 0.980   \\
        ParticleNet (Graph Neural Net on Point Cloud)        & 93.8\%   & 0.985   \\
        \noalign{\smallskip}\hline
    \end{tabular}
\end{table}

\textcolor{red}{Add accuracy figures on the QCD tagging dataset \cite{data_qcdtagging}}

\subsection{Features of probabilistic tagging}

While boosted top tagging is solved to a very high accuracy, the following attributes are still sought for:
\begin{itemize}
    \item To know what confidence we have tagged a single jet with? - As seen from the histograms, some jets are very clearly in the Top or QCD domain, the overlap of the two is the set of jets where most algorithms fail. When tagging, a model should be able to output both the class label and the confidence figure.
    \item Resilliance to unseen input, and ability to fail gracefully if the input jet is not unlike what the model has seen before? This may be due to errors by the clustering algorithm which has clustered multiple jets together or because of an unknown decay type.
\end{itemize}
A probabilistic Bayesian generative model is the best attempt at modelling the probability with which we are tagging a jet.

\textcolor{red}{Show experimental proof that we are indeed resilliant against mutliple-jet in one jet image and against unknown jet types}.
\textcolor{yellow}{We need to explore what set of features help models like ParticleNet \cite{particle_net} perform better in the overlap zone, and it's performance relative to our confidence, as in the Orange comparative scatters.}


%!TEX root = ../OGUSAdoc.tex

This appendix contains derivations from the theory in the body of this book.

\section{Properties of the CES Production Function}\label{SecAppDerivCES}

  The constant elasticity of substitution (CES) production function of capital and labor was introduced by \citet{Solow:1956} and further extended to a consumption aggregator by \citet{Armington:1969}. The CES production function of aggregate capital $K_t$ and aggregate labor $L_t$ we use in Chapter \ref{Chap_Firms} is the following,
  \begin{equation}\tag{\ref{EqFirmsCESprodfun}}
    Y_t = F(K_t, L_t) \equiv Z_t\biggl[(\gamma)^\frac{1}{\ve}(K_t)^\frac{\ve-1}{\ve} + (1-\gamma)^\frac{1}{\ve}(e^{g_y t}L_t)^\frac{\ve-1}{\ve}\biggr]^\frac{\ve}{\ve-1} \quad\forall t
  \end{equation}
  where $Y_t$ is aggregate output (GDP), $Z_t$ is total factor productivity, $\gamma$ is a share parameter that represents the capital share of income in the Cobb-Douglas case ($\ve=1$), and $\ve$ is the elasticity of substitution between capital and labor. The stationary version of this production function is given in Chapter \ref{Chap_Stnrz}. We drop the $t$ subscripts, the ``$\:\hat{\,}\:$''stationary notation, and use the stationarized version of the production function \eqref{EqStnrzCESprodfun} for simplicity.
  \begin{equation}\tag{\ref{EqStnrzCESprodfun}}
    Y =  Z\biggl[(\gamma)^\frac{1}{\ve}(K)^\frac{\ve-1}{\ve} + (1-\gamma)^\frac{1}{\ve}(L)^\frac{\ve-1}{\ve}\biggr]^\frac{\ve}{\ve-1}
  \end{equation}
  The Cobb-Douglas production function is a nested case of the general CES production function with unit elasticity $\ve=1$.
  \begin{equation}\label{EqAppDerivCES_CobbDoug}
    Y = Z(K)^\gamma(L)^{1-\gamma}
  \end{equation}

  \subsection{Wages as a function of interest rates}\label{SecAppDerivCESwr}

    An important property of the CES production function for the solution method of \ogindia is that the interest rate $r_t$ and wage $w_t$ are functions of the capital labor ratio. This property implies that the wage every period $w_t$ is just a function of the interest rate $r_t$, and vice versa. The first step is to show that the output-capital ratio ($Y/K$) and the output-labor ($Y/L$) ratio are both functions of the capital-labor ratio ($K/L$).
    \begin{equation}\label{EqAppDerivCES_YL}
      \begin{split}
      Y &= Z\biggl[(\gamma)^\frac{1}{\ve}(K)^\frac{\ve-1}{\ve} + (1-\gamma)^\frac{1}{\ve}(L)^\frac{\ve-1}{\ve}\biggr]^\frac{\ve}{\ve-1} \\
      &= Z\left[(\gamma)^\frac{1}{\ve}(K)^\frac{\ve-1}{\ve}\left(\frac{L^\frac{\ve-1}{\ve}}{L^\frac{\ve-1}{\ve}}\right) + (1-\gamma)^\frac{1}{\ve}(L)^\frac{\ve-1}{\ve}\right]^\frac{\ve}{\ve-1} \\
      &= ZL\left[(\gamma)^\frac{1}{\ve}\left(\frac{K}{L}\right)^\frac{\ve-1}{\ve} + (1-\gamma)^\frac{1}{\ve}\right]^\frac{\ve}{\ve-1} \\
      \Rightarrow\quad \frac{Y}{L} &= Z\left[(\gamma)^\frac{1}{\ve}\left(\frac{K}{L}\right)^\frac{\ve-1}{\ve} + (1-\gamma)^\frac{1}{\ve}\right]^\frac{\ve}{\ve-1}
      \end{split}
    \end{equation}

    \begin{equation}\label{EqAppDerivCES_YK}
      \begin{split}
      Y &= Z\biggl[(\gamma)^\frac{1}{\ve}(K)^\frac{\ve-1}{\ve} + (1-\gamma)^\frac{1}{\ve}(L)^\frac{\ve-1}{\ve}\biggr]^\frac{\ve}{\ve-1} \\
      &= Z\left[(\gamma)^\frac{1}{\ve}(K)^\frac{\ve-1}{\ve} + (1-\gamma)^\frac{1}{\ve}(L)^\frac{\ve-1}{\ve}\left(\frac{K^\frac{\ve-1}{\ve}}{K^\frac{\ve-1}{\ve}}\right)\right]^\frac{\ve}{\ve-1} \\
      &= ZK\left[(\gamma)^\frac{1}{\ve} + (1-\gamma)^\frac{1}{\ve}\left(\frac{L}{K}\right)^\frac{\ve-1}{\ve}\right]^\frac{\ve}{\ve-1} \\
      \Rightarrow\quad \frac{Y}{K} &= Z\left[(\gamma)^\frac{1}{\ve} + (1-\gamma)^\frac{1}{\ve}\left(\frac{L}{K}\right)^\frac{\ve-1}{\ve}\right]^\frac{\ve}{\ve-1}
      \end{split}
    \end{equation}

    Solving for the firm's first order conditions for capital and labor demand from profit maximization \eqref{EqStnrzProfit} gives the following equations in their respective stationarized forms from Chapter \ref{Chap_Stnrz}.
    \begin{align}
      w &= (Z)^\frac{\ve-1}{\ve}\left[(1-\gamma)\left(\frac{Y}{L}\right)\right]^\frac{1}{\ve} \tag{\ref{EqStnrzFOC_L}} \\
      r &= (1 - \tau^{corp})(Z)^\frac{\ve-1}{\ve}\left[\gamma\left(\frac{Y}{K}\right)\right]^\frac{1}{\ve} - \delta + \tau^{corp}\delta^\tau \tag{\ref{EqFirmFOC_K}}
    \end{align}
    As can be seen from \eqref{EqStnrzFOC_L} and \eqref{EqFirmFOC_K}, the wage $w$ and interest rate $r$ are functions of $Y/L$ and $Y/K$, respectively. Equations \eqref{EqAppDerivCES_YL} and \eqref{EqAppDerivCES_YK} show that both $Y/L$ and $Y/K$ are functions of the capital-labor ratio $K/L$. Substituting \eqref{EqAppDerivCES_YL} and \eqref{EqAppDerivCES_YK} into \eqref{EqStnrzFOC_L} and \eqref{EqFirmFOC_K}, respectively, gives expressions of the wage $w$ and interest rate $r$ in terms of the capital-labor ratio $K/L$.
    \begin{align}
      w &= (1-\gamma)^\frac{1}{\ve}Z\left[(\gamma)^\frac{1}{\ve}\left(\frac{K}{L}\right)^\frac{\ve-1}{\ve} + (1-\gamma)^\frac{1}{\ve}\right]^\frac{1}{\ve-1} \label{EqAppDerivCES_FOCL} \\
      r &= (1 - \tau^{corp})(\gamma)^\frac{1}{\ve}Z\left[(\gamma)^\frac{1}{\ve} + (1-\gamma)^\frac{1}{\ve}\left(\frac{L}{K}\right)^\frac{\ve-1}{\ve}\right]^\frac{1}{\ve-1} - \delta + \tau^{corp}\delta^\tau \label{EqAppDerivCES_FOCK}
    \end{align}
    In the Cobb-Douglas unit elasticity case ($\ve=1$) of the CES production function, the first order conditions are more easily expressed in terms of the capital-labor ratio.
    \begin{align}
      \text{if}\:\:\,\ve=1:\quad w &= (1-\gamma)Z\left(\frac{K}{L}\right)^\gamma \label{EqAppDerivCES_CDFOCL} \\
      \text{if}\:\:\:\ve=1:\quad r &= (1 - \tau^{corp})\gamma Z\left(\frac{L}{K}\right)^{1-\gamma} - \delta + \tau^{corp}\delta^\tau \label{EqAppDerivCES_CDFOCK}
    \end{align}

    With $w$ and $r$ expressed in terms of the capital-labor ratio $K/L$ in \eqref{EqAppDerivCES_FOCL} and \eqref{EqAppDerivCES_FOCK}, we can write the expressions for the capital-labor ratio as a function of the interest rate and, therefore, the wage as a function of the interest rate. We first solve equation \eqref{EqAppDerivCES_FOCK} for the capital-labor ratio to get the expression for $K/L$ as a function of the interest rate $r$.
    \begin{equation}\label{EqAppDerivCES_KLr}
      \frac{K}{L} = \left(\frac{(1-\gamma)^\frac{1}{\ve}}{\left[\frac{r + \delta - \tau^{corp}\delta^\tau}{(1 - \tau^{corp})\gamma^\frac{1}{\ve}Z}\right]^{\ve-1} - \gamma^\frac{1}{\ve}}\right)^\frac{\ve}{\ve-1}
    \end{equation}
    In the Cobb-Douglas unit elasticity case ($\ve=1$), we solve equation \eqref{EqAppDerivCES_CDFOCK} for the capital-labor ration to get the expression for $K/L$ as a function of the interest rate $r$.
    \begin{equation}\label{EqAppDerivCES_CDKLr}
      \text{if}\:\:\:\ve=1:\quad \frac{K}{L} = \left[\frac{(1 - \tau^{corp})\gamma Z}{r + \delta - \tau^{corp}\delta^\tau}\right]^\frac{1}{1-\gamma}
    \end{equation}

    Substituting \eqref{EqAppDerivCES_KLr} into \eqref{EqAppDerivCES_FOCL} gives the expression for the wage $w$ as a function of the interest rate $r$ in the general CES case.
    \begin{equation}\label{EqAppDerivCES_wr}
      w = (1-\gamma)^\frac{1}{\ve}Z\left[(\gamma)^\frac{1}{\ve}\left(\frac{(1-\gamma)^\frac{1}{\ve}}{\left[\frac{r + \delta - \tau^{corp}\delta^\tau}{(1 - \tau^{corp})\gamma^\frac{1}{\ve}Z}\right]^{\ve-1} - \gamma^\frac{1}{\ve}}\right) + (1-\gamma)^\frac{1}{\ve}\right]^\frac{1}{\ve-1}
    \end{equation}
    In the Cobb-Douglas unit elasticity case ($\ve=1$), we substitute \eqref{EqAppDerivCES_CDKLr} into \eqref{EqAppDerivCES_CDFOCL} gives the expression for the wage $w$ as a function of the interest rate $r$.
    \begin{equation}\label{EqAppDerivCES_CDwr}
      \text{if}\:\:\:\ve=1:\quad w = (1-\gamma)Z\left[\frac{(1 - \tau^{corp})\gamma Z}{r + \delta - \tau^{corp}\delta^\tau}\right]^\frac{\gamma}{1-\gamma}
    \end{equation}


\section{Introduction}\label{introduction}
%=========================================

The aim of this paper is to introduce an approach to 2D and 3D
computational topology and geometry using a \emph{GraphBLAS} sparse matrix
representation of \emph{chain complexes} with linear operators $\partial_p$ and $\delta_{p-1} = \partial_p^\top$ between linear \emph{chain} spaces $C_p$:
\[
C_\bullet = (C_p, \partial_p) :=
C_3 \
\substack{
\delta_2 \\
\longleftarrow \\[-1mm]
\longrightarrow \\
\partial_3
}
\ C_2 \
\substack{
\delta_1 \\
\longleftarrow \\[-1mm]
\longrightarrow \\
\partial_2
}
\ C_1 \
\substack{
\delta_0 \\
\longleftarrow \\[-1mm]
\longrightarrow \\
\partial_1
}
\ C_0 .
\]
Let us to remark preliminary that when $p\in \{0,1\}$, a chain complex is a representation of a \emph{graph}, with $[\partial_1]$ the \emph{incidence matrix} between 1-chains (edges) in $C_1$ and 0-chains (vertices) in $C_0$. Also, the multiplication $[\partial_1][\delta_0]=[\partial_1][\partial_1]^t$ gives the \emph{adjacency} matrix of the graph, while the diagonal entries provide the degrees of vertices, defined by the number of incident edges on each vertex. The \emph{GraphBLAS} standard~\cite{GraphBLAS:standard} provides a small set of matrix primitives to compute graph properties that, combined together, allow for easy implementation of fast algorithms on large graphs.

In several application of computational geometry and topology---including
geo-mapping, building information modeling (BIM), medical imaging, CAD and
solid modeling, virtual and augmented reality, finite element modeling
and simulation (FEM, FEA), etc.---the amount and detail of 2D and/or 3D data
continue to grow. Analogously, the need for an unified approach to
graph algorithms and for unified and simplified interfaces, has been
well intercepted by the GraphBLAS initiative and the related
standardization effort~\href{http://graphblas.org}{\texttt{graphblas.org}}.
This paper aim is to show that the domaincovering of this standard library on graphs can be greatly extended, to cover the representation of more general \emph{cellular $d$-complexes} ($1\leq d\leq 3$) and their $p$-skeletons ($0\leq p\leq 3$).

(Co)chain complexes, as well (co)boundary operators, are well-known
basic tools of algebraic topology and homological algebra. In
particular, a \emph{chain complex} is a graded sequence of such linear
operators between graded linear spaces of ``chains''. A $p$-chain can be seen as a subset of a finite set $\texttt{V}$ of Euclidean points whose affine hull has dimension $p$.
Chain spaces and sparse matrices are the components of the Linear Algebraic
Representation (\texttt{LAR})~\cite{Dicarlo:2014:TNL:2543138.2543294}, that is being used for
boundary, decompositive, and enumerative
representations~\cite{Requicha:1980:RRS:356827.356833} of models of rigid solid objects.

Some numerical methods aiming to integrate domain modeling, differential
topology, mathematical modeling, and physical simulations were based on chains and
cochains, starting with~\cite{PALMER1995733,Palmer1993}. In particular,
Discrete Exterior Calculus (DEC) with simplicial complexes was
introduced by \cite{Hirani:2003:DEC:959640} and made popular by
\cite{Desbrun:2006:DDF:1185657.1185665,Elcott:2006:BYO:1185657.1185666}.
Finite Element Exterior Calculus
(FEEC) is an advance in the mathematics of finite element
methods~\cite{arnold_falk_winther_2006,Arnold:2010,Arnold:2018} that employs differential
complexes to construct stable numerical schemes. The Cell
Method~(CM) is a purely algebraic computational method
for modeling and
simulation~\cite{Tonti:1975,Tonti:2013,Ferretti:2014}
based on boundary/coboundary maps and a direct discrete formulation of
field laws. Our own research in geometrical and physical modeling with
chain and cochain complexes was introduced in
\cite{DiCarlo:2009:DPU:1629255.1629273,ieee-tase,Dicarlo:2014:TNL:2543138.2543294}.

More recently, we provided---using sparse
matrices---an algorithmic pipeline~\cite{TSAS:19} to compute the \emph{arrangement} of the
Euclidean \(d\)-space (\(d=2,3\)), i.e.~the partition of
it into a cellular \(d\)-complex, starting from a collection of (possibly intersecting) cellular
(\(d\)-1)-complexes embedded in \(\E^d\). In~\cite{paoluzzi2019finite} we
have shown that the \emph{atoms} of the Boolean algebra generated by
such space partition correspond one-to-one to the columns of the $[\partial_d]$ matrix
of the boundary operator \(\partial_d : C_d \to C_{d-1}\). This allows for fast
native reconstruction of every solid expression in the \emph{solid algebra} of
\(d\)-space generated by the input terms, usually called Constructive Solid Geometry (CSG)
in solid modeling~\cite{Requicha:1980:RRS:356827.356833}.

The topological background of linear chain spaces and chain complexes is summarized in
Section~\ref{sec:background}, together with the concepts of boundary and coboundary linear maps between chain spaces.
In Section~\ref{chain-adjacencies-and-incidensies} an operational definition of topological queries through composition of operators corresponding to products of their sparse matrices is discussed.
In Section~\ref{boolean-algebras} an interpretation as a Boolean algebra of the partition of the Euclidean $d$-space produced by a collection of geometric objects is provided.
The implementation of such concepts using GraphBLAS is given in Section~\ref{graphblas-implementation}. Some simple examples of topology computation using linear algebra are shown in  Section~\ref{examples}.
In the Conclusion Section we briefly summarize our main points, state our findings, and propose some possible extension of this approach.