% Part: methods
% Chapter: proofs
% Section: inference-patterns

\documentclass[../../../include/open-logic-section]{subfiles}

\begin{document}

\olfileid{mth}{prf}{pat}

\olsection{Inference Patterns}

Proofs are composed of individual inferences. When we make an
inference, we typically indicate that by using a word like ``so,''
``thus,'' or ``therefore.''  The inference often relies on one or two
facts we already have available in our proof---it may be something we
have assumed, or something that we've concluded by an inference
already.  To be clear, we may label these things, and in the inference
we indicate what other statements we're using in the inference.  An
inference will often also contain an explanation of \emph{why} our new
conclusion follows from the things that come before it.  There are
some common patterns of inference that are used very often in proofs;
we'll go through some below. Some patterns of inference, like proofs
by induction, are more involved (and will be discussed later).

We've already discussed one pattern of inference: unpacking, or
applying, a definition. When we unpack a definition, we just restate
something that involves the definiendum by using the definiens. For
instance, suppose that we have already established in the course of a
proof that $D = E$ (a). Then we may apply the definition of $=$ for sets
and infer: ``Thus, by definition from (a), every !!{element}
of~$D$ is !!a{element} of~$E$ and vice versa.''

Somewhat confusingly, we often do not write the justification of an
inference when we actually make it, but before.  Suppose we haven't
already proved that $D = E$, but we want to.  If $D = E$ is the
conclusion we aim for, then we can restate this aim also by applying
the definition: to prove $D = E$ we have to prove that every
!!{element} of~$D$ is !!a{element} of~$E$ and vice versa.  So our
proof will have the form: (a) prove that every !!{element} of~$D$ is
!!a{element} of~$E$; (b) every !!{element} of~$E$ is !!a{element}
of~$D$; (c) therefore, from (a) and (b) by definition of $=$, $D = E$.
But we would usually not write it this way. Instead we might write
something like,
\begin{quote}
We want to show $D = E$. By definition of~$=$, this amounts to showing
that every !!{element} of~$D$ is !!a{element} of~$E$ and vice
versa.

(a) \dots (a proof that every !!{element} of~$D$ is !!a{element}
of~$E$) \dots

(b) \dots (a proof that every !!{element}
of~$E$ is !!a{element} of~$D$) \dots
\end{quote}

\subsection{Using a Conjunction}

