% !TEX root = hott_intro.tex

\section{The fundamental theorem of identity types}\label{chap:fundamental}
\sectionmark{The fundamental theorem}

For many types it is useful to have a characterization of their identity types. For example, we have used a characterization of the identity types of the fibers of a map in order to conclude that any equivalence is a contractible map. The fundamental theorem of identity types is our main tool to carry out such characterizations, and with the fundamental theorem it becomes a routine task to characterize an identity type whenever that is of interest.

Our first application of the fundamental theorem of identity types in the present lecture is a simple proof that any equivalence is an embedding. Embeddings are maps that induce equivalences on identity types, i.e., they are the homotopical analogue of injective maps. In our second application we characterize the identity types of coproducts.

Throughout the rest of this book we will encounter many more occasions to characterize identity types. For example, we will show in \cref{thm:eq_nat} that the identity type of the natural numbers is equivalent to its observational equality, and we will show in \cref{thm:eq-circle} that the loop space of the circle is equivalent to $\Z$.

In order to prove the fundamental theorem of identity types, we first prove the basic fact that a family of maps is a family of equivalences if and only if it induces an equivalence on total spaces. This fact will also be used in many other situations, most notably in the characterization of pullback squares in \cref{cor:pb_fibequiv}.

\subsection{Families of equivalences}
Consider a family
\begin{equation*}
f : \prd{x:A}B(x)\to C(x)
\end{equation*}
of maps.

\begin{defn}
We define the map
\begin{equation*}
\total{f}:\sm{x:A}B(x)\to\sm{x:A}C(x).
\end{equation*}
by $\lam{(x,y)}(x,f(x,y))$.
\end{defn}

\begin{lem}\label{lem:fib_total}
  For any family of maps $f:\prd{x:A}B(x)\to C(x)$ and any $t:\sm{x:A}C(x)$,
  there is an equivalence
  \begin{equation*}
    \eqv{\fib{\total{f}}{t}}{\fib{f(\proj 1(t))}{\proj 2(t)}}.
  \end{equation*}
\end{lem}

\begin{proof}
  For any $p:\fib{\total{f}}{t}$ we define $\varphi(t,p):\fib{\proj 1(t)}{\proj 2(t)}$ by $\Sigma$-induction on $p$. Therefore it suffices to define $\varphi(t,(s,\alpha)):\fib{\proj 1(t)}{\proj 2 (t)}$ for any $s:\sm{x:A}B(x)$ and $\alpha:\total{f}(s)=t$. Now we proceed by path induction on $\alpha$, so it suffices to define $\varphi(\total{f}(s),(s,\refl{})):\fib{f(\proj 1(\total{f}(s)))}{\proj 2(\total{f}(s))}$. Finally, we use $\Sigma$-induction on $s$ once more, so it suffices to define
  \begin{equation*}
    \varphi((x,f(x,y)),((x,y),\refl{})):\fib{f(x)}{f(x,y)}.
  \end{equation*}
  Now we take as our definition
  \begin{equation*}
    \varphi((x,f(x,y)),((x,y),\refl{}))\defeq(y,\refl{}).
  \end{equation*}

  For the proof that this map is an equivalence we construct a map
  \begin{equation*}
    \psi(t) : \fib{f(\proj 1(t))}{\proj 2(t)}\to\fib{\total{f}}{t}
  \end{equation*}
  equipped with homotopies $G(t):\varphi(t)\circ\psi(t)\htpy\idfunc$ and $H(t):\psi(t)\circ\varphi(t)\htpy\idfunc$. In each of these definitions we use $\Sigma$-induction and path induction all the way through, until an obvious choice of definition becomes apparent. We define $\psi(t)$, $G(t)$, and $H(t)$ as follows:
  \begin{align*}
    \psi((x,f(x,y)),(y,\refl{})) & \defeq ((x,y),\refl{}) \\
    G((x,f(x,y)),(y,\refl{})) & \defeq \refl{} \\
    H((x,f(x,y)),((x,y),\refl{})) & \defeq \refl{}.\qedhere
  \end{align*}
\end{proof}

\begin{thm}\label{thm:fib_equiv}
Let $f:\prd{x:A}B(x)\to C(x)$ be a family of maps. The following are equivalent:
\begin{enumerate}
\item For each $x:A$, the map $f(x)$ is an equivalence. In this case we say that $f$ is a \define{family of equivalences}.
\item The map $\total{f}:\sm{x:A}B(x)\to\sm{x:A}C(x)$ is an equivalence.
\end{enumerate}
\end{thm}

\begin{proof}
By \cref{thm:equiv_contr,thm:contr_equiv} it suffices to show that $f(x)$ is a contractible map for each $x:A$, if and only if $\total{f}$ is a contractible map. Thus, we will show that $\fib{f(x)}{c}$ is contractible if and only if $\fib{\total{f}}{x,c}$ is contractible, for each $x:A$ and $c:C(x)$. However, by \cref{lem:fib_total} these types are equivalent, so the result follows by \cref{ex:contr_equiv}.
\end{proof}

Now consider the situation where we have a map $f:A\to B$, and a family $C$ over $B$. Then we have the map
\begin{equation*}
  \lam{(x,z)}(f(x),z):\sm{x:A}C(f(x))\to\sm{y:B}C(y).
\end{equation*}
We claim that this map is an equivalence when $f$ is an equivalence. The technique to prove this claim is the same as the technique we used in \cref{thm:fib_equiv}: first we note that the fibers are equivalent to the fibers of $f$, and then we use the fact that a map is an equivalence if and only if its fibers are contractible to finish the proof.

\begin{lem}\label{lem:total-equiv-base-equiv}
  Consider an equivalence $e:A\simeq B$, and let $C$ be a type family over $B$. Then the map
  \begin{equation*}
    \sigma_f(C) \defeq\lam{(x,z)}(f(x),z):\sm{x:A}C(f(x))\to\sm{y:B}C(y)
  \end{equation*}
  is an equivalence.
\end{lem}

\begin{proof}
  We claim that for each $t:\sm{y:B}C(y)$ there is an equivalence
  \begin{equation*}
    \fib{\sigma_f(C)}{t}\simeq \fib{f}{\proj 1(t)}.
  \end{equation*}
  We prove this by constructing
  \begin{align*}
    \varphi(t) & : \fib{\sigma_f(C)}{t}\to\fib{f}{\proj 1 (t)} \\
    \psi(t) & : \fib{f}{\proj 1(t)} \to\fib{\sigma_f(C)}{t} \\
    G(t) & : \varphi\circ\psi\htpy\idfunc\\
    H(t) & : \psi\circ\varphi\htpy\idfunc.
  \end{align*}
  The construction of these functions and homotopies is by using $\Sigma$-induction and path induction all the way through, just as in the proof of \cref{lem:fib_total}. We list the definitions
  \begin{align*}
    \varphi((f(x),z),((x,z),\refl{})) & \defeq (x,\refl{}) \\
    \psi((f(x),z),(x,\refl{})) & \defeq ((x,z),\refl{}) \\
    G((f(x),z),(x,\refl{})) & \defeq \refl{} \\
    H((f(x),z),((x,z),\refl{})) & \defeq \refl{}.
  \end{align*}
  Now the claim follows, since we see that $\varphi$ is a contractible map if and only if $f$ is a contractible map.
\end{proof}

We now combine \cref{thm:fib_equiv,lem:total-equiv-base-equiv}.

\begin{defn}
  Consider a map $f:A\to B$ and a family of maps
  \begin{equation*}
    g:\prd{x:A}C(x)\to D(f(x)),
  \end{equation*}
  where $C$ is a type family over $A$, and $D$ is a type family over $B$. In this situation we also say that $g$ is a \define{family of maps over $f$}. Then we define
  \begin{equation*}
    \total[f]{g}:\sm{x:A}C(x)\to\sm{y:B}D(y)
  \end{equation*}
  by $\total[f]{g}(x,z)\defeq (f(x),g(x,z))$.
\end{defn}

\begin{thm}
  Suppose that $g$ is a family of maps over $f$, and suppose that $f$ is an equivalence. Then the following are equivalent:
  \begin{enumerate}
  \item The family of maps $g$ over $f$ is a family of equivalences.
  \item The map $\total[f]{g}$ is an equivalence.
  \end{enumerate}
\end{thm}

\begin{proof}
  Note that we have a commuting triangle
  \begin{equation*}
    \begin{tikzcd}[column sep=0]
      \sm{x:A}C(x) \arrow[rr,"{\total[f]{g}}"] \arrow[dr,swap,"\total{g}"]& & \sm{y:B}D(y) \\
      & \sm{x:A}D(f(x)) \arrow[ur,swap,"{\lam{(x,z)}(f(x),z)}"]
    \end{tikzcd}
  \end{equation*}
  By the assumption that $f$ is an equivalence, it follows that the map $\sm{x:A}D(f(x))\to \sm{y:B}D(y)$ is an equivalence. Therefore it follows that $\total[f]{g}$ is an equivalence if and only if $\total{g}$ is an equivalence. Now the claim follows, since $\total{g}$ is an equivalence if and only if $g$ if a family of equivalences.
\end{proof}

\begin{comment}
\subsection{Identity systems}

Many types come equipped with a reflexive relation that possesses a similar
structure as the identity type. The observational equality on the natural
numbers is such an example. We have see that it is a reflexive, symmetric, and
transitive relation, and moreover it is contained in any other reflexive
relation. As we will see in this section, the observational equality on the
natural numbers even satisfies a variant of path induction, so in type theory
we really can't distinguish between the identity type and observational
equality.

In this section we will introduce \emph{identity systems}. Those are reflexive
relations on a type that satisfy path induction. We consider identity systems because for many types we can construct a reflexive relation that behaves like the identity type, even though it is not given as such. When we show that a reflexive relation satisfies path induction, what we really show is that in type theory there is no way to distinguish between this relation and the identity type. An example we provide here is the observational equality on $\N$. Characterizing the identity type of a given type in this way is one of the core activities in homotopy type theory.

\begin{defn}
  Let $A$ be a type equipped with a term $a:A$. A \define{(unary) identity system} on $A$ at $a$ consists of a type family $B$ over $A$ equipped with $b:B(a)$, such that for any family of types $P(x,y)$ indexed by $x:A$ and $y:B(x)$, there is a function
  \begin{equation*}
    \mathsf{ind\usc{}id\usc{}sys}:P(a,b)\to \prd{x:A}{y:B(x)}P(x,y)
  \end{equation*}
  equipped with an identification
  \begin{equation*}
    \mathsf{ind\usc{}id\usc{}sys}(p,a,b)=p.
  \end{equation*}
  for every $p:P(a,b)$.
\end{defn}

\begin{rmk}
  Note that in the definition of identity systems we require an identification for the `computation rule', rather than a judgmental equality.
\end{rmk}

\begin{defn}
  Let $A$ be a type. A \define{(binary) identity system} on $A$ consists of a family of types $R(x,y)$ indexed by $x,y:A$ equipped with a dependent function
  \begin{equation*}
    \rho : \prd{x:A}R(x,x),
  \end{equation*}
  such that for each family of types $P(x,y,e)$ indexed by $x,y:A$ and $e:R(x,y)$ and each $a:A$, there is a function
  \begin{equation*}
    \mathsf{ind\usc{}id\usc{}sys}:P(a,a,\rho(a)) \to \Big(\prd{y:A}{e:R(a,y)}P(a,y,e)\Big)
  \end{equation*}
  equipped with an identification
  \begin{equation*}
    \mathsf{ind\usc{}id\usc{}sys}(p,a,\rho(a))=p.
  \end{equation*}
  for every $p:P(a,a,\rho(a))$.
\end{defn}

\begin{thm}
  Observational equality on $\N$ is an identity system.
\end{thm}

\begin{proof}
  First we note that for any family of types $P(m,n,e)$ indexed by $m,n:\N$ and $e:\EqN(m,n)$, there is a type family $P'$ given by
  \begin{equation*}
    P'(m,n,e)\defeq P(\succN(m),\succN(n),e).
  \end{equation*}
  Similarly, for any $p:\prd{n:\N}P(n,n,\mathsf{refl\usc{}Eq}_\N(n))$ we have
  \begin{equation*}
    p':\prd{n:\N}P'(n,n,\mathsf{ref\usc{}Eq}_\N(n))
  \end{equation*}
  given by $p'(n)\defeq p(\succN(n))$. Now we define a function
  \begin{equation*}
    f(m,n,e,P):\Big(\prd{n:\N}P(n,n,\mathsf{refl\usc{}Eq}_\N(n))\Big)\to P(m,n,e)
  \end{equation*}
  for every $m,n:\N$, $e:\EqN(m,n)$ and $P:\prd{x,y:\N}\EqN(x,y)\to\UU$ by induction on $m,n:\N$ by
  \begin{align*}
    f(\zeroN,\zeroN,\ttt,P,p) & \defeq p(\zeroN) \\
    f(\zeroN,\succN(n)) & \defeq \indempty \\
    f(\succN(m),\zeroN) & \defeq \indempty \\
    f(\succN(m),\succN(n),e,P,p) & \defeq f(m,n,e,P',p').
  \end{align*}
  Then we define $\mathsf{ind\usc{}Eq}_\N$ for every $P:\prd{x,y:\N}\EqN(x,y)\to\UU$ by
  \begin{equation*}
    \mathsf{ind\usc{}Eq}_\N(p,m,n,e)\defeq f(m,n,e,P,p).
  \end{equation*}
  This completes the first part of the claim. For the second part, we have to construct an identification
  \begin{equation*}
    \mathsf{comp\usc{}Eq}_\N(p,n):\mathsf{ind\usc{}Eq}_\N(p,n,\mathsf{refl\usc{}Eq}_\N(n))= p
  \end{equation*}
  for any $p:P(n,\mathsf{refl\usc{}Eq}_\N(n))$. This is again by induction on $n:\N$.
\end{proof}
\end{comment}

\subsection{The fundamental theorem}

Many types come equipped with a reflexive relation that possesses a similar
structure as the identity type. The observational equality on the natural
numbers is such an example. We have see that it is a reflexive, symmetric, and
transitive relation, and moreover it is contained in any other reflexive
relation. Thus, it is natural to ask whether observational equality on the natural numbers is equivalent to the identity type.

The fundamental theorem of identity types (\cref{thm:id_fundamental}) is a general theorem that can be used to answer such questions. It describes a necessary and sufficient condition on a type family $B$ over a type $A$ equipped with a point $a:A$, for there to be a family of equivalences $\prd{x:A}(a=x)\simeq B(x)$. In other words, it tells us when a family $B$ is a characterization of the identity type of $A$.

Before we state the fundamental theorem of identity types we introduce the notion of \emph{identity systems}. Those are families $B$ over a $A$ that satisfy an induction principle that is similar to the path induction principle, where the `computation rule' is stated with an identification.

