\newcommand{\aLin}{R}
\newcommand{\bLin}{S}

A program is \emph{sequential} if it lacks $\!\!\PAR\!\!$, and
\emph{synchronization-free} if lacks fences and $\mRA/\mSC$ access.

We consider an extension of Hoare logic with read sets.  The format of triples we will consider is:
\[ \hoare{\aLin\SEMI\aForm}{\aCmd}{\bLin\SEMI\bForm} \]
$\aLin, \bLin$ are multisets of the shared variable bindings of the form $\aLoc = \aVal$.

The triple is intended to capture the the following intended partial correctness semantics.  We only consider terminating computations of $\aCmd$
\begin{itemize}
\item Initial state satisfies $\aLin\ \land\ \aForm $
\item $\bLin\ \subseteq\ \aLin$
\item Final state satisfies $\bForm$
\item If the computation reads a value, say $\aVal$, for $\aLoc$ that it did not write itself, say $n$ times,  then $\aLin \setminus \bLin$ contains the multiset with at least $n$ occurrences of
$\aLoc = \aVal$
\end{itemize}

The rules are as follows.
\begin{itemize}
\item Structure. Weakening
\[
\frac{\aForm_1 \Vdash\ \aForm, \bForm_1 \Vdash\ \bForm,\aLin_1 \supseteq\ \aLin, \bLin \subseteq\ \bLin_1, \hoare{\aLin_1\SEMI\aForm_1}{\aCmd}{\bLin_1 \SEMI\bForm_1}}{ \hoare{\aLin\SEMI\aForm}{\aCmd}{\bLin\SEMI\bForm}}
\]

\item  Structure.  Connectives.
\[ \frac
{\hoare{\aLin\SEMI\aForm_1}{\aCmd}{\bLin\SEMI\bForm_1},  \hoare{\aLin\SEMI\aForm_2}{\aCmd}{\bLin\SEMI\bForm_2}}{ \hoare{\aLin\SEMI \aForm_1 \lor \aForm_2}{\aCmd}{\bLin\SEMI\bForm_1\lor \bForm_2}}
\]

\[ \frac
{\hoare{\aLin\SEMI\aForm_1}{\aCmd}{\bLin\SEMI\bForm_1},  \hoare{\aLin\SEMI\aForm_2}{\aCmd}{\bLin\SEMI\bForm_2}}{ \hoare{\aLin\SEMI \aForm_1 \land \aForm_2}{\aCmd}{\bLin\SEMI\bForm_1\land \bForm_2}}
\]

\item Conditional.
\[\frac
{
    \hoare{\aLin\SEMI\aForm \land\ \aExp}{\aCmd}{\bLin\SEMI\bForm}
    \quad
    \hoare{\aLin\SEMI\aForm\ \land\ \lnot\aExp}{\bCmd}{\bLin\SEMI\bForm}
  }{
    \hoare{\aLin\SEMI\aForm}{\IF{\aExp}\THEN \aCmd \ELSE \bCmd\FI}{\bLin\SEMI\bForm}
  }
\]

\item Sequential composition
\[ \frac
{\hoare{\aLin\SEMI\aForm}{\aCmd}{\aLin_1\SEMI\aForm_1}, \hoare{\aLin_1\SEMI\aForm_1}{\bCmd}{\bLin\SEMI\bForm}}
{\hoare{\aLin\SEMI\aForm}{\aCmd \SEMI \bCmd}{\bLin\SEMI\bForm}}
\]

\item Assignment.  External read.
\[
\hoare{\aLin \cup \{\aLoc = \aVal \}\SEMI\aForm[\aVal/\aReg]}{\aReg \GETS \aLoc}{\aLin \SEMI\aForm}
\]

\item Assignment.  Internal read.  External write.  Register.
\[
\hoare{\aLin\SEMI\aForm[\aLoc/\aReg]}{\aReg \GETS \aLoc}{\aLin \SEMI\aForm}
\]
\[
\hoare{\aLin\SEMI\aForm[\aReg/\aLoc]}{\aLoc \GETS \aReg}{\aLin \SEMI\aForm}
\]
\[
\hoare{\aLin\SEMI\aForm[\aExp/\aReg]}{\aReg\GETS\aExp}{\aLin\SEMI\aForm}
\]

\end{itemize}

\paragraph{Pomsets for Hoare Logic.}
% In \textsection\ref{sec:model}, we used Hoare logic
% \cite{Hoare:1969:ABC:363235.363259,gordonHoare} to reason about
%\emph{dependency analysis} for sequential code.  Here, we use an alternative
% interpretation of Hoare logic to establish the soundness of \emph{program
 % transformations}.

We develop a pomset semantics for pairs of formulae
$\semRW{\aLin\SEMI\aForm}{\bLin\SEMI\bForm}$, and show a relation between $\sem{\aCmd}$ and
$\semRW{\aLin\SEMI\aForm}{\bLin\SEMI\bForm}$ for valid  triples
$\hoare{\aLin\SEMI\aForm}{\aCmd}{\bLin\SEMI\bForm}$.

In this section, we will only consider {\em globally consistent} pomsets, ie. those such that
\[ (\bigwedge_{\aEv}\labelingForm(\aEv)) \wedge\ \bigwedge_{\aEv} \aLoc = \aVal \mid \labelingAct(\aEv) = \DR{\aLoc}{\aVal} \]
is satisfiable.

% In \textsection\ref{sec:model}, preconditions were discharged by read events.  Here, instead, preconditions
% are derived from the read events themselves.

\begin{definition}
  \label{def:prepost}
  Let $\aLin\land\aForm$ be satisfiable, $\aLin\ \supseteq \bLin$, and $\bForm$ is a conjunction of a multiset of atoms of the form $\bLoc= \aVal'$.

$\aPS\in\semRW{\aLin\SEMI\aForm}{\bLin\SEMI\bForm}$
  %We say that $\aPS$ \emph{satisfies} precondition $\aForm$ and postcondition $\bForm$ (notation $\aPS\in\semRW{\aForm}{\bForm}$)
  when it possible to satisfy the following:

\begin{itemize}
\item  Let $\bLocs$ be the set of locations referred to in $\bForm$.  For each $\bLoc\in\bLocs$, choose
  $\aEv_\bLoc\in\Event$ that writes the $\bLoc$.
  Let $\aEvs_\bLocs=\{\aEv_\bLoc\mid\bLoc\in\bLocs\}$.

\item For each $\aLoc\GETS\aVal\in\aLin$, choose a distinct
  $\bEv_\aLoc\in\Event$ that reads $\aLoc$ with value $\aVal$.
  Let $\bEvs_\aLocs=\{\bEv_\aLoc\mid\aLoc\in\aLocs\}$.

\item Require that if $\cEv\le\aEv_\bLoc$ and $\cEv$ is a read, then $\cEv\in\aLin\setminus\bLin$.
\item Require that if $\aEv_\bLoc\le\cEv$ and $\cEv$ is a write to $\bLocs$, then $\cEv\in\aEvs_\bLocs$.
\end{itemize}
\end{definition}
Pictorially, we have:
\begin{tikzdisplay}[node distance=.1ex and 2em]
  \event{r}{\bEvs_\aLocs}{}
  \event{w2}{\cForm\mid\aEvs_\bLocs}{below right=of r}
  \event{w1}{\cEvs_\bLocs}{above right=of w2}
  \po{r}{w2}
  \wk{w1}{w2}
\end{tikzdisplay}
Here, $\aEvs_\bLocs$ are the final writes to $\bLocs$, with precondition $\cForm$.
$\cEvs_\bLocs$ are other writes to $\bLocs$, which must be ordered before $\aEvs_\bLocs$.
$\bEvs_\aLocs$ are the reads that the writes depend upon.

\endinput

To do so, we
 isolate a \emph{linear} fragment of our language that ensures these
restrictions.  We then show the soundness of {\em all} transformations of
synchronization-free sequential programs into this fragment.
%
We end this section with a discussion of specific optimizations, some of
which relax the linearity assumption and include synchronization.

\paragraph{Pomsets for Hoare Logic.}
In \textsection\ref{sec:model}, we used Hoare logic
\cite{Hoare:1969:ABC:363235.363259,gordonHoare} to reason about
\emph{dependency analysis} for sequential code.  Here, we use an alternative
interpretation of Hoare logic to establish the soundness of \emph{program
  transformations}.  We develop a pomset semantics for pairs of formulae
$\semRW{\aForm}{\bForm}$, and show a relation between $\sem{\aCmd}$ and
$\semRW{\aForm}{\bForm}$ for valid Hoare triples
$\hoare{\aForm}{\aCmd}{\bForm}$.  In \textsection\ref{sec:model},
preconditions were discharged by read events.  Here, instead, preconditions
are derived from the read events themselves.

\begin{definition}
  \label{def:prepost}
  Let $\aPS\in\semRW{\aForm\land\cForm}{\bForm}$
  %We say that $\aPS$ \emph{satisfies} precondition $\aForm$ and postcondition $\bForm$ (notation $\aPS\in\semRW{\aForm}{\bForm}$)
  when it possible to satisfy the following:

  Let $\aLocs$ be the set of locations such that $\aLoc\in\aLocs$ exactly
  when $\aForm$ depends on $\aLoc$.  For each $\aLoc\in\aLocs$, choose
  $\bEv_\aLoc\in\Event$ that reads $\aLoc$.
  Let $\bEvs_\aLocs=\{\bEv_\aLoc\mid\aLoc\in\aLocs\}$.
  Let $\aSub$ be the substitution generated % from $\aLocs$
  as follows:
  % For $\aLoc\in\aLocs$,
  $\aLoc\aSub = \aVal$ exactly when $\bEv_\aLoc$ reads $\aVal$ from $\aLoc$.

  Let $\bLocs$ be the set of locations such that $\bLoc\in\bLocs$ exactly
  when $\bForm$ depends on $\bLoc$.  For each $\bLoc\in\bLocs$, choose
  $\aEv_\bLoc\in\Event$ that writes $\bLoc$.
  Let $\aEvs_\bLocs=\{\aEv_\bLoc\mid\bLoc\in\bLocs\}$.
  Let $\bSub$ be the substitution generated % from $\bLocs$
  as follows:
  % For $\bLoc\in\bLocs$,
  $\bLoc\bSub = \aVal$ exactly when $\aEv_\bLoc$ writes $\aVal$ to $\bLoc$.

  Require that $\aForm\aSub$ and $\bForm\bSub$ are satisfiable.

  Require that $\labelingForm(\aEv_\bLoc)$ implies $\cForm$ (for each $\aEv_\bLoc$).

  Require that if $\cEv\le\aEv_\bLoc$ and $\cEv$ is a read, then $\cEv\in\bEvs_\aLocs$.

  Require that if $\aEv_\bLoc\le\cEv$ and $\cEv$ is a write to $\bLocs$, then $\cEv\in\aEvs_\bLocs$.
\end{definition}
Pictorially, we have:
\begin{tikzdisplay}[node distance=.1ex and 2em]
  \event{r}{\bEvs_\aLocs}{}
  \event{w2}{\cForm\mid\aEvs_\bLocs}{below right=of r}
  \event{w1}{\cEvs_\bLocs}{above right=of w2}
  \po{r}{w2}
  \wk{w1}{w2}
\end{tikzdisplay}
Here, $\aEvs_\bLocs$ are the final writes to $\bLocs$, with precondition $\cForm$.
$\cEvs_\bLocs$ are other writes to $\bLocs$, which must be ordered before $\aEvs_\bLocs$.
$\bEvs_\aLocs$ are the reads that the writes depend upon.

Under this interpretation, precondition strengthening in Hoare logic
validates read introduction.  In our semantics, reads have no side effects.
Thus, it should be sound to introduce irrelevant reads.  Yet,
$\sem{x\GETS\aExp\SEMI r\GETS x\SEMI \aCmd}\neq \sem{x\GETS\aExp\SEMI\aCmd}$, even when $r$ does not appear in
$\aCmd$.  To make such equations hold, we define $\readc(\aPSS)$ to saturate
$\aPSS$ with reads.

In addition, Hoare postconditions are properties of \emph{completed} executions.
For example, in $\hoare{\TRUE}{x\GETS1\SEMI x\GETS2}{x{=}2}$, the postcondition
does not hold for the prefix $x\GETS1$.  As a result, we also define
$\readc(\aPSS)$ to restrict attention to completed executions.  % A pomset
% $\aPS\in\aPSS$ is \emph{maximal} if there is no $\aPS'\in\aPSS$ such that
% $\aPS$ is a proper prefix of $\aPS'$.