Perhaps the simplest inference pattern is that of drawing as
conclusion one of the conjuncts of a conjunction. In other words: if
we have assumed or already proved that $p$ and~$q$, then we're
entitled to infer that~$p$ (and also that~$q$).  This is such a basic
inference that it is often not mentioned.  For instance, once we've
unpacked the definition of $D = E$ we've established that every
!!{element} of~$D$ is !!a{element} of~$E$ and vice versa. From this
we can conclude that every !!{element} of~$E$ is !!a{element} of~$D$
(that's the ``vice versa'' part).

\subsection{Proving a Conjunction}

Sometimes what you'll be asked to prove will have the form of a
conjunction; you will be asked to ``prove $p$ and $q$.'' In this case,
you simply have to do two things: prove $p$, and then prove $q$. You
could divide your proof into two sections, and for clarity, label
them. When you're making your first notes, you might write ``(1) Prove
$p$'' at the top of the page, and ``(2) Prove $q$'' in the middle of
the page. (Of course, you might not be explicitly asked to prove a
conjunction but find that your proof requires that you prove a
conjunction. For instance, if you're asked to prove that $D = E$ you
will find that, after unpacking the definition of~$=$, you have to
prove: every !!{element} of~$D$ is !!a{element} of~$E$
\emph{and} every !!{element} of~$E$ is !!a{element} of~$D$).

\subsection{Proving a Disjunction}

When what you are proving takes the form of a disjunction (i.e., it is
an statement of the form ``$p$ or $q$''), it is enough to show that
one of the disjuncts is true.  However, it basically never happens
that either disjunct just follows from the assumptions of your
theorem. More often, the assumptions of your theorem are themselves
disjunctive, or you're showing that all things of a certain kind have
one of two properties, but some of the things have the one and others
have the other property.  This is where proof by cases is
useful (see below).

\subsection{Conditional Proof}

Many theorems you will encounter are in conditional form (i.e., show
that if $p$ holds, then $q$ is also true). These cases are nice and
easy to set up---simply assume the antecedent of the conditional (in
this case, $p$) and prove the conclusion~$q$ from it.  So if your
theorem reads, ``If $p$ then $q$,'' you start your proof with ``assume
$p$'' and at the end you should have proved~$q$.

Conditionals may be stated in different ways. So instead of ``If $p$
then $q$,'' a theorem may state that ``$p$ only if $q$,'' ``$q$ if
$p$,'' or ``$q$, provided $p$.'' These all mean the same and require
assuming $p$ and proving~$q$ from that assumption.  Recall that a
biconditional (``$p$ if and only if (iff) $q$'') is really two
conditionals put together: if $p$ then $q$, and if $q$ then~$p$. All
you have to do, then, is two instances of conditional proof: one for
the first conditional and another one for the second. Sometimes,
however, it is possible to prove an ``iff'' statement by chaining
together a bunch of other ``iff'' statements so that you start with
``$p$'' an end with ``$q$''---but in that case you have to make sure
that each step really is an ``iff.''

\subsection{Universal Claims}

Using a universal claim is simple: if something is true for anything,
it's true for each particular thing.  So if, say, the hypothesis of
your proof is $A \subseteq B$, that means (unpacking the definition
of~$\subseteq$), that, for every $x \in A$, $x \in B$. Thus, if you
already know that $z \in A$, you can conclude $z \in B$.

Proving a universal claim may seem a little bit tricky. Usually these
statements take the following form: ``If $x$ has~$P$, then it
has~$Q$'' or ``All $P$s are $Q$s.'' Of course, it might not fit this
form perfectly, and it takes a bit of practice to figure out what
you're asked to prove exactly. But: we often have to prove that all objects
with some property have a certain other property.

The way to prove a universal claim is to introduce names or variables,
for the things that have the one property and then show that they also
have the other property.  We might put this by saying that to prove
something for \emph{all}~$P$s you have to prove it for an
\emph{arbitrary}~$P$. And the name introduced is a name for an
arbitrary~$P$.  We typically use single letters as these names for
arbitrary things, and the letters usually follow conventions: e.g., we
use $n$ for natural numbers, $!A$ for !!{formula}s, $A$ for sets, $f$
for functions, etc.

The trick is to maintain generality throughout the proof. You start by
assuming that an arbitrary object (``$x$'') has the property~$P$, and
show (based only on definitions or what you are allowed to assume)
that $x$ has the property~$Q$. Because you have not stipulated what
$x$ is specifically, other that it has the property $P$, then you can
assert that all every $P$ has the property~$Q$. In short, $x$ is a
stand-in for \emph{all} things with property~$P$.

\begin{prop}
  For all sets $A$ and $B$, $A \subseteq A \cup B$.
\end{prop}

\begin{proof}
  Let $A$ and $B$ be arbitrary sets.  We want to show that $A
  \subseteq A \cup B$. By definition of $\subseteq$, this amounts to:
  for every $x$, if $x \in A$ then $x \in A \cup B$. So let $x \in A$
  be an arbitrary !!{element} of~$A$. We have to show that $x \in A
  \cup B$. Since $x \in A$, $x \in A$ or $x \in B$. Thus, $x \in
  \Setabs{x}{x \in A \lor x \in B}$. But that, by definition of $\cup
  $, means $x \in A \cup B$.
\end{proof}

\subsection{Proof by Cases}

Suppose you have a disjunction as an assumption or as an already
established conclusion---you have assumed or proved that $p$ or $q$ is
true.  You want to prove $r$.  You do this in two steps: first you
assume that $p$ is true, and prove~$r$, then you assume that $q$ is
true and prove~$r$ again.  This works because we assume or know that
one of the two alternatives holds. The two steps establish that either
one is sufficient for the truth of~$r$.  (If both are true, we have
not one but two reasons for why $r$~is true. It is not necessary to
separately prove that $r$~is true assuming both $p$ and~$q$.)  To
indicate what we're doing, we announce that we ``distinguish cases.''
For instance, suppose we know that $x \in B \cup C$.  $B \cup C$ is
defined as $\Setabs{x}{x \in B \text{ or } x \in C}$. In other words,
by definition, $x \in B$ or $x \in C$. We would prove that $x \in A$
from this by first assuming that $x \in B$, and proving $x \in A$ from
this assumption, and then assume $x \in C$, and again prove $x \in A$
from this.  You would write ``We distinguish cases'' under the
assumption, then ``Case (1): $x \in B$'' underneath, and ``Case (2):
$x \in C$ halfway down the page. Then you'd proceed to fill in the top
half and the bottom half of the page.

Proof by cases is especially useful if what you're proving is itself
disjunctive. Here's a simple example:

\begin{prop}
Suppose $B \subseteq D$ and $C \subseteq E$. Then $B \cup C \subseteq
D \cup E$.
\end{prop}

\begin{proof}
  Assume (a) that $B \subseteq D$ and (b) $C \subseteq E$. By
  definition, any $x \in B$ is also $\in D$ (c) and any $x \in C$ is
  also $\in E$ (d).  To show that $B \cup C \subseteq D \cup E$, we
  have to show that if $x \in B \cup C$ then $x \in D \cup E$ (by
  definition of $\subseteq$). $x \in B \cup C$ iff $x \in B$ or $x \in
  C$ (by definition of~$\cup$). Similarly, $x \in D \cup E$ iff $x \in
  D$ or $x \in E$. So, we have to show: for any $x$, if $x \in B$ or
  $x \in C$, then $x \in D$ or $x \in E$.

  \begin{quote}
  So far we've only unpacked definitions!{} We've reformulated our
  proposition without $\subseteq$ and $\cup$ and are left with trying
  to prove a universal conditional claim. By what we've discussed
  above, this is done by assuming that $x$ is something about which we
  assume the ``if'' part is true, and we'll go on to show that the
  ``then'' part is true as well. In other words, we'll assume that $x
  \in B$ or $x \in C$ and show that $x \in D$ or $x \in
  E$.\footnote{This paragraph just explains what we're doing---it's
    not part of the proof, and you don't have to go into all this
    detail when you write down your own proofs.}
  \end{quote}

  Suppose that $x \in B$ or $x \in C$. We have to show that $x \in D$
  or $x \in E$. We distinguish cases.

  Case 1: $x \in B$. By (c), $x \in D$. Thus, $x \in D$ or $x \in
  E$. (Here we've made the inference discussed in the preceding
  subsection!)

  Case 2: $x \in C$. By (d), $x \in E$. Thus, $x \in D$ or $x \in E$.
 \end{proof}

\subsection{Proving an Existence Claim}

When asked to prove an existence claim, the question will usually be
of the form ``prove that there is an~$x$ such that $\dots x \dots$'',
i.e., that some object that has the property described by ``$\dots x
\dots$''. In this case you'll have to identify a suitable object show
that is has the required property.  This sounds straightforward, but a
proof of this kind can be tricky. Typically it involves
\emph{constructing} or \emph{defining} an object and proving that the
object so defined has the required property. Finding the right object
may be hard, proving that it has the required property may be hard,
and sometimes it's even tricky to show that you've succeeded in
defining an object at all!{}

Generally, you'd write this out by specifying the object, e.g., ``let
$x$ be \dots'' (where \dots{} specifies which object you have in
mind), possibly proving that $\dots$ in fact describes an object that
exists, and then go on to show that $x$ has the property~$Q$. Here's a
simple example.

\begin{prop}
  Suppose that $x \in B$. Then there is an~$A$ such that $A \subseteq
  B$ and $A \neq \emptyset$.
\end{prop}

\begin{proof}
  Assume $x \in B$. Let $A = \{x\}$.
  \begin{quote}
    Here we've defined the set~$A$ by enumerating its
    !!{element}s. Since we assume that $x$ is an object, and we can
    always form a set by enumerating its !!{element}s, we don't have
    to show that we've succeeded in defining a set~$A$ here.  However,
    we still have to show that $A$ has the properties required by the
    proposition. The proof isn't complete without that!{}
  \end{quote}
  Since $x \in A$, $A \neq \emptyset$.
  \begin{quote}
    This relies on the definition of $A$ as $\{x\}$ and the obvious
    facts that $x \in \{x\}$ and $x \notin \emptyset$.
  \end{quote}
  Since $x$ is the only !!{element} of~$\{x\}$, and $x \in B$, every
  !!{element} of~$A$ is also !!a{element} of~$B$. By definition
  of~$\subseteq$, $A \subseteq B$.
\end{proof}

\subsection{Using Existence Claims}

Suppose you know that some existence claim is true (you've proved it,
or it's a hypothesis you can use), say, ``for some~$x$, $x \in A$'' or
``there is an $x \in A$.''  If you want to use it in your proof, you
can just pretend that you have a name for one of the things which your
hypothesis says exist. Since $A$ contains at least one thing, there
are things to which that name might refer. You might of course not be
able to pick one out or describe it further (other than that it is
$\in A$). But for the purpose of the proof, you can pretend that you
have picked it out and give a name to it. It's important to pick a
name that you haven't already used (or that appears in your
hypotheses), otherwise things can go wrong. In your proof, you
indicate this by going from ``for some $x$, $x \in A$'' to ``Let $a
\in A$.''  Now you can reason about~$a$, use some other hypotheses, etc.,
until you come to a conclusion, $p$. If $p$ no longer mentions~$a$, $p$ is
independent of the asusmption that $a \in A$, and you've shown that it
follows just from the assumption ``for some $x$, $x \in A$.''

\begin{prop}
If $A \neq \emptyset$, then $A \cup B \neq \emptyset$.
\end{prop}

\begin{proof}
  Suppose $A \neq \emptyset$. So for some $x$, $x \in A$.
  \begin{quote}
    Here we first just restated the hypothesis of the
    proposition. This hypothesis, i.e., $A \neq \emptyset$, hides an
    existential claim, which you get to only by unpacking a few
    definitions. The definition of $=$ tells us that $A = \emptyset$
    iff every $x \in A$ is also $\in \emptyset$ and every $x \in
    \emptyset$ is also $\in A$. Negating both sides, we get: $A \neq
    \emptyset$ iff either some $x \in A$ is $\notin \emptyset$ or some
    $x \in \emptyset$ is $\notin A$. Since nothing is $\in \emptyset$,
    the second disjunct can never be true, and ``$x \in A$ and $x
    \notin \emptyset$'' reduces to just $x \in A$. So $x \neq
    \emptyset$ iff for some $x$, $x \in A$. That's an existence
    claim. Now we use that existence claim by introducing a name for
    one of the !!{element}s of~$A$:
  \end{quote}
  Let $a \in A$.
  \begin{quote}
    Now we've introduced a name for one of the things~$\in A$. We'll
    continue to argue about~$a$, but we'll be careful to only assume
    that $a \in A$ and nothing else:
  \end{quote}
  Since $a \in A$, $a \in A \cup B$, by definition of~$\cup$. So for
  some $x$, $x \in A \cup B$, i.e., $A \cup B \neq \emptyset$.
  \begin{quote}
    In that last step, we went from ``$a \in A \cup B$'' to ``for some
    $x$, $x \in A \cup B$.'' That doesn't mention $a$ anymore, so we
    know that ``for some $x$, $x \in A \cup B$'' follows from ``for
    some $x$, $x \in A$ alone.'' But that means that $A \cup B \neq
    \emptyset$.
  \end{quote}
\end{proof}

It's maybe good practice to keep bound variables like ``$x$'' separate
from hypothtical names like $a$, like we did. In practice, however, we
often don't and just use $x$, like so:
\begin{quote}
Suppose $A \neq \emptyset$, i.e., there is an $x \in A$. By definition
of $\cup$, $x \in A \cup B$. So $A \cup B \neq \emptyset$.
\end{quote}
However, when you do this, you have to be extra careful that you use
different $x$'s and $y$'s for different existential claims. For
instance, the following is \emph{not} a correct proof of ``If $A \neq
\emptyset$ and $B \neq \emptyset$ then $A \cap B \neq \emptyset$''
(which is not true).
\begin{quote}
Suppose $A \neq \emptyset$ and $B \neq \emptyset$. So for some $x$, $x
\in A$ and also for some $x$, $x \in B$. Since $x \in A$ and $x \in
B$, $x \in A \cap B$, by definition of~$\cap$. So $A \cap B \neq
\emptyset$.
\end{quote}
Can you spot where the incorrect step occurs and explain why the
result does not hold?

\end{document}


\documentclass[a4paper,11pt]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{float}
\usepackage[utf8]{inputenc}

\title{MaS Assignment I\\
\large The Chirikov Map}
\author{Klaas Kliffen s2369494}
\date{\today}

\begin{document}

\maketitle

\section{Introduction}

The Chirikov map is defined by the set of functions:
\begin{align}
p_{n+1} &= p_n + K \text{ sin}[2\pi x_n] / (2*\pi)\\
x_{n+1} &= x_n + p_{n+1}
\end{align}
These are taken modulo 1, to produce the following functions:
\begin{align}
p_{n+1} &= \{p_n + K \text{ sin}[2\pi x_n] / (2*\pi)\} \text{ mod} 1\\
x_{n+1} &= \{x_n + p_{n+1}\} \text{ mod} 1
\end{align}

\subsection*{Initialisation}
The system is initialised by $\{x_0,p_0\} \in [0,1] \times [0,1]$

\subsection*{a) 'Orbits' in the $x$-$p$ plane for fixed $K$}
The first part of the assignment assumes a fixed value of $K = 1$ and varies the initial conditions. The aim of this part will be to distinguish between different kind of 'orbits'.

\subsection*{b) Behaviour for different values of $K$}
The second part will use the orbits from the first part and will use a varying value for $K$.
The aim of this part will be to explore the changing orbits for an increasing value of $K$

\section{Methods}
This section globally describes the adapted functions used in this assignment.

\subsection*{a) 'Orbits' in the $x$-$p$ plane for fixed $K$}
To generate the values describing the orbit, the logstep function is expanded to now accept 2 values and calculates the results from the equations 3 and 4.
This function can be used to explore the different kind of orbits given the initial values.\\
To plot multiple orbits for a given $K$, the logstep is called multiple times, each with different pseudo-random initial values. The calculated values are then stored in two arrays to be plotted.

\subsection*{b) Behaviour for different values of $K$}
The channelmovie is function is adapted to 'step' over $K$ instead of $r$ and to call the function to plot the orbits, rather then the channelplot.

\section{Results}
\subsection*{a) 'Orbits' in the $x$-$p$ plane for fixed $K$}
There are three types of orbits that can be found. These will be addressed each in its own section.
\subsection*{Points}
Barely visible are two single points in figure \ref{pointorbit} at $(0,0.5)$ and $(0.5,0.5)$. From figure \ref{pointval} it is clear that $p$ stays constant, with $x$ switching between the two points.
\begin{figure}[H]
\centering
\includegraphics[width=.8\textwidth]{pointorbit.png}
\caption{Orbit plot of two points}
\label{pointorbit}
\end{figure}
\begin{figure}[H]
\centering
\includegraphics[width=.8\textwidth]{pointsvalues.png}
\caption{The values for $p$ and $x$ in the first steps }
\label{pointval}
\end{figure}

\subsection*{Curves}
\begin{figure}[H]
\centering
\includegraphics[width=.8\textwidth]{curvesorbit.png}
\caption{Orbit plot of four curves}
\label{curveorbit}
\end{figure}
\begin{figure}[H]
\centering
\includegraphics[width=.8\textwidth]{curvesvalues.png}
\caption{The values for $p$ and $x$ in the first steps }
\label{curveval}
\end{figure}

\newpage