\begin{defn}
  Let $A$ be a type equipped with a term $a:A$. A \define{(unary) identity system} on $A$ at $a$ consists of a type family $B$ over $A$ equipped with $b:B(a)$, such that for any family of types $P(x,y)$ indexed by $x:A$ and $y:B(x)$,
  the function
  \begin{equation*}
    h\mapsto h(a,b):\Big(\prd{x:A}{y:B(x)}P(x,y)\Big)\to P(a,b)
  \end{equation*}
  has a section.
\end{defn}

The most important implication in the fundamental theorem is that (ii) implies (i). Occasionally we will also use the third equivalent statement. We note that the fundamental theorem also appears as Theorem 5.8.4 in \cite{hottbook}.

\begin{thm}\label{thm:id_fundamental}
Let $A$ be a type with $a:A$, and let $B$ be be a type family over $A$ with $b:B(a)$.
Then  the following are logically equivalent for any family of maps
\begin{equation*}
  f:\prd{x:A}(a=x)\to B(x).
\end{equation*}
\begin{enumerate}
\item The family of maps $f$ is a family of equivalences.
\item The total space
\begin{equation*}
\sm{x:A}B(x)
\end{equation*}
is contractible.
\item The family $B$ is an identity system.
\end{enumerate}
In particular the canonical family of maps
\begin{equation*}
\mathsf{path\usc{}ind}_a(b):\prd{x:A} (a=x)\to B(x)
\end{equation*}
is a family of equivalences if and only if $\sm{x:A}B(x)$ is contractible.
\end{thm}

\begin{proof}
  First we show that (i) and (ii) are equivalent.
  By \cref{thm:fib_equiv} it follows that the family of maps $f$ is a family of equivalences if and only if it induces an equivalence
  \begin{equation*}
    \eqv{\Big(\sm{x:A}a=x\Big)}{\Big(\sm{x:A}B(x)\Big)}
  \end{equation*}
  on total spaces. We have that $\sm{x:A}a=x$ is contractible. Now it follows by \cref{ex:contr_equiv}, applied in the case
  \begin{equation*}
    \begin{tikzcd}[column sep=3em]
      \sm{x:A}a=x \arrow[rr,"\total{f}"] \arrow[dr,swap,"\eqvsym"] & & \sm{x:A}B(x) \arrow[dl] \\
      & \unit & \phantom{\sm{x:A}a=x}
    \end{tikzcd}
  \end{equation*}
  that $\total{f}$ is an equivalence if and only if $\sm{x:A}B(x)$ is contractible.

  Now we show that (ii) and (iii) are equivalent. Note that we have the following commuting triangle
  \begin{equation*}
    \begin{tikzcd}[column sep=0]
      \prd{t:\sm{x:A}B(x)}P(t) \arrow[rr,"\mathsf{ev\usc{}pair}"] \arrow[dr,swap,"{\mathsf{ev\usc{}pt}(a,b)}"] & & \prd{x:A}{y:B(x)}P(x,y) \arrow[dl,"{\lam{h}h(a,b)}"] \\
      \phantom{\prd{x:A}{y:B(x)}P(x,y)} & P(a,b)
    \end{tikzcd}
  \end{equation*}
  In this diagram the top map has a section. Therefore it follows by \cref{ex:3_for_2} that the left map has a section if and only if the right map has a section. Notice that the left map has a section for all $P$ if and only if $\sm{x:A}B(x)$ satisfies singleton induction, which is by \cref{thm:contractible} equivalent to $\sm{x:A}B(x)$ being contractible.
\end{proof}

\subsection{Embeddings}
As an application of the fundamental theorem we show that equivalences are embeddings. The notion of embedding is the homotopical analogue of the set theoretic notion of injective map.

\begin{defn}
An \define{embedding}\index{embedding|textbf} is a map $f:A\to B$ satisfying the property that
\begin{equation*}
\apfunc{f}:(\id{x}{y})\to(\id{f(x)}{f(y)})
\end{equation*}
is an equivalence for every $x,y:A$. We write $\mathsf{is\usc{}emb}(f)$ for the type of witnesses that $f$ is an embedding.
\end{defn}

Another way of phrasing the following statement is that equivalent types have equivalent identity types.

\begin{thm}
\label{cor:emb_equiv}
Any equivalence is an embedding.\index{embedding!equivalences are embeddings|textit}\index{equivalence!is an embedding|textit}
\end{thm}

\begin{proof}
Let $e:\eqv{A}{B}$ be an equivalence, and let $x:A$. Our goal is to show that
\begin{equation*}
\apfunc{e} : (\id{x}{y})\to (\id{e(x)}{e(y)})
\end{equation*}
is an equivalence for every $y:A$. By \cref{thm:id_fundamental} it suffices to show that
\begin{equation*}
\sm{y:A}e(x)=e(y)
\end{equation*}
is contractible for every $y:A$. Now observe that there is an equivalence
\begin{samepage}
\begin{align*}
\sm{y:A}e(x)=e(y) & \eqvsym \sm{y:A}e(y)=e(x) \\
& \jdeq \fib{e}{e(x)}
\end{align*}
\end{samepage}
by \cref{thm:fib_equiv}, since for each $y:A$ the map
\begin{equation*}
\mathsf{inv} : (e(x)=e(y))\to (e(y)= e(x))
\end{equation*}
is an equivalence by \cref{ex:equiv_grpd_ops}.
The fiber $\fib{e}{e(x)}$ is contractible by \cref{thm:contr_equiv}, so it follows by \cref{ex:contr_equiv} that the type $\sm{y:A}e(x)=e(y)$ is indeed contractible.
\end{proof}

\begin{comment}
As a first application of the fundamental theorem, we compute the identity type of a coproduct.