Let $\readc(\aPSS)$ be the set $\aPSS'$ where $\aPS'\in\aPSS'$ when there is
a completed pomset $\aPS\in\aPSS$ and some set $D$ such that
$\Event'= \Event'\uplus D$, ${\le'} \supseteq{\le}$,
$\labeling'(\aEv) = \labeling(\aEv)$, and for every $\bEv\in D$ there are
$\aLoc$ and $\aVal$ such that
$\labelingAct'(\bEv)=(\DR[\mRLX]{\aLoc}{\aVal})$.

\begin{theorem}
  \label{thm:hoare}
  Let $\aCmd$ be synchronization-free and sequential.  Then
  $\hoare{\aForm}{\aCmd}{\bForm}$ if and only if
  $\notdisjoint{\semRW{\aForm}{\bForm}}{\readsem{\aCmd}}$.
\begin{proof}
  The proof proceeds by induction on the number of steps of derivation of the
  proof of the Hoare triple.

  We first consider the structural rules.  Precondition strengthening follows
  from augmentation closure.  The proof that the structural rule of
  disjunction:
  \begin{displaymath}
    \frac{\hoare{\aForm_1}{\aCmd}{\bForm_1},  \hoare{\aForm_2}{\aCmd}{\bForm_2}}{ \hoare{\aForm_1 \lor \aForm_2}{\aCmd}{\bForm_1\lor \bForm_2}}
  \end{displaymath}
  holds  follows from closure of the semantics under disjuncts. The proof for the structural rule of conjunction:
  \begin{displaymath}
    \frac{\hoare{\aForm_1}{\aCmd}{\bForm_1},  \hoare{\aForm_2}{\aCmd}{\bForm_2}}{ \hoare{\aForm_1 \land \aForm_2}{\aCmd}{\bForm_1\land \bForm_2}}
  \end{displaymath}
  follows from the fact that pomsets have only concurrency and no conflict.

  The remaining cases that use the rules for deducing Hoare triples by
  structural induction on the command follow directly from the semantics.
  The only subtleties are in the write rule, which uses $\parallel$ to ensure
  disjunction closure.
\end{proof}
\end{theorem}
% To illustrate multiple writes consider:
% \begin{gather*}
%   \hoare{\TRUE}{x\GETS 1 \SEMI x \GETS 2}{x=2}
%   \\
%   \hbox{\begin{tikzinline}[node distance=1em]
%       \event{w1}{\DW{x}{1}}{}
%       \event{w2}{\DW{x}{2}}{right=of w1}
%       \wk{w1}{w2}
%     \end{tikzinline}}
% \end{gather*}

Preconditions can be placed in $\aForm$ or $\cForm$ in
Definition~\ref{def:prepost}, resulting in different pomsets:
\begin{gather*}
  \hoare{x=1}{y \GETS x}{y=1}
  \\
    \hbox{\begin{tikzinline}[node distance=1em]
        \event{r}{\DR{x}{1}}{}
        \event{w}{\DW{y}{1}}{right=of r}
        \po{r}{w}
      \end{tikzinline}}
    \qquad\qquad
    \hbox{\begin{tikzinline}[node distance=1em]
        \event{r}{\DR{x}{1}}{}
        \event{w}{x=1 \mid \DW{y}{1}}{right=1ex of r}
      \end{tikzinline}}
\end{gather*}
Control dependencies are calculated correctly:
\begin{gather*}
  \hoare{\TRUE}{\IF{x} \THEN y \GETS 1 \ELSE y \GETS 1 \FI}{y=1}
  \\
    \hbox{\begin{tikzinline}[node distance=1em]
        \event{r}{\DR{x}{1}}{}
        \event{w}{\DW{y}{1}}{right=1ex of r}
      \end{tikzinline}}
\end{gather*}
% In contrast, in a semantics that forbids load buffering, where the best that one can prove is
% $\hoare{x=v} {r \GETS x \SEMI \IF{r=1} \THEN y \GETS 1 \ELSE y \GETS 1 \FI}{y= 1}
% $.

For any consistent set of preconditions, we can always find a single pomset
that includes all of the required writes.
\begin{gather*}
  \hoare{x_1=1}{y_1 \GETS x_1}{y_1=1}
  \qquad
  \hoare{x_2=1}{y_2 \GETS x_2}{y_2=1}
  \\
    \hbox{\begin{tikzinline}[node distance=1em]
        \event{rx}{\DR{x_1}{1}}{}
        \event{wy}{\DW{y_1}{1}}{right=of rx}
        \event{ru}{\DR{x_2}{1}}{right=1ex of wy}
        \event{wv}{\DW{y_2}{1}}{right=of ru}
        \rf{rx}{wy}
        \rf{ru}{wv}
      \end{tikzinline}}
\end{gather*}
\begin{corollary}
  If $\bigwedge_{i\in I}\aForm_i$ is satisfiable:
  \begin{displaymath}
    \textstyle\bigwedge_{i\in I}\hoare{\aForm_i}{\aCmd}{\bForm_i} \Longleftrightarrow
    \notdisjoint{\textstyle\bigcap_{i\in I}\semRW{\aForm_i}{\bForm_i}}{\readsem{\aCmd}}.
  \end{displaymath}
\end{corollary}

\paragraph{Linearity.}
A command $\aCmd$ is \emph{linear} if for every $\aPS\in\sem{\aCmd}$, there is
at most one read and at most one write on any location.  Intuitively, this
means that the context around $\aCmd$ is unable to interfere with the atomic
execution of $\aCmd$; dually, neither can the atomic execution of $\aCmd$
interfere with the context.  From an arbitrary command, it is a
straightforward exercise to construct a linear command that is sequentially
equivalent.

We say that $\aCmd$ and $\aCmd'$ \emph{satisfy the same Hoare triples} when
$\hoare{\aForm}{\aCmd}{\bForm}$ if and only if
$\hoare{\aForm}{\aCmd'}{\bForm}$, for every $\aForm$ and $\bForm$.

\begin{corollary}\label{seqcompleteness}
  Let $\aCmd$ and $\aCmd'$ be synchronization-free and sequential.  Further,
  let $\aCmd'$ be linear.
  Then $\aCmd$ and $\aCmd'$ satisfy the same Hoare
  triples if and only if $\readsem{\aCmd} \supseteq \readsem{\aCmd'}$.
  % If $\aCmd$ and $\aCmd'$ satisfy the same Hoare
  % triples then $\readsem{\aCmd} \supseteq \readsem{\aCmd'}$.
%   \begin{proof}
%     The pomsets in the semantics of a linear sequential program fragment,
%     such as $\sem{\bCmd}$, are generated by the augmentation closure of
%     pomsets that have a special format that only include edges of the
%     form: \begin{tikzdisplay}[node distance=1em]
%       \event{r}{\smash{\vec{\bForm}}\mid\DR{\vec{\bLoc}}{\vec{\aVal}}}{}
%       \eventl{\aEv}{w}{\aForm\mid\DW{\aLoc}{\bVal}}{below right=of r}
%       \po{r}{w}
%     \end{tikzdisplay}
%     where $\vec{\bLoc}\GETS \vec{\aLoc}$ has no conflicting assignments to the same variable, and where each $\aLoc$ appears in at most one write event. Thus, using  theorem~\ref{hoareGen}, we deduce that $\sem{\bCmd}$ is completely determined by the Hoare triples satisfied by $\bCmd$.
%
%     By the hypothesis of this theorem, $\aCmd$ satisfies the same Hoare triples as $\bCmd$.  Using  theorem~\ref{hoareGen}, we deduce that $\sem{\bCmd} \subseteq \fsat(\sem{\aCmd})$.
% \end{proof}
\end{corollary}

\paragraph{Valid Rewrites.}
\ When $\readc\sem{\aCmd} \supseteq \readc\sem{\aCmd'}$, we say that $\aCmd'$ is
a \emph{valid transformation} of $\aCmd$.

To enable reasoning about program fragments, transformation validity must be
preserved by \emph{contexts}.  In \textsection\ref{sec:model}, we defined the
semantics by prefixing one action at a time.  This helps to make the
semantics understandable, but it also creates impoverished contexts.

To allow for richer contexts, we appeal to the alternate presentation of the
language given in \textsection\ref{sec:semicolon}.  We refactor the syntax
of commands and define contexts:
\begin{align*}
  \aCmd,\,\bCmd
  \BNFDEF& \SKIP
  \mkern-2mu\BNFSEP\mkern-2mu \FENCE^{\fmode}
  \mkern-2mu\BNFSEP\mkern-2mu \aReg\GETS\aExp
  % \mkern-2mu\BNFSEP\mkern-2mu \aReg\GETS \aLoc^{\amode}
  % \mkern-2mu\BNFSEP\mkern-2mu \aLoc^{\amode}\GETS\aExp
  \mkern-2mu\BNFSEP\mkern-2mu \aReg\GETS \REF{\cExp}^{\amode}
  \mkern-2mu\BNFSEP\mkern-2mu \REF{\cExp}^{\amode}\GETS\aExp
  \\[-.5ex]
  \BNFSEP&\aCmd \PAR \bCmd
  \mkern-2mu\BNFSEP\mkern-2mu\aCmd \SEMI \bCmd
  \mkern-2mu\BNFSEP\mkern-2mu \VAR\aLoc\SEMI \aCmd
  \mkern-2mu\BNFSEP\mkern-2mu \IF{\aExp} \THEN \aCmd \ELSE \bCmd \FI
  \\
  \aCtxt,\,\bCtxt
  \BNFDEF& \hole{}
  \mkern-2mu\BNFSEP\mkern-2mu \aCtxt \PAR \bCmd
  \mkern-2mu\BNFSEP\mkern-2mu \aCmd \PAR \bCtxt
  \mkern-2mu\BNFSEP\mkern-2mu \aCtxt \SEMI \bCmd
  \mkern-2mu\BNFSEP\mkern-2mu \aCmd \SEMI \bCtxt
  \mkern-2mu\BNFSEP\mkern-2mu \VAR\aLoc\SEMI \aCtxt
  \\[-.5ex]
  \BNFSEP& \IF{\aExp} \THEN \aCtxt \ELSE \bCmd \FI
  \mkern-2mu\BNFSEP\mkern-2mu \IF{\aExp} \THEN \aCmd \ELSE \bCtxt \FI
\end{align*}

\begin{lemma}%\label{freadssatcomp}[Compositionality of $\freadsat$]
  Let $\bCtxt$ be a context
  % \footnote{%
  %   The results of this section hold for contexts of the example language
  %   given in \textsection\ref{sec:model} and extended in \textsection\ref{sec:variants}.
  %   % \begin{math}
  %   %   \begin{array}[t]{rcl}
  %   %     \aCtxt,\,\bCtxt
  %   %     &\BNFDEF& \hole{}
  %   %     \BNFSEP \aReg\GETS\aExp\SEMI \aCtxt
  %   %     \BNFSEP \aReg\GETS\aLoc^{\amode}\SEMI \aCtxt
  %   %     \BNFSEP \aLoc^{\amode}\GETS\aExp\SEMI \aCtxt
  %   %     \\[-.5ex]
  %   %     &\BNFSEP&\aCtxt \PAR \bCmd
  %   %     \BNFSEP \aCmd \PAR \bCtxt
  %   %     \BNFSEP \VAR\aLoc\SEMI \aCtxt
  %   %     \\[-.5ex]
  %   %     &\BNFSEP& \IF{\aExp} \THEN \aCtxt \ELSE \bCmd \FI
  %   %     \BNFSEP \IF{\aExp} \THEN \aCmd \ELSE \bCtxt \FI
  %   %   \end{array}
  %   % \end{math}
  %   The results of this section hold for contexts of the example language
  %   given in \textsection\ref{sec:model} and extended in \textsection\ref{sec:variants}.
  %   The results also hold for the more general contexts of
  %   \textsection\ref{sec:semicolon}, which includes full sequential composition:
  %   \begin{displaymath}
  %     \begin{array}[t]{rcl}
  %       \aCtxt,\,\bCtxt
  %       &\BNFDEF& \hole{}
  %       \BNFSEP \aCtxt \SEMI \bCmd
  %       \BNFSEP \aCmd \SEMI \bCtxt
  %       \BNFSEP \aCtxt \PAR \bCmd
  %       \BNFSEP \aCmd \PAR \bCtxt
  %       \BNFSEP
  %       \\[-.5ex]
  %       &\BNFSEP& \VAR\aLoc\SEMI \aCtxt
  %       \BNFSEP \IF{\aExp} \THEN \aCtxt \ELSE \bCmd \FI
  %       \BNFSEP \IF{\aExp} \THEN \aCmd \ELSE \bCtxt \FI
  %     \end{array}
  %   \end{displaymath}}
and $\readc\sem{\aCmd} \supseteq \readc\sem{\aCmd'}$:
\begin{displaymath}
  \readc\sem{\bCtxt\hole{\aCmd}} \supseteq \readc\sem{\bCtxt\hole{\aCmd'}}
\end{displaymath}
\end{lemma}

To discuss valid transformations without getting lost in notation, we present
them using simple locations, rather than calculated addresses.  The extension
is simple: For address expressions $\REF{\aExp}$ and $\REF{\bExp}$, replace
$\aLoc=\bLoc$ by provable equality of $\aExp$ and $\bExp$, and
$\aLoc\neq\bLoc$ by provable inequality.  Operations on
sets can be defined similarly.
%
Let $\free(\aCmd)$ be the set of locations and registers that occur in $\aCmd$.

Theorem \ref{thm:hoare} immediately validates peephole optimizations, such as
redundant load \eqref{RL}, store forwarding \eqref{SF}, dead store \eqref{DS},
and independent reorderings.  Using the semantics directly, we can prove
some properties without using $\readc$.
Note that if $\aPSS'\supseteq\aPSS$, then $\readc(\aPSS')\supseteq \readc(\aPSS)$.
\begin{align*}
  \taglabel{RL}
  \readsem{\aReg \GETS \aLoc \SEMI \bReg  \GETS \aLoc} &\supseteq
  \readsem{\aReg \GETS \aLoc \SEMI \bReg  \GETS \aReg}
  \\
  \taglabel{SF}
  \readsem{\aLoc \GETS \aExp \SEMI \bReg  \GETS \aLoc} &\supseteq
  \readsem{\aLoc \GETS \aExp \SEMI \bReg  \GETS \aExp}
  \\
  \taglabel{DS}
  \sem{\aLoc \GETS \aExp \SEMI \aLoc  \GETS \bExp} &\supseteq
  \sem{\aLoc \GETS \bExp}
  \\
  \taglabel{WW}
  \sem{\aLoc \GETS \aExp \SEMI \bLoc  \GETS \bExp} &=
  \sem{\bLoc  \GETS \bExp\SEMI \aLoc \GETS \aExp} &%\text{if } \aLoc{\neq}\bLoc
  \\
  \taglabel{RW}
  \sem{\aReg \GETS \aLoc \SEMI \bLoc  \GETS \bExp} &=
  \sem{\bLoc  \GETS \bExp\SEMI \aReg \GETS \aLoc} &%\text{if } \aLoc{\neq}\bLoc
  \\
  \taglabel{RR}
  \sem{\aReg \GETS \aLoc \SEMI \bReg  \GETS \bLoc} &=
  \sem{\bReg  \GETS \bLoc\SEMI \aReg \GETS \aLoc} &%\text{if } \aLoc{\neq}\bLoc
\end{align*}
% \eqref{WW}, \eqref{RW} and \eqref{RR} require that two sides of the semicolon
% have disjoint ids; for example, \eqref{RW} requires $\disjoint{{\free(\aReg
%     \GETS \aLoc)}}{{\free(\bLoc \GETS \bExp)}}$.
\textcoor{red}{\eqref{RR} requires either $\aReg\neq\bReg$ or
  $\aLoc=\bLoc$.}  \eqref{WW} and \eqref{RW} require that two sides of the
semicolon have disjoint ids; for example, \eqref{RW} requires
$\disjoint{{\free(\aReg \GETS \aLoc)}}{{\free(\bLoc \GETS \bExp)}}$.
\eqref{RL} and \eqref{SF} follow from read closure.  \eqref{DS} follows from
the write elimination allowed in Definition \ref{def:cover}.

% Reads on the same location are ordered in our model; thus, read optimizations
% are limited by the power of aliasing analysis
% \cite[\textsection2.3]{DBLP:conf/java/Pugh99}.  If $\aLoc\neq\bLoc$, then:
\textcoor{red}{Since reads are unordered in our model, read optimizations are not limited by
the power of aliasing analysis, as they are with stronger models of coherence
\cite[\textsection2.3]{DBLP:conf/java/Pugh99}.  Composing \eqref{RR} and
\eqref{RL}, for $\aReg_2\neq\bReg$ we have:}
\begin{displaymath}
  \readsem{r_1\GETS \aLoc \SEMI
  s\GETS \bLoc \SEMI
  r_2\GETS \aLoc}
  \supseteq
  \readsem{r_1\GETS \aLoc \SEMI
  s\GETS \bLoc \SEMI
  r_2\GETS r_1}
\end{displaymath}
%However, this fails if $\aLoc=\bLoc$.
This holds regardless of whether $\aLoc=\bLoc$.
% \begin{displaymathsmall}
%   \sem{r_1\GETS \REF{\aExp} \SEMI
%   s\GETS \REF{\bExp} \SEMI
%   r_2\GETS \REF{\aExp}}
%   \supseteq
%   \sem{r_1\GETS \REF{\aExp} \SEMI
%   s\GETS \REF{\bExp} \SEMI
%   r_2\GETS r_1}
% \end{displaymathsmall}
% This holds regardless of whether $\aExp=\bExp$.

By induction on the length of the pomsets in $\aCmd$, we can use the
reorderings to establish, more generally, that when $\aCmd$ and $\bCmd$ are
assignment sequences and $\disjoint{\free(\aCmd)}{\free(\bCmd)}$:
\begin{gather*}
  \sem{\aCmd \SEMI \bCmd} = \sem{\bCmd \SEMI \aCmd}
\end{gather*}
% Appealing directly to the semantics, we can establish general properties for
% redundant load \eqref{RLp}, store forwarding \eqref{SFp}, and roach-motel
% \eqref{A}, \eqref{R}:
The semantics also validates roach-motel reorderings.  Let $\aCmd$ be
synchronization-free, with disjoint ids as before:
\begin{align*}
  % \taglabelp{RL}
  % \sem{\aReg \GETS \aLoc  \SEMI \bReg \GETS \aLoc  \SEMI \aCmd} &\supseteq
  % \sem{\aReg \GETS \aLoc \SEMI \aCmd[\aReg/\bReg]}
  % \\
  % \taglabelp{SF}
  % \sem{\aLoc \GETS \aExp \SEMI \bReg \GETS \aLoc \SEMI \aCmd} &\supseteq
  % \sem{\aLoc \GETS \aExp \SEMI \aCmd[\aExp/\bReg]}
  % \\
  \taglabel{A}
  \sem{\aCmd \SEMI \bReg \GETS \aLoc^\mRA} &\supseteq
  \sem{\bReg \GETS \aLoc^\mRA\SEMI  \aCmd}
  \\
  \taglabel{R}
  \sem{\aLoc^\mRA \GETS \aExp \SEMI \aCmd } &\supseteq
  \sem{\aCmd \SEMI \aLoc^\mRA \GETS \aExp }
\end{align*}
% Again, we suppose that $\aCmd$ is an assignment sequence and disjoint
% identifiers.
% \eqref{A} and \eqref{R} require
% disjoint names, as in \eqref{WW} and
% \eqref{RW}. In addition, \eqref{A} and \eqref{R} require that $\aCmd$ is
% synchronization-free.

As expected, sequential and parallel composition commute with conditionals
and location binding, and conditionals and location binding commute with each
other.  We show sequential scope extrusion \eqref{SSE}, which concerns
sequential composition and location binding:
\begin{align*}
  % \taglabel{PSE}
  % \sem{\aCmd\PAR \VAR\aLoc\SEMI\bCmd}\allowbreak &=
  % \sem{\VAR\aLoc\SEMI(\aCmd\PAR\bCmd)}
  % \\
  \taglabel{SSE}
  \sem{\aCmd\SEMI \VAR\aLoc\SEMI\bCmd}\allowbreak &=
  \sem{\VAR\aLoc\SEMI(\aCmd\SEMI\bCmd)}
  % \\
  % \taglabel{CSE}
  % \sem{\IF{\aExp}\THEN\aCmd\ELSE \VAR\aLoc\SEMI\bCmd\FI}\allowbreak &=
  % \sem{\VAR\aLoc\SEMI \IF{\aExp}\THEN\aCmd\ELSE\bCmd\FI}
\end{align*}
\eqref{SSE} requires that $\aLoc$ does not appear in $\aCmd$.

Many laws hold for the conditional.  We show case analysis \eqref{CA} and
dead code elimination \eqref{DC}.
\begin{align*}
  \taglabel{CA}
  \sem{\IF{\aExp}\THEN\aCmd\ELSE\aCmd\FI} &=
  \sem{\aCmd}
  \\
  \taglabel{DC}
  \sem{\IF{\aExp}\THEN\aCmd\ELSE\bCmd\FI} &=
  \sem{\aCmd}
\end{align*}
\eqref{DC} requires that $\aExp$ be a tautology.  The correctness of
\eqref{CA} follows from disjunction closure (Definition
\ref{def:dis}).

% Suppose $\cExp\neq\dExp$ is a tautology.  Then the following
%reorderings hold.
%  \begin{align*}
% \begin{align*}
%    \tag{R-R}
%    \sem{\aReg \GETS \REF{\cExp} \SEMI \bReg \GETS \REF{\dExp}
%\SEMI \aCmd} &=
%    \sem{\bReg \GETS \REF{\dExp} \SEMI \aReg \GETS \REF{\cExp}
%\SEMI \aCmd}
%    &&\textif \aReg\notin\free(\dExp) \textand \bReg\notin\free(\cExp)
 %   \\
 %   \tag{R-W}
 %   \sem{\aReg \GETS \REF{\cExp} \SEMI \REF{\dExp} \GETS \bExp
%\SEMI \aCmd} &=
%    \sem{\REF{\dExp} \GETS \bExp \SEMI \aReg \GETS \REF{\cExp}
%\SEMI \aCmd}
%    &&\textif \aReg\notin\free(\dExp) \cup\free(\bExp)
%    \\
 %   \tag{W-W}
 %   \sem{\REF{\cExp} \GETS \aExp \SEMI \REF{\dExp} \GETS \bExp \SEMI
%\aCmd} &=
 %   \sem{\REF{\dExp} \GETS \bExp \SEMI \REF{\cExp} \GETS \aExp \SEMI
%\aCmd}
%  \end{align*}
% \begin{proof}
% The semantics of sequential composition $\aCmd \SEMI \bCmd$, where
% the only enforced $\lt$ relationships come from conflict on locations or
%release or acquire actions.    The roach-motel reorderings that increase
%the scope of synchronization are valid because the pomsets in the
%semantics of the right hand sides are augmentations of a pomset on the
%left hand side.
%\end{proof}
%\end{lemma}

% \begin{lemma}%[Reorderings]
% Suppose $\cExp\neq\dExp$ is a tautology.  Then the following
%reorderings hold.
 % \begin{align*}
%    \tag{R-Acq}
 %   \sem{\aReg \GETS \REF{\cExp} \SEMI \bReg \GETS \REF{\dExp}^\mRA
%\SEMI \aCmd} &\supseteq
 %   \sem{\bReg \GETS \REF{\dExp}^\mRA\SEMI \aReg \GETS \REF{\cExp}
%\SEMI \aCmd}
% &&\textif \aReg\notin\free(\dExp) \textand \bReg\notin\free(\cExp)
 %   \\
 %   \tag{W-Acq}
 %   \sem{\REF{\dExp} \GETS \bExp \SEMI\aReg \GETS \REF{\cExp}^\mRA
%\SEMI\aCmd} &\supseteq
%    \sem{\aReg \GETS \REF{\cExp}^\mRA  \SEMI \REF{\dExp}\GETS \bExp
%\SEMI \aCmd}
%    &&\textif \aReg\notin\free(\dExp) \cup\free(\bExp)
 %   \\
% \tag{Rel-R}
%\sem{\REF{\dExp}^\mRA \GETS \bExp \SEMI\aReg \GETS \REF{\cExp}
%\SEMI \aCmd} &\supseteq
 %   \sem{ \aReg \GETS \REF{\cExp} \SEMI \REF{\dExp}^\mRA \GETS \bExp
%\SEMI \aCmd}
%   &&\textif \aReg\notin\free(\dExp) \cup\free(\bExp)
 %   \\
 %   \tag{Rel-W}
 %   \sem{\REF{\cExp}^\mRA \GETS \aExp \SEMI \REF{\dExp} \GETS \bExp %\SEMI \aCmd} &\supseteq
 %   \sem{\REF{\dExp} \GETS \bExp \SEMI \REF{\cExp}^\mRA \GETS \aExp
%\SEMI \aCmd}
%  \end{align*}
%\begin{proof}
%The proof follows from noticing that the pomsets in the semantics of the
%right hand sides are augmentations of a pomset on the left hand side.
%\end{proof}
%\end{lemma}

% \paragraph*{Compiler optimizations.} Reordering and peephole optimizations
% can be combined to describe common compiler optimizations.  We illustrate
% using common subexpression elimination,
% following~\citet{Dolan:2018:BDR:3192366.3192421}:
% Consider the command
% \begin{math}
%   (\aReg \GETS \aLoc *2  \SEMI \aCmd \SEMI \bReg \GETS \aLoc * 2)
% \end{math}
% where $\aCmd$ is independent of $\aReg$.  Reordering yields
% \begin{math}
%   (\aCmd \SEMI \aReg \GETS \aLoc *2  \SEMI  \bReg \GETS \aLoc * 2),
% \end{math}
% followed by redundant load to yield
% \begin{math}
%   (\aCmd \SEMI \aReg \GETS \aLoc * 2 \SEMI  \bReg \GETS \aReg).
% \end{math}

% Similarly, the treatment of loop-invariant code motion, dead-store
% elimination and constant propagation
% from~\citet{Dolan:2018:BDR:3192366.3192421} follow.

% Since our model is more generous about permitted reorderings, we
% permit optimizations that they forbid.  Consider:
%\begin{math}
 % (\aReg \GETS \aLoc \SEMI \bLoc \GETS \cLoc  \SEMI \aLoc \GETS
%\aReg).
%\end{math}
%Reordering, permitted by us, but forbidden by them, yields
%\begin{math}
%  (\aReg \GETS \aLoc \SEMI \aLoc \GETS \aReg \SEMI \bLoc \GETS
%\cLoc),
%\end{math}
%followed by the valid elimination of redundant load
%\begin{math}
%  (\aReg \GETS \aLoc \SEMI \aLoc \GETS \aReg \SEMI \bLoc \GETS %
%\cLoc).
%\end{math}

\paragraph{Invalid Rewrites.}
Relevant read introduction is invalid:
\begin{align*}
  %\tag{Read-Intro-Invalid}
  \sem{\aReg \GETS \aLoc \SEMI \IF{\aReg {\neq} \aReg} \THEN \cLoc \GETS 1 \FI}
  &\not\supseteq
  \sem{\aReg \GETS \aLoc \SEMI \bReg \GETS \aLoc  \SEMI \IF{\aReg {\neq}\bReg} \THEN \cLoc \GETS 1 \FI}
\end{align*}
These are distinguished by the context
\begin{math}
  \hole{} \PAR x\GETS1\PAR x\GETS2.
\end{math}

Write introduction is invalid, even for equal values:
\begin{align*}
  \sem{\aLoc \GETS 1 \SEMI \aCmd}
  &\not\supseteq
  \sem{\aLoc \GETS 1 \SEMI \aLoc \GETS 1 \SEMI \aCmd}
\end{align*}
These are distinguished by the context:
\begin{displaymath}
  \hole{} \PAR
  r\GETS x \SEMI
  x\GETS2 \SEMI
  s\GETS x\SEMI
  \IF{\aReg {=} \aReg} \THEN \cLoc \GETS 1 \FI
\end{displaymath}
With weaker notions of coherence
\cite{Manson:2005:JMM:1047659.1040336}, these
commands are indistinguishable.

Thread inlining is invalid (see \textsection\ref{sec:model}):
\begin{math}
  \sem{\aCmd \PAR \bCmd}
  \not\supseteq
  \sem{\aCmd \SEMI \bCmd}.
\end{math}

% // p and q might be aliased
% int i = p
% // concurrent write to p.x by another thread
% int j = q
% int k = p

% Since p and q only might be aliased, but are not definitely aliased, then the
% use of q cannot be optimized away (if it were known that p and q pointed to
% the same object, then it would be legal to replace the assignments to j and k
% with assignments of the value of i). Consider the case where p and q are in
% fact aliased, and another thread writes to the memory location for p/q
% between the first use of p and the use of q; the use of q will see the
% new value. It will be illegal for the second use of p (stored into k) to
% get the same value as was stored into i. However, a fairly standard compiler
% optimization would involve eliminating the getfield for k and replacing it
% with a reuse of the value stored into i. Un- fortunately, that optimization
% is illegal in any language that requires Coherence.

% One way to think of it is that since a read of a memory location may cause
% the thread to become aware of a write by another thread, it must be treated
% in the compiler as a possible write.

\citet{BoehmOOTA} considers the following programs:
\begin{gather*}
  \sem{r\GETS y\SEMI x\GETS r}
  \not\supseteq
  \sem{r\GETS y\SEMI \IF{r \NOTEQ 1} \THEN z\GETS 1\SEMI r\GETS 1\FI \SEMI x\GETS r}
\end{gather*}
The left command is half of the \oota{} example from
\textsection\ref{sec:logic} \eqref{oota1}.  The right command is dubbed \rfub{}, for
\emph{Register assignment From an Unexecuted Branch}.
\citeauthor{BoehmOOTA} observes that in the context $x\GETS y \PAR \hole{}$,
these programs have different behaviors.  Yet the \oota{} example on the left
never writes $1$.  Why should the unexecuted branch change that?  As it turns
out, both branches of the conditional in \rfub{} can execute, since the write
to $x$ is independent of the read from $y$.  Considering just the two threads
above, we have $\hoare{\TRUE}{\text{\rfub}}{x=1}$, but not
$\hoare{\TRUE}{\text{\oota}}{x=1}$.  As a result, it is expected that \rfub{}
may have additional behaviors.  The change in the thread from \oota{} to
\rfub{} is not a valid refinement under Hoare logic and thus it is not valid
in our semantics.
% Let $\aCmd$ be the right
% thread in \eqref{rfub}.
% \begin{align*}
%   \aCmd = r\GETS y\SEMI \IF{r \NOTEQ 1} \THEN z\GETS 1\SEMI r\GETS 1\FI  \SEMI x\GETS r
% \end{align*}
% Then, $\hoare{\TRUE}{\aCmd}{x=1} $ and $\hoare{y \neq 1}{\bCmd}{z=1}$.  Thus, the traditional sequential semantics {\em does not} attribute any cause for the write of $1$ to $x$, as seen by the execution:
% \begin{tikzdisplay}[node distance=1em]
%  \event{ry}{\DR{y}{1}}{}
%  \event{wa}{\DW{z}{1}}{right=of ry}
%  \event{wx}{\DW{x}{1}}{right=of wa}
%  \rf{ry}{wa}
% \end{tikzdisplay}
% % Consider a fragment from example~\eqref{rfub}.
% % \begin{align*}
% % \bCmd:  r \GETS y \SEMI \IF{r \NOTEQ 42} \THEN a \GETS 1 \SEMI s \GETS 42 \FI \SEMI x \GETS 42
% % \end{align*}
% % Then, $\hoare{\TRUE}{\bCmd}{x=42} $ and $\hoare{y \neq 42}{\bCmd}{a= 1} $.  Thus, the traditional sequential semantics {\em does not} attribute any cause for the write of $42$ to $x$, as seen by the execution:
% % \begin{tikzdisplay}[node distance=1em]
% %  \event{ry}{\DR{y}{41}}{}
% %  \event{wx}{\DW{x}{42}}{right=of ry}
% %  \event{wa}{\DW{a}{1}}{below=of rx}
% %  \rf{ry}{wa}
% % \end{tikzdisplay}
% Consider the
% following, where all locations are initialized to $0$.  In \textsection\ref{sec:logic} we provide machinery to prove that \oota{} is
% incapable of writing $1$.  The question is whether this should be possible
% for \rfub, which changes \oota{} only to include a \emph{Register assignment
%   From an Unexecuted Branch} \cite{BoehmOOTA}:?
% \begin{align*}
%   \label{oota}  \tag{\textsc{oota}}
%   y\GETS x
%   \PAR&
%   r\GETS y\SEMI
%   x\GETS r
%   \\
%   \tag{\rfub1}
%   \label{rfub}
%   y\GETS x
%   \PAR&
%   r\GETS y\SEMI
%   \IF{r \NOTEQ 1} \THEN z\GETS 1\SEMI r\GETS 1\FI  \SEMI x\GETS r
% \end{align*}
% %and the following \emph{Out Of Thin Air} litmus test:

% {\bf MOVE TO APPENDIX??.

% Given $\aCmd$, define
% $\linV{\aCmd}$ as follows.
% \begin{definition}
% With each shared variable $\aLoc$, we associate a thread local variable $\aLocLoc$ and two boolean variables $\aRead,\aChanged$ that will be local to the program fragment.

% \begin{align*}
% \linV{\aCmd}= & \VAR\vec{\aLocLoc} \SEMI \VAR \vec{\aRead} \SEMI \VAR \vec{\aChanged} \SEMI  \\
% & \vec{\aRead} =\vec{0} \SEMI \vec{\aChanged} = \vec{0} \SEMI \\
% & \aCmd' \SEMI   \\
% & \overline{\IF \aChanged\  \aLoc= \aLocLoc}
% \end{align*}
% where:
% $\aCmd'$ is derived from $\aCmd$ by replacing:
% \begin{itemize}
% \item  each read $\aReg = \aLoc$ by $\aRead = 1 \SEMI \IF {(\aChanged \lor\ \aRead)} \THEN\  \aReg= \aLocLoc \ELSE\  \aReg= \aLoc \SEMI \FI $,
% \item each write $\aLoc = \aExp$ by $\aChanged =1 \SEMI \aLocLoc = \aExp$
% \end{itemize}
% \end{definition}
% From the soundness and completeness of Hoare logic for sequential operational semantics (eg. see formalization in~\citet{gordonHoare}), we deduce for any $\aForm, \bForm$:
% \[ \hoare{\aForm}{\aCmd}{\bForm}  \Longleftrightarrow\  \hoare{\aForm}{\linV{\aCmd}}{\bForm} \]
% }

\endinput

\subsection{Full abstraction for synchronization free threads}
Our semantics is complete for reasoning about full-thread optimizations of synchronization free programs.

In the rest of this section, we only consider commands $\aCmd,\bCmd$ that are
restriction-free, composition-free (ie. single-threaded), and
synchronization-free (ie. no acquire, release, fence).

In order to develop the proof,

This closure permits us to  describe a normal form for the top-level pomsets that arise in single-threaded and synchronization free code.
\begin{definition}
$\aPS$ is in normal form if:
\begin{itemize}
% \item All preconditions on events are tautologies.
\item If $\bEv \lt \aEv$ and  $\bEv$ is a write, then $\aEv$ is a write or read on the same variable.
\item If $\bEv \lt \aEv$ and  $\aEv$ is a read, then $\bEv$ is a write on the same variable.

% \item $\aEv \gtN \bEv$ only if $ \aEv\ (\lt \cup \reco)^{\star} \  \bEv$.
\item If $\aEv, \aEv'$ have the same read action label, then there exists a write $\bEv$ on the same location such that $\aEv \gtN \bEv \gtN \aEv'$.
%\item  If $\aEv, \aEv'$ have the same write action label, then
%there exists a event $\bEv$ on the same location as $\aEv$ such
%that  $\bEv$ has a different action label and $\aEv \gtN \bEv \gtN
%\aEv'$.
\end{itemize}
\end{definition}
In a normal form pomset, the successors of a write event (resp. the predecessors of a read) are related in the coherence order to the event.  Any two events with the same read label are separated by a write in the $\reco$ order.

It suffices to consider normal forms when distinguishing single-threaded, synchronization free code at the top level.  The normal forms determine the full semantics by the closure properties of the semantics.

\begin{lemma}\label{unrhd}
Every top-level pomset of $\freadsat\sem{\aCmd}$ is a top-level pomset of $\freadsat\sem{\bCmd}$ if and only if
every top-level normal form pomset of $\freadsat\sem{\aCmd}$ is a top-level normal form pomset of $\freadsat\sem{\bCmd}$.
\begin{proof}
The proof proceeds by induction on structure.  The key case is prefixing.  The only edges $\lt$-edges out of writes  and into read actions enforced by prefixing are $\reco$ edges.  Read prefixing permits the reuse of events to ensure that distinct read events not separated by $\reco$ have distinct read labels.
\end{proof}
\end{lemma}

We develop testers for top-level pomsets in normal form.  We  follow~\citet{Plotkin:1997:TSP:266557.266600}, albeit in a concrete form appropriate to our setting.

Let $\aPS$ be a top-level pomset in normal form with events $\aEv_1, \ldots,
\aEv_n$.  For all $i$, we assume a new location $b_i$.    Let $\freshaval$ be a fresh value that does not occur in $\aPS$.

Let $\vec{\bEv}$ be all  the predecessors of $\aEv_i$ in $\lt$. Let $\vec{c}$ be the corresponding sub vector of $b_i$'s.
\begin{itemize}
\item
If $\aEv_i$ has label $\DR{\aLoc}{\aVal}$, we define a program $\testP{\aPS}{i}$ as follows:
\[
  \testP{\aPS}{i} = (
  % \vec{\aReg} \GETS \vec{c}  \SEMI
  \IF{\vec{c}=\vec{1}} \THEN x \GETS \aVal \SEMI  \FENCE \SEMI b_i \GETS 1 \FI)
\]
\item
If $\aEv_i$ has label $\DW{\aLoc}{\aVal}$, we define a program $\testP{\aPS}{i}$ as follows:
\[
  \testP{\aPS}{i} = (
  % \vec{\aReg} \GETS \vec{c}  \SEMI
  \IF{\vec{c}=\vec{1}} \THEN %\aReg = \aLoc \SEMI
  \IF{\aLoc = \aVal} \THEN \aLoc = \freshaval \SEMI \FENCE \SEMI b_i \GETS 1  \FI \FI)
\]
\end{itemize}
$\testP{\aPS}{i}$ is as expected, matching the reads (resp. writes) in $\aPS$ by writes (resp. reads).  The fresh value is used to flush out prior writes and reset to see fresh writes.

\begin{definition}[Tester for $\aPS$]\label{testAPS}
The tester context for $\aPS$, $\testP{\aPS}{}\hole{}$ is
\[
b \GETS b_{1} \land  \cdots \land b_{n}
\PAR  \testP{\aPS}{1}
\PAR   \cdots
\PAR  \testP{\aPS}{n}
\PAR \hole{}
\]
\end{definition}
The constraints of the normal form ensure that if the labels of any two events are the same, then one is a predecessor of the other.

\begin{lemma}\label{tester}
$\sem{\testP{\aPS}{}\hole{\aCmd}}$  has a pomset that sets $b$ to $1$ iff $\aPS \in \freadsat\sem{\aCmd}$.
\begin{proof}
It suffices to prove that there is a pomset that sets $b$ to $1$ in
 $\freadsat\sem{b \GETS b_{1} \land  \cdots \land b_{n}
\PAR  \testP{\aPS}{1}
\PAR   \cdots
\PAR  \testP{\aPS}{n}} \parallel \bPS$ iff $\aPS$ is an augmentation of $\bPS$.

We prove by induction on $\lt$ that $\testP{\aPS}{i}\hole{\aCmd}$  sets $b_i$ to $1$ iff the event $\aEv_i$ is enabled. Result follows.
\end{proof}
\end{lemma}

\begin{theorem}
  Let $\aCmd_1$ and $\aCmd_2$ be restriction-free, composition-free and
  synchronization free.  Then all top-level pomsets of
  $\freadsat\sem{\aCmd_1}$ are also pomsets of $\freadsat\sem{\aCmd_2}$ if
  and only if for all parallel contexts $\bCmd$, all top-level pomsets of
  $\freadsat\sem{\aCmd_1 \PAR \bCmd}$ are also pomsets of
  $\freadsat\sem{\aCmd_2 \PAR \bCmd}$
\begin{proof}
  The forward implication follows from the compositionality of the semantics.

  For the converse, pick a top level pomset in normal form in
  $\aPS \in \freadsat\sem{\aCmd_1} \setminus \freadsat\sem{\aCmd_2} $.  The
  required context is given by the tester context $\testP{\aPS}{}\hole{}$.
 \end{proof}
\end{theorem}

The full abstraction theorem applies only to full threads.  The reason for this limited statement is that our impoverished language does not permit  parallel composition to be used freely as the continuation in arbitrary sequential contexts.  A full abstraction theorem that applies also to commands can be achieved with these richer distinguishing contexts.


\subsection*{Abstract}\label{abstract}
\addcontentsline{toc}{subsection}{Abstract}

Conservation auctions are tools for natural resource managers to cost-efficiently protect biodiversity and ecosystem services. Benefits particularly induce uncertainty in the value to be maximised. Therefore learning about benefits is valuable to decide which bids will be successful. Here we use the concept of expected value of sample information to assess how an agency should allocate a limited learning budget among bids to conduct a conservation auction that yields the most cost-efficient return on investment. We propose a simple model where an agent has two or more assets among which they must pick the single most cost-efficient to invest in with an auction. The cost-efficiency of each asset is more or less uncertain and there is some budget allocated to reduce the uncertainty of the assets. The agent must decide how to allocate the learning budget among the assets to maximize the expected benefit of the auction. Using a mix of analytical, heuristic and simulation solutions to the model we glean a number of rules-of-thumb that may be helpful to agencies conducting conservation auctions. When learning budgets are small, then it is best to learn about the most marginal assets. Then, as the budget increases it becomes more optimal to learn about assets which have uncertain cost-efficiency in the more general sense. Finally, as learning budgets become large enough, resources can be allocated evenly across all uncertain assets. Our findings imply that a naive even allocation to learning among assets in a conservation auction may lead to less than cost-efficient outcomes.


\begin{document}

\chapter{Design}

\label{chapter:design}

As with any research project, many different attempts were made to come up with
a solution to the objectives stated in Ch.~\ref{chapter:objectives}. Three
different techniques were developed in sequence and one technique was theorized
but never implemented to try and provide a solution that best matched the
sought behaviour for the planner.  The theorized technique included using a bug
algorithm~\cite{weir} in space-time to find a path through the dynamic
environment.  The first attempt was a simple potential field that would take
into account the predicted trajectories of the obstacles, and leverage this
information to provide safer paths. The second attempt included generating a
probabilistic roadmap in space-time and using stock graph search algorithms
such as Dijkstra's algorithm and Edmonds' algorithm to derive low costs paths
through the environment. The last attempt, and the most successful is a planner
that uses a two dimensional probabilistic roadmap to sample the search space
and then uses a variant of best first search to expand nodes in space-time to
find the low cost paths through the stochastic dynamic environment.  These four
attempts are described individually and in more detail in this section.

\section{Space-time Bug Algorithm}

The initial design for this project was to use a bug algorithm that operates in
space-time. Bug algorithms work by moving the robot towards the goal until it
reaches an obstacle. Once an obstacle has been reached, the bug algorithm will
move the robot along the edge of the obstacle until the obstacle is no longer
between the robot and the goal. The robot will then move to the goal and repeat
this process if necessary. An example of this algorithm in practice is shown in
Fig.~\ref{fig:bug}. This proposed design was going to treat the dynamic
obstacles moving in two dimensions as static obstacles in three dimensions
where time is the third dimension. The robot would use the bug algorithm to
move through the environment in three dimensions. A constraint would have been
added to the movement of the robot which would be that it could not move
backward in the last dimension, time.  The benefit of this design is that
completeness could be proven geometrically, it is a computationally simple
algorithm, and it could be easily implemented for use on a mobile robot. This
design was not implemented because of several fundamental flaws discovered
during the design phase. Firstly, by thinking of dynamic obstacles as static
obstacles in space-time, the robot would have to rely on perfect information
about the movement of the dynamic obstacles, i.e.  there could be very little
uncertainty about the movements or predictions of the movements in the dynamic
obstacles. For the planner to be able to handle uncertainty in the motion of
the obstacles \emph{a priori}, obstacles would need to be increased in their
size (emphasizing the possible positions of the dynamic obstacles) as time
increases. This could lead to possibly unrecoverable configurations because
obstacles in space-time could be seen as overlapping thus not providing a
collision free area for the robot to move through. It was ultimately decided
not to continue with this design but instead to leverage a more stochastic and
probabilistic definition of the dynamic obstacles and to use planning
techniques more suited for stochastic dynamic environments.

\begin{figure}[h!]

    \centering

    \includegraphics[width=0.7\linewidth]{figs/bug}

    \caption{This image shows an example of the bug algorithm determining hit
    points obstacles in order to move around them to reach the goal. This image
is courtesy of Dr.\ Erion Plaku.}

    \label{fig:bug}

\end{figure}

\section{Potential Fields}

\label{sec:costpf}

Using a potential fields planner was an initial attempt to plan through
uncertain dynamic environments since they are frequently used to plan around
dynamic obstacles due to their reactive behaviour~\cite{pf, wallar_taros_2013,
wallar_ssci_2014_boids}.  The difference between the standard potential field
implementations and the one developed for this project was that the repulsive
obstacle field at a position $(x, y)$ was proportional to the cost distribution
at $(x, y)$ for a given time interval.  This is shown more formally in
Eq.~\ref{eq:badpotential}.

\begin{equation}
    U_{\Var{rep}}(p, t_0, t_m, A) = k \cdot P(p_x, p_y, t_0, t_m, A)
    \label{eq:badpotential}
\end{equation}

In Eq.~\ref{eq:badpotential}, the function $P$ is defined in Eq.~\ref{eq:prob},
and $k > 0$ is a constant.  The attractive potential field was kept the same as
the standard potential field implementation for robotic motion planning as
shown in Eq.~\ref{eq:badpotentialattr}

\begin{equation}
    U_{\Var{att}}(p, g) = c \cdot ||p - g||^2
    \label{eq:badpotentialattr}
\end{equation}

In Eq.~\ref{eq:badpotentialattr}, $c$ is a scaling constant such that $c > 0$.
The potential field planner would use the sum of these two fields to measure
the potential through the environment in order to eventually reach the goal by
successively moving to the area within the robot's sensing radius that had the
minimal potential.  Algo.~\ref{algo:pf} describes more formally how the
potential field planner generates a path through the environment.

\begin{algorithm}[ht]

    \caption{$\Function{PF}(q, g, O, A, R)$}
    \algorithmicrequire{
        \\$q$: Configuration of the robot
        \\$g$: Goal configuration
        \\$O$: Set of static obstacles
        \\$A$: Set of dynamic obstacles
        \\$R$: Goal radius
    }
    \\\algorithmicensure{
        \\A temporal path from the initial configuration of the robot
        to the goal configuration using potential fields.
    }

    \label{algo:pf}
    \begin{algorithmic}[1]
        \setcounter{ALC@line}{0}
        \vspace*{1mm}

        \STATE $q_{\Var{min}} \leftarrow q$
        \STATE $p_{\Var{min}} \leftarrow \infty$
        \STATE $\theta \leftarrow 0$
        \WHILE {$\theta \leq 2\pi$}
            \STATE $q' \leftarrow q + \delta t \cdot s \cdot
            \Function{Rot}(\theta)$
            \STATE $p \leftarrow U_{\Var{rep}}(q', O \cup A)
            + U_{\Var{att}}(q', g)$
            \IF {$p < p_{\Var{min}}$}
               \STATE $p_{\Var{min}} \leftarrow p$
                \STATE $q_{\Var{min}} \leftarrow q'$
            \ENDIF
            \STATE $\theta \leftarrow \theta + \delta \theta$
            \FORALL {$a \in A$}
                \STATE $\Function{Step}(a)$
            \ENDFOR
        \ENDWHILE

        \IF {$||q_{\Var{min}} - g|| < R$}
            \RETURN $\{p_{min}\}$
        \ENDIF

        \RETURN $\{q_{\Var{min}}\} \cup \Function{PF}(q_{\Var{min}}, g, O, A, R)$
    \end{algorithmic}
\end{algorithm}

Through some qualitative testing, these types of potential fields were still
leading the robot into unsafe areas and caused the robot to collide with the
dynamic obstacles regardless of velocity of the obstacles and the velocity of
the robot. After some manipulation of the constants used for the repulsive and
attractive potentials, there was only a nominal improvement which lead the
author to move towards sampling based motion planning techniques which are
outlined in Sec.~\ref{sec:stroadmap} and Sec.~\ref{sec:finaldesign}.

\section{Three Dimensional Spatio-temporal Roadmap}

\label{sec:stroadmap}

The second attempt at devising a solution to the primary objective in
Ch.~\ref{chapter:objectives} was to create a three dimensional probabilistic
roadmap that can capture the connectivity of a two dimensional surface in
space-time. A spatio-temporal probabilistic roadmap (PRM) is a directed,
weighted graph, $(V, E)$, that represents the spatio-temporal connectivity of
the search space by randomly sampling points and connecting them such that if
$((i, t), (j, t')) \in E$, then both $i$ and $j$ must not collide with an
obstacle at times $t$ and $t'$ respectively, $||i - j|| \leq d$ where $d$
indicates the maximum distance between connected nodes can be from one another,
there must not be a collision with any obstacle along the edge from $i$ and $j$
in the time interval $[t, t']$, $|t - t'| < \delta t$, and $t < t'$~\cite{prm,
stprm}.  For the attempted space-time PRM, each node would be a vector, $(x, y,
t)$, which represents a two dimensional location, $(x, y)$, at a certain
absolute time $t$, and instead of randomly sampling a point in the environment,
a node in the graph would be randomly selected and propagated forward in time
by some random change in time such that the constraints for the roadmap are
still satisfied.  This algorithm is shown more formally in
Algo.~\ref{algo:diprm}.

\begin{algorithm}[ht]
    \caption{$\Function{TemporalRoadmap}(N, d, \delta t, s, p, O, A)$}
    \algorithmicrequire{
        \\$N$: Maximum number of samples
        \\$d$: Maximum distance between neighbouring nodes
        \\$\delta t$: Maximum time difference between nodes
        \\$s$: Speed of the robot
        \\$p$: Initial configuration of the robot
        \\$A$: Set of dynamic obstacles
        \\$O$: Set of obstacles
    }
    \\\algorithmicensure{
        \\An weighted directed graph of points describing where it is possible
        for the robot to move from its initial configuration.
    }
    \label{algo:diprm}
    \begin{algorithmic}[1]
        \setcounter{ALC@line}{0}
        \vspace*{1mm}

        \STATE $V \leftarrow \{(p, 0)\}$
        \FOR{$i = 1$ \TO $N$}
            \STATE $(n, t) \leftarrow \Function{RandomSelection}(V)$
            \STATE $t' \leftarrow t + \Function{UniformRandom}(\varepsilon, \delta t)$
            \STATE $\theta \leftarrow \Function{UniformRandom}(0, 2\pi)$
            \STATE $q \leftarrow n + s \cdot t' \cdot \Function{Rot}(\theta)$
            \IF{$\bigwedge_{o \in O} \neg \Function{Collision}(o, q)$}
                \FORALL {$(v, \tau) \in V$}
                    \IF {$||v - q|| < d \wedge |\tau - t'| < \delta t$}
                        \IF {$\tau < t'$}
                            \STATE $E \leftarrow E \cup \{((v, t), (v, t'),
                            C(v, q, \tau, t', A))\}$
                        \ELSE
                            \STATE $E \leftarrow E \cup \{((q, t'), (v, t),
                            C(q, v, t', \tau, A))\}$
                        \ENDIF
                    \ENDIF
                \ENDFOR
                \STATE $V \leftarrow V \cup \{(q, t)\}$
            \ENDIF
        \ENDFOR
        \RETURN $(V, E, W)$
    \end{algorithmic}
\end{algorithm}

With the generated roadmap, the first thought was to use a graph search
algorithm such as A*~\cite{astar} or Dijkstra's algorithm~\cite{dijkstra} to
find the path through the environment that had the lowest overall weight.  The
weight for an edge, $(i, j)$, defined as the line integral over the cost
surface for a given set of dynamic obstacles with a time interval of $[i_t,
j_t]$.  The notion of a cost distribution is described in
Ch.~\ref{chapter:methodology} and the formal equation for this line integral is
given in Eq.~\ref{eq:cost}.  This space-time roadmap approach yielded mixed
results.  The robot would sometimes evade the obstacles, but with the same
incidence, the planner would lead the robot directly into a collision with a
dynamic obstacle. After some testing, it was discovered that since graph search
algorithms seek to find the path with minimum combined weight through the
graph, these algorithms are biased to return paths with a smaller number of
vertices.  This is because paths with a larger number of vertices will have a
higher overall weight. Since shortest path algorithms try to minimize this
overall weight, paths which may be safer but may take longer may not be
returned by these algorithms.

To overcome this, instead of searching over the entire graph, the search could
occur over the minimum spanning tree of the graph.  Since the roadmap is a
directed graph, Edmonds' algorithm~\cite{edmonds} was used since other minimum
spanning tree algorithms such as Kruskal's algorithm~\cite{kruskal} and Prim's
greedy algorithm~\cite{prim} only work on undirected graphs. Using the minimum
spanning tree would minimize the maximum cost associated with a path from the
initial configuration to the goal configuration thus moving the robot away from
high cost areas in space-time. Through qualitative analysis, this approach was
shown to still lead the robot to high cost areas and even into collisions with
obstacles.

This approach using a three dimensional probabilistic roadmap did not work in
practice regardless of the search algorithm because of the number of nodes that
need to be sampled in space-time in order for it to be effective.  Nodes in the
roadmap indicate where in the environment the robot is able to travel to from a
starting location in space-time. If the number of nodes is too small the, the
goal may not even be in the graph, and thus the robot will never reach it.
Also, the less nodes in the graph the less optimal the generated path is, but
the more nodes added to the graph, the more computationally difficult it
becomes to search. Lastly, the main flaw with this approach is that it biases
the sampling to areas that already have a high sample density and therefore may
not sample nodes in the goal region until sufficiently many samples have been
made.

\section{Two Dimensional Probabilistic Roadmap With Temporal Best First Search}

\label{sec:finaldesign}

After consideration for other sampling based motion planning techniques such as
rapidly exploring random trees~\cite{rrt} and expansive space trees~\cite{est}
the author chose to explore using a custom graph search algorithm over a two
dimensional probabilistic roadmap due to the lack of ability for classical
sampling based techniques to deal with time-dependent edge costs. The idea was
to use a probabilistic roadmap to capture the connectivity of the two
dimensional environment and to generate a search tree through the roadmap that
encodes the temporal information for each point in a tree node and is therefore
able to account for time-dependent edge costs. This graph search algorithm is a
temporal analogue of best-first search which tries to expand the best current
node in a search tree based on some heuristic~\cite{bestfs}. The heuristic in
this project is to expand the node in the search tree that has the minimum cost
as defined in Eq.~\ref{eq:cost}. A more complete and in depth description of
this method is given in Ch.~\ref{chapter:methodology}.

\end{document}


\chapter{Jet Tagging via Particle Clouds}

Representing Jets is a core component of ML on Jet Physics. In
\href{run:../papers/Jet\ Tagging\ via\ Particle\ Clouds.pdf}{this paper},
they are represented by particle clouds, which considers Jet as an
unordered set of its constituent particles.

\section{Jets}
Jet is a collimated spray of particles. It is one of the most ubiqutous
objects in proton-proton collision events at the LHC.

\begin{definition}[Particle Jets]{def:particle-jet}
    A Jet is defined as a narrow cone of hadrons and other particles
    produced by the hadronization of a quark or gluon in a particle physics
    or heavy ion experiment.
    (- Wikipedia)
\end{definition}

\noindent Jet exhibits different characteristics when initiated by different
particles. Jets initiated by gluons tend to have broader energy spectrum
than jets initiated by quarks.

\subsection{Characteristics}
TODO : Find different characteristics due to different initiating particles.

\subsection{Generating Data}

\paragraph{} The Large Hadron Collider (LHC) is the place, where all the particle-particle collisions occur and live data can be generated. As this data is too huge, CERN has developed toolchain known as Root, which is a command-line interface and with tools known as Pythia and MadGragh is used to generate the data.

\paragraph{} This data is not the actual data which is observed in the LHC, but rather the result of the simulations which are generated locally and is based on the phsics incorporated by them in CERN. They are close enough to the actual data, hence all algorithms are trained on it.

% TODO : More information on how to generate data

\section{Jet Tagging}

\paragraph{} Jet Tagging is one of the most important topics of interest and study in the  field of Jet Physics.

\begin{definition}[Jet Tagging]{def:jet-tagging}
    Jet tagging is finding the source particle that initiated the Jet.
\end{definition}

\noindent The study of Jet Tagging has been done for a long time. The first and initial methods consisted of QCD theory to distinguish between quark and gluon Jets.

\paragraph{} The newer approaches involve Machine Learning where Jets are viewed as images, sequences, trees, graphs or set of particles. The tagging isdone using deep NNs.

\subsection{QCD Theory}

\begin{definition}[Quantum Chromodynamics]{def:qcd-particle-theory}
    In theoretical physics, quantum chromodynamics (QCD) is the theory of the strong interaction between quarks and gluons, the fundamental particles that make up composite hadrons such as the proton, neutron and pion.
\end{definition}
% TODO : More information on QCD theory and how it was used to study Jets

\section{Jet Representation}
The effectiveness and efficiency of ML techniques on jet physics relies
heavily on how a jet is represented. Some of the mainsteam representations
and a new representation used by this paper is reviewed and explained here.

\subsection{Image-Based Representation}

\paragraph{} One of earliest (and successful) representation of jets is image representation.  In this method, the energy deposition on each cell is used pixel intensity which creates an image of the Jet.

\paragraph{} The enery deposition of a Jet is measured b a calorimeter. It is done on a fine-grained spatial cells, thus giving a matrix value table, which can be  used as a pixel value, thus constructing an image representation of the jet.

\paragraph{} This approach is used and studied extensively for various jet tagging tasks. Examples include W boson tagging, top tagging, and quark-gluon tagging.  CNNs (and modifications) are used with this representation as they provide a natural extension of Computer Vision tasks.

\paragraph{} They have an extensive advantage over traditional methods motivated by QCD theory. The QCD theory motivates multivaraite methods using observables.

\paragraph{} There are two major downsides to this reprsentation though, which makes it less efficient and thus not universally used. The first is its inability to take additional information in a meaningful manner. This is due to the fact that the data given by the calorimeter is non additive to the data that can be retrieved later.

\paragraph{} Another downside is the sparseness of the generated image. This is due to the fact that jet has particles in the order of $O(10) - O(100)$. This means that the image requires around $O(100)$ pixels. But a jet image requires $O(1000)$ pixels to contain a jet. Hence, most of the pixels are blank. This makes CNNs computatationaly innefective on jet images.

\subsection{Particle-Based Representation}
Another popular way of representing the jet is as a collection of its constituent particles.

\subsection{Particle Cloud}
In the previous section, different representation of Jets were given, which were helpful in jet tagging using ML. In this paper, a different and novel way of representation of jets is proposed known as particle cloud. It is analogous to point cloud reprsentation (3D shapes) which is used in Computer Vision(CV).

\paragraph{} In this paper, they designed ParticleNet, which is based on Dynamic Graph Convolution Neural Network (DGCNN). This operates directly on particle clouds for jet tagging.

\paragraph{} The idea is that the most natural representation of jets is an unordered, permutation-invariant set of particles. It is a special ase of Particle based representation, thus has all of its benifits (Flexibility, Smaller Size, Efficiency, etc).

\paragraph{} As particle cloud is so similar in structure to cloud representation, all the algorithms applicable to it are helpful to make algorithms for particle clouds.

\begin{note}[Message Passing Neural Nets]{note:mpnn-as-a-representation}
    There are other representations as well which are useful. One of them is
    represnting jets as graphs, with the vertices as particles. Message Passing
    NNs (MPNNs) with variations are used on these representations, and depending
    on how the adjacency matrices are defined, it can have better performance
    than the RecNNs. There is however a cache that the definition of adjacency
    matrix might not respect permutation symmetry of the particles.
\end{note}

\section{Machine Learning Algorithm}
This paper talks in detail about ParticleNet, a CNN-like deep NN for Jet Tagging.
The permutation symmetry makes particle cloud representation one of the most
natural representation, but the best performace can be acheived only if a
good algorithm is used.

\subsection{Convolutional Neural Networks}
CNNs are the staple algorithm to use when working with images. Hence, almost
every algorithm developed for images is based on CNNs. There are two major reasons
why they are so successful.

\begin{definition}
    Convolution is a mathematical operation $*$, defined as :

    \begin{equation*}
        (f*g)(t) \triangleq \int_{-\infty}^{\infty} f(\tau)g(t - \tau) d\tau
    \end{equation*}

    \noindent This operation is translation independant. This is defined for
    a continuous function.
\end{definition}

\paragraph{} Convolution operations exploit translational symmetry of images by using shared kernels across the complete image. This reduces number of parameters and allows them to be learnt more effectively.

\paragraph{} The second reason is that CNNs use heirarchical approach of learning features. This means that CNN layers can be effectively statcked to form a deep network.

\begin{note}
    aA single CNN layer can learn a more global feature than the previous one.
    This means that when stacking them, the earlier ones can learn local
    features, whereas the deeper ones can learn more global features. As they
    follow a hierarchy, this property is known as heirarchical approach.
\end{note}

\subsection{Edge Convolution}

\paragraph{} As CNNs are very useful and effective against images, a similar approach for
learning point cloud data is promoted, but as standard CNNs cannot be applied
on the point cloud representation, some modifications must be made to the
algorithm to make it usable.
\paragraph{} One of the major hurdles is that point cloud representation does not have
a regular matrix like shape, but is rather irregular distribution. Hence,
the basis for the convolution (local patch of each point on which the
kernel operates), is to be defined.
\paragraph{} Another problem is that the regular convolution operation, in the form of
$\sum \mathcal{K}_jx_j$ ($\mathcal{K}_j$ : $j^{th}$ kernel, $x_j$ : $j^{th}$
feature) is not permutation invariant. Hence, this also needs to be
modified.

\paragraph{} Edge Convolution is a modification of the standard convolution operation
for point clouds. This operation requires the point cloud as a graph, with
each point represting a vertex and the edges are constructed as connections
between the k nearest neighbours of the point.

\begin{definition}[Edge Convolution]{}
    The EdgeConv operation is as follows :

    \begin{equation*}
        x_i' \triangleq \fbox{$\phantom{5}$}_{j=1}^k h_\theta(x_i,x_{i_j})
    \end{equation*}

    \noindent In this defintion, the variables and operations are as below :\\
    $\fbox{$\phantom{5}$}$ : Channel-wise symmetric aggregation operation\\
    $h_\theta : \mathcal{R}^F \times \mathcal{R}^F \rightarrow \mathcal{R}^F$\\
    $x_i$ : Feature Vector of point $x_i$
\end{definition}

\noindent In the defintion of EdgeConv given above, the function is  parametrized by the set of learnable parametes $\theta$. In this paper, a  specialized form of edge function is used.

\paragraph{} The $h$ function used is defined as :

\begin{equation*}
    h_\theta(x_i,x_{i_j}) = \overline{h}_\theta(x_i,x_i - x_{i_j})
\end{equation*}

\noindent In this, the function $\overline{h}_\theta$ can be implemented as a  multilayer perceprtron, whose parameters are shared among all the edges. Also  in this paper, the aggregation operation used is mean, rather than max which was the function used in the original paper. The EdgeConv operation thus is :

\begin{equation*}
    x_i' = \frac{1}{k} \sum_{j=1}^k \overline{h}_\theta(x_i,x_i - x_{i_j})
\end{equation*}

\noindent An EdgeConv block is implemented according to the diagram given below :

\begin{center}
    \includegraphics[scale=0.3]{img/theory-ml-particlenet/edge-conv.png}
\end{center}

\noindent The hyperparameters of the EdgeConv operation are the number of neighbours $k$, and the number of channels $C = <C_1,C_2,C_3>$, each corresponding to  number of units in the linear transformation layer.

\paragraph{} As this operation preserves the dataset as a point cloud, they can be stacked just as easily as standard convolutions.

\begin{note}
    Multilayer Perceptron is a class of feedforward ANNs. The term, though is used ambiguously to classify any feedforward ANN.
\end{note}

\noindent The stackability also allows a us to view the feature vectors learnt as new coordinates of the original points in the latent space. This allows determination of distance between points in this new space (Computed while  determining $h_\theta$). This means that proximitiy of points can be dynamically  learnt using EdgeConv. This results in the DGCNN, in which the graph describing  the point clouds are dynamically updated to reflect the changes in the edges.

\subsection{ParticleNet}
ParticleNet is a sort of modified and specialized version of DGCNN, which has different design choices to suit the jet tagging task. It makes extensive use of EdgeConv operation, but has specialized configuration to make it suit better.

\paragraph{} The ParticleNet algorithm is given in the diagram given below :

\begin{center}
    \includegraphics[scale=0.25]{img/theory-ml-particlenet/particle-net.png}
\end{center}

\noindent These are the two implementations of ParticleNet which were used in the paper. All the results published in the paper were using this algorithm.


\subsubsection{Morning Star}\label{weapon:morningStar}
Weapon, Blunt, Two-Handed, Regular, Melee\\
Size: L\\
Cost: 150 Gold

\textbf{Bash}\\
4 AP, ST to hit, \passus{1} Reach\\
1d6 + \sfrac{1}{2}\texttimes ST + 1d6 + \sfrac{1}{2}\texttimes ST Piercing Damage\\
When reducing a creature to 0 Health with this Attack, you can choose to knock them out instead of killing them.\\
If you gain a bonus on the damage of this attack, you can choose if the bonus applies to the blunt damage or the piercing damage.


\chapter{Literature Review \& Theory Description}
As previously mentioned in the introduction section, the read-out circuit has two operation modes.
DC-sweep mode controls the drain current ($I_D$) of nanowire while Transient Measurement mode is for current variance measurement.
Each of them refers to different sources.
Section 2.1 talks about the reason why we perform $I_D$-$V_G$ sweep.
It is then followed by the literature review related to the circuit design of DC-sweep mode.
The literature related to Transient Measurement mode circuit design is in section 2.2.
The last section discusses the two assumptions mentioned in section 1.2.

\section{DC Sweep: $I_D$-$V_G$ Curves}
This section reviews the knowledge and an article that is related to DC-sweep mode.

\subsection{$I_D$-$V_G$ and Transconductance}
A common method for examining nanowire electrical properties is to perform DC sweep.
Among all kinds of sweep method, we choose the $I_D$-$V_G$ in respect of the physical characteristic.
In the n-type transistor, the binding of negatively charged biomolecules induces surface-near silicon ions discharged and thus increases the threshold voltage.
It is straightforward to think of these binding molecules as a voltage signal input to the gate with its value depends on the concentration.
And this voltage signal effects nanowire in the same way $V_G$ does.
So by plotting $I_D$-$V_G$ curves, we can have a thumbnail of how concentration affects the $I_D$.

\subsection{The Source Follower Structure} \label{section:SF}

\begin{figure}[h]
    \centering
    \includegraphics[width=5cm]{images/chapter2/SourceFollower.png}
    \fontsize{6}{7}\selectfont
    \caption{Sorce Follower}
    \label{fig:SF}
\end{figure}

As one of the basic single stage amplifier, source follower (common drain) are employed to transfer voltage signal from gate to source while keeping $I_D$ constant.
The transfer function can be derived as:
\setlength{\mathindent}{5.5cm}
\begin{align}
    \frac{V_{out}}{V_{in}} & = \frac{r_{ds}g_m}{1 + r_{ds}g_m} \\    \label{eq:sfTF}
                           & \approx 1 \qquad \text{ for } \quad r_{ds}g_m >> 1
\end{align}
$g_m$ is the transconductance ($\frac{\partial I_D}{\partial V_{GS}}$) and $r_{ds}$ is the drain-to-source resistance.
Although we have not seen the structure being applied to the nanowire, there have been several applications in the read-out circuits of ISFET (Ion-sensitive Field-effect Transistor)\cite{SF1, SF2} for a while.

The read-out circuit in \cite{SF1} employs ISFET as a biological transducer that converts detected bio-signals into electrical signals, which resembles our nanowire biosensor.
It adopts the source follower structure as its analog front-end.
The potential change induced by the biomolecules at the gate of ISFET is converted to the source.
This structure requires a biasing current which needs to be stable, noiseless or wide-range on demand.
Since the biasing current is usually under micro-scale or even nano-scale, it is impractical to use an external current source.
The article \cite{SF1} uses two resistors and an op-amp to design a current scale down circuit.
As in Fig.\ref{fig:ISFET}, bias current decreases in proportional to the resistance ratio (N) as the current source circuit I{\scriptsize B}.

\begin{figure}[h]
    \centering
    \includegraphics[width=12cm]{images/chapter2/ISFET.png}
    \fontsize{6}{7}\selectfont
    \caption{ISFET readout circuit in \cite{SF1}}
    \label{fig:ISFET}
\end{figure}
The circuit in Fig.\ref{fig:ISFET} also removes the short channel effect by keeping $V_{DS}$ at a constant value (0.5v).
It adopts two op-amp based unit gain buffer to force the voltage at drain follows the source.

Attention should be paid to the impedance matching between the device-under-test (DUT) and the current source circuit.
The output impedance of current source should be much larger than the input impedance of the DUT.
By using nanowire as the DUT, the input impedance of it is:

\begin{align}
    & \frac{r_{ds}}{1 + g_mr_{ds}}\\
\intertext{This equation can be simplified as:}
    & \frac{1}{g_m} \qquad \text{ for } \quad g_mr_{ds} >> 1 \label{eq:rsf2}
\end{align}
The output impedance of the current source $I_B$ is:
\begin{equation} \label{eq:rcs}
    N\times Z_{DS}
\end{equation}

$Z_{DS}$ is the impedance of the current source I{\scriptsize DS} in Fig.\ref{fig:ISFET}.
In the integrated circuit, $Z_{DS}$ is non-ideal but usually close to the $r_{ds}$ of a single MOSFET.

As mentioned, Eq.(\ref{eq:rcs}) should be far larger than Eq.(\ref{eq:rsf2}).
However, $g_m$ is proportional to $I_B$, which means Eq.(\ref{eq:rsf2}) is inversely proportional to N.
When the biasing current decreases, the output impedance of I{\scriptsize B} decreases while the input impedance at the source of ISFET increases.
This relationship determines the limit for $I_B$.
We observed this boundary when we constructed this circuit with discrete elements.
These will be presented and discussed in chapter 4.

The source follower structure provides a direct signal transition method.
It is a good candidate for the read-out circuit with the aim of detecting transconductance or threshold voltage variance.
Nevertheless, post-processing such as amplification and filtering is necessary.
The experiment results in \cite{SF1} are untreated.
Significant signal attenuation exists, which is mainly caused by low-frequency noise and ISFET drift \cite{Drift}.
The drift problem is dealt with by signal processing techniques while noise problem is left untreated.

\section{Small Signal (AC) Measurement Method Review}  \label{sec:AC}
The previous section mentioned that he source follower exhibits compelling advantages as a signal processing structure of nano-device.
However, the structure faces obstacles when being applied to the small signal detection.
Parasitic capacitors and resistors can influence the results.

\begin{figure}[ht]
    \centering
    \includegraphics[width=5cm]{images/chapter2/SourceFollower_wi_parasiticCap.png}
    \fontsize{6}{7}\selectfont
    \caption{Sorce Follower with parasitic capacitance}
    \label{fig:SF_pC}
\end{figure}

As the parasitic elements are included in Fig.\ref{fig:SF_pC}, the transfer function Eq.(\ref{eq:sfTF}) is modified as:
\begin{align}
    \frac{V_{out}}{V_{in}} = \frac{r_{ds}(sC_{gs} + gm)}{1 + r_{ds}(gm + s(C_{gs}+C_s))}
\end{align}
The equation can be similar to Eq.(\ref{eq:sfTF}) which roughly equals to 1 as long as $C_s$ is far smaller than $C_{gs}$.
Unfortunately, $C_s$ can be close to or greater than $C_{gs}$ since the output of the source follower is connected to a next stage input or a pad.
In that case, the signal may be attenuated.

We want to build another circuit structure that can not only perform AC signal measurement but also disregard parasitic capacitance.
We started by reviewing the works trying to measure the parasitic capacitance.
Below, the works from two teams aim to measure the drain-to-source resistance ($R_{NW}$) and the drain-to-source capacitance ($C_{NW}$).
The review focuses on the function and design theory of their read-out circuits.

\subsection{RC Time Delay Measuring}
\begin{figure}[!htbp]
    \centering
    \includegraphics[width=10cm]{images/chapter2/uv1.png}
    \caption{(a) Schematic of \cite{Juv1}.}
    \label{fig:tot1}
\end{figure}

The measurement system for ZnO-nanowire based sensor array from \cite{Juv1} applies the Time-over-Threshold technique to its read-out circuit (Fig.\ref{fig:tot1}).
The circuit alternatively charges an on-chip capacitor ($C_{int}$) with a constant current and discharges it through the nano-material resistance (nanowire).
An inverter with its output switches from on to off when the capacitor is charged to its input threshold voltage, and vice versa.
This behavior converts information of nanowire such as capacitance and resistance into time information.

The work presented in \cite{Juv1} does not have enough explanation of how they interpret the capacitance and resistance information.
It merely mentioned that a microcontroller is responsible for the calculation.
Besides, the work lacks simulation and experiment of measuring complex devices.
Most of the results are the measurement of a concrete resistor as the substitute for nanowire, and $C_{NW}$ is regarded as $0pF$.
The only nanowire experiment does not have good performance.
It seems that the design may only be applied to a device with pure resistance or pure capacitance.

The recent publican \cite{Juv2} by the team is more elaborate and contains the measurement of complex devices (A device composed of a discrete resistor and a discrete capacitor).
\begin{figure}[!htbp]
    \centering
    \includegraphics[width=12cm]{images/chapter2/uv2.png}
    \caption{Schematic of \cite{Juv2}.}
    \label{fig:tot2}
\end{figure}

In Fig.\ref{fig:tot2}, nanowire appends between point A and B.
The charging current can be applied from Mp1 or Mp2, which is determined by the ``sel'' signal with the aid from MUXs.
Below, it is assumed that sel = 1 and point B is virtual ground.
(When the sel = 0, the circuit measures the device with a reversed biasing current.)
The circuit design concept is the same as \cite{Juv1}.
The current charge both $C_{int}$ and $C_{NW}$.
When the voltage at A exceed the threshold voltage, the output switches off and causes Mp1 to turn off.
(It is notable that the inverter at the output stage in \cite{Juv1} is replaces by a Schmitt trigger in \cite{Juv2})
Then the capacitor discharges through nanowire ($r_{ds}$).

The bottom-right plot in Fig.\ref{fig:tot2} defines $T_0$ as the charging time and $T_1$ as the discharging time.
The calculation of the $R_{NW}$ and $C_{NW}$  can be simplified as:
\setlength{\mathindent}{2cm}
\begin{align}
                         C_{NW}            & = T_0 - C_{base}\\
                         R_{NW}            & = \frac{T_1R_{par}}{(C_{NW} + C_{base})R_{par} - T_1}\\
    \text{where} \qquad  R_{NW} || R_{par} & = \frac{T_1}{C_{NW} + C_{base}}
\end{align}
$C_{base}$ are the $C_{int}$ plus parasitic capacitance and $R_{par}$ the parasitic resistance.
These parasitic elements come from the transistor in the integrated circuit block such as MUX and Mp.
It is notable that we do not consider the hysteresis of the Schmitt trigger here owing to simplicity.

\subsection{Complex Impedance Solving}
The nanowire-based hydrogen sensor measurement system in \cite{Jlockin} adopts another method.
It uses a lock-in amplifier to realize both resistive and capacitive impedance measurement.

\begin{figure}[!htbp]
        \centering
        \includegraphics[width=13cm]{images/chapter2/lockin.png}
        \caption{Block diagram of the lock-in amplifier in \cite{Jlockin}}
        \label{fig:lockin}
\end{figure}

As the previous method, it treats nanowire as a device with complex impedance.
The nanowire is modeled as a resistor and a capacitor in parallel connection.
The system applies a sinusoidal voltage signal to one end of the device.
Another end of the device is virtually grounded by a transimpedance amplifier (TIA).
The TIA then converts the current variance into a voltage output which depends on the complex impedance of the nanowire.
The resistance is in the real part while the capacitance is in the virtual part.
\setlength{\mathindent}{5.5cm}
\begin{align}
    V_{out} &= I_{NW}R_{TIA} \\
    I_{NW} &= V_{in}(\frac{1}{R_{NW}} + j 2\pi fC_{NW})
\end{align}
$f$ is the frequency of input signal.

The output of TIA is followed by a controllable bandpass filter (BP).
The BP removes high-order harmonic interferences.
Then the signal is demodulated.
The resistive and capacitive impedance values are resolved through two channels: I and Q with their phase different by 90 degrees.
A mixer which is a linear multiplier performs the demodulation.
With a radio frequency (RF) input and a local oscillator (LO) input, it produces an output signal that consists of signals with frequencies $f_{RF} + f_{LO}$ and $f_{RF} - f_{LO}$.

\subsection{Comparison and Conclusion} \label{sec:ch2CC}

\begin{table}[!hbt]
    {\fontfamily{}\fontsize{10}{14}\selectfont
    \centering
    \begin{tabular}{l|cp{4cm}}
        & \cite{Juv2} & \cite{Jlockin}\\
        \hline
        R meas range & 1M - 1G & 10 - 40k\\
        \hline
        R meas error & < 2.5\% & < 2\%\\
        \hline
        C meas range & 100fF - 1uF & 0.5 - 1.8nF\\
        \hline
        C meas error & < 3\% & < 3\%\\
        \hline
        Detection of Input Current Varinace &  $120\mu A$ - $0.12n A$ & $3\mu A$ - $60n A$ \\
        \hline
        SNR & > 45dB & - \\
        \hline
        Input referred noise & - & 190 nV/sqrt(Hz) @ 5 kHz \\
        \hline
        CMOS Technology & 0.13um & 0.18um\\
        \hline
        Power consumption & 14.82uW & 2mW\\
    \end{tabular}
    \caption{Specification Summary}
    \label{tb:LVtable}
    }
\end{table}
We compare the Method 1 (Sec.2.2.1) and Method 2 (Sec.2.2.2) here.
Both of them focus on detecting the $R_{NW}$ difference.
According to the comparison table below (\ref{tb:LVtable}), we can see the resistor measurement range of Method 1 is different from Method 2 by a large extent.
It is not appropriate to make a comparison directly.
These ranges are conformed to a detecting range for the current variance, which is also more helpful for our circuit design.

The resistance measuring range of Method 1 is $1M \Omega \sim 1G \Omega$.
Since the circuit applies an input ac signal with amplitude of $120m V$ to the nanowire device, the equivalent current variance is $120\mu A \sim 0.12n A$.

As for Method 2, the measuring range relates to the noise.
A $3m V$ output referred noise limits the detecting range.
According th the article, this noise value is equivalent to a 2\% resistance resolution.
Therefore, the output voltage range should be $3m V \sim 0.15V$.
Moreover, the gain of the post-stage (BP and last-stage low pass filter) is 5 and the Rf in the TIA is 10k
Hence the current variance that circuit can detect should be $60n A \sim 3\mu A$.

The relatively narrow current detection range of Method 2 should be because of the TIA block it adopts.
Our method adopts this TIA block and will discuss this problem in Section.\ref{sec:Ibias}.

Method 2 performs well when it comes to noise suppression.
In fact, the circuit in Method 1 does not provide noise reduction ability.
The particular structure it uses (The article \cite{Juv1} mentioned it as Micro-for-Nano (M4N) approach \cite{M4N}.) is the one responsible for that.

Method 1 has lower power consumption. However, it does not include the power of microcontroller and may be underestimated.

Overall, Method 1 has the advantage in detecting range and accuracy while Method 2 has better noise suppression.

In our project, capacitance measurement is not our object.
But we still need to consider the parasitic capacitor effect in our circuit design.
Method 1 converts the resistance information into time (frequency) information.
If one wants to avoid the effect of the parasitic capacitor, he should apply a $C_{int}$ that is much larger than $C_{NW}$.
However, it is not practical in integrated design because the chip size is limited.

Method 2 uses a TIA to measure resistance and capacitance together first and then resolves the complex value.
We can write the complex impedance value as:
\begin{align}
      \frac{R_{NW}}{1 + i2\pi f R_{NW} C_{NW}} \label{eq:comlex}
\end{align}
In Eq.(\ref{eq:comlex}), $i$ is the imaginary unit and $f$ is the signal frequency.
The equation can be simplified as $R_{NW}$ when $i2\pi f R_{NW} C_{NW} < 0.1$.
The simplification can be applied when the signal frequency or $C_{NW} R_{NW}$ is small enough.

Since our goal is to ignore the capacitance and merely detect the resistance (or transconductance), Method 2 is more suitable for us.
Because it is easier to separate capacitive and resistive measurement by Method 2 than by Method 1.

\section{Two assumption for Dealing with Device Variability Problem} \label{sec:assumpDiscuss}
In chapter 1, to deal with device variability problem, we assume that:
\begin{enumerate}
    \item The transconductance ($g_m = \frac{\partial I_D}{\partial V_{G}}$) of nanowire in weak inversion is linearly dependent on $I_D$ and independent of $V_{G}$.
    \item The change of the biomolecule concentration can induce potential change on the surface of the gate of a nanowire..
\end{enumerate}
We discuss them in this section.

\subsection{Transconductance and $I_D$} \label{section:IdGm}
With the MOSFET model of weak and strong inversion, we have the $I_D$ equations of MOSFET :
\setlength{\mathindent}{1.5cm}
\begin{align}
    \text{weak inversion:} \quad I_D   = & I_0e^{\kappa V_{GS}/\phi_t}(1 - e^{-V_{DS}/\phi_t})  \label{eq:Ikappa} \\
                                       = & I_0e^{\kappa V_{GS}/\phi_t} \quad \text{where $V_{DS} > 4 \phi_t$ } \\
    \text{strong inversion:} \quad I_D = & \mu C_{ox} \frac{W}{L}((V_{GS} - V_{th})V_{DS} - \frac{V_{DS}^2}{2}) \\
                                       = \frac{1}{2} \mu C_{ox} & \frac{W}{L}(V_{GS} - V_{th})^2 \text{ }\text{ where $V_{DS} > V_{GS} - V_{th}$} \label{eq:ID_Strong}
\end{align}

$V_{GS}$ is the gate-to-source voltage ($V_{GS} = V_G - V_S$).
It will be written as $V_G$ in the following paragraphs since source is considered to be grounded.
$C_{ox}$ is the oxide capacitance and $\mu$ is the electron mobility.
Both of them depends on doping concentration.
$W$ and $L$ are the width and length of the transistor.
$\phi_t$ is the thermal voltage depending on temperature.
The $\kappa$ is the gate coupling coefficient.
To be noted that we ignore the short channel effect, which does not effect our discussion since $V_{DS}$ is always kept constant.

We then derive $g_m$:
\begin{align}
    \text{weak inversion:} \quad g_m & = \frac{\kappa I_D}{\phi_t} \label{eq:gm_weak} \\
    \text{strong inversion:} \quad g_m & = \sqrt{2 \mu C_{ox} (\frac{W}{L})I_{D}} \label{eq:gm_strong}
\end{align}

The Eq.(\ref{eq:gm_weak}) shows that the $g_m$ in weak inversion is affected by the gate coupling effect.
This effect is illustrated in Fig.\ref{fig:gateCouple}.
The $\kappa$ is actually the ratio of voltage divider:
\begin{equation}
    \kappa = \frac{C_{ox}}{C_{ox} + C_{dep}}
\end{equation}
The fact that $C_{dep}$ varies with $V_G$ makes $\kappa$ a non-linear parameter.
Its value ranges from 0.4 to 0.9.
The structure of nanowire is different from MOSFET and is illustrated in Fig.\ref{fig:gateCouple_NW}
The SiO2 insulator in MOSFET is replaced by the solvent and the $C_{ox}$ becomes $C_{sol}$.
According to the famous Gouy-Chapman model, the potential difference in the solution affect the double layer capacitance in solution \cite{ElecChem}.
Thus, it is still true that $V_G$ affect $gm$.
Nevertheless, it is convinced that the $\kappa$ value is very close to 1 because $C_{sol}$ is much greater that $C_{dep}$.
This will be discussed later.

As for the strong inversion, $g_m$ linearly depends on $\sqrt{I_D}$ and independent of $V_G$.
However, in nanowire, the $C_{ox}$ is replaced by $C_{sol}$ and is affected by $V_G$ and the solvent concentration.
Therefore, the assumption 1 cannot be applied to nanowire in strong inversion region.

\begin{figure}[bt!h]
    \centering
    \includegraphics[width=0.8\linewidth]{images/chapter2/kappa.png}
    \caption{The gate coupling effect in MOSFET \cite{bookOfUltra}.}
    \label{fig:gateCouple}
\end{figure}
\begin{figure}[bt!h]
    \centering
    \includegraphics[width=0.8\linewidth]{images/chapter2/kappa_liquid.png}
    \caption{The gate coupling effect in nanowire.}
    \label{fig:gateCouple_NW}
\end{figure}

\subsubsection*{Estimation of $C_{sol}$}
$C_{sol}$ can be estimated by applying the famous Gouy–Chapman–Stern model \cite{bookOfElecMethod}.
The model explains the double-layer capacitance ($C_{DL}$), which is the structure appears on the contact surface between liquid and metal or solid particle.
The capacitance is considered to be two capacitors in series:
\begin{equation}
    \frac{1}{C_{DL}} = \frac{1}{C_{stern}} + \frac{1}{C_D}
\end{equation}
$C_{stern}$ represents the capacitor in the stern layer and $C_D$ represents the capacitor in diffusion layer.
For DNA solution and PBS as buffer, the relative permittivity is 8 \cite{dnaepisilon} and debye length is about 0.7nm.
$C_{stern}$ is therefore roughly 97$\mu/cm^2$.
As for $C_D$, the value is hard to know since it relates to ion concentration and fluid potential.
However, the model implies that $C_{DL}$ is mostly dominated by $C_{stern}$.
Only if the solution contains scarce solvent, $C_D$ should be taken into consideration.
It is clearly not our case because the PBS buffer we use has high ion concentration.

\subsection{A Simple Model for Concentration Effect}
In \cite{DN17}, the team plots the $I_D$-$V_G$ curves and study how the curves change with the concentration of biomolecules.
We observed that in the plot (Fig.\ref{fig:DN17Fig6d}) with a log scale for the y-axis, curves with different concentrations exhibit the same rising trend when $I_D$ is low (< 100nA).
Each curve seems to be different from each other by a constant shift.
We found that this concentration effect can be explained by applying the weak inversion current equation of MOSFET.

\begin{align}
    & I_{D1} = I_{0} e^{\kappa(V_{G}) / \phi_t} \\
    & I_{D2} = I_{0} e^{\kappa(V_{G} + \Delta v) / \phi_t} \\
    \rightarrow & I_{D2} = f(\Delta v) \times I_{D1} \quad \text{where} \quad f(\Delta v) = e^{\Delta v / \phi_t} \label{eq:vc}
\end{align}

The $I_{D1}$ and $I_{D2}$ are the current of two nanowire devices immersed in solutions with different concentrations.
The ($\Delta v$) is a concentration related variable we create.
The Eq.(\ref{eq:vc}) implies that when nanowire is in weak inversion region, its $\log I_D$ difference is independent of $V_G$.
\begin{align}
    \log I_{D2} - \log I_{D1} = \log \frac{I_{D2}}{I_{D1}} = \log f(\Delta v) = \Delta v / \phi_t
\end{align}

As for the strong inversion region corresponding to the large current segments in Fig.\ref{fig:DN17Fig6d}, the difference among the curves diminish as $V_G$ increases.
This is reasonable when $V_{G}$ is far larger than $\Delta v$ and the concentration effect becomes ignorable.

We will further prove the two assumptions by the data of biology experiment in section.\ref{section:disparityBio}.

\begin{figure}[!htbp]
    \centering
    \includegraphics[width=8cm]{images/chapter2/DN18Fig3D.png}
    \caption{Concentration-dependent electric response($I_D-V_G$) of biotin-modified poly-Si NWFET following biotin–streptavidin interaction.\cite{DN17}}
    \label{fig:DN17Fig6d}
\end{figure}

%


\chapter{Taylor and Fourier analysis}


\chapter{Analysis in sensor space \label{Chap:eeg:sensoranalysis}}

This chapter describes how to perform statistical analyses of EEG/MEG data. This requires transforming data from SPM M/EEG format to image files (NIfTI format). Once the data are in image format the analyses for M/EEG are procedurally identical to 2nd level analyses for fMRI.  We therefore refer the reader to the fMRI section for further details of this last step.

In the drop down ``Images'' menu, select the function \texttt{Convert to images}. This will open the batch tool for conversion to images. You will need to select the input dataset, that can be either a mat-file on disk or a dependency from a previous processing step.
\\
Then you need to set the 'mode' of conversion. M/EEG data in general case can be up to 5-dimensional (3 spatial dimensions, time and frequency). SPM statistical machinery can only handle up to 3 dimensions. Although this is a purely implementational limitation and the theory behind SPM methods can be extended to any dimensionality, in practice high-dimensional statistical results can be very hard to interpret not least due to our inability as humans to visualise them. Furthermore, unconstrained high-dimensional test would incur very severe penalty for multiple comparisons and should in most case be avoided. Thus, our purpose is to reduce our data dimensionality to be 3 or less. The three spatial dimensions in which the sensors reside can be reduced to two by projecting their locations onto a plane. Further reduction of dimensionality will involve averaging over one of the dimensions. The choices for 'mode' option correspond to all the different possibilities to average over a subset of data timensions. Some of the options are only relevant for time-frequency data where the frequency dimension is present.
\\
'Conditions' options makes it possible to only convert data for a subset of conditions in the file. This is especially useful for batch pipeline building. The conversion module outputs as a dependency a list of all the generated NIfTI images. These can be used as input to subsequent steps (e.g. statistical design specification). By including the 'Convert2images' module several times in batch each condition can have a separate dependency and enter in a different place in the statistical design (e.g. for two-sample t-test between two groups of trials).
\\
The 'Channels' option makes it possible to select a subset of channels for conversions. These can be either selected by modality (e.g. 'EEG') or chosen by name of by a list in a mat-file (e.g. to average over all occipital channels).
\\
'Time window' and 'Frequency window' options limit the data range for conversion which is especially important if the data are averaged over this range. Make sure you only include the range of interest.
\\
Finally the 'Directory prefix' option specifies the prefix for the directory where images will be written out. This is important if several different groups of images are generated from the same dataset (e.g. from different modalities or different channel groups).
\\
\subsection{Output}
 When running the tool a direcory will be created at the dataset location. Its name will be the name of the dataset with the specified prefix. In this directory there will be a nii-file for each condition. In the case of averaged dataset these will be 3D images (where some dimensions can have size of 1). In the case of an epoched dataset there will be 4D-NIfTI images where every frame will contain a trial.
\\
\subsubsection{Averaging over time or frequency}
Although 2D scalp images averaged over time or frequency dimension can be created directly in conversion to images, they can also be generated by averaging over part of the Z dimension of previously created 3D images. This is done via 'Collapse time' tool in the 'Images' menu.
\\
\subsubsection{Masking}
When you set up your statistical analysis, it might be useful to use an explicit mask to limit your analysis to a fixed time window of interest. Such a mask can be created by selecting \texttt{Mask images} from ``Images'' dropdown menu. You will be asked to provide one unsmoothed image to be used as a template for the mask. This can be any of the images you exported. Then you will be asked to specify the time (or frequency) window of interest and the name for the output mask file. This file can then enter in your statistical design under the 'Explicit mask' option or when pressing the 'small volume' button in the 'Results' GUI and choosing the 'image' option to specify the volume.
\\
\subsection{Smoothing}
The images generated from M/EEG data must be smoothed prior to second level analysis using the \textsc{Smooth images} function in the drop down ``Images'' menu. Smoothing is necessary to accommodate spatial/temporal variability between subjects and make the images better conform to the assumptions of random field theory. The dimensions of the smoothing kernel are specified in the units of the original data (e.g. [mm mm ms] for space-time, [Hz ms] for time-frequency). The general guiding principle for deciding how much to smooth is the matched filter idea, which says that the smoothing kernel should match the data feature one wants to enhance. Therefore, the spatial extent of the smoothing kernel should be more or less similar to the extent of the dipolar patterns that you are looking for (probably something of the order of magnitude of several cm).  In practice you can try to smooth the images with different kernels designed according to the principle above and see what looks best. Smoothing in time dimension is not always necessary as filtering the data has the same effect. For scalp images you should set the 'Implicit masking' option to 'yes' in order to keep excluding the areas outside the scalp from the analysis.
\\

Once the images have been smoothed one can proceed to the second level analysis.