In figure \ref{curveorbit} 4 curves. These curves are closed and symmetrical, which can be seen in the lower right and left side of the image.  The values of $p$ are between two range: a higher range, yielding the two top curves and a lower range, yielding the lower two curves. The value of $x$ varies between four ranges. In figure \ref{curveval} it can be seen that $x$ has a two different peak height at the top. The curves are visited in an fixed order as figure \ref{curveval} shows for the first few steps. Although the curve with $x$ values of 0.4 and 0.6 cannot be seen in this graph. It becomes clear that there are two alternating periods between the curves on the bottom and the top, in which the two lower curves are visited in an alternating order first. After a number of these periods, the two upper curves are visited in an alternating order.

\subsection*{Areas}
In figure \ref{areaorbit} two dotted areas can be seen. One on the top layer and one on the bottom. These areas seem to be symmetrical around the centre point of the image. These areas seem to be filled with chaotic values. In figure \ref{areaval} the values show peaks at the bottom and the top of the image, suggesting that the top area and the bottom area are visited in an alternating order.

\begin{figure}[H]
\centering
\includegraphics[width=.8\textwidth]{areaorbit.png}
\caption{Orbit plot of two areas}
\label{areaorbit}
\end{figure}

\newpage
\begin{figure}[H]
\centering
\includegraphics[width=.8\textwidth]{areavalues.png}
\caption{The values for $p$ and $x$ in the first steps }
\label{areaval}
\end{figure}

\subsection*{b) Behaviour for different values of $K$}

The figures 7 to 22 are taken at different values for $K$ in an increasing order.

\subsubsection*{Increasing value of $K$}
In figures 7 to 17 ($K$ values in the range of [0,1]) it can be seen that the straight lines at $K = 0$ slowly curve into two curves at the horizontal centre of the image. In between similar structures of curves visible.
Upward of $K = 0.9$ areas of chaotic dots appear and take up most of the image after $K = 2$, destroying the curves in the centre of the image.
After values of 3.0 for $K$ most of the area of the image is taken up by the chaotic region.\\
Around $K = 1.25$ six smaller curves can be seen on the edges of the two large centre curves. These become bigger and move outwards away from the centre of the large curve. When $K$ reaches a value of 2.0, these satellite curves are dissolved into the chaotic region of the image. This behaviour seems similar to the period doubling of the logistic map. For values of $K$ between 2.25 and 3.0, another instance of these smaller curves can be seen.

\subsubsection*{KAM orbits}
The lines displaying a KAM orbit are not very clearly visible, due to resolution errors. Instead the value 0.971635 as described by Greene\cite{kval} is used as the value for $K_c$. Figures 12 to 15 show plots of orbits for values of $K$ between 0.95 and 1.0. Although figures 14 and 15 show orbits spanning the entire interval of $[0,1]$, when zooming in, it becomes clear these do not follow a closed curve and are more of a chain of curves.

\begin{figure}[H]
\centering
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k0.png}
\caption{Orbits for $K = 0$}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k01.png}
\caption{Orbits for $K = 0.1$}
\end{minipage}
\end{figure}

\begin{figure}[H]
\centering
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k03.png}
\caption{Orbits for $K = 0.3$}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k05.png}
\caption{Orbits for $K = 0.5$}
\end{minipage}
\end{figure}

\begin{figure}[H]
\centering
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k08.png}
\caption{Orbits for $K = 0.8$}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k095.png}
\caption{Orbits for $K = 0.95$}
\end{minipage}
\end{figure}

\begin{figure}[H]
\centering
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{kc.png}
\caption{Orbits for $K_c = 0.97164$}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k098.png}
\caption{Orbits for $K = 0.98$}
\end{minipage}
\end{figure}

\begin{figure}[H]
\centering
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{koneorbits.png}
\caption{Orbits for $K = 1.0$}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k125.png}
\caption{Orbits for $K = 1.25$}
\end{minipage}
\end{figure}

\begin{figure}[H]
\centering
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k15.png}
\caption{Orbits for $K = 1.5$}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k175.png}
\caption{Orbits for $K = 1.75$}
\end{minipage}
\end{figure}

\begin{figure}[H]
\centering
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k20.png}
\caption{Orbits for $K = 2.0$}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k225.png}
\caption{Orbits for $K = 2.25$}
\end{minipage}
\end{figure}

\begin{figure}[H]
\centering
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k25.png}
\caption{Orbits for $K = 2.5$}
\end{minipage}\hfill
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=\textwidth]{k30.png}
\caption{Orbits for $K = 3.0$}
\end{minipage}
\end{figure}

\section{Conclusion and discussion}

\subsection{a) 'Orbits' in the $x$-$p$ plane for fixed $K$}
From the different initial conditions three types of 'orbits' can be determined: Points, curves and areas. Each of these types has a certain order in which points are visited. For point orbits, these are clearly defined. For curves both values will vary in between ranges. For areas, the $x$ value will vary over the complete interval of $[0,1]$ and $p$ will vary only over smaller ranges.

\newpage

\subsection{b) Behaviour for different values of $K$}
For an increasing value of $K$ the amount of chaotic regions will increase. For values up to $K = 0.9$ the regions will be very small to non existent. After that the regions will grow. For values of $K$ in between $[1.0,1.75]$ and $[2.0,3.0]$ there will be a similar process to period doubling with smaller curves moving outward of the large centre curve. After $K = 3.0$ the image will only consist of the centre two curves and a chaotic region.\\
Exploring the limit of KAM orbits around the value of $K_c = 0.971635$ did not lead to observable results. Possibly to issues with the resolution of the plot and the amount of points per orbit plotted.

\subsection{Discussion}
Some of the images are not very clear. This is probably caused by the resolution at which they were taken. This is very visible in the example plots for $K_c$ where the plots of near $K$ values also show lines crossing the image completely horizontal. When zooming in on these lines, it becomes clear it has gaps in between evenly spaced dots. It is hard to prove from figures alone that a line could cross the entire horizontal scale of an image. Depending on the resolution and the amount of point generated for an orbit, this can change.\\
The plots of orbits for an increasing value of $K$ were generated by a pseudo-random number generator for the initial values. The random number generator was not seeded, so each image contains different orbits. The results would be more clear if each image was generated with the same initial values and $K$ being the only free variable.

\begin{thebibliography}{1337}
\bibitem{kval}
Greene, John M.\\
\emph{A method for determining a stochastic transition}\\
Journal of Mathematical Physics, 20, 1183-1201 (1979)\\ DOI:http://dx.doi.org/10.1063/1.524170

\end{thebibliography}
\end{document}


\subsection{Function approximation for Q}

eg NN from state/action to R


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

\marginpar{Monday\\ 2020-10-26, \\ compiled \\ \today}

We have seen if the gradient of the log-posterior is linear in the parameters: \(\vec{\nabla} L (\vec{x}) = A \vec{x} + \vec{c}\) then the covariance matrix is \(\Sigma_{ij} = \qty(- A^{-1})_{ij}\).
Matrix inversion is slow, so we seek faster methods in general.

Are there situations in which the gradient of the log-posterior is indeed linear?
We need the noise to be Gaussian --- this is common, by the CLT this approximation is good if there are many concurring sources.
For simplicity, we will assume that the measurements are statistically independent --- this is not strictly necessary, what we will show holds even if this is not true.
Formally, this means that for two measurements \(d_i\) and \(d_j\) we have \(\mathbb{P}(d_i, d_j) = \mathbb{P}(d_i) \mathbb{P}(d_j)\).

Then, the likelihood reads
%
\begin{align}
\mathscr{L} (d_i | \vec{x}) = \frac{1}{\sqrt{2 \pi } \sigma }
\exp(- \frac{1}{2} \frac{(d_i - \mu )^2}{\sigma^2})
\,.
\end{align}

Let us assume that only the \emph{mean} is a function of the parameters of our theory (and of the observation number!) \(\mu = \mu_i (\vec{x})\).
As usual, with the independence assumption we find
%
\begin{align}
\mathscr{L} (d_i | \vec{x}) &\propto \prod_i
\exp(- \frac{1}{2} \frac{(\qty(d_i - \mu (\vec{x}))^2)}{\sigma^2})   \\
L &\propto - \frac{1}{2} \sum _{i=1}^{n} \frac{(d_i - \mu _i (\vec{x}))^2}{\sigma_i^2}
\,.
\end{align}

A sum of squares of Gaussian variables is distributed like a \(\chi^2\) variable (with \(n\) degrees of freedom, in our case): in this case, \(L = - \chi^2 / 2\), so minimizing the \(\chi^2\) corresponds to minimizing the likelihood.

A crucial condition in order for the problem to be linear is that the mean \(\mu _i (\vec{x})\) must be a linear function of the parameter vector: \(\mu _i (\vec{x}) = A \vec{x} + \vec{c}\).
Assuming a flat prior, our log-posterior reads
%
\begin{align}
\log P = L \propto \chi^2 = \sum _{i=1}^{n} \frac{1}{\sigma_i^2}
\qty[ d_i - \sum _{j} A_{ij} x_j - c_i ]^2
\,.
\end{align}

What we want to show is that this implies that the gradient of the posterior, evaluated at the maximum, is linear in the parameter: it reads
%
\begin{align}
\pdv{L}{x_k} = \sum _{i} \frac{2}{\sigma _i^2}
\qty[ d_i - \sum _{j} A_{ij} x_j - c_i ] A_{ik}
\,.
\end{align}

This is linear: one could see it by eye, but let us also compute its second derivative to make sure:
%
\begin{align}
\pdv[2]{L}{x_l}{x_k}
=
\sum _{i} \frac{2}{\sigma _i^2}
\qty[- A_{il} A_{ik}] = -2 \qty( A^{\top} \Sigma^{-1} A)_{lk}
\,.
\end{align}

This is a constant, so the initial expression was indeed linear.
This is the usual least-squares fitting: people often simply do this without much care for the assumptions they are making.

\subsection{Frequentist vs Bayesian}