\begin{defn}
Let $A$ and $B$ be types in $\UU$. We construct equivalences
\begin{align*}
(\id[A+B]{\inl(x)}{\inl(x')}) & \eqvsym (\id[A]{x}{x'}) \\
(\id[A+B]{\inl(x)}{\inr(y')}) & \eqvsym \emptyt \\
(\id[A+B]{\inr(y)}{\inl(x')}) & \eqvsym \emptyt \\
(\id[A+B]{\inr(y)}{\inr(y')}) & \eqvsym (\id[B]{y}{y'}).
\end{align*}
\end{defn}

\begin{constr}
We define by double induction on the disjoint sum the binary relation
\begin{equation*}
E : (A+B)\to (A+B)\to\UU
\end{equation*}
given by
\begin{align*}
E({\inl(x)},{\inl(x')}) & \defeq \id[A]{x}{x'} \\
E({\inl(x)},{\inr(y')}) & \defeq \emptyt \\
E({\inr(y)},{\inl(x')}) & \defeq \emptyt \\
E({\inr(y)},{\inr(y')}) & \defeq (\id[B]{y}{y'}).
\end{align*}
Moreover, we have a term $\rho:\prd{s:A+B}E(s,s)$ defined by $\rho(\inl(x))\defeq\refl{x}$ and $\rho(\inr(y))\defeq\refl{y}$.

Our goal is to construct an equivalence $\eqv{(\id{s}{t})}{E(s,t)}$ for any $s,t:A+B$.
By \cref{thm:id_fundamental} it suffices to show that for any $s:A+B$, the type
\begin{equation*}
\sm{t:A+B}E(s,t)
\end{equation*}
is contractible. The center of contraction is taken to be $\pairr{s,\rho(s)}$, so it remains to construct the contraction
\begin{equation*}
\prd{t:A+B}{e:E(s,t)} \pairr{s,\rho(s)}=\pairr{t,e}.
\end{equation*}
This is done by induction on $s$ and $t$, so we have to show that
\begin{align*}
& \prd{x':A}{p:x=x'} \pairr{\inl(x),\refl{x}}=\pairr{x',p} \\
& \prd{y':A}{q:\emptyt} \pairr{\inl(x),\refl{x}}=\pairr{y',q} \\
& \prd{x':A}{q:\emptyt} \pairr{\inr(y),\refl{y}}=\pairr{x',q} \\
& \prd{y':A}{p:y=y'} \pairr{\inr(y),\refl{y}}=\pairr{y',p}.
\end{align*}
The first and fourth case are easily shown by path induction on $p$, and the second and third case are easily shown by induction on the empty type.
\end{constr}
\end{comment}

\subsection{Disjointness of coproducts}

To give a second application of the fundamental theorem of identity types, we characterize the identity types of coproducts. Our goal in this section is to prove the following theorem.

\begin{thm}\label{thm:id-coprod-compute}
Let $A$ and $B$ be types. Then there are equivalences
\begin{align*}
(\inl(x)=\inl(x')) & \eqvsym (x = x')\\
(\inl(x)=\inr(y')) & \eqvsym \emptyt \\
(\inr(y)=\inl(x')) & \eqvsym \emptyt \\
(\inr(y)=\inr(y')) & \eqvsym (y=y')
\end{align*}
for any $x,x':A$ and $y,y':B$.
\end{thm}

In order to prove \cref{thm:id-coprod-compute}, we first define
a binary relation $\mathsf{Eq\usc{}coprod}_{A,B}$ on the coproduct $A+B$.

\begin{defn}
Let $A$ and $B$ be types. We define
\begin{equation*}
\mathsf{Eq\usc{}coprod}_{A,B} : (A+B)\to (A+B)\to\UU
\end{equation*}
by double induction on the coproduct, postulating
\begin{align*}
\mathsf{Eq\usc{}coprod}_{A,B}(\inl(x),\inl(x')) & \defeq (x=x') \\
\mathsf{Eq\usc{}coprod}_{A,B}(\inl(x),\inr(y')) & \defeq \emptyt \\
\mathsf{Eq\usc{}coprod}_{A,B}(\inr(y),\inl(x')) & \defeq \emptyt \\
\mathsf{Eq\usc{}coprod}_{A,B}(\inr(y),\inr(y')) & \defeq (y=y')
\end{align*}
The relation $\mathsf{Eq\usc{}coprod}_{A,B}$ is also called the \define{observational equality of coproducts}\index{observational equality!of coproducts}.
\end{defn}

\begin{lem}
The observational equality relation $\mathsf{Eq\usc{}coprod}_{A,B}$ on $A+B$ is reflexive, and therefore there is a map
\begin{equation*}
\mathsf{Eq\usc{}coprod\usc{}eq}:\prd{s,t:A+B} (s=t)\to \mathsf{Eq\usc{}coprod}_{A,B}(s,t)
\end{equation*}
\end{lem}

\begin{constr}
The reflexivity term $\rho$ is constructed by induction on $t:A+B$, using
\begin{align*}
\rho(\inl(x))\defeq \refl{\inl(x)}  & : \mathsf{Eq\usc{}coprod}_{A,B}(\inl(x)) \\
\rho(\inr(y))\defeq \refl{\inr(y)} & : \mathsf{Eq\usc{}coprod}_{A,B}(\inr(y)).\qedhere
\end{align*}
\end{constr}

To show that $\mathsf{Eq\usc{}coprod\usc{}eq}$ is a family of equivalences, we will use the fundamental theorem, \cref{thm:id_fundamental}. Moreover, we will use the functoriality of coproducts (established in \cref{ex:coproduct_functor}), along with the following facts about $\Sigma$-types, coproducts, and the empty type:
\begin{align*}
\sm{t:A+B}P(t) & \eqvsym \Big(\sm{x:A}P(\inl(x))\Big)+\Big(\sm{y:B}P(\inr(y))\Big)\\
\sm{x:A}\emptyt & \eqvsym \emptyt \\
A+\emptyt & \eqvsym A.
\end{align*}
All of these equivalences are straightforward to construct, so we leave them as an exercise to the reader.

\begin{lem}\label{lem:is-contr-total-eq-coprod}
For any $s:A+B$ the total space
\begin{equation*}
\sm{t:A+B}\mathsf{Eq\usc{}coprod}_{A,B}(s,t)
\end{equation*}
is contractible.
\end{lem}

\begin{proof}
We will do the proof by induction on $s$. The two cases are similar, so we only show that the total space
\begin{equation*}
\sm{t:A+B}\mathsf{Eq\usc{}coprod}_{A,B}(\inl(x),t)
\end{equation*}
is contractible. Note that we have equivalences
\begin{samepage}
\begin{align*}
& \sm{t:A+B}\mathsf{Eq\usc{}coprod}_{A,B}(\inl(x),t) \\
& \eqvsym \Big(\sm{x':A}\mathsf{Eq\usc{}coprod}_{A,B}(\inl(x),\inl(x'))\Big)+\Big(\sm{y':B}\mathsf{Eq\usc{}coprod}_{A,B}(\inl(x),\inr(y'))\Big) \\
& \eqvsym \Big(\sm{x':A}x=x'\Big)+\Big(\sm{y':B}\emptyt\Big) \\
& \eqvsym \Big(\sm{x':A}x=x'\Big)+\emptyt \\
& \eqvsym \sm{x':A}x=x'.
\end{align*}%
\end{samepage}%
The latter type is contractible by \cref{thm:total_path}.
\end{proof}

\begin{proof}[Proof of \cref{thm:id-coprod-compute}]
The proof is now concluded with an application of \cref{thm:id_fundamental}, using \cref{lem:is-contr-total-eq-coprod}.
\end{proof}

\begin{exercises}
\item
  \begin{subexenum}
  \item \label{ex:is-emb-empty}Show that the map $\emptyt\to A$ is an embedding for every type $A$.
  \item \label{ex:is-emb-inl-inr}Show that $\inl:A\to A+B$ and $\inr:B\to A+B$ are embeddings for any two types $A$ and $B$.
  \end{subexenum}
\item Consider an equivalence $e:A\simeq B$. Construct an equivalence
  \begin{equation*}
    (e(x)=y)\simeq(x=e^{-1}(y))
  \end{equation*}
  for every $x:A$ and $y:B$.
\item Show that
\begin{equation*}
(f\htpy g)\to (\mathsf{is\usc{}emb}(f)\leftrightarrow\mathsf{is\usc{}emb}(g))
\end{equation*}
for any $f,g:A\to B$.
\item \label{ex:emb_triangle}Consider a commuting triangle
\begin{equation*}
\begin{tikzcd}[column sep=tiny]
A \arrow[rr,"h"] \arrow[dr,swap,"f"] & & B \arrow[dl,"g"] \\
& X
\end{tikzcd}
\end{equation*}
with $H:f\htpy g\circ h$.
\begin{subexenum}
\item Suppose that $g$ is an embedding. Show that $f$ is an embedding if and only if $h$ is an embedding.
\item Suppose that $h$ is an equivalence. Show that $f$ is an embedding if and only if $g$ is an embedding.
\end{subexenum}
\item \label{ex:is-equiv-is-equiv-functor-coprod}Consider two maps $f:A\to A'$ and $g:B \to B'$.
  \begin{subexenum}
  \item Show that if the map
    \begin{equation*}
      f+g:(A+B)\to (A'+B')
    \end{equation*}
    is an equivalence, then so are both $f$ and $g$ (this is the converse of \cref{ex:coproduct_functor_equivalence}).
  \item \label{ex:is-emb-coprod}Show that $f+g$ is an embedding if and only if both $f$ and $g$ are embeddings.
  \end{subexenum}
\item \label{ex:htpy_total}
\begin{subexenum}
\item Let $f,g:\prd{x:A}B(x)\to C(x)$ be two families of maps. Show that
\begin{equation*}
\Big(\prd{x:A}f(x)\htpy g(x)\Big)\to \Big(\total{f}\htpy \total{g}\Big).
\end{equation*}
\item Let $f:\prd{x:A}B(x)\to C(x)$ and let $g:\prd{x:A}C(x)\to D(x)$. Show that
\begin{equation*}
\total{\lam{x}g(x)\circ f(x)}\htpy \total{g}\circ\total{f}.
\end{equation*}
\item For any family $B$ over $A$, show that
\begin{equation*}
\total{\lam{x}\idfunc[B(x)]}\htpy\idfunc.
\end{equation*}
\end{subexenum}
\item \label{ex:id_fundamental_retr}Let $a:A$, and let $B$ be a type family over $A$.
\begin{subexenum}
\item Use \cref{ex:htpy_total,ex:contr_retr} to show that if each $B(x)$ is a retract of $\id{a}{x}$, then $B(x)$ is equivalent to $\id{a}{x}$ for every $x:A$.
\item Conclude that for any family of maps
\begin{equation*}
f : \prd{x:A} (a=x) \to B(x),
\end{equation*}
if each $f(x)$ has a section, then $f$ is a family of equivalences.
\end{subexenum}
\item Use \cref{ex:id_fundamental_retr} to show that for any map $f:A\to B$, if
\begin{equation*}
\apfunc{f} : (x=y) \to (f(x)=f(y))
\end{equation*}
has a section for each $x,y:A$, then $f$ is an embedding.
\item \label{ex:path-split}We say that a map $f:A\to B$ is \define{path-split}\index{path-split|textbf} if $f$ has a section, and for each $x,y:A$ the map
\begin{equation*}
\apfunc{f}(x,y):(x=y)\to (f(x)=f(y))
\end{equation*}
also has a section. We write $\mathsf{path\usc{}split}(f)$\index{path_split(f)@{$\mathsf{path\usc{}split}(f)$}|textbf} for the type
\begin{equation*}
\mathsf{sec}(f)\times\prd{x,y:A}\mathsf{sec}(\apfunc{f}(x,y)).
\end{equation*}
Show that for any map $f:A\to B$ the following are equivalent:
\begin{enumerate}
\item The map $f$ is an equivalence.
\item The map $f$ is path-split.
\end{enumerate}
\begin{comment}
\item \label{ex:eqv_sigma_mv}Consider a map
\begin{equation*}
f:A \to \sm{y:B}C(y).
\end{equation*}
\begin{subexenum}
\item Construct a family of maps
\begin{equation*}
f':\prd{y:B} \fib{\proj 1\circ f}{y}\to C(y).
\end{equation*}
\item Construct an equivalence
\begin{equation*}
\eqv{\fib{f'(b)}{c}}{\fib{f}{(b,c)}}
\end{equation*}
for every $(b,c):\sm{y:B}C(y)$.
\item Conclude that the following are equivalent:
\begin{enumerate}
\item $f$ is an equivalence.
\item $f'$ is a family of equivalences.
\end{enumerate}
\end{subexenum}
\item \label{ex:coh_intro}Consider a type $A$ with base point $a:A$, and let $B$ be a type family on $A$ that implies the identity type, i.e., there is a term
\begin{equation*}
\alpha : \prd{x:A} B(x)\to (a=x).
\end{equation*}
Show that the \define{coherence reduction map}
\begin{equation*}
\mathsf{coh\usc{}red} : \Big(\sm{y:B(a)}\alpha(a,y)=\refl{a}\Big) \to \Big(\sm{x:A}B(x)\Big)
\end{equation*}
defined by $\lam{(y,q)}(a,y)$ is an equivalence.
\end{comment}
\item \label{ex:fiber_trans}Consider a triangle
\begin{equation*}
\begin{tikzcd}[column sep=small]
A \arrow[rr,"h"] \arrow[dr,swap,"f"] & & B \arrow[dl,"g"] \\
& X
\end{tikzcd}
\end{equation*}
with a homotopy $H:f\htpy g\circ h$ witnessing that the triangle commutes.
\begin{subexenum}
\item Construct a family of maps
\begin{equation*}
\mathsf{fib\usc{}triangle}(h,H):\prd{x:X}\fib{f}{x}\to\fib{g}{x},
\end{equation*}
for which the square
\begin{equation*}
\begin{tikzcd}[column sep=8em]
\sm{x:X}\fib{f}{x} \arrow[r,"\total{\mathsf{fib\usc{}triangle}(h,H)}"] \arrow[d] & \sm{x:X}\fib{g}{x} \arrow[d] \\
A \arrow[r,swap,"h"] & B
\end{tikzcd}
\end{equation*}
commutes, where the vertical maps are as constructed in \cref{ex:fib_replacement}.
\item Show that $h$ is an equivalence if and only if $\mathsf{fib\usc{}triangle}(h,H)$ is a family of equivalences.
\end{subexenum}
\begin{comment}
\item Let $f:A\to B$ be a map, and let $s,t : \fib{f}{b}$. Consider the function
\begin{equation*}
\varphi : (s=t)\to \fib{\apfunc{f}}{\ct{\proj 2(s)}{\proj 2(t)^{-1}}}
\end{equation*}
given by $\varphi(\refl{s})=(\refl{\proj 1(s)},\mathsf{right\usc{}inv}(\proj 2(s))^{-1})$. Show that this map is an equivalence. Conclude that for any $q:f(x)=f(y)$ we have an equivalence
\begin{equation*}
((x,q)=(y,\refl{f(y)})) \simeq \fib{\apfunc{f}}{q}.
\end{equation*}
\item Construct an equivalence
\begin{equation*}
\eqv{\big(\sm{x:A}f(x)=y\big)}{\big(\sm{x:A}y=f(x)\big)}.
\end{equation*}
%Conclude that $\sm{x:A}a=x$ is contractible for any $a:A$.
\end{comment}
\end{exercises}


% !TEX root = ../zeth-protocol-specification.tex

\chapter{Extended discussion on the security of $\mimc{}$ in different settings}\label{appendix:mimc-security}

In the original design proposed in the $\mimc{}$ paper~\cite{albrecht2016mimc}, the round function is represented as a ``shifted'' permutation via a cubic map (i.e.~the round input message is added to the key and round constant - the ``shift'' -, and a map $x^{\exponent{}}$ permutes the element in the underlying field $\FFx{2^n}$, $n \in \NN$, where $\gcd(\exponent{}, 2^n - 1) = 1$). This function (which is a permutation and therefore invertible) acts as a substitution box (S-box) and brings non-linearity to the scheme, as usually required for security.

In other sections of the paper, however, the $\mimc{}$ authors proposed generalizations to the initial design. These allow $\mimc{}$ to be used:
\begin{itemize}
    \item over prime fields of odd characteristic (i.e.~$\FFx{p}$, $p$ odd prime),
    \item with different permutation polynomials (i.e.~using different exponents in the round function)
\end{itemize}

Understanding the relationships between these various settings is required in order to use $\mimc{}$ to operate over prime fields of odd characteristic with a non-cubic permutation monomial.

Overall, for $\mimc{}$ to be considered secure, it is important that no attack in the literature (that may provide a significant speedup compared to ``exhaustive key search'') can succesfully be mounted by a $\ppt$ adversary. Two main families of attacks exist: statistical attacks and algebraic attacks.

\paragraph{Statistical attacks.}

In the ``Security Analysis'' section~\cite[Section 4.2]{albrecht2016mimc}, the authors explain that since the cubic function is an Almost Perfect Nonlinear map (\apn)\footnote{A function $f(x) = x^{\exponent{}}$ over $\FFx{p^n}$ is said to be differentially $k$-uniform if $k$ is the maximum number of solutions $x \in \FFx{p^n}$ of $f(x + d) - f (x) = D$ where $d, D \in \FFx{p^n}$ and $d \neq 0$. If $f$ is a 2-uniform mapping, we say that $f$ is almost perfect nonlinear. See e.g.~\cite{DBLP:journals/tit/HellesethRS99} for more information.}, linear attacks pose no threat to $\mimc{}$.

We observe that this claim aligns with~\cite[Theorem 2]{DBLP:journals/tit/HellesethRS99}. In fact if $\mimc{}$ is operated over $\FFx{2^n}$, it is easy to see that the degree of the cubic map can be expressed as $3 = 2^t + 1$, where $t = 1$, and where $n$ and $1$ are trivially coprime. This case is covered by~\cite[Theorem 2]{DBLP:journals/tit/HellesethRS99} which confirms that the cubic function $S(x) = x^3$ over $\FFx{2^n}$ is an APN/2-uniform mapping, as desired for differential and linear cryptanalysis resistance.

Likewise, in~\cite[Section 5.1]{albrecht2016mimc} the authors claim that, provided that the cubic map is a permutation over the prime field of interest, $\mimc{}$ can be used to operate over prime fields of odd characteristic. In this case too, $S(x) = x^3$ is an APN, provided $p \neq 3$ (as reported by~\cite[Theorem 3, item 3]{DBLP:journals/tit/HellesethRS99}).

In~\cite[Section 5.3]{albrecht2016mimc} the choice of the map degree is relaxed to be of the general form $2^t \pm 1$. Unfortunately, the authors showed that the case $\exponent{} = 2^t + 1$ is not as good as it initially seems in $\FFx{2^n}$, due to term cancellation in fields of characteristic 2 that renders the resulting polynomial sparse\footnote{Since the round function is a polynomial, the whole scheme can be seen as a polynomial with overall degree and ``sparsity'' that depends on the underlying field characteristic, degree of the round function and number of rounds.}. More precisely the degree of the polynomial will be bounded by $3^r$, $r$ being the number of rounds, which does not constitute an improvement on the case of $\exponent{} = 3$. For this very reason, exponents of the form $2^t + 1, t > 1$, may not be of interest (sparse polynomial and more expensive arithmetic in the round function).

Likewise, if the map degree $\exponent{}$ is chosen to be of the form $2^t + 1$, with $\gcd(\exponent{}, 2^n - 1) = 1$ in the context of $\mimc{}$ over $\FFx{2^n}$, it is necessary to bear in mind that, without the extra requirement that $t$ needs to be coprime with $n$, then this case is not covered by~\cite[Theorem 2]{DBLP:journals/tit/HellesethRS99}, and $S(x) = x^\exponent{}$ does not have differential 2-uniformity anymore - violating the claim made in~\cite[Section 4.2]{albrecht2016mimc} paragraph ``Linear Attacks'' about optimal resistance against linear and differential cryptanalysis. (In fact, depending on the value of $g = \gcd(n, t)$, the map $S(x) = x^{2^t + 1}$ would be differentially $2^g$-uniform~\cite{DBLP:conf/eurocrypt/Nyberg93} - contrasting with the setting considered in paragraph ``Linear attacks'' where $\exponent{} = 3$).
The case $\exponent{} = 2^t - 1$ does not yield an APN over $\FFx{2^n}$ either (except in the case $t = 2$ which reduces to the case $2^{t'} + 1$ for $t' = 1$). Similar observations show that picking round function degrees of the form $2^t \pm 1$ in the context where $\mimc{}$ is defined over prime fields $\FFx{p}$, $p$ odd prime, does not yield APNs.

\medskip

Overall, when studying the resistance of $\mimc{}$ against statistical attacks, we are interested in the probability that an input difference ($d$) is mapped into an output difference ($D$). That is, we are studying the probability of the following event:
\[
    F(x + d) - F(x) = D
\]
where $F$ is a function that may either represent a single round, a set of rounds, or the full cipher.

Over a single round of $\mimc{}$ (i.e.~$F(x) = S(x)$), this probability is bounded by $(\exponent{}-1)/p$ \emph{provided that the exponent $\exponent{}$ is ``small''} (i.e.~small compared to the size of the field).
By assuming that the different rounds of the scheme are independent, the probability that an input difference gets mapped to an output difference, when $F$ represents the full cipher, becomes bounded as $\Pr[F(x + d) - F(x) = D] \leq ((\exponent{}-1)/p)^\rounds$.

For security, we want $((\exponent{}-1)/p)^\rounds$ to be bounded by $2^{-\secpar}$, where $\secpar$ is the security level (e.g.~128). Hence, we need
\[
    \left(\frac{\exponent{}-1}{p}\right)^\rounds \leq 2^{-\secpar}
\]
that is, we want
\[
    \rounds \geq \frac{\secpar}{\log_2(\frac{p}{\exponent{}-1})}
\]

As such, if the exponent is much smaller than the size of the field, few rounds are sufficient to prevent the differential attacks.

\paragraph{Algebraic attacks.}

While permutation monomials of degree $\exponent{} = 2^t \pm 1$ may not constitute APNs in the various $\mimc{}$ settings, it is important to note (as highlighted by Grassi in~\cite{mimc-security-communications}) that when working over finite fields $\FFx{p}$ of \emph{large} prime characteristic $p$ or extension fields $\FFx{2^n}$ of large extension degrees $n$, the algebraic attacks (exploiting the low-degree of the cipher) are much more efficient than the statistical attacks (i.e.~they can break a much higher number of rounds).

In fact, when considering security against algebraic attacks, we want (roughly speaking) the polynomial that defines the cipher to be of maximum degree and full (or at least, dense). That is we want the degree of the polynomial to be higher than $2^{\secpar}$. Since in $\mimc{}$ the S-box is defined as $S(x) = x^{\exponent{}}$, then after $\rounds$ rounds the degree of the polynomial describing the cipher is $\exponent{}^{\rounds}$. Hence, we need

\[
    \exponent{}^{\rounds} \geq 2^{\secpar}
\]
that is, we want
\[
    \rounds \geq \secpar \log_{\exponent}(2)
\]

\begin{remark}
    More rounds may be required as advised in~\cite{DBLP:conf/asiacrypt/Eichlseder0LORS20} to prevent some algebraic attacks that can be mounted when $\mimc{}$ is used over binary fields $\FFx{2^n}$.
\end{remark}

It is important to note that the security analysis related to algebraic attacks relies on the fact that the polynomial describing the cipher is dense/full. If this assumption is violated, a more granular security analysis needs to be carried out for the setting of interest.

\begin{notebox}
    For \emph{small exponents and large prime fields} (e.g.~for $\secpar = 128$, $p = 2^{128}$ and $\exponent{} = 3$), we see that the lower bound on the number of rounds is (much) smaller in the context of statistical attacks than in the context of algebraic attacks. As such, we see that in such settings algebraic attacks are much more powerful than statistical attacks. Hence, when instantiating $\mimc{}$ with a \emph{small} exponent of the form $2^t \pm 1$, it is crucial to make sure that, even if the resulting map is not an APN, the polynomial describing the cipher remains full/dense. Importantly, if the setting is changed (e.g.~to use exponents that are ``big'' w.r.t.~the field size) the security analysis proposed in~\cite{albrecht2016mimc} must be changed.
\end{notebox}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% APP.TEX						    July 1990      %
%                                                                          %
% This file is part of the AMS-LaTeX Version 1.0 distribution              %
%   American Mathematical Society, Technical Support Group,                %
%   P. O. Box 6248, Providence, RI 02940                                   %
%   800-321-4AMS (321-4267) or 401-455-4080                                %
%   Internet: Tech-Support@Math.AMS.com                                    %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\appendix
\chapter[Nonselfadjoint Equations]%
{On the Eigenvalues and Eigenfunctions\\
of Certain Classes of Nonselfadjoint Equations}

\section{Compact operators} In an appropriate Hilbert space, all
the equations considered below can be reduced to the
form
\begin{equation}
y=L(\lambda)y+f,\qquad L(\lambda)=K_0+\lambda K_1+\dots+\lambda^n
K_n,
\end{equation}
where $y$ and $f$ are elements of the Hilbert space,
$\lambda$ is a complex parameter, and the $K_i$ are
compact operators.

A compact operator $R(\lambda)$ is the resolvent of
$L(\lambda)$ if $(E+R)(E-L)=E$.  If the resolvent exists
for some $\lambda=\lambda_0$, it is a meromorphic function
of $\lambda$ on the whole plane.  We say that $y$ is
an eigenelement for the eigenvalue $\lambda=c$, and that
$y_1,\dots,y_k$ are elements associated with it (or
associated elements) if
\begin{equation}
y=L(c)y,\quad y_k=L(c)y_k+\frac{1}{1!}\,\frac{\partial L(c)}{\partial c}
y_{k-1}+\dots+\frac{1}{k!}\,\frac{\partial^kL(c)}{\partial c^k}y.
\end{equation}
Note that if $y$ is an eigenelement and $y_1,\dots,y_k$
are elements associated with it, then $y(t)=e^{ct}(y_k
+y_{k-1}t/1!+\dots+yt^k/k!)$ is a solution of the equation
$y=K_0y+K_1\partial y/\partial t+\dots+K_n\partial^ny/
\partial t^n$.

\endinput


\section{Basic notion}
In order to make notation clear, we will make difference between these
two symbols: $\subseteq$ and $\subsetneq$. Let $A,B$ be arbitrary
sets. $A\subseteq B$ means that subset with the possibility of $A=B$.
While $A\subsetneq B$ means strict subset, i.e., $A\neq B$.

\bigskip

\noindent Notation:\par
\begin{tabular}{lp{13cm}}
$\thread_i$                     &  threads                  \\
$\V=\{\vrtx_i\}$                     & set of vertices $\vrtx_i$, the vertices are represented by numbers $1, \ldots, |\V|$  \\
$\E=\{\edge_i\}\subseteq \V\times \V$          & set of eges     \\
$\G=(\V, \E)$                       & a graph                   \\
%$l_i, l_{ij}$                    & \\
$\G_1\subgrphisoeq \G', \G_2\subgrphisoneq \G'$               & graph $\G_1$ is subgraph isomorphic with $\G'$ or $\G_2$ is strictly subgraph isomorphic with $\G'$, i.e., $\G_2\neq \G'$  \\
$\pattern$                       & a graph that is a pattern \\
$c_i=(\vrtx_i, \vrtx_j, \lbl_i, \lbl_{ij}, \lbl_j)$  &  5-tuple description of edge; single element of a DFS code \\
%$\dfscode(\G)=(c_1,\ldots, c_n)$     &  a canonical code  of a graph $\G$  \\
$\mindfscode(\G)$                       & minimal (canonical) DFS code of a graph $\G$ \\
$\embed(\G,\G'), \G\subgrphisoeq \G'$    & the set of all embeddings of a graph $\G$ in $\G'$ \\
$\extend(\G,\G'), \G\subgrphisoeq \G'$     & is the set of extensions of the graph $\G$ from the right-most path of $\mindfscode(\G)$ in the graph $\G'$\\
$\extend_{\db}(\G)=\bigcup_{\G'\in\db}\extend(\G, \G')$       & set of all extensions of the right-most path of $\mindfscode(\G)$ of graphs in $\db$ \\
$\db=\{\G_i\}$           & the database of graphs \\
$\embedcol_i$            & $i$-th embedding column containing elements $(idx,vid)$ \\
$\neigharray, \neighoffsetarray, \elabelarray, \vlabelarray$   & neighborhood array, neighborhood offset array, vertex label array \\
$\rmpath$                & is the set of indices into $\mindfscode(\G)$ describing the edges on the right-most path \\
$\rmpath^{GPU}$           & is the set of vertex ids of pattern $\pattern$ on the right-most path \\
$\extensionarray$        & an array containing information of possible extensions \\
\end{tabular}

\bigskip

\notacmnt{robert}{Array should be typeset using math bold font, e.g.,
  $\mathbf{L}$. Sets should be typeset using calligraphic font, e.g.,
  $\mathcal{L}$ or its specific notation, e.g., $\extend_{\db}(\G)$.}

\bigskip

\notacmnt{robert}{Use typewriter for fields in arrays, e.g., $\extensionarray[i].\texttt{row}$}

\bigskip

\bigskip

\notacmnt{robert}{Arrays are always indexed from \textbf{0} !!!!}

\bigskip

The GSpan algorithm, and its variants, works by depth-first search expanding of the pattern adding
edge-by-edge and checking the minimality of the pattern DFS code.

\notacmnt{robert}{We have to add the following notation:  1) extension array; 2) labels of edges and vertices; 3)}

\bigskip


\chapter{Notation}

\begin{table}[H]
\centering
\begin{tabular}{c l} \hline
\textbf{Notation}&\textbf{Description} \\ \hline
$G$&influence graph\\
$V$&set of nodes of $G$\\
$E$&set of edges of $G$\\
$W$&set of influence weights corresponding to each edge in $E$\\
$w_{u,v}$&weight of edge $(u,v)$\\
$n$&$|V|$, number of nodes\\
$m$&$|E|$, number of edges\\
\hline
\end{tabular}
\caption{Notation used.}
\label{tab:thesis_notation}
\end{table}


\chapter{Polynomials and Rationals}

Many operations in computer algebra are concerned with polynomials
\index{Polynomial} and rational functions\index{Rational function}.  In
this section, we review some of the switches and operators available for
this purpose.  These are in addition to those that work on general
expressions (such as {\tt DF} and {\tt INT}) described elsewhere.  In the
case of operators, the arguments are first simplified before the
operations are applied.  In addition, they operate only on arguments of
prescribed types, and produce a type mismatch error if given arguments
which cannot be interpreted in the required mode with the current switch
settings.  For example, if an argument is required to be a kernel and
{\tt a/2} is used (with no other rules for {\tt A}), an error
\begin{verbatim}
        A/2 invalid as kernel
\end{verbatim}
will result.

With the exception of those that select various parts of a polynomial or
rational function, these operations have potentially significant effects on
the space and time associated with a given calculation. The user should
therefore experiment with their use in a given calculation in order to
determine the optimum set for a given problem.

One such operation provided by the system is an operator {\tt LENGTH}
\ttindex{LENGTH} which returns the number of top level terms in the
numerator of its argument.  For example,
\begin{verbatim}
        length ((a+b+c)^3/(c+d));
\end{verbatim}
has the value 10.  To get the number of terms in the denominator, one
would first select the denominator by the operator {\tt DEN}\ttindex{DEN}
and then call {\tt LENGTH}, as in
\begin{verbatim}
        length den ((a+b+c)^3/(c+d));
\end{verbatim}
Other operations currently supported, the relevant switches and operators,
and the required argument and value modes of the latter, follow.

\section{Controlling the Expansion of Expressions}

The switch {\tt EXP}\ttindex{EXP} controls the expansion of expressions.  If
it is off, no expansion of powers or products of expressions occurs.
Users should note however that in this case results come out in a normal
but not necessarily canonical form.  This means that zero expressions
simplify to zero, but that two equivalent expressions need not necessarily
simplify to the same form.

{\it Example:} With {\tt EXP} on, the two expressions
\begin{verbatim}
        (a+b)*(a+2*b)
\end{verbatim}
and
\begin{verbatim}
        a^2+3*a*b+2*b^2
\end{verbatim}
will both simplify to the latter form.  With {\tt EXP}
off, they would remain unchanged, unless the complete factoring {\tt
(ALLFAC)} option were in force. {\tt EXP} is normally on.

Several operators that expect a polynomial as an argument behave
differently when {\tt EXP} is off, since there is often only one term at
the top level.  For example, with {\tt EXP} off
\begin{verbatim}
        length((a+b+c)^3/(c+d));
\end{verbatim}
returns the value 1.

\section{Factorization of Polynomials}\index{Factorization}
{\REDUCE} is capable of factorizing univariate and multivariate polynomials
that have integer coefficients, finding all factors that also have integer
coefficients. The package for doing this was written by Dr. Arthur C.
Norman and Ms. P. Mary Ann Moore at The University of Cambridge. It is
described in P. M. A. Moore and A. C. Norman, ``Implementing a Polynomial
Factorization and GCD Package'', Proc. SYMSAC '81, ACM (New York) (1981),
109-116.

The easiest way to use this facility is to turn on the switch
{\tt FACTOR},\ttindex{FACTOR} which causes all expressions to be output in
a factored form.  For example, with {\tt FACTOR} on, the expression
{\tt A\verb|^|2-B\verb|^|2} is returned as {\tt (A+B)*(A-B)}.

It is also possible to factorize a given expression explicitly.  The
operator {\tt FACTORIZE}\ttindex{FACTORIZE} that invokes this facility is
used with the syntax
\begin{verbatim}
     FACTORIZE(EXPRN:polynomial[,INTEXP:prime integer]):list,
\end{verbatim}
the optional argument of which will be described later. Thus to find and
display all factors of the cyclotomic polynomial $x^{105}-1$, one could
write:
\begin{verbatim}
        factorize(x^105-1);
\end{verbatim}
The result is a list of factor,exponent pairs.
In the above example, there is no overall numerical factor in the result,
so the results will consist only of polynomials in x.  The number of such
polynomials can be found by using the operator {\tt LENGTH}.\ttindex{LENGTH}
If there is a numerical factor, as in factorizing $12x^{2}-12$,
that factor will appear as the first member of the result.
It will however not be factored further.  Prime factors of such numbers
can be found, using a probabilistic algorithm, by turning on the switch
{\tt IFACTOR}.\ttindex{IFACTOR}  For example,
\begin{verbatim}
        on ifactor; factorize(12x^2-12);
\end{verbatim}
would result in the output
\begin{verbatim}
	{{2,2},{3,1},{X + 1,1},{X - 1,1}}.
\end{verbatim}

If the first argument of {\tt FACTORIZE} is an integer, it will be
decomposed into its prime components, whether or not {\tt IFACTOR} is on.

Note that the {\tt IFACTOR} switch only affects the result of {\tt FACTORIZE}.
It has no effect if the {\tt FACTOR}\ttindex{FACTOR} switch is also on.

The order in which the factors occur in the result (with the exception of
a possible overall numerical coefficient which comes first) can be system
dependent and should not be relied on. Similarly it should be noted that
any pair of individual factors can be negated without altering their
product, and that {\REDUCE} may sometimes do that.

The factorizer works by first reducing multivariate problems to univariate
ones and then solving the univariate ones modulo small primes. It normally
selects both evaluation points and primes using a random number generator
that should lead to different detailed behavior each time any particular
problem is tackled. If, for some reason, it is known that a certain
(probably univariate) factorization can be performed effectively with a
known prime, {\tt P} say, this value of {\tt P} can be handed to
{\tt FACTORIZE}\ttindex{FACTORIZE} as a second
argument. An error will occur if a non-prime is provided to {\tt FACTORIZE} in
this manner. It is also an error to specify a prime that divides the
discriminant of the polynomial being factored, but users should note that
this condition is not checked by the program, so this capability should be
used with care.

Factorization can be performed over a number of polynomial coefficient
domains in addition to integers. The particular description of the relevant
domain should be consulted to see if factorization is supported. For
example, the following statements will factorize $x^{4}+1$ modulo 7:
\begin{verbatim}
        setmod 7;
        on modular;
        factorize(x^4+1);
\end{verbatim}
The factorization module is provided with a trace facility that may be useful
as a way of monitoring progress on large problems, and of satisfying
curiosity about the internal workings of the package. The most simple use
of this is enabled by issuing the {\REDUCE} command\ttindex{TRFAC}
{\tt on trfac;} .
Following this, all calls to the factorizer will generate informative
messages reporting on such things as the reduction of multivariate to
univariate cases, the choice of a prime and the reconstruction of full
factors from their images.  Further levels of detail in the trace are
intended mainly for system tuners and for the investigation of suspected
bugs.  For example, {\tt TRALLFAC} gives tracing information at all levels
of detail.  The switch that can be set by {\tt on timings;} makes it
possible for one who is familiar with the algorithms used to determine
what part of the factorization code is consuming the most resources.
{\tt on overview}; reduces the amount of detail presented in other forms of
trace.  Other forms of trace output are enabled by directives of the form
\begin{verbatim}
        symbolic set!-trace!-factor(<number>,<filename>);
\end{verbatim}
where useful numbers are 1, 2, 3 and 100, 101, ... .  This facility is
intended to make it possible to discover in fairly great detail what just
some small part of the code has been doing --- the numbers refer mainly to
depths of recursion when the factorizer calls itself, and to the split
between its work forming and factorizing images and reconstructing full
factors from these.  If {\tt NIL} is used in place of a filename the trace
output requested is directed to the standard output stream.  After use of
this trace facility the generated trace files should be closed by calling
\begin{verbatim}
        symbolic close!-trace!-files();
\end{verbatim}
{\it NOTE:} Using the factorizer with {\tt MCD}\ttindex{MCD} off will
result in an error.

\section{Cancellation of Common Factors}
Facilities are available in {\REDUCE} for cancelling common factors in the
numerators and denominators of expressions, at the option of the user. The
system will perform this greatest common divisor computation if the switch
{\tt GCD}\ttindex{GCD} is on. ({\tt GCD} is normally off.)

A check is automatically made, however, for common variable and numerical
products in the numerators and denominators of expressions, and the
appropriate cancellations made.

When {\tt GCD} is on, and {\tt EXP} is off, a check is made for square
free factors in an expression.  This includes separating out and
independently checking the content of a given polynomial where
appropriate. (For an explanation of these terms, see Anthony C. Hearn,
``Non-Modular Computation of Polynomial GCDs Using Trial Division'', Proc.
EUROSAM 79, published as Lecture Notes on Comp.  Science, Springer-Verlag,
Berlin, No 72 (1979) 227-239.)

{\it Example:} With {\tt EXP}\ttindex{EXP} off and {\tt GCD}\ttindex{GCD}
on,
the polynomial {\tt a*c+a*d+b*c+b*d} would be returned as {\tt (A+B)*(C+D)}.

Under normal circumstances, GCDs are computed using an algorithm described
in the above paper. It is also possible in {\REDUCE} to compute GCDs using
an alternative algorithm, called the EZGCD Algorithm, which uses modular
arithmetic.  The switch {\tt EZGCD}\ttindex{EZGCD}, if on in addition to
{\tt GCD}, makes this happen.

In non-trivial cases, the EZGCD algorithm is almost always better
than the basic algorithm, often by orders of magnitude.  We therefore
{\em strongly\/} advise users to use the {\tt EZGCD} switch where they have the
resources available for supporting the package.

For a description of the EZGCD algorithm, see J. Moses and D.Y.Y. Yun,
``The EZ GCD Algorithm'', Proc. ACM 1973, ACM, New York (1973) 159-166.

{\it NOTE:}
This package shares code with the factorizer, so a certain amount of trace
information can be produced using the factorizer trace switches.

\subsection{Determining the GCD of Two Polynomials}
This operator, used with the syntax
\begin{verbatim}
        GCD(EXPRN1:polynomial,EXPRN2:polynomial):polynomial,
\end{verbatim}
returns the greatest common divisor of the two polynomials {\tt EXPRN1} and
{\tt EXPRN2}.

{\it Examples:}
\begin{verbatim}
        gcd(x^2+2*x+1,x^2+3*x+2) ->  X+1
        gcd(2*x^2-2*y^2,4*x+4*y) ->  2*X+2*Y
        gcd(x^2+y^2,x-y)         ->  1.
\end{verbatim}

\section{Working with Least Common Multiples}

Greatest common divisor calculations can often become expensive if
extensive work with large rational expressions is required. However, in
many cases, the only significant cancellations arise from the fact that
there are often common factors in the various denominators which are
combined when two rationals are added. Since these denominators tend to be
smaller and more regular in structure than the numerators, considerable
savings in both time and space can occur if a full GCD check is made when
the denominators are combined and only a partial check when numerators are
constructed. In other words, the true least common multiple of the
denominators is computed at each step. The switch {\tt LCM}\ttindex{LCM}
is available for this purpose, and is normally on.

In addition, the operator {\tt LCM},\ttindex{LCM} used with the syntax
\begin{verbatim}
        LCM(EXPRN1:polynomial,EXPRN2:polynomial):polynomial,
\end{verbatim}
returns the least common multiple of the two polynomials {\tt EXPRN1} and
{\tt EXPRN2}.

{\it Examples:}
\begin{verbatim}
        lcm(x^2+2*x+1,x^2+3*x+2) ->  X**3 + 4*X**2 + 5*X + 2
        lcm(2*x^2-2*y^2,4*x+4*y) ->  4*(X**2 - Y**2)
\end{verbatim}

\section{Controlling Use of Common Denominators}

When two rational functions are added, {\REDUCE} normally produces an
expression over a common denominator. However, if the user does not want
denominators combined, he or she can turn off the switch {\tt MCD}
\ttindex{MCD} which controls this process.  The latter switch is
particularly useful if no greatest common divisor calculations are
desired, or excessive differentiation of rational functions is required.

{\it CAUTION:}  With {\tt MCD} off, results are not guaranteed to come out in
either normal or canonical form.  In other words, an expression equivalent
to zero may in fact not be simplified to zero.  This option is therefore
most useful for avoiding expression swell during intermediate parts of a
calculation.

{\tt MCD}\ttindex{MCD} is normally on.

\section{REMAINDER Operator}\ttindex{REMAINDER}

This operator is used with the syntax
\begin{verbatim}
     REMAINDER(EXPRN1:polynomial,EXPRN2:polynomial):polynomial.
\end{verbatim}
It returns the remainder when {\tt EXPRN1} is divided by {\tt EXPRN2}.  This
is the true remainder based on the internal ordering of the variables, and
not the pseudo-remainder. The pseudo-remainder \ttindex{PSEUDO\_REMAINDER}
and in general pseudo-division \ttindex{PSEUDO\_DIVIDE} of polynomials
can be calculated after loading  the {\tt polydiv} package.
Please refer to the documentation of this package for details.

{\it Examples:}
\begin{verbatim}
        remainder((x+y)*(x+2*y),x+3*y) ->  2*Y**2
        remainder(2*x+y,2)             ->  Y.
\end{verbatim}

{\it CAUTION:} In the default case, remainders are calculated over the
integers.  If you need the remainder with respect to another domain, it
must be declared explicitly.

{\it Example:}
\begin{verbatim}
        remainder(x^2-2,x+sqrt(2)); -> X^2 - 2
        load_package arnum;
        defpoly sqrt2**2-2;
        remainder(x^2-2,x+sqrt2); -> 0
\end{verbatim}

\section{RESULTANT Operator}\ttindex{RESULTANT}

This is used with the syntax
\begin{verbatim}
     RESULTANT(EXPRN1:polynomial,EXPRN2:polynomial,VAR:kernel):
        polynomial.
\end{verbatim}
It computes the resultant of the two given polynomials with respect to the
given variable, the coefficients of the polynomials can be taken from any
domain. The result can be identified as the determinant of a
Sylvester matrix, but can often also be thought of informally as the
result obtained when the given variable is eliminated between the two input
polynomials. If the two input polynomials have a non-trivial GCD their
resultant vanishes.

The switch {\tt Bezout}\ttindex{Bezout} controls the computation of the
resultants. It is off by default. In this case a subresultant algorithm
is used. If the switch Bezout is turned on, the resultant is computed via
the Bezout Matrix. However, in the latter case, only polynomial coefficients
are permitted.

\begin{samepage}
The sign conventions used by the resultant function follow those in R.
Loos, ``Computing in Algebraic Extensions'' in ``Computer Algebra --- Symbolic
and Algebraic Computation'', Second Ed., Edited by B. Buchberger, G.E.
Collins and R. Loos, Springer-Verlag, 1983. Namely, with {\tt A} and {\tt B}
not dependent on {\tt X}:

\begin{verbatim}
                               deg(p)*deg(q)
   resultant(p(x),q(x),x)= (-1)             *resultant(q,p,x)

                            deg(p)
   resultant(a,p(x),x)   = a

   resultant(a,b,x)      = 1
\end{verbatim}
\end{samepage}

{\it Examples:}

\begin{samepage}
\begin{verbatim}
                                     2
   resultant(x/r*u+y,u*y,u)   ->  - y
\end{verbatim}
\end{samepage}

{\it calculation in an algebraic extension:}

\begin{samepage}
\begin{verbatim}
   load arnum;
   defpoly sqrt2**2 - 2;

   resultant(x + sqrt2,sqrt2 * x +1,x) -> -1
\end{verbatim}
\end{samepage}

{\it or in a modular domain:}

\begin{samepage}
\begin{verbatim}
   setmod 17;
   on modular;

   resultant(2x+1,3x+4,x)    -> 5
\end{verbatim}
\end{samepage}
\section{DECOMPOSE Operator}\ttindex{DECOMPOSE}

The {\tt DECOMPOSE} operator takes a multivariate polynomial as argument,
and returns an expression and a list of equations from which the
original polynomial can be found by composition.  Its syntax is:
\begin{verbatim}
     DECOMPOSE(EXPRN:polynomial):list.
\end{verbatim}
For example:
\begin{verbatim}
     decompose(x^8-88*x^7+2924*x^6-43912*x^5+263431*x^4-
                    218900*x^3+65690*x^2-7700*x+234)
                   2                  2            2
              -> {U  + 35*U + 234, U=V  + 10*V, V=X  - 22*X}
                                     2
     decompose(u^2+v^2+2u*v+1)  -> {W  + 1, W=U + V}
\end{verbatim}
Users should note however that, unlike factorization, this decomposition
is not unique.

\section{INTERPOL operator}\ttindex{INTERPOL}

Syntax:
\begin{verbatim}
        INTERPOL(<values>,<variable>,<points>);
\end{verbatim}

where {\tt <values>} and {\tt <points>} are lists of equal length and
{\tt <variable>} is an algebraic expression (preferably a kernel).

{\tt INTERPOL} generates an interpolation polynomial {\em f\/} in the given
variable of degree length({\tt <values>})-1.  The unique polynomial {\em f\/}
is defined by the property that for corresponding elements {\em v\/} of
{\tt <values>} and {\em p\/} of {\tt <points>} the relation $f(p)=v$ holds.

The Aitken-Neville interpolation algorithm is used which guarantees a
stable result even with rounded numbers and an ill-conditioned problem.

\section{Obtaining Parts of Polynomials and Rationals}

These operators select various parts of a polynomial or rational function
structure. Except for the cost of rearrangement of the structure, these
operations take very little time to perform.

For those operators in this section that take a kernel {\tt VAR} as their
second argument, an error results if the first expression is not a
polynomial in {\tt VAR}, although the coefficients themselves can be
rational as long as they do not depend on {\tt VAR}.  However, if the
switch {\tt RATARG}\ttindex{RATARG} is on, denominators are not checked
for dependence on {\tt VAR}, and are taken to be part of the coefficients.

\subsection{DEG Operator}\ttindex{DEG}

This operator is used with the syntax
\begin{verbatim}
        DEG(EXPRN:polynomial,VAR:kernel):integer.
\end{verbatim}
It returns the leading degree\index{Degree} of the polynomial {\tt EXPRN}
in the variable {\tt VAR}.  If {\tt VAR} does not occur as a variable in
{\tt EXPRN}, 0 is returned.

{\it Examples:}
\begin{verbatim}
        deg((a+b)*(c+2*d)^2,a) ->  1
        deg((a+b)*(c+2*d)^2,d) ->  2
        deg((a+b)*(c+2*d)^2,e) ->  0.
\end{verbatim}
Note also that if {\tt RATARG} is on,
\begin{verbatim}
        deg((a+b)^3/a,a)       ->  3
\end{verbatim}
since in this case, the denominator {\tt A} is considered part of the
coefficients of the numerator in {\tt A}.  With {\tt RATARG} off, however,
an error would result in this case.

\subsection{DEN Operator}\ttindex{DEN}

This is used with the syntax:
\begin{verbatim}
        DEN(EXPRN:rational):polynomial.
\end{verbatim}
It returns the denominator of the rational expression {\tt EXPRN}.  If
{\tt EXPRN} is a polynomial, 1 is returned.

{\it Examples:}
\begin{verbatim}
        den(x/y^2)   ->  Y**2
        den(100/6)   ->  3
                [since 100/6 is first simplified to 50/3]
        den(a/4+b/6) ->  12
        den(a+b)     ->  1
\end{verbatim}

\subsection{LCOF Operator}\ttindex{LCOF}

LCOF is used with the syntax
\begin{verbatim}
        LCOF(EXPRN:polynomial,VAR:kernel):polynomial.
\end{verbatim}
It returns the leading coefficient\index{Leading coefficient} of the
polynomial {\tt EXPRN} in the variable {\tt VAR}.  If {\tt VAR} does not
occur as a variable in {\tt EXPRN}, {\tt EXPRN} is returned.
\extendedmanual{\newpage}
{\it Examples:}
\begin{verbatim}
        lcof((a+b)*(c+2*d)^2,a) ->  C**2+4*C*D+4*D**2
        lcof((a+b)*(c+2*d)^2,d) ->  4*(A+B)
        lcof((a+b)*(c+2*d),e)   ->  A*C+2*A*D+B*C+2*B*D
\end{verbatim}

\subsection{LPOWER Operator}\ttindex{LPOWER}

\begin{samepage}
Syntax:
\begin{verbatim}
        LPOWER(EXPRN:polynomial,VAR:kernel):polynomial.
\end{verbatim}
LPOWER returns the leading power of {\tt EXPRN} with respect to {\tt VAR}.
If {\tt EXPRN} does not depend on {\tt VAR}, 1 is returned.
\end{samepage}

{\it Examples:}
\begin{verbatim}
        lpower((a+b)*(c+2*d)^2,a) ->  A
        lpower((a+b)*(c+2*d)^2,d) ->  D**2
        lpower((a+b)*(c+2*d),e)   ->  1
\end{verbatim}

\subsection{LTERM Operator}\ttindex{LTERM}

\begin{samepage}
Syntax:
\begin{verbatim}
        LTERM(EXPRN:polynomial,VAR:kernel):polynomial.
\end{verbatim}
LTERM returns the leading term of {\tt EXPRN} with respect to {\tt VAR}.
If {\tt EXPRN} does not depend on {\tt VAR}, {\tt EXPRN} is returned.
\end{samepage}

{\it Examples:}
\begin{verbatim}
        lterm((a+b)*(c+2*d)^2,a) ->  A*(C**2+4*C*D+4*D**2)
        lterm((a+b)*(c+2*d)^2,d) ->  4*D**2*(A+B)
        lterm((a+b)*(c+2*d),e)   ->  A*C+2*A*D+B*C+2*B*D
\end{verbatim}

{\COMPATNOTE} In some earlier versions of REDUCE, {\tt LTERM} returned
{\tt 0} if the {\tt EXPRN} did not depend on {\tt VAR}.  In the present
version, {\tt EXPRN} is always equal to {\tt LTERM(EXPRN,VAR)} $+$ {\tt
REDUCT(EXPRN,VAR)}.

\subsection{MAINVAR Operator}\ttindex{MAINVAR}

Syntax:
\begin{verbatim}
        MAINVAR(EXPRN:polynomial):expression.
\end{verbatim}
Returns the main variable (based on the internal polynomial representation)
of {\tt EXPRN}. If {\tt EXPRN} is a domain element, 0 is returned.

{\it Examples:}

Assuming {\tt A} has higher kernel order than {\tt B}, {\tt C}, or {\tt D}:
\begin{verbatim}
        mainvar((a+b)*(c+2*d)^2) ->  A
        mainvar(2)               ->  0
\end{verbatim}

\subsection{NUM Operator}\ttindex{NUM}

Syntax:
\begin{verbatim}
        NUM(EXPRN:rational):polynomial.
\end{verbatim}
Returns the numerator of the rational expression {\tt EXPRN}.  If {\tt EXPRN}
is a polynomial, that polynomial is returned.

{\it Examples:}
\begin{verbatim}
        num(x/y^2)  ->  X
        num(100/6)   ->  50
        num(a/4+b/6) ->  3*A+2*B
        num(a+b)     ->  A+B
\end{verbatim}

\subsection{REDUCT Operator}\ttindex{REDUCT}

Syntax:
\begin{verbatim}
        REDUCT(EXPRN:polynomial,VAR:kernel):polynomial.
\end{verbatim}
Returns the reductum of {\tt EXPRN} with respect to {\tt VAR} (i.e., the
part of {\tt EXPRN} left after the leading term is removed).  If {\tt
EXPRN} does not depend on the variable {\tt VAR}, 0 is returned.

{\it Examples:}
\begin{verbatim}
     reduct((a+b)*(c+2*d),a) ->  B*(C + 2*D)
     reduct((a+b)*(c+2*d),d) ->  C*(A + B)
     reduct((a+b)*(c+2*d),e) ->  0
\end{verbatim}

{\COMPATNOTE} In some earlier versions of REDUCE, {\tt REDUCT} returned
{\tt EXPRN} if it did not depend on {\tt VAR}.  In the present version, {\tt
EXPRN} is always equal to {\tt LTERM(EXPRN,VAR)} $+$ {\tt
REDUCT(EXPRN,VAR)}.

\section{Polynomial Coefficient Arithmetic}\index{Coefficient}
{\REDUCE} allows for a variety of numerical domains for the numerical
coefficients of polynomials used in calculations.  The default mode is
integer arithmetic, although the possibility of using real coefficients
\index{Real coefficient} has been discussed elsewhere.  Rational
coefficients have also been available by using integer coefficients in
both the numerator and denominator of an expression, using the {\tt ON
DIV}\ttindex{DIV} option to print the coefficients as rationals.
However, {\REDUCE} includes several other coefficient options in its basic
version which we shall describe in this section.  All such coefficient
modes are supported in a table-driven manner so that it is
straightforward to extend the range of possibilities.  A description of
how to do this is given in R.J. Bradford, A.C. Hearn, J.A. Padget and
E. Schr\"ufer, ``Enlarging the {\REDUCE} Domain of Computation,'' Proc. of
SYMSAC '86, ACM, New York (1986), 100--106.

\subsection{Rational Coefficients in Polynomials}\index{Coefficient}
\index{Rational coefficient}
Instead of treating rational numbers as the numerator and denominator of a
rational expression, it is also possible to use them as polynomial
coefficients directly. This is accomplished by turning on the switch
{\tt RATIONAL}.\ttindex{RATIONAL}

{\it Example:} With {\tt RATIONAL} off, the input expression {\tt a/2}
would be converted into a rational expression, whose numerator was {\tt A}
and denominator 2.  With {\tt RATIONAL} on, the same input would become a
rational expression with numerator {\tt 1/2*A} and denominator {\tt 1}.
Thus the latter can be used in operations that require polynomial input
whereas the former could not.

\subsection{Real Coefficients in Polynomials}\index{Coefficient}
\index{Real coefficient}
The switch {\tt ROUNDED}\ttindex{ROUNDED} permits the use of arbitrary
sized real coefficients in polynomial expressions.  The actual precision
of these coefficients can be set by the operator {\tt PRECISION}.
\ttindex{PRECISION} For example, {\tt precision 50;} sets the precision to
fifty decimal digits.  The default precision is system dependent and can
be found by {\tt precision 0;}.  In this mode, denominators are
automatically made monic, and an appropriate adjustment is made to the
numerator.

{\it Example:} With {\tt ROUNDED} on, the input expression {\tt a/2} would
be converted into a rational expression whose numerator is {\tt 0.5*A} and
denominator {\tt 1}.

Internally, {\REDUCE} uses floating point numbers up to the precision
supported by the underlying machine hardware, and so-called {\em
bigfloats} for higher precision or whenever necessary to represent numbers
whose value cannot be represented in floating point.  The internal
precision is two decimal digits greater than the external precision to
guard against roundoff inaccuracies.  Bigfloats represent the fraction and
exponent parts of a floating-point number by means of (arbitrary
precision) integers, which is a more precise representation in many cases
than the machine floating point arithmetic, but not as efficient.  If a
case arises where use of the machine arithmetic leads to problems, a user
can force {\REDUCE} to use the bigfloat representation at all precisions by
turning on the switch {\tt ROUNDBF}.\ttindex{ROUNDBF}  In rare cases,
this switch is turned on by the system, and the user informed by the
message
\begin{verbatim}
        ROUNDBF turned on to increase accuracy
\end{verbatim}

Rounded numbers are normally printed to the specified precision.  However,
if the user wishes to print such numbers with less precision, the printing
precision can be set by the command {\tt PRINT\_PRECISION}.
\ttindex{PRINT\_PRECISION} For example, {\tt print\_precision 5;} will
cause such numbers to be printed with five digits maximum.

Under normal circumstances when {\tt ROUNDED} is on, {\REDUCE} converts the
number 1.0 to the integer 1.  If this is not desired, the switch
{\tt NOCONVERT}\ttindex{NOCONVERT} can be turned on.

Numbers that are stored internally as bigfloats are normally printed with
a space between every five digits to improve readability.  If this
feature is not required, it can be suppressed by turning off the switch
{\tt BFSPACE}.\ttindex{BFSPACE}

Further information on the bigfloat arithmetic may be found in T. Sasaki,
``Manual for Arbitrary Precision Real Arithmetic System in {\REDUCE}'',
Department of Computer Science, University of Utah, Technical Note No.
TR-8 (1979).

When a real number is input, it is normally truncated to the precision in
effect at the time the number is read.  If it is desired to keep the full
precision of all numbers input, the switch {\tt ADJPREC}\ttindex{ADJPREC}
(for {\em adjust precision\/}) can be turned on.  While on, {\tt ADJPREC}
will automatically increase the precision, when necessary, to match that
of any integer or real input, and a message printed to inform the user of
the precision increase.

When {\tt ROUNDED} is on, rational numbers are normally converted to
rounded representation.  However, if a user wishes to keep such numbers in
a rational form until used in an operation that returns a real number,
the switch {\tt ROUNDALL}\ttindex{ROUNDALL} can be turned off.  This
switch is normally on.

Results from rounded calculations are returned in rounded form with two
exceptions: if the result is recognized as {\tt 0} or {\tt 1} to the
current precision, the integer result is returned.

\subsection{Modular Number Coefficients in Polynomials}\index{Coefficient}
\index{Modular coefficient}
{\REDUCE} includes facilities for manipulating polynomials whose
coefficients are computed modulo a given base.  To use this option, two
commands must be used; {\tt SETMOD} {\tt <integer>},\ttindex{SETMOD} to set
the prime modulus, and {\tt ON MODULAR}\ttindex{MODULAR} to cause the
actual modular calculations to occur.
For example, with {\tt setmod 3;} and {\tt on modular;}, the polynomial
{\tt (a+2*b)\verb|^|3} would become {\tt A\verb|^|3+2*B\verb|^|3}.

The argument of {\tt SETMOD} is evaluated algebraically, except that
non-modular (integer) arithmetic is used.  Thus the sequence
\begin{verbatim}
        setmod 3; on modular; setmod 7;
\end{verbatim}
will correctly set the modulus to 7.

Modular numbers are by default represented by integers in the interval
[0,p-1] where p is the current modulus.  Sometimes it is more convenient
to use an equivalent symmetric representation in the interval
[-p/2+1,p/2], or more precisely
[-floor((p-1)/2), ceiling((p-1)/2)],
especially if the modular numbers map objects that include
negative quantities.  The switch {\tt BALANCED\_MOD}\ttindex{BALANCED\_MOD}
allows you to select the symmetric representation for output.

Users should note that the modular calculations are on the polynomial
coefficients only.  It is not currently possible to reduce the exponents
since no check for a prime modulus is made (which would allow
$x^{p-1}$ to be reduced to 1 mod p).  Note also that any division by a
number not co-prime with the modulus will result in the error ``Invalid
modular division''.

\subsection{Complex Number Coefficients in Polynomials}\index{Coefficient}
\index{Complex coefficient}
Although {\REDUCE} routinely treats the square of the variable {\em i\/} as
equivalent to $-1$, this is not sufficient to reduce expressions involving
{\em i\/} to lowest terms, or to factor such expressions over the complex
numbers.  For example, in the default case,
\begin{verbatim}
        factorize(a^2+1);
\end{verbatim}
gives the result
\begin{verbatim}
	{{A**2+1,1}}
\end{verbatim}
and
\begin{verbatim}
        (a^2+b^2)/(a+i*b)
\end{verbatim}
is not reduced further.  However, if the switch
{\tt COMPLEX}\ttindex{COMPLEX} is turned on, full complex arithmetic is then
carried out.  In other words, the above factorization will give the result
\begin{verbatim}
	{{A + I,1},{A - I,1}}
\end{verbatim}
and the quotient will be reduced to {\tt A-I*B}.

The switch {\tt COMPLEX} may be combined with {\tt ROUNDED} to give complex
real numbers; the appropriate arithmetic is performed in this case.

Complex conjugation is used to remove complex numbers from denominators of
expressions.  To do this if {\tt COMPLEX} is off, you must turn the switch
{\tt RATIONALIZE}\ttindex{RATIONALIZE} on.


\section{Summary} \label{sec:summary}

We trained various linear regression models like OLS, ridge, and lasso to fit polynomials to the Franke function with noise. Thereafter, we used the model to predict the output for unseen test data. Various statistics like $MSE$, $R^2$ Error, and generalization error were used to probe the model performance. We also applied resampling techniques to reduce the uncertainty in the statistics. Along with finding optimal parameters directly using closed-form solutions, we also utilized stochastic gradient descent to find optimal parameters. We discovered that OLS is better at predicting than lasso and ridge for the sample data considered. When the lasso and ridge models tend to more OLS like behavior i.e. $\lambda_l$ and $\lambda_r$ tend to 0, the prediction improves. OLS performed several orders of magnitude better than lasso regression and a few orders of magnitude better than ridge in terms of the prediction error. We also experienced the problem of overfitting when the training data was less numerous and particularly during bootstrap resampling where the effective data that the model could 'see' during the training phase was reduced due to sampling with replacement. \newline
In addition, we used logistic regression and Support Vector Machines to fit a model to the Wisconsin Breast Cancer data. Overall, we showed that SVM with a linear kernel is the best performing classification algorithm for this setup. Nonetheless, all tested methods performed well when classifying benign classes. While the performance could be improved for malignant ones.


\documentclass{tufte-book}
\title{Acoustic Propagation Modelling}
\author{Aaron Kaw}

\input{C:/Users/aaron/OneDrive/Science/Programming/LaTeX/AaronLibrary.tex}

\newcommand{\bty}{\text{bty}}
\newcommand{\ati}{\text{ati}}
\newcommand{\bnd}{\text{bnd}}
\newcommand{\inc}{\text{inc}}
\newcommand{\rfl}{\text{rfl}}
\renewcommand{\max}{\text{max}}
\renewcommand{\min}{\text{min}}
\newcommand{\ray}{\text{ray}}
\newcommand{\spn}{\text{spn}}
\newcommand{\nse}{\text{nse}}
\newcommand{\erf}{\text{erf}}
\newcommand{\dtc}{\text{dtc}}
\newcommand{\fal}{\text{fal}}
\newcommand{\erfc}{\text{erfc}}

\newcommand{\DT}{\text{DT}}
\newcommand{\NL}{\text{NL}}
\newcommand{\SL}{\text{SL}}
\newcommand{\TL}{\text{TL}}

\begin{document}
\maketitle

\tableofcontents

\part{Helmholtz Equation}
Taken from Computational Ocean Acoustics\cite{jensen2011computational}.

\A{
	O(\omega^2): && \Abs{\nabla\tau}^2 &= \frac{1}{c^2(\vec{x})} \\
	O(\omega^1): && 2\nabla\tau \cdot \nabla A_0 + \Par{\nabla^2\tau}A_0 &= 0 \\
	O(\omega^{1 - j}): && 2\nabla\tau \cdot \nabla A_j + \Par{\nabla^2\tau}A_j &= -\nabla^2 A_{j-1}
}

\chapter{Eikonal Equation}
The eikonal equation
\A{
	\Abs{\nabla\tau}^2 &= \frac{1}{c^2(\vec{x})}
}
is a first-order nonlinear PDE for modelling the path taken by a ray.

\section{First-Order System}
In cylindrical coordinates,
\A{
	\Dif{r}{s} &= c\xi(s) & \Dif{\xi}{s} &= \frac{-1}{c(r, z)^2} \Part{c}{r} \\
	\Dif{z}{s} &= c\zeta(s) & \Dif{\zeta}{s} &= \frac{-1}{c(r, z)^2} \Part{c}{z} \\
	\Dif{\tau}{s} &= \frac{1}{c(r, z)}
}
with initial conditions
\A{
	r &= r_0 & \xi &= \frac{\cos(\theta_0)}{c(r_0, z_0)} \\
	z &= z_0 & \zeta &= \frac{\sin(\theta_0)}{c(r_0, z_0)} \\
	\tau &= 0
}
and boundary conditions defined as reflection off the bathymetry $z_\bty(r)$ and altimetry $z_\ati(r)$.
\A{
	\theta_i &= c(r, z) \cos^{-1}\Par{\xi_i} \\
	&= c(r, z) \sin^{-1}\Par{\zeta_i} \\
	\theta_r &= 2\theta_\bnd - \theta_i \\
	\xi_r &= \frac{\cos(\theta_r)}{c(r, z)} \\
	\zeta_r &= \frac{\sin(\theta_r)}{c(r, z)}
}

\chapter{Boundary Reflection}
\A{
	\vec{t}_\rfl &= \vec{t}_\inc - 2\Par{\vec{t}_\inc \cdot \vec{n}_\bnd} \vec{n}_\bnd
}

\chapter{Sonar Equations}
\section{Detection Threshold}
\subsection{Detection Index}
The detection index is expressed as
\A{
	d &= \Par{\frac{\mu_\spn - \mu_\nse}{\sigma_\nse}}^2
}
For a Gaussian noise and signal-plus-noise with a non-fluctuating signal, note that $\sigma_\nse = \sigma_\spn$ so
\A{
	f_\nse(x) &= \frac{1}{\sqrt{2\pi\sigma_\nse^2}}\exp\Brace{\frac{-1}{2}\Par{\frac{x - \mu_\nse}{\sigma_\nse}}^2} \\
	f_\spn(x) &= \frac{1}{\sqrt{2\pi\sigma_\nse^2}}\exp\Brace{\frac{-1}{2}\Par{\frac{x - \mu_\spn}{\sigma_\nse}}^2}
}
Their respective cumulative density functions are
\A{
	F_\nse(x) &= \frac{1}{2}\Brack{1 + \erf\Par{\frac{x - \mu_\nse}{\sqrt{2}\sigma_\nse}}} \\
	F_\spn(x) &= \frac{1}{2}\Brack{1 + \erf\Par{\frac{x - \mu_\spn}{\sqrt{2}\sigma_\nse}}}
}
The probability of detection and probability of false alarm are defined via the point at which the two density values meet, integrated above as
\A{
	p_\dtc &= 1 - \frac{1}{2}\Brack{1 + \erf\Par{\frac{x - \mu_\spn}{\sqrt{2}\sigma_\nse}}}, &
	p_\fal &= 1 - \frac{1}{2}\Brack{1 + \erf\Par{\frac{x - \mu_\nse}{\sqrt{2}\sigma_\nse}}} \\
	\Rightarrow p_\dtc &= \frac{1}{2}\erfc\Par{\frac{x - \mu_\spn}{\sqrt{2}\sigma_\nse}}, & p_\fal &= \frac{1}{2}\erfc\Par{\frac{x - \mu_\nse}{\sqrt{2}\sigma_\nse}} \\
	\Rightarrow x &= \mu_\spn + \sqrt{2}\sigma_\nse\erfc^{-1}\Par{2p_\dtc}, &
	x &= \mu_\nse + \sqrt{2}\sigma_\nse\erf^{-1}\Par{2p_\fal}
}
So equating these expressions yields
\A{
	\mu_\spn + \sqrt{2}\sigma_\nse\erfc^{-1}\Par{2p_\dtc} &= \mu_\nse + \sqrt{2}\sigma_\nse\erfc^{-1}\Par{2p_\fal} \\
	\Rightarrow \Par{\frac{\mu_\spn - \mu_\nse}{\sigma_\nse}}^2 &= 2\Brack{\erfc^{-1}\Par{2p_\fal} - \erfc^{-1}\Par{2p_\dtc}}^2
}
where the left hand side is the definition of the detection index. Thus,
\A{
	d &= 2\Brack{\erfc^{-1}\Par{2p_\fal} - \erfc^{-1}\Par{2p_\dtc}}^2
}
Rearranged,
\A{
	p_\dtc &= \frac{1}{2}\erfc\Par{\erfc^{-1}\Par{2p_\fal} - \sqrt{\frac{d}{2}}}
}

\bibliographystyle{apalike}
\bibliography{Prop}

\part{Appendix}
\chapter{Concocting Equations}
\section{Celerity}
\A{
	c_\max &= 1600 \\
	c_\min &= 1500 \\
	c(r, z) &= c_0 + c_1 z + c_2 z^2 \\
	c_0 + c_1 z_\ati + c_2 z_\ati^2 &= c(r, z_\ati) = c_\max \\
	c_0 + c_1 \frac{z_\ati + z_\bty}{2} + c_2 \Par{\frac{z_\ati + z_\bty}{2}}^2 &= c(r, \frac{z_\ati + z_\bty}{2}) = c_\min \\
	c_0 + c_1 z_\bty + c_2 z_\bty^2 &= c(r, z_\bty) = c_\max \\
	\Matrix{ccc}{
		1 & z_\ati & z_\ati^2 \\
		1 & \frac{z_\ati + z_\bty}{2} & \Par{\frac{z_\ati + z_\bty}{2}}^2 \\
		1 & z_\bty & z_\bty^2
	} \Matrix{c}{
		c_0 \\ c_1 \\ c_2
	} &= \Matrix{c}{
		c_\max \\ c_\min \\ c_\max
	}
}

\section{Bathymmetry}
\A{
	z_\min &= 700 \\
	z_\max &= 1000 \\
	r_0 &= 300 \\
	z_\bty(r) &= z_\max - \Par{z_\max - z_\min}\exp\Par{-\frac{\Par{r - r_0}^2}{A_r}} \\
	z_\bty\Par{\frac{r_0}{3}} &= z_\min + \frac{z_\min + z_\max}{10} = z_\max - \Par{z_\max - z_\min}\exp\Par{-\frac{\Par{r - r_0}^2}{A_r}} \\
	z_\min + \frac{z_\min + z_\max}{10} &= z_\max - \Par{z_\max - z_\min}\exp\Par{-\frac{\Par{r - r_0}^2}{A_r}} \\
	\Par{z_\max - z_\min}\exp\Par{-\frac{\Par{r - r_0}^2}{A_r}} &= z_\max - z_\min - \frac{z_\min + z_\max}{10} \\
	\exp\Par{-\frac{\Par{r - r_0}^2}{A_r}} &= \frac{\dfrac{9}{10}z_\max - \dfrac{11}{10}z_\min}{z_\max - z_\min} \\
	-\frac{\Par{r - r_0}^2}{A_r} &= \ln\Par{\dfrac{9z_\max- 11z_\min}{10\Par{z_\max - z_\min}}} \\
	A_r &= \frac{4r_0^2/9}{\ln\Par{\dfrac{9z_\max- 11z_\min}{10\Par{z_\max - z_\min}}}}
}

\chapter{Sonar Equation Manipulation}
\section{Calculating Probability of Detection}
\A{
	d &= Bt\Par{\frac{\SL - \TL}{B\NL}}^2 \\
	p_\dtc &= \frac{1}{2}\erfc\Par{\sqrt{\frac{d}{2}} + \erfc^{-1}\Par{2p_\fal}}
}

\end{document}


\paragraph{}
A polyhedral cell can be regarded as one of the subdomain in the SBFEM as plotted in Fig.~\ref{oct_fig:sbfem_intro}.
Similar to SBFEM in 2D which has been introduced in Sec.~\ref{iso_section:formulation}, only the boundary surface requires discretization and a scaling center $O$ located at the place where all boundary surfaces of the subdomain are visible is necessary.

\begin{figure}
    \centering
    \begin{subfigure}[b]{0.48\linewidth}
        \scalebox{0.5}{
            \includegraphics{octree/images/sbfem3d.eps}
        }
        \caption{Scaling center located inside of the subdomain}
        \label{oct_fig:sbfem_intro_a}
    \end{subfigure}
    \begin{subfigure}[b]{0.48\linewidth}
        \scalebox{0.5}{
            \includegraphics{octree/images/sbfem3d_b.eps}
        }
        \caption{Scaling center located on one of the edges}
        \label{oct_fig:sbfem_intro_b}
    \end{subfigure}
    \caption[Polyhedral SBFEM subdomain in 3D]{Polyhedral subdomain in SBFEM}
    \label{oct_fig:sbfem_intro}
\end{figure}
%
A scaling center on the edge as shown in Fig.~\ref{oct_fig:sbfem_intro_b} is also valid which increases the flexibility and allow the concave subdomain.
In this situation, the triangulated faces containing the scaling center will not be discretized.

\paragraph{}
The transformation between SBFEM coordinate $(\xi, \eta, \zeta)$ and Cartesian coordinate $(x, y, z)$ can be derived from Eq.~\ref{lr_eq:sbfem_boundary_interpolate} and Eq.~\ref{lr_eq:sbfem_scaling} as:
\begin{subequations}
\begin{align}
    x(\xi, \eta, \zeta) & = \xi \hat{x}(\eta, \zeta)  = \xi \mathbf{N}(\eta, \zeta) \mathbf{\hat{x}} \\
    y(\xi, \eta, \zeta) & = \xi \hat{y}(\eta, \zeta)  = \xi \mathbf{N}(\eta, \zeta) \mathbf{\hat{y}} \\
    z(\xi, \eta, \zeta) & = \xi \hat{z}(\eta, \zeta)  = \xi \mathbf{N}(\eta, \zeta) \mathbf{\hat{z}}
\end{align}
\end{subequations}
%
where $(\hat{x}, \hat{y}, \hat{z})$ stands for the point in Cartesian coordinate on the boundary, $(\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}})$ represents the nodal coordinate vectors and $\mathbf{N}$ is the shape function.
The corresponding Jacobian matrix in 3D on the boundary $(\xi = 1)$ can be expressed as:
\begin{equation}
    \mathbf{J} (\eta, \zeta) =
    \begin{bmatrix}
        x(\eta, \zeta)      &   y(\eta, \zeta)      &   z(\eta, \zeta)  \\
        x(\eta, \zeta),_{\eta}      &   y(\eta, \zeta),_{\eta}      &   z(\eta, \zeta),_{\eta}  \\
        x(\eta, \zeta),_{\zeta}      &   y(\eta, \zeta),_{\zeta}      &   z(\eta, \zeta),_{\zeta}  \\
    \end{bmatrix}
\end{equation}
%
and the displacement interpolation in Eq.~\ref{lr_eq:sbfem_disp_interpolation} becomes
\begin{equation}
    \mathbf{u}(\xi, \eta, \zeta) = \mathbf{N} (\eta, \zeta) \mathbf{u} (\xi)
\end{equation}
%
The linear operator in Eq.~\ref{lr_eq:sbfem_l_operator} becomes
\begin{equation}
    \mathbf{L} = \mathbf{b}_1 (\eta, \zeta) \frac{\partial}{\partial \xi} +
    \frac{1}{\xi}\left(
        \mathbf{b}_2 (\eta, \zeta) \frac{\partial}{\partial \eta} +
        \mathbf{b}_3 (\eta, \zeta) \frac{\partial}{\partial \zeta}
    \right)
\end{equation}
%
Little $b$ matrix in Eq.~\ref{lr_eq:sbfem_little_b} becomes
\begin{subequations}
\begin{align}
    \mathbf{b}_1 (\eta, \zeta) &= \frac{1}{|\mathbf{J}|}
    \begin{bmatrix}
        y,_{\eta} z,_{\zeta} - z,_{\eta} y,_{\zeta} & 0 & 0 \\
        0 & z,_{\eta} x,_{\zeta} - x,_{\eta} z,_{\zeta} & 0 \\
        0 & 0 & x,_{\eta} y,_{\zeta} - y,_{\eta} x,_{\zeta} \\
        0 & x,_{\eta} y,_{\zeta} - y,_{\eta} x,_{\zeta} & z,_{\eta} x,_{\zeta} - x,_{\eta} z,_{\zeta} \\
        x,_{\eta} y,_{\zeta} - y,_{\eta} x,_{\zeta} & 0 & y,_{\eta} z,_{\zeta} - z,_{\eta} y,_{\zeta} \\
        z,_{\eta} x,_{\zeta} - x,_{\eta} z,_{\zeta} & y,_{\eta} z,_{\zeta} - z,_{\eta} y,_{\zeta} & 0
    \end{bmatrix} \\
    \mathbf{b}_2 (\eta, \zeta) &= \frac{1}{|\mathbf{J}|}
    \begin{bmatrix}
        y,_{\zeta} z - z,_{\zeta} y & 0 & 0 \\
        0 & z,_{\zeta} x - x,_{\zeta} z & 0 \\
        0 & 0 & x,_{\zeta} y - y,_{\zeta} x \\
        0 & x,_{\zeta} y - y,_{\zeta} & z,_{\zeta} x - x,_{\zeta} z \\
        x,_{\zeta} y - y,_{\zeta} & 0 & y,_{\zeta} z - z,_{\zeta} y \\
        z,_{\zeta} x - x,_{\zeta} z & y,_{\zeta} z - z,_{\zeta} y & 0
    \end{bmatrix} \\
    \mathbf{b}_3 (\eta, \zeta) &= \frac{1}{|\mathbf{J}|}
    \begin{bmatrix}
        y z,_{\eta} - z y,_{\eta} & 0 & 0 \\
        0 & z x,_{\eta} - x z,_{\eta} & 0 \\
        0 & 0 & x y,_{\eta} - y x,_{\eta} \\
        0 & x y,_{\eta} - y x,_{\eta} & z x,_{\eta} - x z,_{\eta} \\
        x y,_{\eta} - y x,_{\eta} & 0 & y z,_{\eta} - z y,_{\eta} \\
        z x,_{\eta} - x z,_{\eta} & y z,_{\eta} - z y,_{\eta} & 0
    \end{bmatrix}
\end{align}
\end{subequations}
%
Follow the same manner in Sec.~\ref{iso_section:formulation}, the strains can be expressed as
\begin{equation}
    \epsilon(\xi, \eta, \zeta) =
    \mathbf{B}_1 (\eta, \zeta) \mathbf{u} (\xi),_\xi +
    \frac{1}{\xi} \mathbf{B}_2 (\eta, \zeta) \mathbf{u} (\xi)
\end{equation}
%
where
\begin{subequations}
\begin{align}
    \mathbf{B}_1 (\eta, \zeta) & =
    \mathbf{b}_1 (\eta, \zeta) \mathbf{N} (\eta, \zeta) \\
    \mathbf{B}_2 (\eta, \zeta) & =
    \mathbf{b}_2 (\eta, \zeta) \mathbf{N} (\eta, \zeta),_\eta +
    \mathbf{b}_3 (\eta, \zeta) \mathbf{N} (\eta, \zeta),_\xi
\end{align}
\end{subequations}
%
The stress in Eq.~\ref{lr_eq:sbfem_stress} becomes
\begin{equation}
    \sigma(\xi, \eta, \zeta) = \mathbf{D} \left(
        \mathbf{B}_1 (\eta, \zeta) \mathbf{u} (\xi),_\xi +
        \frac{1}{\xi} \mathbf{B}_2 (\eta, \zeta) \mathbf{u} (\xi)
    \right)
\end{equation}
%
and the ODE equation in Eq.~\ref{lr_eq:sbfem_ODE} becomes
\begin{equation}
    \mathbf{E}_0 \xi^2 \mathbf{u}(\xi),_{\xi\xi} +
    (2\mathbf{E}_0 + \mathbf{E}_1^T - \mathbf{E}_1)\xi \mathbf{u}(\xi),_{\xi} -
    (\mathbf{E}_1^T - \mathbf{E}_2) \mathbf{u}(\xi)
    = 0
\label{oct_eq:sbfem_ode}
\end{equation}
%
The coefficient matrices $\mathbf{E}_0$, $\mathbf{E}_1$ and $\mathbf{E}_2$ for element $e$ are expressed as
\begin{subequations}
\begin{align}
    \mathbf{E}_0 = \int_e \mathbf{B}_1^T \mathbf{D} \mathbf{B}_1 |\mathbf{J}| d\eta d\zeta \\
    \mathbf{E}_1 = \int_e \mathbf{B}_2^T \mathbf{D} \mathbf{B}_1 |\mathbf{J}| d\eta d\zeta \\
    \mathbf{E}_2 = \int_e \mathbf{B}_2^T \mathbf{D} \mathbf{B}_2 |\mathbf{J}| d\eta d\zeta
\end{align}
\end{subequations}
%
The internal nodal forces $\mathbf{q}(\xi)$ on the boundary can be determined as \citep{Son2004a}
\begin{equation}
    \mathbf{q} (\xi) = \xi (
        \mathbf{E}_0 \xi \mathbf{u}(\xi),_\xi +
        \mathbf{E}_1^T \mathbf{u}(\xi)
    )
\label{oct_eq:sbfem_nodal_forces}
\end{equation}
%
$X(\xi)$ is introduced to reduce the order of the ODE in Eq.~\ref{oct_eq:sbfem_ode} as
\begin{equation}
    \mathbf{X} (\xi) =
    \begin{bmatrix}
        \xi^{0.5} \mathbf{u}(\xi) \\
        \xi^{-0.5} \mathbf{q}(\xi)
    \end{bmatrix}
\label{oct_eq:sbfem_x}
\end{equation}
%
substituting Eq.~\ref{oct_eq:sbfem_x} and Eq.~\ref{oct_eq:sbfem_nodal_forces} into Eq.~\ref{oct_eq:sbfem_ode} yields
\begin{equation}
    \xi \mathbf{X} (\xi),_\xi =
    -\mathbf{Z} \mathbf{X} (\xi)
\end{equation}
%
where $Z$ is the hamiltonian matrix
\begin{equation}
    \mathbf{Z} =
    \begin{bmatrix}
        \mathbf{E}_0^{-1} \mathbf{E}_1^T - 0.5 \mathbf{I}   &   -\mathbf{E}^{-1}_0 \\
        -\mathbf{E}_2 + \mathbf{E}_1 \mathbf{E}_0^{-1} \mathbf{E}_1^T   &   -(
            \mathbf{E}_1 \mathbf{E}_0^{-1} - 0.5 \mathbf{I}
        )
    \end{bmatrix}
\label{oct_eq:sbfem_z}
\end{equation}
%
An eigenvalue decomposition of Eq.~\ref{oct_eq:sbfem_z} is performed and it yields
\begin{equation}
    \mathbf{X} (\xi) =
    \begin{bmatrix}
        \Phi_{u1}   &   \Phi_{u2} \\
        \Phi_{q1}   &   \Phi_{q2}
    \end{bmatrix}
    \begin{bmatrix}
        \xi^{-\lambda}  &   0 \\
        0   &   \xi^{\lambda}
    \end{bmatrix}
    \begin{bmatrix}
        \mathbf{c}_1  &   0   \\
        0   &   \mathbf{c}_2
    \end{bmatrix}
\label{oct_eq:sbfem_eigenvalue}
\end{equation}
%
where $\pm\lambda$ is the eigenvalue and $-\lambda$ is corelate to the real parts.
$\Phi$ is part of the matrix of the eigenvector matrix.
$\mathbf{c}_1$ and $\mathbf{c}_2$ stand for the integration constant.
Modal displacements and forces in Eq.~\ref{lr_eq:sbfem_general_sol_str} becomes
\begin{subequations}
\begin{align}
    \mathbf{u}(\xi) &= \mathbf{\Phi}_{u1} \xi^{-\Lambda-0.5\mathbf{I}} \mathbf{c}_1
    \label{oct_eq:sbfem_general_sol_disp} \\
    \mathbf{q}(\xi) &= \mathbf{\Phi}_{q1} \xi^{-\Lambda+0.5\mathbf{I}} \mathbf{c}_2
    \label{oct_eq:sbfem_general_sol_str}
\end{align}
\end{subequations}
%
The stiffness matrix then can be derived as
\begin{equation}
    \mathbf{K} = \Phi_{q1} \Phi_{u1}^{-1}
\end{equation}


\documentclass{amsart}

\usepackage{amssymb}
\usepackage{amsmath}

\title{PDE: Assignment 4}
\author{Mark Ditsworth}

\begin{document}
	\maketitle

	\section{Problem 1}
	Consider the operator $\hat{A} = -c(x)\triangledown^2$ in a 2d region $\Omega \subset \mathbb{R}^2$ with Dirichlet boundaries where $c(x) > 0$. Suppose the eigenfunctions of $\hat{A}$ are $u_n(x)$ with eigenvalues $\lambda_n$ numbered in order ($\lambda_1 < \lambda_2 <\dots$).Let $G(x,x')$ be the Green's function of $\hat{A}$.

	\subsection{Part 1}
	If $f(x) = \sum_{n}\alpha_n u_n(x)$, show $\alpha_n$ in terms of $f$ and $u_n$. Then find $\int_\Omega G(x,x')f(x')d^2x'$ in terms of $\alpha_n$ and $u_n$.
	\\
	\subsection{Part 2}
	For any possible value of $u(x)$, find
	\[
		\frac{\int_\Omega \int_\Omega \frac{1}{c(x)}\overline{u(x)}G(x,x')u(x')d^2xd^2x'}{\int_{\Omega} \frac{|u(x'')|^2}{c(x'')}d^2x''}
	\]
	\\\\
	\section{Problem 2}
	Solve the Laplacian eigenproblem $-\triangledown^2u = \lambda u$ in a 2d radius-1 cylinder, $r<=1$ with Dirichlet boundary conditions $u|_{r=1,\Omega} = 0$ by ``brute force" in Julia and compare to the analytical Bessel solutions.
	\\\\\\
	\section{Problem 3}
	Recall that the displacement $u(x,t)$ of a string (with fixed ends $u(0,t) = u(L,t) = 0$) satisfies the wave equation $\frac{\partial^2u}{\partial x^2} + f(x,t) = \frac{\partial^2u}{\partial t^2}$, where $f(x,t)$ is an external force density (pressure) on the string.
\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PROBLEM 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Problem 1}

Consider a critical sphere composed of a homogeneous multiplying medium, and surrounded by a reflecting shell of non-multiplying material with a thickness equal to half the radius of the sphere. Outside of the reflector is vacuum.
\begin{enumerate}[a)]
\item Write the diffusion equation and boundary conditions describing this system.
\item Calculate the flux in both regions that are not vacuum.
\item Determine the reflector savings.
\end{enumerate}