The conceptual meaning of a credible interval is different from that of a confidence interval.
Sometimes, especially when we have few data points, they are also quantitatively different.

\begin{itemize}
    \item For a frequentist a parameter \(T\) is a fixed unknown number, not a random variable;
    \item data \(x\) are random variables given by their frequency with which they occur in many repetitions;
    \item both the Bayesian and the frequentist build a \emph{statistical estimator} \(f\), which is a function giving an estimate for the parameter starting from the data: \(f(x)\) yields \(t\), an estimate for \(T\);
    \item the distribution of the estimator --- which is a random variable since its argument is --- is called a \emph{sampling distibution} (for example, a \(\chi^2\) distribution);
    \item the frequentist builds a \(b \%\) confidence interval, which is an interval for \(t\) such that it will contain \(T\) \(b \%\) of the time.
\end{itemize}

In the Gaussian limit the confidence interval and the credible interval coincide.
In the frequentist case we write the Confidence Interval as
%
\begin{align}
\mathbb{P}\qty(-\num{1.96}
\leq \frac{\mu_0 - \mu }{\sigma / \sqrt{n}}
\leq \num{1.96}) \approx \num{.95}
\,,
\end{align}
%
while in the Bayesian case we write the Credible interval as
%
\begin{align}
\mathbb{P}\qty(\mu_0 - \num{1.96} \frac{\sigma }{\sqrt{n}}
\leq \mu \leq \mu_0 + \num{1.96} \frac{\sigma }{\sqrt{n}}) \approx \num{.95}
\,.
\end{align}

These two are written in terms of different variables: \(\mu_0\), the estimate of the mean from the data, in the frequentist case, and the parameter \(\mu \) in the Bayesian case.

If we also need to estimate the standard deviation we need to use a Student's \(t\) distribution: it converges to a Gaussian, but with few data it has fatter tails.

Now, we see an example of the failings of frequentist statistics \cite[]{vanderplasFrequentismBayesianismIII2014}.
The probability is given by \(\mathbb{P}(x | T) = \exp(T - x) [x \geq T]\). We are given a dataset \([10, 12,  15]\).
A frequentist will build an estimator: we have
%
\begin{align}
\expval{x} = \int x \mathbb{P}(x) \dd{x}  = T +1
\,,
\end{align}
%
So the arithmetic mean of \(x\) converges to \(T +1\), therefore we average the results and subtract one.
Our confidence interval will then look like \(\hat{T} -2 \sqrt{N} \leq T \leq T + 2 \sqrt{N}\).
This is derived from an asymptotic estimate, but it is close to the true result.
We find \([\num{10.2}, \num{12.5}]\): but we know that \(T \leq 10\)!

In a Bayesian approach, we do not even need to take a uniform prior for \(T \leq \min (\text{data})\). This is fixed by the data, since the likelihood includes a Heaviside theta.
The likelihood then looks like
%
\begin{align}
\mathbb{P}(T | x) = \exp(T - x) [T < x]
\,.
\end{align}

The \(\alpha \)-interval we get is \(T = x _{\text{min}} + \log \alpha  / N\).
\todo[inline]{To include more of the discussion.}

\end{document}


%Suggested order of slides
% slides-info-entropy
% slides-info-diffent
% slides-info-sourcecoding
% slides-info-kl
% slides-info-cross-entropy-kld
% slides-info-ml
% slides-info-mutual-info

\subsection{Entropy}
\includepdf[pages=-]{../slides-pdf/slides-info-entropy.pdf}

\subsection{Differential Entropy}
\includepdf[pages=-]{../slides-pdf/slides-info-diffent.pdf}

\subsection{Entropy and Optimal Code Length}
\includepdf[pages=-]{../slides-pdf/slides-info-sourcecoding.pdf}

\subsection{Kullback-Leibler Divergence}
\includepdf[pages=-]{../slides-pdf/slides-info-kl.pdf}

\subsection{Cross-Entropy, KL and Source Coding}
\includepdf[pages=-]{../slides-pdf/slides-info-cross-entropy-kld.pdf}

\subsection{Information Theory for Machine Learning}
\includepdf[pages=-]{../slides-pdf/slides-info-ml.pdf}

\subsection{Joint Entropy and Mutual Information}
\includepdf[pages=-]{../slides-pdf/slides-info-mutual-info.pdf}


\documentclass[]{article}
\usepackage{graphicx}
\usepackage{caption}
\graphicspath{ {./images/} }

% Minted
\usepackage[cache=false]{minted}
	\usemintedstyle{vs}
	\usepackage{xcolor}
		\definecolor{light-gray}{gray}{0.97}

\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{hyperref}
\usepackage{comment}

\title{Data Mining: Exercise 5-1}
\author{Brandon Hosley}
\date{\today}

\begin{document}
\maketitle

\section*{Preliminary: }

\begin{minted}[breaklines,bgcolor=light-gray]{python}
raw_df = spark.read.csv("/user/data/CSC533DM/titanic.csv", header=True, inferSchema=True)
raw_df.describe().show()

filtered_df = raw_df.select(['Survived', 'Pclass', 'Gender', 'Age', 'SibSp', 'Parch', 'Fare'])
\end{minted}
\includegraphics[width=\linewidth]{image0}

Outliers will be calculated based on their original distribution in the data set, but removed from a common set.
The intention of doing it this way is to prevent removal of one feature's outliers from altering the calculation of subsequent ranges and outliers.

\clearpage

\section*{Assignment 1: Remove outliers from Fare}

\begin{minted}[breaklines,bgcolor=light-gray]{python}
quantiles = filtered_df.approxQuantile("Fare",[0.25, 0.75],0.0)
Q1, Q3 = quantiles[0], quantiles[1]
IQR = Q3-Q1
fareLowerRange, fareUpperRange = Q1 - 1.5 * IQR, Q3 + 1.5 * IQR
fareLowerRange, fareUpperRange

trimmed_df = filtered_df \
	.filter(filtered_df.Fare > fareLowerRange) \
	.filter(filtered_df.Fare < fareUpperRange)
trimmed_df.count()
\end{minted}
\includegraphics[width=\linewidth]{image1}

\section*{Assignment 2: Remove outliers from Age}

\begin{minted}[breaklines,bgcolor=light-gray]{python}
# Check for Nulls
filtered_df.filter(filtered_df.Age.isNull()).count()
# Impute missing values with arithmetic mean
from pyspark.ml.feature import Imputer
imputer = Imputer(strategy='mean', inputCols=['Age'], outputCols=['ImputedAge'])
filtered_df = imputer.fit(filtered_df).transform(filtered_df)

# Find IQR
quantiles = filtered_df.approxQuantile('ImputedAge', [0.25, 0.75], 0.0)
Q1, Q3 = quantiles[0], quantiles[1]
IQR = Q3-Q1
ageLowerRange, ageUpperRange = Q1 - 1.5 * IQR, Q3 + 1.5 * IQR
# Count outliers
filtered_df.filter(filtered_df.ImputedAge < ageLowerRange).count() + \
filtered_df.filter(filtered_df.ImputedAge > ageUpperRange).count()

# Re-trim
trimmed_df = filtered_df \
	.filter(filtered_df.Fare > fareLowerRange) \
	.filter(filtered_df.Fare < fareUpperRange) \
	.filter(filtered_df.ImputedAge > ageLowerRange) \
	.filter(filtered_df.ImputedAge < ageUpperRange)
trimmed_df.count()
\end{minted}
First we check for nulls. \\
Then we impute the arithmetic mean into the null values. \\
Then we calculate the IQR. \\
Last we count number of outliers. \vspace{1em} \\
\includegraphics[width=\linewidth]{image2.1} \\

Since there are outliers we then update the trimming filter. \\
It is necessary to do it this way as the previously trimmed dataframe does not have the imputed ages available for filtering. \vspace{1em} \\
\includegraphics[width=\linewidth]{image2.2}

\clearpage

\section*{Assignment 3: Remove outliers from Siblings-Spouses}

\begin{minted}[breaklines,bgcolor=light-gray]{python}
# Check for Nulls
filtered_df.filter(filtered_df.SibSp.isNull()).count()

# Find IQR
quantiles = filtered_df.approxQuantile('SibSp',[0.25, 0.75],0.0)
Q1, Q3 = quantiles[0], quantiles[1]
IQR = Q3-Q1
sibSpLowerRange, sibSpUpperRange = Q1 - 1.5*IQR, Q3 + 1.5*IQR
# Count outliers
filtered_df.filter(filtered_df.SibSp<sibSpLowerRange).count()+ \
filtered_df.filter(filtered_df.SibSp>sibSpUpperRange).count()

# Trim
trimmed_df = trimmed_df \
	.filter(trimmed_df.SibSp > sibSpLowerRange) \
	.filter(trimmed_df.SibSp < sibSpUpperRange)
trimmed_df.count()
\end{minted}

\includegraphics[width=\linewidth]{image3.1} \\

No null values means no need to impute missing data. \\

\includegraphics[width=\linewidth]{image3.2} \\

\clearpage

\section*{Assignment 4: Remove outliers from }

\begin{minted}[breaklines,bgcolor=light-gray]{python}
# Check for Nulls
filtered_df.filter(filtered_df.Parch.isNull()).count()

# Find IQR
quantiles = filtered_df.approxQuantile('Parch',[0.25, 0.75],0.0)
Q1, Q3 = quantiles[0], quantiles[1]
IQR = Q3-Q1
parchLowerRange, parchUpperRange = Q1 - 1.5*IQR, Q3 + 1.5*IQR
# Count outliers
filtered_df.filter(filtered_df.Parch<parchLowerRange).count()+ \
filtered_df.filter(filtered_df.Parch>parchUpperRange).count()

# Check IQR
parchLowerRange, parchUpperRange
# Check result if Applied to trim
trimmed_df.filter(trimmed_df.Parch == parchUpperRange).count()

# Trim
trimmed_df = trimmed_df.filter(trimmed_df.Parch == parchUpperRange)
trimmed_df.count()
\end{minted}
\includegraphics[width=\linewidth]{image4.1}

The large count of outliers raises some concern.
It is worth looking into. \vspace{1em}

The reason is that Q1 and Q3 are both 0, resulting from the vast majority of samples being 0; everything above is treated as an outlier.
It may be problematic to filter this data, especially if there is not significant overlap between this data and the previously filtered outliers.
This is checked as well.

\clearpage

\section*{Assignment 5: Redo HW 4-2 with the new, no-outliers dataset. Explain the differences in results.}

\begin{minted}[breaklines,bgcolor=light-gray]{python}
# Index Gender
from pyspark.ml.feature import StringIndexer
indexed_df = StringIndexer(inputCol="Gender", outputCol="IndexedGender").fit(trimmed_df).transform(trimmed_df)

# Vectorize Features
from pyspark.ml.feature import VectorAssembler
assembler = VectorAssembler(inputCols=['Pclass', 'SibSp', 'Parch', 'Fare', 'ImputedAge', 'IndexedGender'], outputCol='features')
features_df = assembler.transform(indexed_df)

# Train-Test Split
(trainingData, testData) = features_df.randomSplit([0.8, 0.2])
trainingData.count()
testData.count()
trainingData.count() + testData.count()
features_df.count()

# trainingData
from pyspark.ml.classification import RandomForestClassifier
rf = RandomForestClassifier(labelCol="Survived", featuresCol="features")
modelRF = rf.fit(trainingData)

# Evaluate
from pyspark.ml.evaluation import BinaryClassificationEvaluator
predictions = modelRF.transform(testData)
evaluator = BinaryClassificationEvaluator(labelCol="Survived", rawPredictionCol="prediction", metricName="areaUnderROC")
evaluator.evaluate(predictions)
evaluator = BinaryClassificationEvaluator(labelCol="Survived", rawPredictionCol="prediction", metricName="areaUnderPR")
evaluator.evaluate(predictions)
\end{minted}
\includegraphics[width=\linewidth]{image5.1}

In the first iteration of HW 4-2 the AUROC was 0.791043 and AUPR was 0.738639.
As shown in the image removing all outliers actually decreased the effectiveness of the model based on these metrics.
When trimming is done again but leaving the Parent-Child outliers in the data set we get slightly better results. \\
\includegraphics[width=\linewidth]{image5.2}

In this case the AUROC is improved slightly and the AUPR is decreased more than the AUROC gains. This version of the model is slightly less likely to introduce false positives but it also slightly less precise overall.

\end{document}

\begin{minted}[breaklines,bgcolor=light-gray,fontsize=\footnotesize]{python}
\end{minted}
\includegraphics[width=\linewidth]{image1}


\section{Monitor Specification Correctness}~\label{sec:verispec}

As RV is applied to  guarantee sophisticated properties, the
monitor specifications themselves will grow in complexity and may become
prone to error.  Our experience with a number of case studies
involving complex monitor properties is that we were able to discover
many simple theorems that should hold for a correct specification.  Hence, applying formal proof tools to the monitors to
ensure they are correct can safeguard that the last line of
defense is actually effective. Ideally, specification verification
capabilities should be integrated into the RV framework so engineers
could write specifications, verify their correctness, and generate
monitors in a seamless fashion.

\paragraph{Challenge:}  \emph{Assure  the correctness of the monitor
specification.}

\paragraph{Copilot Approach:}
 Copilot supports automated proofs of specification
 properties  through its {\tt Copilot.Theorem} module.  Applying a
``synchronous observer'' approach~\cite{amast93}, properties \emph{about}
Copilot programs are specified \emph{within} Copilot itself. In particular,
properties are encoded with standard Boolean streams and Copilot streams are
sufficient to encode past-time linear temporal logic~\cite{ptltl}.

 A proposition is a Copilot value of type \texttt{Prop} \texttt{Existential}
 or \texttt{Prop} \texttt{Universal}, which can be introduced using \texttt{exists} and
\texttt{forall}, respectively. These are functions taking as an argument a
normal Copilot stream of type \lstinline{Stream Bool}. Propositions can be added
to a specification using the \texttt{prop} and \texttt{theorem} functions,
where \texttt{theorem} must also be passed a tactic for automatically proving
the proposition. Currently, proof engines  based on
Satisfiability Modulo Theories (\textsc{smt})   are used to discharge
proofs.  The Copilot prover was first introduced
in~\cite{pike-rv-15}, where its utility was demonstrated in assuring
notoriously subtle voting algorithms.

In the course of the analysis of the separation criteria, a team of
domain experts used the PVS interactive prover to prove theorems that
characterize the correctness of the criteria.  We were able to apply
the Copilot prover using Z3~\cite{DeMoura2008} to prove many of these theorems
within the Copilot framework. Among the properties proven about the
horizontal separation criteria are:

\resizebox{.9\linewidth}{!}{
\begin{minipage}{\linewidth}
\begin{eqnarray*}
\texttt{horiz\_criteria}(\bm{sx},  \bm{sy},
\epsilon,  \bm{vx},  \bm{vy}) & \Longleftrightarrow &
\texttt{horiz\_criteria}(\bm{-sx},  \bm{-sy},
\epsilon, \bm{-vx},  \bm{-vy})   \\ \\
( \texttt{horiz\_criteria}(\bm{sx},\bm{sy},
\epsilon, \bm{vx},\bm{vy}) \  \wedge &&  \\
\texttt{horiz\_criteria} (\bm{sx},  \bm{sy},
\epsilon,  \bm{wx}, \bm{wy}) )& \Longrightarrow&
\texttt{horiz\_criteria} (\bm{sx}, \bm{sy},
\epsilon,\bm{vx},\bm{vy})\\ \\
( \texttt{horiz\_criteria}(\bm{sx},  \bm{sy},
\epsilon,  \bm{vx},  \bm{vy}) \   \wedge  &&\\
\texttt{horiz\_criteria}(\bm{sx},  \bm{sy}, \epsilon',  \bm{vx},
\bm{vy}) )  &\Longrightarrow & \epsilon = \epsilon'
\end{eqnarray*}
\end{minipage}
}

 \vspace{\belowdisplayskip}

\noindent
\paragraph{}A few of the properties proven in PVS involve continuous mathematics
that remains beyond the capabilities of fully automated tools,
but combined with testing, we have a convincing argument that the
specification is correct.

%\begin{lstlisting}[frame=single]
%\lstinine{ horizont(sx, sy, e, vx vy)
% <==>  horizontalCriterionForConflictResolution -sx -sy e -v'x -v'y}
%\end{lstlisting}
%
%and
%
%\begin{lstlisting}[frame=single]
%\lstinine{ horizontalCriterionForConflictResolution sx sy e v'x v'y
%  &&  horizontalCriterionForConflictResolution sx sy e w'x w'y ==>
%  horizontalCriterionForConflictResolution sx sy e (v'x+w'x) (v'y + w'y)}
%\end{lstlisting}

%\begin{itemize}
%\item Monitor specs are safety properties.
%\item Spec needs to be validated against the requirements. Maybe spec
%  language needs to be closer to  language of domain.  Copilot
%  libraries.
%\item Many LTL specs may be very strait forward, but we found that the
%  specs in FT and airspace management were subtle and easy to get
%  wrong.
%\item Modern verification tools such as SMT solvers can be integrated
%% with the RV framework.
%\item An example from Airspace management.
%\end{itemize}


\documentclass{memoir}
\usepackage{notestemplate}
\usetikzlibrary{matrix,arrows.meta}

%\logo{~/School-Work/Auxiliary-Files/resources/png/logo.png}
%\institute{Rice University}
%\faculty{Faculty of Whatever Sciences}
%\department{Department of Mathematics}
%\title{Class Notes}
%\subtitle{Based on MATH xxx}
%\author{\textit{Author}\\Gabriel \textsc{Gress}}
%\supervisor{Linus \textsc{Torvalds}}
%\context{Well, I was bored...}
%\date{\today}

%\makeindex

\begin{document}

% \maketitle

% Notes taken on

The idea of a tensor product of modules \(M,N\) is to form another module in which we can take products \(mn\) of elements \(m \in M\) and \(n \in N\).

\begin{defn}[Ring Extension]
	Let \(R\leq S\). If \(\prescript{}{S}N\) is a left \(S\)-module, then \(N\) can also construct a left \(R\)-module since the elements of \(R\) act on \(N\) by assumption.\\

	More generally, if \(f:R\to S\) is a ring homomorphism from \(R\) into \(S\) with \(f(1_R) = 1_S\), then \(N\) can be considered as an \(R\)-module with \(rn = f(r)n\) for \(r \in R\) and \(n \in N\). We consider \(S\) a \textbf{ring extension of \(R\)} and the resulting \(R\)-module is said to be obtained from \(N\) by \textbf{restriction of scalars} from \(S\) to \(R\).
\end{defn}
One might wonder if the reverse can be done-- taking a ring \(R\) and attempting to extend the scalars to a larger ring. This cannot be done in general-- for example, one can check that \(\Z\) cannot be made into a \(\Q\)-module.\\

However, while \(\Z\) cannot be made into a \(\Q\)-module, it is contained in a \(\Q\)-module (\(\prescript{}{\Q}\Q\)). That is, there is an embedding of the \(\Z\)-module \(\prescript{}{\Z}\Z\) into the \(\Q\)-module \(\prescript{}{\Q}\Q\). This isn't always the case however-- to see this, consider the \(\Z\)-module \(\prescript{}{\Z}N\) where \(N\) is a finite abelian group. One can check that there are no nonzero homomorphisms into any \(\Q\)-module.\\

Our goal will be to construct a module which is the best candidate for which we can embed into.

\begin{defn}[Tensor Product of Modules]
	Let \(\prescript{}{R}N\) be a general \(R\)-module that we wish to embed into some \(S\)-modue. First we will try and define a product of the form \(sn\) for \(s \in S\), \(n \in N\).\\

	We start by considering the free \(\Z\)-module on the set \(S\times N\). This is the collection of all finite commuting sums of elements of the form \((s_i,n_i)\) with no relations imposed on \(sn\). Our \(S\)-module structure requires that we must satisfy the relations
	\begin{align*}
		r_1:& \quad(s_1+s_2)n = s_1n + s_2n \\
		r_2:& \quad s(n_1+n_2) = sn_1 + sn_2\\
		r_3:& \quad (sr)n = s(rn)
	\end{align*}
	for \(s_1,s_2,s \in S\), \(r \in R\), and \(n \in N\). We let \(H\leq N\) be the subgroup given by \(H := \langle r_1,r_2,r_3 \rangle \), that is, all elements of the form above, and consider \(N / H\). We denote this quotient group by \(S \otimes_R N\) and call it the \textbf{tensor module product of \(S\) and \(N\) over \(R\)}. We denote \(s \otimes n\) the coset containing \((s,n)\) in \(S \otimes_R N\) and so we have
	\begin{align*}
		(s_1+s_2) \otimes n = s_1\otimes n + s_2 \otimes n\\
		s \otimes (n_1+n_2) = s\otimes n_1 + s \otimes n_2\\
		sr \otimes n = s \otimes rn.
	\end{align*}
	The elements of \(S \otimes_R N\) are called \textbf{tensors of modules} and can be written as finite sums of \textbf{simple tensors of modules} of the form \(s \otimes n\) with \(s \in S, n \in N\).\\

	Now we give the tensor module product \(S \otimes_R N\) an \(S\)-module action by
	\begin{align*}
		s\left( \sum_{\textrm{finite}} s_i \otimes n_i \right) = \sum_{\textrm{finite}} (ss_i) \otimes n_i.
	\end{align*}
	We call this module \(\prescript{}{S}(S \otimes_R N)\) the \textbf{\(S\)-module obtained by extension of scalars from the \(R\)-module \(N\)}.
\end{defn}
The natural map \(\iota: N \to S \otimes_R N\) defined by \(n\mapsto 1 \otimes n\). Because \(1 \otimes rn = r(1 \otimes n)\), it follows that \(\iota\) is an \(R\)-module homomorphism from \(N\) to \(S \otimes_R N\). It is not injective in general, and so \(S \otimes_R N\) need not contain an isomorphic copy of \(N\).\\

Because the relatons imposed were the minimal relations necessary, one would expect that \(S \otimes_R N\) is the best possible \(S\)-module for a module homomorphism.

\begin{thm}[Universal Property for Tensor Modules]
	Let \(R\leq S\), let \(\prescript{}{R}N\) be a left \(R\)-module and let \(\iota: N \to S \otimes_R N\) be the \(R\)-module homomorphism defined by \(\iota(n) = 1 \otimes n\). Suppose that \(\prescript{}{S}L\) is an arbitrary left \(S\)-module and \(\varphi :N \to L\) is an \(R\)-module homomorphism from \(N\) to \(L\). Then there is a unique \(S\)-module homomorphism \(\Phi :S \otimes_R N \to L\) such that \(\varphi = \Phi \circ \iota \) and the diagram commutes:
\begin{center}
			\begin{tikzpicture}
  \matrix (m)
    [
      matrix of math nodes,
      row sep    = 3em,
      column sep = 4em
    ]
    {
	    N & S \otimes_R N \\
	     & L            \\
    };
  \path
  (m-1-2) edge [->] node [right] {\(\Phi \)} (m-2-2)
    (m-1-1) edge [->] node [above] {\(\iota\)} (m-1-2)
      (m-1-1) edge [->] node [below] {$\varphi$} (m-2-2);
\end{tikzpicture}
\end{center}
Conversely, if \(\Phi :S \otimes_R N \to L\) is an \(S\)-module homomorphism then \(\varphi  = \Phi \circ \iota\) is an \(R\)-module homomorphism from \(N\) to \(L\).
\end{thm}

\begin{cor}
	Let \(\iota:N \to S \otimes_R N\) be the \(R\)-module homomorphism from the universal property of free modules. Then \(N / \textrm{Ker}\iota\) is the unique largest quotient of \(N\) that can be embedded in any \(S\)-module.\\

	In particular, \(N\) can be embedded as an \(R\)-submodule of some left \(S\)-module if and only if \(\iota\) is injective.
\end{cor}

\begin{exmp}

\end{exmp}

\subsection{General Tensor Product}
\label{sub:general_tensor_product}

Notice that forming \(S\otimes_R N\) as an abelian group only required \(S_R\) to be a right \(R\)-module and \(\prescript{}{R}N\) a left \(R\)-module. We can construct an abelian group \(M \otimes_R N\) for any right \(R\)-module \(M_R\) and any left \(R\)-module \(\prescript{}{R}N\).\\

The \(S\)-module structure on \(\prescript{}{S}{(S \otimes_R N)}\) required only a left \(S\)-module structure on \(\prescript{}{S}S\) and the compatibility relation
\begin{align*}
	s'(^2) = (s's)r.
\end{align*}

\begin{defn}[Tensor]
	Let \(\prescript{}{R}N\) be a left \(R\)-module and \(M_R\) a right \(R\)-module. We obtain an abelian group by quotient of the free \(\Z\)-module on \(M\times N\) by the subgroup \(H = \langle r_1,r_2,r_3 \rangle \), where
	\begin{align*}
		r_1:& \quad (m_1+m_2,n) = (m_1,n) + (m_2,n)\\
		r_2:& \quad (m, n_1+n_2) = (m,n_1) + (m,n_2)\\
		r_3:& \quad (mr,n) = (m,rn)
	\end{align*}
	for \(m,m_1,m_2 \in M\), \(n,n_1,n_2 \in N\), and \(r \in R\). We denote this by
	\begin{align*}
		M \otimes_R N := \prescript{}{\Z}(M \times N) / \langle r_1,r_2,r_3 \rangle
	\end{align*}
	and call it the \textbf{tensor product of \(M\) and \(N\) over \(R\)}. The elements of \(M \otimes_R N\) are called \textbf{tensors}, and the coset \(m \otimes n \in M \otimes_R N\) is called a \textbf{simple tensor}. Every tensor can be written (non-uniquely) as a finite sum of simple tensors.
\end{defn}
Keep in mind that \(m \otimes n\) are cosets and not elements directly-- so caution must be used when defining maps on tensor products. That is, one needs to check that a map is well-defined on the entirety of a coset.\\

Furthermore, caution must be exercised when comparing tensor products. For example, if \(M \leq M'\), we can have \(m \otimes n = 0\) in \(M' \otimes_R N\) but \(m \otimes n \neq 0\) in \(M \otimes_R N\). This essentially captures the notion that when more elements are included, the cosets will change. Hence there is no reason to expect \(M \otimes_R N \leq M' \otimes_R N\).

\begin{defn}
	Let \(M_R\) be a right \(R\)-module, \(\prescript{}{R}N\) a left \(R\)-module, and \(L\) an abelian group. A map \(\varphi :M\times N \to L\) is called \textbf{\(R\)-balanced} or \textbf{middle linear with respect to \(R\)} if
	\begin{align*}
		\varphi (m_1+m_2,n) &= \varphi(m_1,n) + \varphi (m_2,n)\\
		\varphi (m,n_1+n_2) &= \varphi (m,n_1) + \varphi (m,n_2)\\
		\varphi (m,rn) &= \varphi (mr,n)
	\end{align*}
	for all \(m,m_1,m_2 \in M\), \(n,n_1,n_2 \in N\) and \(r \in R\).
\end{defn}
We can define a map \(\iota:M\times N \to M \otimes_R N\) with \(\iota(m,n) = m \otimes n\). This map is not a group homomorphism but it is in fact \(R\)-balanced.

\begin{thm}[Universal Property of Tensor Products]
	Let \(R\) be a ring, \(M_R\) a right \(R\)-module, and \(\prescript{}{R}N\) a left \(R\)-module. Let \(M \otimes_R N\) be the tensor product of \(M\) and \(N\) over \(R\) and let \(\iota: M \times N \to M \otimes_R N\) be the \(R\)-balanced map defined by \(\iota(m,n) = m \otimes n\). Then for any group homomorphism \(\Phi :M \otimes_R N \to L\) to an abelian group \(L\), the composite map
	\begin{align*}
		\varphi = \Phi \circ \iota
	\end{align*}
	is an \(R\)-balanced map from \(M \times N \to L\). Conversely, if \(L\) is an abelian group and \(\varphi :M \times N \to L\) is any \(R\)-balanced map, then there is a unique group homomorphism \(\Phi: M \otimes_R N \to L\) such that \(\varphi  = \Phi \circ \iota\).\\

	In other words, there is a correspondence between \(\varphi \) and \(\Phi \) by the commutative diagram:
\begin{center}
			\begin{tikzpicture}
  \matrix (m)
    [
      matrix of math nodes,
      row sep    = 3em,
      column sep = 4em
    ]
    {
	    M \times N & M \otimes_R N \\
	     & L            \\
    };
  \path
  (m-1-2) edge [->] node [right] {\(\Phi \)} (m-2-2)
    (m-1-1) edge [->] node [above] {\(\iota\)} (m-1-2)
      (m-1-1) edge [->] node [below] {$\varphi$} (m-2-2);
\end{tikzpicture}
\end{center}
and this correspondence establishes a bijection between \(R\)-balanced maps and group homomorphisms, by the bijection between \(\varphi \) and \(\Phi \).
\end{thm}

\begin{cor}
	Suppose \(D\) is an abelian group and \(\iota':M \times N \to D\) is an \(R\)-balanced map such that
	\begin{itemize}
		\item \(D = \langle \textrm{Im}(\iota')\rangle \)
		\item every \(R\)-balanced map defined on \(M\times N\) factors through \(\iota'\)
	\end{itemize}
	Then there is an isomorphism \(f: M \otimes_R N \cong D\) of abelian groups with \(\iota' = f \circ \iota\)
\end{cor}

Now we'd like to give this abelian group a module structure. We simply need to impose a compatibility structure on \(M\) to obtain this.

\begin{defn}
	Let \(R,S\) be rings. An abelian group \(M\) induces a \textbf{\((S,R)\)-bimodule} if \(M\) forms a left \(S\)-module, a right \(R\)-module, and \(s(mr) = (sm)r\) for all \(s \in S, r \in R, m \in M\).
\end{defn}

\begin{exmp}
	Let \(R\) be a commutative ring. A left \(R\)-module \(\prescript{}{R}M\) can always be given the structure of a right \(R\)-module by simply defining \(mr = rm\), and hence \(M\) becomes a \((R,R)\)-bimodule. We call this the \textbf{standard} \(R\)-module structure on \(M\).
\end{exmp}
Notice that if \(N\) has a left \(R\)-module structure and \(M\) a \((S,R)\)-bimodule structure, then we have once again
\begin{align*}
	s \left( \sum_{\textrm{finite}} m_i \otimes n_i \right) = \sum_{\textrm{finite}} (sm_i) \otimes n_i
\end{align*}
and hence there is a well-defined action of \(S\) so that \(M \otimes_R N\) can be considered a left \(S\)-module. It follows that for fixed \(s\), \((m,n)\mapsto sm \otimes n\) is an \(R\)-balanced map, and hence there is a well-defined group homomorphism \(\lambda_s:M\otimes_R N \to M \otimes_R N\) that satisfies \(\lambda_s(m \otimes n) = sm \otimes n\).\\

A special case we might encounter is when \(M,N\) are left modules over a commutative ring \(R\), and \(S = R\). Then the standard \(R\)-module structure on \(M\) gives \(M\) the structure of an \((R,R)\)-bimodule and hence \(M \otimes_R N\) always has the structure of a left \(R\)-module.

\begin{defn}
	Let \(R\) be a commutative ring and let \(M,N,L\) be left \(R\)-modules. The map \(\varphi : M \times N \to L\) is called \textbf{\(R\)-bilinear} if it is \(R\)-linear in every factor:
	\begin{align*}
		\varphi (r_1m_1+r_2m_2,n) &= r_1 \varphi (m_1,n) + r_2 \varphi (m_2,n)\\
		\varphi (m,r_1n_1 + r_2n_2) = r_1 \varphi (m,n_1) + r_2 \varphi (m,n_2)
	\end{align*}
	for all \(m, m_1, m_2 \in M\), \(n,n_1,n_2 \in N\), and \(r_1,r_2 \in R\).
\end{defn}

\begin{cor}
	Suppose \(R\) is a commutative ring, and \(M,N\) two left \(R\)-modules. Let \(M \otimes_R N\) be the tensor product of \(M\) and \(N\) over \(R\), where \(M\) is given the standard \(R\)-module structure. Then \(M \otimes_R N\) is a left \(R\)-module with
	\begin{align*}
		r(m \otimes n) = (rm) \otimes n = (mr) \otimes n = m \otimes (rn)
	\end{align*}
	and the map \(\iota:M \times N \to M \otimes_R N\) with \(\iota(m,n) = m \otimes n\) is an \(R\)-bilinear map. If \(L\) is any left \(R\)-module then there is a bijection between \(R\)-bilinear maps and \(R\)-module homomorphisms induced by the bijection between \(\varphi: M\times N \to L \) and \(\Phi: M \otimes_R N \to L \) via the commutative diagram:
\begin{center}
			\begin{tikzpicture}
  \matrix (m)
    [
      matrix of math nodes,
      row sep    = 3em,
      column sep = 4em
    ]
    {
	    M \times N & M \otimes_R N \\
	     & L            \\
    };
  \path
  (m-1-2) edge [->] node [right] {\(\Phi \)} (m-2-2)
    (m-1-1) edge [->] node [above] {\(\iota\)} (m-1-2)
      (m-1-1) edge [->] node [below] {$\varphi$} (m-2-2);
\end{tikzpicture}
\end{center}
\end{cor}

\begin{exmp}

\end{exmp}

\begin{thm}[Tensor Product of Homomorphisms]
	Let \(M, M'\) be right \(R\)-modules, let \(N,N'\) be left \(R\)-modules. Suppose \(\varphi :M \to M'\) and \(\psi : N \to N'\) are \(R\)-module homomorphisms. Then there is a unique group homomorphism denoted by \(\varphi  \otimes \psi \) given by
	\begin{align*}
		\varphi \otimes \psi : M \otimes_R N \to M' \otimes_R N'\\
		(\varphi \otimes \psi )(m \otimes n) = \varphi (m) \otimes \psi (n)
	\end{align*}
	for all \(m \in M\) and \(n \in N\).\\

	If \(M,M'\) are \((S,R)\)-bimodules for some ring \(S\), and \(\varphi \) is also an \(S\)-module homomorphism, then \(\varphi \otimes \psi \) is a homomorphism of left \(S\)-modules. Hence if \(R\) is commutative then \(\varphi \otimes \psi \) is always an \(R\)-module homomorphism for the standard \(R\)-module structures.
\end{thm}
Notice that the uniqueness conditions tells us that if \(\lambda :M' \to M''\) and \(\mu : N' \to N''\) are \(R\)-module homomorphisms, then
\begin{align*}
	(\lambda \otimes u ) \circ (\varphi  \otimes \psi ) = (\lambda \circ \varphi ) \otimes (\mu  \otimes \psi ).
\end{align*}
In fact, we can use this idea to extend the tensor product into an \(n\)-fold tensor product.

\begin{thm}
	Suppose \(M\) is a right \(R\)-module, \(N\) is an \((R,T)\)-bimodule, and \(L\) is a left \(T\)-module. Then there is a unique isomorphism
	\begin{align*}
		(M \otimes_R N) \otimes_T L \cong M \otimes_R (N \otimes_T L)
	\end{align*}
	of abelian groups such that
	\begin{align*}
		(m \otimes_R n) \otimes l \mapsto m \otimes_R(n \otimes_R l).
	\end{align*}
	If \(M\) is an \((S,R)\)-bimodule, then this is an isomorphism of \(S\)-modules.
\end{thm}

\begin{cor}
	Let \(R\) be a commutative ring and \(M,N,L\) form left \(R\)-modules. Then
	\begin{align*}
		(M \otimes_R N) \otimes_R L \cong M \otimes_R(N \otimes_R L)
	\end{align*}
\end{cor}
Of course, it will be useful to use the natural extension of a bilinear map.

\begin{defn}
	Let \(R\) be a commutative ring and  let \(M_1,M_2,\ldots,M_n\) and \(L\) form \(R\)-modules with the standard \(R\)-module structures. A map \(\varphi : M_1 \times  \ldots \times M_n \to L\) is called \textbf{\(n\)-multilinear over \(R\)} if it is an \(R\)-module homomorphism in each component:
	\begin{align*}
		\varphi (m_1,\ldots,m_{i-1},rm_i + r'm'_i, m_{i+1},\ldots,m_n) = r \varphi(m_1,\ldots,m_i,\ldots,m_n) + r' \varphi (m_1,\ldots,m_i', \ldots, m_n)
	\end{align*}
\end{defn}
Hence we can define an \(n\)-fold tensor product by iterating the tensor product of pairs of modules.

\begin{cor}
	Let \(R\) be a commutative ring and let \(M_1,\ldots,M_n,L\) be \(R\)-modules. Let \(M_1 \otimes_R M_{2} \otimes_R \ldots \otimes_R M_n\) be the sequence of tensor products of pairs of these modules and let
	\begin{align*}
		\iota:M_1\times \ldots \times M_n \to M_1 \otimes_R \ldots \otimes_R M_n\\
		\iota(m_1,\ldots,m_n) = m_1 \otimes_R \ldots \otimes_R m_n.
	\end{align*}
	Then for every \(R\)-module homomorphism \(\Phi : M_1 \otimes_R \ldots \otimes_R M_n \to L\) the map \(\varphi = \Phi \circ \iota\) is \(n\)-multilinear from \(M_1\times \ldots\times M_n\to L\).\\

	If \(\varphi :M_1\times \ldots\times M_n \to L\) is an \(n\)-multilinear map then there is a unique \(R\)-module homomorphism \(\Phi :M_1 \otimes_R \ldots \otimes_R M_n \to L\) such that \(\varphi  = \Phi \circ \iota\). This bijection induces a bijection between \(n\)-multilinear maps and \(R\)-module homomorphisms for which the following diagram commutes:
\begin{center}
			\begin{tikzpicture}
  \matrix (m)
    [
      matrix of math nodes,
      row sep    = 3em,
      column sep = 4em
    ]
    {
	    M \times \ldots \times M_n & M \otimes_R \ldots \otimes_R M_n \\
	     & L            \\
    };
  \path
  (m-1-2) edge [->] node [right] {\(\Phi \)} (m-2-2)
    (m-1-1) edge [->] node [above] {\(\iota\)} (m-1-2)
      (m-1-1) edge [->] node [below] {$\varphi$} (m-2-2);
\end{tikzpicture}
\end{center}
\end{cor}

We once again have a containment condition.

\begin{thm}[Tensor Products of Direct Sums]
	Let \(M, M'\) be right \(R\)-modules and let \(N, N'\) be left \(R\)-modules. Then there are unique group isomorphisms
	\begin{align*}
		(M \oplus M') \otimes_R N \cong (M \otimes_R N) \oplus (M' \otimes_R N)\\
		M \otimes_R (N \oplus N') \cong (M \otimes_R N) \oplus (M \otimes_R N')\\
		(m,m') \otimes n \mapsto (m \otimes n, m' \otimes n)\\
		m \otimes(n,n') \mapsto (m \otimes n, m \otimes n').
	\end{align*}
	If \(M,M'\) are also \((S,R)\)-bimodules, then these are isomorphisms of left \(S\)-modules. In particular, if \(R\) is commutative, these are isomorphisms of \(R\)-modules.
\end{thm}
Of course, this theorem extends inductively to any finite direct sum of \(R\)-modules (in fact any arbitrary direct sums). In essense, tensor products commute with direct sums.

\begin{cor}
	The module obtained from the free \(R\)-module \(N \cong \prescript{}{R}R^{n}\) by extension of scalars from \(R\) to \(S\) is the free \(S\)-module \(\prescript{}{S}S^{n}\):
	\begin{align*}
		S \otimes_R R^{n} \cong S^{n}
	\end{align*}
as left \(S\)-modules.
\end{cor}

\begin{cor}
	Let \(R\) be a commutative ring and let \(M \cong R^{s}\), \(N \cong R^{t}\) form free \(R\)-modules with bases \(m_1,\ldots,m_s\) and \(n_1,\ldots,n_t\) respectively.  Then \(M \otimes_R N\) forms a free \(R\)-module of rank \(st\) with basis \(m_i \otimes n_j\), \(1\leq i\leq s\) and \(1\leq j\leq t\), so that:
	\begin{align*}
		R^{s} \otimes_R R^{t} \cong R^{st}.
	\end{align*}
\end{cor}

\begin{rmrk}
	The tensor product of two free modules of arbitrary rank over a commutative ring is free.
\end{rmrk}

\begin{prop}
	Suppose \(R\) is a commutative ring and \(M,N\) form left \(R\)-modules via the standard \(R\)-module structures. Then there is a unique \(R\)-module isomorphism
	\begin{align*}
		M \otimes_R N \cong N \otimes_R M\\
		m \otimes n \mapsto n \otimes m
	\end{align*}
\end{prop}
One might think that if \(M=N\), the above conditions are not necessary, but in fact it is not the case. Some tensors do have the property that \(a \otimes b = b \otimes a\) for \(a,b \in M\), which we refer to as symmetric tensors, to be studied later.

\begin{prop}
	Let \(R\) be a commutative ring and let \(A,B\) be \(R\)-algebras. Then the multiplication
	\begin{align*}
		(a \otimes b) (a' \otimes b') = a a' \otimes b b'
	\end{align*} is well-defined and makes \(A\otimes_R B\) into an \(R\)-algebra.
\end{prop}

\begin{exmp}

\end{exmp}

% \printindex
\end{document}


\chapter{{\tt Network}: Simple Max-flow solver}
\par
First, some background on how the {\tt Network} object is used
to find a minimal weight separator.
The process is rather complex.
\par
We are given a partition of the vertices $V$ into three disjoint sets,
$B$, $Y$ and $W$, where $Y$ is a ``wide'' separator (i.e., not a
minimal separator).
We construct a network from this vertex partition, solve a max flow
problem on this network, and then find one or more mincuts that
correspond to a separator $S \subset Y$ with minimal vertex weight.
\par
Here are the steps by which the {\tt GPart} object contructs the
network.
\begin{itemize}
\item
All nodes in $B$ are collapsed into the source $s$.
\item
All nodes in $W$ are collapsed into the sink $t$.
\item
$Y$ is partitioned into four sets:
\begin{itemize}
\item
$Y_B$ are those nodes adjacent to $B$ but not adjacent to $W$.
\item
$Y_W$ are those nodes adjacent to $W$ but not adjacent to $B$.
\item
$Y_I$ are those nodes adjacent to neither $W$ nor $B$.
\item
$Y_{B,W}$ are those nodes adjacent to both $W$ and $B$.
\end{itemize}
Normally, by construction,
$Y_{B,W} = \emptyset$, but the code should work fine otherwise.
\item
Each $y \in Y_B$ becomes one node $y$ in the network,
and the edge $(s,y)$ has capacity $weight(y)$.
\item
Each $y \in Y_W$ becomes one node $y$ in the network,
and the edge $(y,t)$ has capacity $weight(y)$.
\item
Each $y \in Y_I$ becomes two nodes in the network, $y^-$ and $y^+$.
The edge $(y^-,y^+)$ has capacity $weight(y)$.
\item
An edge $(x,y)$ where $x \in Y_B$ and $y \in Y_B$ is not found in
the network. (It is not necessary.)
Similarly,
an edge $(x,y)$ where $x \in Y_W$ and $y \in Y_W$ is not found in
the network.
\item
An edge $(x,y)$ where $x \in Y_B$ and $y \in Y_I$ becomes two edges,
$(x,y^-)$ and $(y^+,x)$, both with infinite capacity.
\item
An edge $(y,z)$ where $y \in Y_I$ and $z \in Y_W$ becomes two edges,
$(y^+,z)$ and $(z,y^-)$, both with infinite capacity.
\item
An edge $(x,y)$ where $x \in Y_I$ and $y \in Y_I$ becomes two edges,
$(x^+,y^-)$ and $(y^+,x^-)$, both with infinite capacity.
\end{itemize}
\par
The {\tt Network} object can be constructed fairly simply.
It is initialized by specifying the number of nodes in the network,
including the source and sink.
Arcs can be added one at a time and it is not necessary to know
the total number of arcs ahead of time.
To specify an arc one needs to provide the first and second
vertices, the capacity and the present flow.
\par
Once we have constructed the network, we solve the max flow problem
in a very simple manner, basically the Ford-Fulkerson algorithm
that generates augmenting paths.
No doubt this can be improved, and it would be welcome because for
large three dimensional finite element graphs, up to sixty per cent
of the time is spent smoothing the separators, and most of this
time is spent solving a max flow problem.
\par
However, the network we generate in practice have
two special properties:
\begin{itemize}
\item
The networks are very shallow, i.e., the distance from the source
to the sink is generally 3-6 in practice.
This reduces the potential improvement of a pre-push algorithm.
\item
The maximum capacity of an edge is small, usually 6-12.
Therefore scaling algorithms have little applicability.
\end{itemize}
Finding a minimal separator gives rise to networks of a special
nature and that may require specialized solution techniques.
In fact, there is a more straightforward approach that generates a
network where each vertex in $Y$ becomes {\it one} node in the
network (as opposed to two network nodes for a vertex in $Y_I$).
For this special network, all edges have infinite capacity and it
is the vertices that have finite capacity.
In any case, the {\tt Network} object is but a naive and
straightforward implementation of the simplest max flow solution
scheme and will no doubt be improved.


%!TEX root =  ../main.tex

\section{Properties and Operators}
\subsection{Closure}
Suppose you attempted to help a young child with some mathematic problems.
Suppose further this child knew next
to nothing about fractions yet.  Perhaps they understand the notion of debt ---
negative numbers --- but no greater
sets of numbers.  What can you talk to them about?  What must you avoid?
Consider the following list of procedures you know:

\begin{itemize}
\item Addition
\item Subtraction
\item Multiplication
\item Division
\item Distribution of Multiplication over Addition
\item Squaring
\item Square roots
\end{itemize}

The question before us is one of \gls{closure}.  A set is closed under an operator
if doing the operation on any member of
the set produces another member of the set.  For example, the integers are closed under addition, subtraction, and multiplication, but not division.

\begin{example}
\exProblem
Are the Real numbers closed under square rooting?

\exSolution
No.  Disproof by counterexample: $\sqrt{-4} = 4i$
\end{example}

\subsection{Identity and Invertibility}
Over a given set, most operators have an \textbf{identity element} that leaves
them unchanged.  For example, the
identity of addition is 0, because adding zero does not change a number.
Similarly, multiplication has
the identity element of 1, because multiplying by one leaves a number unchanged.

\begin{example}
\exProblem
What is the identity of set union?

\exSolution
$\varnothing$ when joined to any set will not change the set in any way.
\end{example}

It is possible to have more than one identity for a given operator over a particular set.
One effect of having an
identity element is that it becomes possible to define ``undoing'' a particular operator.  For instance,
multiplicative inverse of every number except 0 is one, which shows that multiplication by $m$ can be
undo by multiplying by $\frac{1}{m}$.  The additive inverse of some number $x$ is $-x$, because together
they add to the additive identity 0.  An operation may be invertible without being commutative (see below)

\subsection{Associativity}
Suppose we have one operator and three operands.  In what order do we proceed?  Many times,
it does not matter.  Addition and multiplication are associative over most numbers, so $(3+2)+1$
is the same as $3+(2+1)$ and $(2\cdot 3) \cdot 4$ is the same as $2\cdot(3\cdot 4)$.  Division is
not associative, and neither are powers.

\reminder{\lefthand}{A cute way to remember this property is to think of friends associating together.  If three girls are friend --- call them Jill, Sandra, and Bree --- then it doesn't matter which we we draw the association.  Jill and Sandra are friends, and together they're friends with Bree.  That is the same as Sandra and Bree being friends, and  together being friends with Jill.  $(J \cup S) \cup B = J \cup (S \cup B)$.}

\begin{example}
\exProblem
Is rock-paper-scissors\footnote{Or even better, rock-paper-scissors-lizard-Spock!} associative?

\exSolution
No.  Disproof by counterexample:\\
(rock vs. paper) vs. scissors $\rightarrow$ paper vs. scissors $\rightarrow$ scissors\\
rock vs. (paper vs. scissors) $\rightarrow$ rock vs scissors $\rightarrow$ rock
\end{example}

\subsection{Commutativity}
Many operators do not care in which order the operands come.  Addition and multiplication are the same
forwards and backwards!  But subtraction and division yield very different results when done in the
reverse.  This property is called commutativity.

\subsection{Distributivity}
A very complicated property, yet a very well known one, is the distributive property.  This property
requires \emph{two} operators to be performed on a set.  For example, multiplication \emph{is}
distributive over addition.  e.g. $2(3+4) = 2\cdot7 = 2\cdot3 + 2\cdot4 = 6 + 8 = 14$.

\begin{example}
\exProblem
Is division distributive over addition?  Are powers distributive over multiplication?

\exSolution
No and yes.

No.  $2\div(3+4) \ne 2\div3 + 2\div4$.
Yes.  $(3\cdot4)^2 = 12^2 = 3^2\cdot4^2 = 9\cdot16 = 144$
\end{example}

Exercise: clock-math closure