\achapter{\Program{}}
\label{Program}
\aauthor{Matthieu Sozeau}
\index{Program}

We present here the \Program\ tactic commands, used to build certified
\Coq\ programs, elaborating them from their algorithmic skeleton and a
rich specification \cite{Sozeau06}. It can be thought of as a dual of extraction
(see Chapter~\ref{Extraction}). The goal of \Program~is to program as in a regular
functional programming language whilst using as rich a specification as
desired and proving that the code meets the specification using the whole \Coq{} proof
apparatus. This is done using a technique originating from the
``Predicate subtyping'' mechanism of \PVS \cite{Rushby98}, which generates type-checking
conditions while typing a term constrained to a particular type.
Here we insert existential variables in the term, which must be filled
with proofs to get a complete \Coq\ term. \Program\ replaces the
\Program\ tactic by Catherine Parent \cite{Parent95b} which had a similar goal but is no longer
maintained.

The languages available as input are currently restricted to \Coq's term
language, but may be extended to \ocaml{}, \textsc{Haskell} and others
in the future. We use the same syntax as \Coq\ and permit to use implicit
arguments and the existing coercion mechanism.
Input terms and types are typed in an extended system (\Russell) and
interpreted into \Coq\ terms. The interpretation process may produce
some proof obligations which need to be resolved to create the final term.

\asection{Elaborating programs}
The main difference from \Coq\ is that an object in a type $T : \Set$
can be considered as an object of type $\{ x : T~|~P\}$ for any
wellformed $P : \Prop$.
If we go from $T$ to the subset of $T$ verifying property $P$, we must
prove that the object under consideration verifies it. \Russell\ will
generate an obligation for every such coercion. In the other direction,
\Russell\ will automatically insert a projection.

Another distinction is the treatment of pattern-matching. Apart from the
following differences, it is equivalent to the standard {\tt match}
operation (see Section~\ref{Caseexpr}).
\begin{itemize}
\item Generation of equalities. A {\tt match} expression is always
  generalized by the corresponding equality. As an example,
  the expression:

\begin{verbatim}
  match x with
  | 0 => t
  | S n => u
  end.
\end{verbatim}
will be first rewritten to:
\begin{verbatim}
  (match x as y return (x = y -> _) with
  | 0 => fun H : x = 0 -> t
  | S n => fun H : x = S n -> u
  end) (eq_refl n).
\end{verbatim}

  This permits to get the proper equalities in the context of proof
  obligations inside clauses, without which reasoning is very limited.

\item Generation of inequalities. If a pattern intersects with a
  previous one, an inequality is added in the context of the second
  branch. See for example the definition of {\tt div2} below, where the second
  branch is typed in a context where $\forall p, \_ <> S (S p)$.

\item Coercion. If the object being matched is coercible to an inductive
  type, the corresponding coercion will be automatically inserted. This also
  works with the previous mechanism.
\end{itemize}

\subsection{Syntactic control over equalities}
\label{ProgramSyntax}
To give more control over the generation of equalities, the typechecker will
fall back directly to \Coq's usual typing of dependent pattern-matching
if a {\tt return} or {\tt in} clause is specified. Likewise,
the {\tt if} construct is not treated specially by \Program{} so boolean
tests in the code are not automatically reflected in the obligations.
One can use the {\tt dec} combinator to get the correct hypotheses as in:

\begin{coq_eval}
Require Import Program Arith.
\end{coq_eval}
\begin{coq_example}
Program Definition id (n : nat) : { x : nat | x = n } :=
  if dec (leb n 0) then 0
  else S (pred n).
\end{coq_example}

The let tupling construct {\tt let (x1, ..., xn) := t in b}
does not produce an equality, contrary to the let pattern construct
{\tt let '(x1, ..., xn) := t in b}.
Also, {\tt {\term}:>} explicitly asks the system to coerce {\tt \term} to its
support type. It can be useful in notations, for example:
\begin{coq_example}
Notation " x `= y " := (@eq _ (x :>) (y :>)) (only parsing).
\end{coq_example}

This notation denotes equality on subset types using equality on their
support types, avoiding uses of proof-irrelevance that would come up
when reasoning with equality on the subset types themselves.

The next two commands are similar to their standard counterparts
Definition (see Section~\ref{Basic-definitions}) and Fixpoint (see Section~\ref{Fixpoint}) in that
they define constants. However, they may require the user to prove some
goals to construct the final definitions.

\subsection{\tt Program Definition {\ident} := {\term}.
  \comindex{Program Definition}\label{ProgramDefinition}}

This command types the value {\term} in \Russell\ and generates proof
obligations. Once solved using the commands shown below, it binds the final
\Coq\ term to the name {\ident} in the environment.

\begin{ErrMsgs}
\item \errindex{{\ident} already exists}
\end{ErrMsgs}

\begin{Variants}
\item {\tt Program Definition {\ident} {\tt :}{\term$_1$} :=
    {\term$_2$}.}\\
  It interprets the type {\term$_1$}, potentially generating proof
  obligations to be resolved. Once done with them, we have a \Coq\ type
  {\term$_1'$}. It then checks that the type of the interpretation of
  {\term$_2$} is coercible to {\term$_1'$}, and registers {\ident} as
  being of type {\term$_1'$} once the set of obligations generated
  during the interpretation of {\term$_2$} and the aforementioned
  coercion derivation are solved.
\item {\tt Program Definition {\ident} {\binder$_1$}\ldots{\binder$_n$}
       {\tt :}\term$_1$ {\tt :=} {\term$_2$}.}\\
  This is equivalent to \\
   {\tt Program Definition\,{\ident}\,{\tt :\,forall} %
       {\binder$_1$}\ldots{\binder$_n$}{\tt ,}\,\term$_1$\,{\tt :=}} \\
       \qquad {\tt fun}\,{\binder$_1$}\ldots{\binder$_n$}\,{\tt =>}\,{\term$_2$}\,%
       {\tt .}
\end{Variants}

\begin{ErrMsgs}
\item \errindex{In environment {\dots} the term: {\term$_2$} does not have type
    {\term$_1$}}.\\
    \texttt{Actually, it has type {\term$_3$}}.
\end{ErrMsgs}

\SeeAlso Sections \ref{Opaque}, \ref{Transparent}, \ref{unfold}

\subsection{\tt Program Fixpoint {\ident} {\params} {\tt \{order\}} : type := \term
  \comindex{Program Fixpoint}
  \label{ProgramFixpoint}}

The structural fixpoint operator behaves just like the one of Coq
(see Section~\ref{Fixpoint}), except it may also generate obligations.
It works with mutually recursive definitions too.

\begin{coq_eval}
Admit Obligations.
\end{coq_eval}
\begin{coq_example}
Program Fixpoint div2 (n : nat) : { x : nat | n = 2 * x \/ n = 2 * x + 1 } :=
  match n with
  | S (S p) => S (div2 p)
  | _ => O
  end.
\end{coq_example}

Here we have one obligation for each branch (branches for \verb:0: and \verb:(S 0): are
automatically generated by the pattern-matching compilation algorithm).
\begin{coq_example}
  Obligation 1.
\end{coq_example}

One can use a well-founded order or a measure as termination orders using the syntax:
\begin{coq_eval}
Reset Initial.
Require Import Arith.
Require Import Program.
\end{coq_eval}
\begin{coq_example*}
Program Fixpoint div2 (n : nat) {measure n} :
  { x : nat | n = 2 * x \/ n = 2 * x + 1 } :=
  match n with
  | S (S p) => S (div2 p)
  | _ => O
  end.
\end{coq_example*}

The order annotation can be either:
\begin{itemize}
\item {\tt measure f (R)?} where {\tt f} is a value of type {\tt X}
  computed on any subset of the arguments and the optional
  (parenthesised) term {\tt (R)} is a relation
  on {\tt X}. By default {\tt X} defaults to {\tt nat} and {\tt R} to
  {\tt lt}.
\item {\tt wf R x} which is equivalent to {\tt measure x (R)}.
\end{itemize}

\paragraph{Caution}
When defining structurally recursive functions, the
generated obligations should have the prototype of the currently defined functional
in their context. In this case, the obligations should be transparent
(e.g. defined using {\tt Defined}) so that the guardedness condition on
recursive calls can be checked by the
kernel's type-checker. There is an optimization in the generation of
obligations which gets rid of the hypothesis corresponding to the
functionnal when it is not necessary, so that the obligation can be
declared opaque (e.g. using {\tt Qed}). However, as soon as it appears in the
context, the proof of the obligation is \emph{required} to be declared transparent.

No such problems arise when using measures or well-founded recursion.

\subsection{\tt Program Lemma {\ident} : type.
  \comindex{Program Lemma}
  \label{ProgramLemma}}

The \Russell\ language can also be used to type statements of logical
properties. It will generate obligations, try to solve them
automatically and fail if some unsolved obligations remain.
In this case, one can first define the lemma's
statement using {\tt Program Definition} and use it as the goal afterwards.
Otherwise the proof will be started with the elobarted version as a goal.
The {\tt Program} prefix can similarly be used as a prefix for {\tt Variable}, {\tt
  Hypothesis}, {\tt Axiom} etc...

\section{Solving obligations}
The following commands are available to manipulate obligations. The
optional identifier is used when multiple functions have unsolved
obligations (e.g. when defining mutually recursive blocks). The optional
tactic is replaced by the default one if not specified.

\begin{itemize}
\item {\tt [Local|Global] Obligation Tactic := \tacexpr}\comindex{Obligation Tactic}
  Sets the default obligation
  solving tactic applied to all obligations automatically, whether to
  solve them or when starting to prove one, e.g. using {\tt Next}.
  Local makes the setting last only for the current module. Inside
  sections, local is the default.
\item {\tt Show Obligation Tactic}\comindex{Show Obligation Tactic}
  Displays the current default tactic.
\item {\tt Obligations [of \ident]}\comindex{Obligations} Displays all remaining
  obligations.
\item {\tt Obligation num [of \ident]}\comindex{Obligation} Start the proof of
  obligation {\tt num}.
\item {\tt Next Obligation [of \ident]}\comindex{Next Obligation} Start the proof of the next
  unsolved obligation.
\item {\tt Solve Obligations [of \ident] [with
    \tacexpr]}\comindex{Solve Obligations}
  Tries to solve
  each obligation of \ident using the given tactic or the default one.
\item {\tt Solve All Obligations [with \tacexpr]} Tries to solve
  each obligation of every program using the given tactic or the default
  one (useful for mutually recursive definitions).
\item {\tt Admit Obligations [of \ident]}\comindex{Admit Obligations}
  Admits all obligations (does not work with structurally recursive programs).
\item {\tt Preterm [of \ident]}\comindex{Preterm}
  Shows the term that will be fed to
  the kernel once the obligations are solved. Useful for debugging.
\item {\tt Set Transparent Obligations}\optindex{Transparent Obligations}
  Control whether all obligations should be declared as transparent (the
  default), or if the system should infer which obligations can be declared opaque.
\item {\tt Set Hide Obligations}\optindex{Hide Obligations}
  Control whether obligations appearing in the term should be hidden
  as implicit arguments of the special constant
  \texttt{Program.Tactics.obligation}.
\item {\tt Set Shrink Obligations}\optindex{Shrink Obligations}
  Control whether obligations defined by tactics should have their
  context minimized to the set of variables used in the proof of the
  obligation, to avoid unnecessary dependencies.
\end{itemize}

The module {\tt Coq.Program.Tactics} defines the default tactic for solving
obligations called {\tt program\_simpl}. Importing
{\tt Coq.Program.Program} also adds some useful notations, as documented in the file itself.

\section{Frequently Asked Questions
  \label{ProgramFAQ}}

\begin{itemize}
\item {Ill-formed recursive definitions}
  This error can happen when one tries to define a
  function by structural recursion on a subset object, which means the Coq
  function looks like:

  \verb$Program Fixpoint f (x : A | P) := match x with A b => f b end.$

  Supposing $b : A$, the argument at the recursive call to f is not a
  direct subterm of x as b is wrapped inside an {\tt exist} constructor to build
  an object of type \verb${x : A | P}$.  Hence the definition is rejected
  by the guardedness condition checker. However one can use
  wellfounded recursion on subset objects like this:

\begin{verbatim}
Program Fixpoint f (x : A | P) { measure (size x) } :=
  match x with A b => f b end.
\end{verbatim}

  One will then just have to prove that the measure decreases at each recursive
  call. There are three drawbacks though:
  \begin{enumerate}
  \item A measure function has to be defined;
  \item The reduction is a little more involved, although it works well
    using lazy evaluation;
  \item Mutual recursion on the underlying inductive type isn't possible
    anymore, but nested mutual recursion is always possible.
  \end{enumerate}
\end{itemize}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "Reference-Manual"
%%% compile-command: "BIBINPUTS=\".\" make QUICK=1 -C ../.. doc/refman/Reference-Manual.pdf"
%%% End:


% comparison results (number of nodes expanded, time, etc.) for the path finding problemsas the Pacman plans and replans in the environment; figures are helpful here.

\section{Evaluation}\label{sec:eval}
	\subsection{Configuration and Metrics}
    The four metrics used to measure the performance of the search algorithms were path length, nodes expanded, memory usage, and running time. Path length describes the length of the final path that Pacman took in order to find the goal state. This path is the same path that is visualized in the Pacman environment. Nodes expanded measures the number of nodes that needed to be expanded, i.e. popped from the priority queue in order to complete the search. The nodes expanded metric is linked to both time and space complexity. This is because the more nodes expanded, the longer the search will take. Also, the more nodes expanded, the deeper the queue, and the more space is needed to store those nodes in the queue. Memory use describes the maximum amount of memory used at a given point in time (in MB) by the Pacman Python process. The memory usage was  captured using the $\texttt{valgrind}$ utility. Running time captures the effective amount of time was needed to guide the agent to the goal location. The runtime was captures by using the linux $\texttt{time}$ command.

    All of these metrics were measured as a function of maze size, i.e. the effective area of a the Pacman maze in test. Note that there is not a direct linear relationship between maze size and search complexity, since the maze size does not capture other factors, such as complexity or wall count. However, the maze size is correlated with search complexity and in general, the larger the maze size, the more complex the search problem.

    A* search was also included as a baseline comparison. Note that the A* algorithm has a totally observable environment, whereas the other three algorithms only have a partially observable environment, namely the 4 adjacent cells in the Pacman environment.

    The experiments were run using a machine with 8-core Intel i5 1.6 GHz processor and 12 GB of RAM.

    \subsection{Experiments and Discussion}

    We executed and collected metrics for each search algorithm against four different environments: the pre-defined tiny (7x7), small (22x10), medium (36x18), and big (37x37) mazes of the Pacman domain. Results were tabulated, graphed, and the decision was made to switch the units to logarithmic for better visibility. Each approach was executed once, as the pathfinding process for these algorithms is deterministic.

	For all algorithms, the path lengths increase with respect to the maze size (see Figure 1). The A* algorithm has the best performance as expected, followed by NRA* and D* Lite, and finally be LPA*. The explanation for the low performance of LPA* is that it continually backtracks to the intersection point, which contributes to the path cost.

\begin{figure}[t]
	\centering
	\includegraphics[width=7cm]{PathLength.png}
	\caption{Path Length v. Maze Size}
	\label{fig:1}
\end{figure}

	\begin{figure}[t]
		\centering
		\includegraphics[width=7cm]{NodesExpanded.png}
		\caption{Nodes Expanded v. Maze Size}
		\label{fig:2}
	\end{figure}

	\vspace{-0mm}
	For all algorithms, the number of nodes expanded increases with respect to the maze size (see Figure 2). The order of performance from best to worst is as expected: A*, D* Lite, LPA*, and NRA*. The low performance for NRA* can be explained by the re-planning nature of its implementation. Every time it hits a wall on its expected path, it re-plans from scratch, i.e. the nodes explored and nodes in its fringe are not carried over when calling A* again. This is what LPA* and D* Lite aim to avoid.

	\begin{figure}[t]
		\centering
		\includegraphics[width=7cm]{Memory.png}
		\caption{Memory v. Maze Size}
		\label{fig:3}
	\end{figure}

	For all algorithms, the amount of memory increases with respect to the maze size (see Figure 3). The order of performance from best to worst is: D* Lite, NRA*, A*, and finally LPA*. D* Lite slightly out-performs all other algorithms because of specific measures it takes to only re-evaluate those nodes that will have an affect on the final path. Again, the low performance of LPA* is due to the backtracking nature. This is somewhat counterintutive, as A* and NRA* do not maintain in-memory structures of the same complexity as the other two; we conclude that the memory usage is likely dominated by the Pacman domain implementation itself, as memory usage and path length are highly correlated.

	\begin{figure}[t]
		\centering
		\includegraphics[width=7cm]{Time.png}
		\caption{Runtime v. Maze Size}
		\label{fig:4}
	\end{figure}

	For all algorithms, the runtime  increases with respect to the maze size (see Figure 4). A* and D* Lite are the best performers, with alternating dominance. Interestingly, this shows that even if the agent has partially observable environment information, it can potentially perform just as fast or faster than an agent with total observability of the environment, using the right strategy, namely D* Lite in this case. This is because A* follows a ``perfectionist" strategy, and finding the optimal route may take computational longer than the ``good enough" route found by D* Lite. These are followed by NRA* and finally LPA*. These two struggle due to their re-planning or backtracking natures, respectively.

	Overall, D* Lite is the most competitive of the re-planning algorithms, especially in computation time. LPA* was not as competitive as we expected, primarily due to the backtracking process necessitated by the Pacman domain integration.


\section{Channels}
\subsection{Purpose}
This program permits some conditioning of a stream of photons. The two currently-supported tasks are a time or pulse offset for each channel, and the complete suppression of signal on a channel. This can be useful for dealing with data where a channel is not useful, or which exhibits a significant time offset from another.

This program retains the sortedness of the time-offset stream.

\subsection{Command-line syntax}
%\input{programs/channels.usage}

\subsubsection{Input}
The input is a stream of T2 or T3 photons.

\subsubsection{Output}
The output is a stream of T2 or T3 photons, with appropriate modifications made. The stream remains sorted.

\subsection{Examples of usage}
\subsubsection{Suppressing a channel}
\begin{verbatim}
> picoquant --file-in data.ht3 |
  channels --mode t3 --channels 4
           --suppress 3
0,5425,81920
0,130044,43280
2,165687,66856
0,207951,6880
1,216750,20704
...
\end{verbatim}

\subsubsection{Offsetting a channel}
\begin{verbatim}
> picoquant --file-in data.ht3 |
  channels --mode t3 --channels 4
           --pulse-offsets 0,0,-100000,0
0,5425,81920
3,18404,69612
3,24332,55816
2,65687,66856
3,119890,71728
3,120337,86164
0,130044,43280
...
\end{verbatim}

\subsubsection{Suppressing one channel, while offsetting another}
\begin{verbatim}
> picoquant --file-in data.ht3 |
  channels --mode t3 --channels 4
           --pulse-offsets 0,0,-100000,0
           --suppress 3
0,5425,81920
2,65687,66856
0,130044,43280
0,207951,6880
1,216750,20704
...
\end{verbatim}

\subsection{Implementation}
The two tasks in this program are separate but closely related. The stream is processed photon-by-photon, and with each passing photon a list of channels is checked to see whether the photon is to be processed. If it is, time and pulse offsets are applied and it is added to a preallocated queue, and the process continues until the queue is full. At that point, the photons in the queue are sorted, up to the photons which could be unsorted. This is specified by the maximal difference in time (T2) or pulse (T3) between any two offset channels, so any photon which is not as distance from the final photon as this difference could still be unsorted.

For example, if channel 0 has an offset of -10 and the following photons are produced, the first two are certainly sorted:
\begin{verbatim}
0,-10
1,1
1,20
\end{verbatim}
All further photons from channel 1 will have a time of at least 20, but photons from channel 0 could have a time of 10 or less, once the time offset is applied. But the photon (1,1) could not be affected, because even a photon on channel 0 with initial time 20 would only have an offset time of 10, and thus the first two photons are guaranteed to be sorted.

Once the valid photons are yielded, processing continues in this fashion until the end of the stream is reached, at which point the remaining photons are sorted and yielded.

The algorithm goes roughly as follows:
\lstset{language=Python}
\begin{lstlisting}
photon_queue = list()
max_offset_difference = max(offsets) - min(offsets)

for photon in photons:
    if not suppress(photon):
        photon_queue.append(photon)

    if photon_queue.full():
        photon_queue.sort()
        for photon in photon_queue:
             if distance(photon_queue.back(), photon)
                 > max_offset_difference:
                 yield(photon)
                 photon_queue.pop(photon)
\end{lstlisting}

The act of suppressing photons costs nearly nothing, so the sorting and yielding process is the most expensive part of this program. The current algorithm used to sort the photons is quicksort (from the standard C library), though it is possible that others exist which are more effective for dealing with nearly-sorted lists. Overall, the cost of sorting the photons in small chunks ($2^{10}$ at a time, by default) is low compared to other operations, and at worst costs O($\abs{\photons}\ln{\abs{\photons}}$).


\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{float}
\usepackage{a4wide}
\usepackage{hyperref}
\usepackage{alltt}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{calc}
\usepackage[3D]{movie15}
\usepackage{attachfile}
\usepackage{cleveref}

\usetikzlibrary{3d,calc,fadings,decorations.pathreplacing}
\usetikzlibrary{decorations.pathmorphing,decorations.markings,trees,positioning,arrows}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}

\attachfilesetup{
appearance=true
}

\input{//sol.ita.chalmers.se/groups/bom-kt/VC_Sem/Betongbyggnad_KG/Projekt/1047Klorid_transport/Misc/LaTeX/newcommands_Filip.tex}

\title{Heterogeneous 3D model of concrete}
\begin{document}
\maketitle

\begin{abstract}
Documentation of heterogeneous 3D model of concrete written in MATLAB by \filip. The model implementation solves the heat/diffusion equation both for stationary and transient conditions. All MATLAB code required to use the model is attached to this PDF. Just click the pins to open each \verb|*.m|-file.
\end{abstract}

\tableofcontents

\newpage

\section{MATLAB files}

\subsection{\texttt{SVEGenerator.m} \attachfile[
    icon=PushPin,
    author=SVEGenerator.m,
    description=doubleclick to open in MATLAB
]{\pathtothreede/preprocessor/SVEGenerator.m}
}
\begin{itemize}
\item generates random structured SVE.
\item saves topology data for input to \verb|PreProcessor.m|.
\end{itemize}

\subsection{\texttt{computeDiffusivity.m} \attachfile[
    icon=PushPin,
    author=computeDiffusivity.m,
    description=doubleclick to open in MATLAB
]{\pathtothreede/solvers/computeDiffusivity.m}
}
\begin{itemize}
\item works as a wrapper around LinStatSolver.m and StatPostProcessor.m to compute the 9 components of the homogenized diffusivity tensor.
\item the implementation is parallelized for speed.
\item requires nothing.
\end{itemize}

\subsection{\texttt{PreProcessor.m} \attachfile[
    icon=PushPin,
    author=PreProcessor.m,
    description=doubleclick to open in MATLAB
]{\pathtothreede/preprocessor/PreProcessor.m}
}
\begin{itemize}
\item discretizes SVE to structured grid.
\item creates and saves topology matrices for input to the processor files.
\item requires input data generated by \verb|SVEGenerator.m|.
\end{itemize}

\subsection{\texttt{findITZ.m} \attachfile[
    icon=PushPin,
    author=findITZ.m,
    description=doubleclick to open in MATLAB
]{\pathtothreede/preprocessor/findITZ.m}
}
\begin{itemize}
\item computes $A_\itz, V_\ballast$ and $V_\cement$ in \cref{interfaceVoxel}.
\item called by \verb|PreProcessor.m|.
\end{itemize}

\subsection{\texttt{LinStatSolver.m} \attachfile[
    icon=PushPin,
    author=LinStatSolver.m,
    description=doubleclick to open in MATLAB
]{\pathtothreede/solvers/LinStatSolver.m}
}
\begin{itemize}
\item Solves the linear system of equations, $\ts{K}\ta{a} = \ta{f}$.
\item Dirichlet and convective boundary conditions types are implemented.
\item requires input data generated by \verb|PreProcessor.m|.
\end{itemize}

\subsection{\texttt{LinTransSolver.m} \attachfile[
    icon=PushPin,
    author=LinTransSolver.m,
    description=doubleclick to open in MATLAB
]{\pathtothreede/solvers/LinTransSolver.m}
}
\begin{itemize}
\item Solves the linear system of equations, $\ts{C}\dot{\ta{a}} + \ts{K}\ta{a} = \ta{f}$.
\item convective boundary conditions types are implemented.
\item requires input data generated by \verb|PreProcessor.m|.
\end{itemize}

\subsection{\texttt{StatPostProcessor.m} \attachfile[
    icon=PushPin,
    author=StatPostProcessor.m,
    description=doubleclick to open in MATLAB
]{\pathtothreede/postprocessor/StatPostProcessor.m}
}
\begin{itemize}
\item post processor routine for \verb|LinStatSolver.m|
\item generates \verb|.vtk| file which can be imported to eg Paraview for visualization.
\end{itemize}

\subsection{\texttt{TransPostProcessor.m} \attachfile[
    icon=PushPin,
    author=TransPostProcessor.m,
    description=doubleclick to open in MATLAB
]{\pathtothreede/postprocessor/TransPostProcessor.m}
}
\begin{itemize}
\item post processor routine for \verb|TransStatSolver.m|
\item generates \verb|.vtk| file which can be imported to eg Paraview for visualization.
\end{itemize}

\section{Element node numbering}

\begin{figure}[H]
\centering
\begin{tikzpicture}[decoration={
    markings,
    mark=at position 0.5 with {\arrow{>}}}]
\pgfmathsetmacro{\cubex}{4}
\pgfmathsetmacro{\cubey}{4}
\pgfmathsetmacro{\cubez}{4}

\coordinate (A) at (0,0,0);
\coordinate (B) at (\cubex,0,0);
\coordinate (C) at (\cubex,0,-\cubez);
\coordinate (D) at (0,0,-\cubez);
\coordinate (E) at (0,\cubey,0);
\coordinate (F) at (\cubex,\cubey,0);
\coordinate (G) at (\cubex,\cubey,-\cubez);
\coordinate (H) at (0,\cubey,-\cubez);

\draw[line width=1pt,->] (-4,0,0) -- (-3,0,0) node[below] {$x$};
\draw[line width=1pt,->] (-4,0,0) -- (-4,1,0) node[left] {$z$};
\draw[line width=1pt,->] (-4,0,0) -- (-4,0,-1.5) node[right] {$y$};

% Segment lines
\draw[line width=1pt,postaction={decorate}] (A) -- (B) node[draw,rectangle,midway,below=2mm] {$1$};
\draw[line width=1pt,postaction={decorate}] (B) -- (C) node[draw,rectangle,midway,right=2mm] {$2$};
\draw[line width=1pt,postaction={decorate}] (D) -- (C) node[draw,rectangle,midway,below=2mm] {$3$};
\draw[line width=1pt,postaction={decorate}] (A) -- (D) node[draw,rectangle,midway,right=2mm] {$4$};

\draw[line width=1pt,postaction={decorate}] (E) -- (F) node[draw,rectangle,midway,above=2mm] {$5$};
\draw[line width=1pt,postaction={decorate}] (F) -- (G) node[draw,rectangle,midway,left=2mm] {$6$};
\draw[line width=1pt,postaction={decorate}] (H) -- (G) node[draw,rectangle,midway,above=2mm] {$7$};
\draw[line width=1pt,postaction={decorate}] (E) -- (H) node[draw,rectangle,midway,left=2mm] {$8$};

\draw[line width=1pt,postaction={decorate}] (A) -- (E) node[draw,rectangle,midway,left=2mm] {$9$};
\draw[line width=1pt,postaction={decorate}] (B) -- (F) node[draw,rectangle,midway,right=2mm] {$10$};
\draw[line width=1pt,postaction={decorate}] (C) -- (G) node[draw,rectangle,midway,right=2mm] {$11$};
\draw[line width=1pt,postaction={decorate}] (D) -- (H) node[draw,rectangle,midway,left=2mm] {$12$};

% Node numbering
\begin{scope}[nodes={inner sep=2pt,draw,circle}]
\node[left=2mm] at (A) {$1$};
\node[right=2mm] at (B) {$2$};
\node[right=2mm] at (C) {$3$};
\node[left=2mm] at (D) {$4$};
\node[left=2mm] at (E) {$5$};
\node[right=2mm] at (F) {$6$};
\node[right=2mm] at (G) {$7$};
\node[left=2mm] at (H) {$8$};
\end{scope}

\end{tikzpicture}
\caption{Node numbers in circles and line segments in rectangles.}
\end{figure}

\section{ITZ implementation}

\begin{figure}[H]
\centering
\scalebox{1.5}{
\begin{tikzpicture}
\pgfmathsetmacro{\cubex}{2}
\pgfmathsetmacro{\cubey}{2}
\pgfmathsetmacro{\cubez}{2}

\coordinate (A) at (0,0,0);
\coordinate (B) at (\cubex,0,0);
\coordinate (C) at (\cubex,0,-\cubez);
\coordinate (D) at (0,0,-\cubez);
\coordinate (E) at (0,\cubey,0);
\coordinate (F) at (\cubex,\cubey,0);
\coordinate (G) at (\cubex,\cubey,-\cubez);
\coordinate (H) at (0,\cubey,-\cubez);

\draw[dashed,line width=1pt] (A) -- (D) -- (C);
\draw[dashed,line width=1pt] (D) -- (H);

\path[fill=gray,opacity=0.3] ($(A)!.30!(E)$) -- ($(B)!.45!(F)$) -- (F) -- (E) -- cycle;
\path[fill=gray,opacity=0.3] ($(B)!.45!(F)$) -- ($(C)!.55!(G)$) -- (G) -- (F) -- cycle;
\path[fill=gray,opacity=0.3] (E) -- (F) -- (G) -- (H) -- cycle;

\draw[line width=1pt] (A) -- (B) -- (F) -- (E) -- cycle;
\draw[line width=1pt] (B) -- (C) -- (G) -- (F);
\draw[line width=1pt] (G) -- (H) -- (E);

% Normal
\draw[|->, >=stealth] ($(A)!.50!(G)$) -- ++(-75:1.0) node[below] {$\ts{n}$};

\path[fill=black] ($(A)!.25!(E)$) -- ($(A)!.30!(E)$) -- ($(B)!.45!(F)$) -- ($(B)!.40!(F)$) -- cycle;
\path[fill=black] ($(B)!.40!(F)$) -- ($(B)!.45!(F)$) -- ($(C)!.55!(G)$) -- ($(C)!.50!(G)$) -- cycle;

\path[fill=black,opacity=0.3] ($(A)!.30!(E)$) -- ($(B)!.45!(F)$) -- ($(C)!.55!(G)$) -- ($(D)!.40!(H)$) -- cycle;
\draw[line width=1pt] ($(A)!.30!(E)$) -- ($(B)!.45!(F)$) -- ($(C)!.55!(G)$) -- ($(D)!.40!(H)$) -- cycle;
\path[pattern=north west lines, pattern color=black] ($(A)!.30!(E)$) -- ($(B)!.45!(F)$) -- ($(C)!.55!(G)$) -- ($(D)!.40!(H)$) -- cycle;

% Annotation
\draw[o-] ($(E)!.50!(G)$) .. controls +(80:0.5) and +(180:0.5) .. ($(B)!1.60!(F)$) node[right] {$V_\ballast$};
\draw[o-] ($(B)!.20!(G)$) .. controls +(0:0.5) and +(180:0.5) .. (3,0.5) node[right] {$V_\cement$};
\draw[o-] ($(A)!.55!(G)$) .. controls +(45:0.5) and +(180:0.5) .. ($(E)!1.50!(F)$) node[right] {$A_\itz$};
\draw[|<->|,>=stealth] (A) ++(-90:0.5) -- ++(0:2) node[fill=white,midway] {$h$};
\draw[|<-,>=stealth] ($(A)!.25!(E)$) ++(180:0.32) -- ++(-90:0.4);
\draw[|<-,>=stealth] ($(A)!.30!(E)$) ++(180:0.32) -- ++(90:0.4) node[left] {$t$};

\end{tikzpicture}
}
\caption{Interface voxel.}
\label{interfaceVoxel}
\end{figure}

\subsection{Line-sphere intersection}

\begin{align}
d = -(\ta{l}\cdot(\ta{o}-\ta{c})) \pm \sqrt{(\ta{l}\cdot(\ta{o}-\ta{c}))^2 - (\ta{o}-\ta{c})^2 +r^2}
\end{align}

\subsection{Voigt assumption}

\subsubsection{Isotropic}
\begin{align}
\bar{D} = \frac{1}{2}(D_\text{a}+D_\text{c}) + \frac{t}{h}D_\text{ITZ}
\end{align}

\subsubsection{Anisotropic}
\begin{align}
\bar{\ts{D}} = \frac{V_\text{a}D_\text{a} + V_\text{c}D_\text{c}}{V_\text{a}+V_\text{c}}\ts{I} + \frac{A_\text{ITZ}D_\text{ITZ}t}{V_\text{a}+V_\text{c}}\left(\ts{I} - \ta{n}\otimes\ta{n}\right)
\end{align}

\end{document}


\section{Concurrent Object-Oriented Calculus}

\begin{frame}
\frametitle{Concurrent Object-Oriented Calculus}
\framesubtitle{Featherweight Java}

\begin{definition}
Featherweight Java (FJ) is a generic name for Java-related core calculi, an object-oriented core language.
\end{definition}

The calculus used is a variant of Featherweight Java with destructive field updates, concurrency and explicit lock support, but without inheritance and type casts.
\end{frame}

\begin{frame}
\frametitle{Concurrent Object-Oriented Calculus}
\framesubtitle{Abstract Syntax Tree}
\begin{center}
  \begin{minipage}{0.8\linewidth}
    \begin{grammar}
    <D> $\coloncolonequals$ class C($\vec{f}:\vec{T}$) \{$\vec{f}:\vec{T}; \vec{M}$\}

    <M> $\coloncolonequals$ m($\vec{x}:\vec{T}$)\{t\}:T

    <t> $\coloncolonequals$ stop | error | v | let x:T = e in t

    <e> $\coloncolonequals$ t | if v then e else e | v.f | v.f := v
        \indalt v.m($\vec{v}$) | spawn t
        \indalt new C($\vec{v}$) | new L
        \indalt v.lock | v.unlock
        \indalt if v trylock then e else e

    <v> $\coloncolonequals$ r | x | ()

    <T> $\coloncolonequals$ C | B | Unit | L
    \end{grammar}
  \end{minipage}
\end{center}
\end{frame}

\begin{frame}
\frametitle{Concurrent Object-Oriented Calculus}
\framesubtitle{Abstract Syntax Tree - Thread Syntax}
\begin{center}
  \begin{minipage}{0.8\linewidth}
    \begin{grammar}
    <D> $\coloncolonequals$ class C($\vec{f}:\vec{T}$) \{$\vec{f}:\vec{T}; \vec{M}$\}

    <M> $\coloncolonequals$ m($\vec{x}:\vec{T}$)\{t\}:T
\end{grammar}
    \fcolorbox{red}{yellow}{
    \minipage[t]{\linewidth}
    \begin{grammar}
        <t> $\coloncolonequals$ stop | error | v | let x:T = e in t
    \end{grammar}
    \endminipage}\hfill
\begin{grammar}
    <e> $\coloncolonequals$ t | if v then e else e | v.f | v.f := v
        \indalt v.m($\vec{v}$) | spawn t
        \indalt new C($\vec{v}$) | new L
        \indalt v.lock | v.unlock
        \indalt if v trylock then e else e

    <v> $\coloncolonequals$ r | x | ()

    <T> $\coloncolonequals$ C | B | Unit | L
    \end{grammar}
\end{minipage}
\end{center}
\end{frame}

\begin{frame}
\frametitle{Concurrent Object-Oriented Calculus}
\framesubtitle{Abstract Syntax Tree - Expression Syntax}
\begin{center}
  \begin{minipage}{0.8\linewidth}
    \fcolorbox{red}{yellow}{
    \minipage[t]{\linewidth}
    \begin{grammar}
    <e> $\coloncolonequals$ t | if v then e else e | v.f | v.f := v
        \indalt v.m($\vec{v}$) | spawn t
        \indalt new C($\vec{v}$) | new L
        \indalt v.lock | v.unlock
        \indalt if v trylock then e else e
    \end{grammar}
    \endminipage}\hfill
\end{minipage}
\end{center}
\begin{itemize}
    \item \ccode{if v trylock then e else e} checks the availability of a lock v for the current thread, in which case v is taken
    \item \ccode{spawn t} starts a new thread which evaluates t in parallel with the spawning thread.
    \item \ccode{new L} dynamically creates a new thread
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Concurrent Object-Oriented Calculus}
\framesubtitle{Abstract Syntax Tree - Variable and Type Syntax}
\begin{center}
  \begin{minipage}{0.5\linewidth}
    \fcolorbox{red}{yellow}{
    \minipage[t]{\linewidth}
    \begin{grammar}
      <v> $\coloncolonequals$ r | x | ()
    \end{grammar}
    \endminipage}\hfill
\begin{itemize}
    \item $r$ = reference
    \item $x$ = variable
    \item $()$ = unit value
\end{itemize}
\end{minipage}
\end{center}

\begin{minipage}{0.8\linewidth}
    \fcolorbox{red}{yellow}{
    \minipage[t]{\linewidth}
    \begin{grammar}
    <T> $\coloncolonequals$ C | B | Unit | L
    \end{grammar}
    \endminipage}\hfill
\begin{itemize}
    \item $L$ = interface Lock from Java
    \item $B$ = basic types
    \item $C$ = class names
\end{itemize}
\end{minipage}
\end{frame}

Methodologies Software Processes/Assignments/Safe Locking for Multi-Threaded Java Presentation/slides/abstract_syntax_tree.tex


    \filetitle{length}{Length of tseries object}{tseries/length}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
n = length(x)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{x} {[} tseries {]} Tseries object.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{n} {[} numeric {]} - Number of periods from the first to the
  last available observation in the input tseries object.
\end{itemize}

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}


\documentclass{article}

\usepackage[affil-it]{authblk}

\usepackage[USenglish,american]{babel}

\usepackage{amsfonts,amsmath,amsthm,amssymb}

\usepackage{tikz}
\usepackage{float}
\setlength{\parindent}{0mm}
\setlength{\parskip}{.5em}
\usepackage[letterpaper, margin=1in]{geometry}
%\usepackage{showframe}
\usepackage{graphicx}

\usepackage{multicol,caption}
\setlength\columnsep{25pt}

\usepackage{enumerate}

\usepackage{verbatim}
\usepackage{listings}

\usepackage{siunitx}

\usepackage{color}

%%
%% Julia definition (c) 2014 Jubobs
%%
\lstdefinelanguage{Julia}%
  {morekeywords={abstract,break,case,catch,const,continue,do,else,elseif,%
      end,export,false,for,function,immutable,import,importall,if,in,%
      macro,module,otherwise,quote,return,switch,true,try,type,typealias,%
      using,while},%
   sensitive=true,%
   alsoother={$},%
   morecomment=[l]\#,%
   morecomment=[n]{\#=}{=\#},%
   morestring=[s]{"}{"},%
   morestring=[m]{'}{'},%
}[keywords,comments,strings]%

\lstset{%
    language         = Python,
    basicstyle       = \footnotesize\ttfamily,,
    keywordstyle     = \bfseries\color{blue},
    stringstyle      = \color{magenta},
    commentstyle     = \color{red},
    showstringspaces = false,
    backgroundcolor  = \color{lightgray},
    numbers          = left,
    title            = \lstname,
    numberstyle      = \tiny\color{lightgray}\ttfamily,
}

\usepackage{xspace}
\usepackage{url}
\usepackage{cite}

\usepackage{coffee4}

\newcommand{\Bold}{\mathbf}

\title{Denoising and Labeling Hydrophone Data}
\date{\today}
\author{Philip Robinson}
\affil{Oregon Health Sciences University}

\begin{document}

\maketitle

\begin{abstract}
  There is a need for an index of acoustic events and associated metadata for University of Hawaii's Aloha Cabled Observatory (ACO) hydrophone recordings. Currently searching the audio recordings is done at human pace by listening to the audio stream, which is prohibitive at approximately 10 years of content.
The proposal is to develop a processing system that creates simple data store of vocals and metadata associated with vocalization events, renders a denoised~\cite{Baskar2015StudyOD,specsub2008,Berouti1979EnhancementOS} copy of those vocalization events, and provide a simple time based retrieval system. The system is written using \texttt{python} and the \texttt{scipy}~\cite{Jones2001} libraries for signal processing. %
 The extended goal of this work is to use whale vocalization as a proxy measurement of migration patterns, and attempt to identify migratory changes against known climate events. In order to accomplish this task, noise in audio recording should be smoothed or removed, vocalizations must be localized/indexed, features of speech must be extracted, species must be identified~\cite{2014ASAJ} or clustered.
% , \texttt{ponyorm} for light weight authoring of data store, and \texttt{paramiko} if needed for accessing remote recordings of original data.
\end{abstract}

\begin{multicols}{2}

\section{Introduction}

University of Hawaii's ACO has approximately 10 years of hydrophone data, in need of indexing, labeling, and cleaning. To enable further research and bootstrap more advanced indexing techniques, a data retrieval, analysis, and labeling tool is Provided is a simple module enabling these three features. The module provided include:

\begin{itemize}
    \setlength\itemsep{0em}
\item reading \& listen to ACO encoded data
\item standard \texttt{datetime} units for navigation
\item parameterized visualizations for audio units
\item simple denoising via spectral subtraction
\item center wave by empirical mode decomposition
\end{itemize}

\section{Data Retrieval}

The ACO data is gathered at N$22^\circ45.110'$ W$158^\circ00'$.
The recordings are encoded as variable bit-width raw sensor readings (fixed-width for each chunk of 4096 samples). Each file is saved as a 5 minute chunk, named with it's datetime stamp. The set elected for this project was 24K samples per second (there exists a 96K as well).

\begin{figure}[H]
  \centering

\begin{lstlisting}
from aco import ACOio, datetime, timedelta

loader = ACOio('./basedir/')
target = datetime(
    day=18, month=2, year=2016,
    hour=7, minute=55
)

src = loader.load(datetime)
snip = src[
  timedelta(seconds=7):
  timedelta(seconds=11)
]
snip.View()
\end{lstlisting}

  \includegraphics[width=\columnwidth]{./rawwave.png}
  \caption{Raw Data}
  \label{fig:rawwav}

\end{figure}

It is visible, from \texttt{(Figure~\ref{fig:rawwav})} that the direct current gain is not centered at zero, nor trivially accumulative. This is a consequence of changes in atmospheric pressure, due to the ocean's motion, attenuating the signal. Without these changes in atmospheric pressure the current gain can be corrected by removing the mean of the original signal, however in this case empirical mode decomposition is used to yield more accurate results. This will be addressed in greater detail later.

\begin{figure}[H]
  \centering

  \includegraphics[width=\columnwidth]{./rawvocal.png}
  \caption{Raw Vocalization}
  \label{fig:rawvoc}

\end{figure}

It is also not obvious this track has a vocalization, highlighted in \texttt{(Figure~\ref{fig:rawvoc})}. This pattern is indicative of high amounts of noise. Usually, a better perspective is gained using the \texttt{logspectrum}, however as seen \texttt{(Figure~\ref{fig:rawspec})} this is mostly non-informative. This is for two reasons. Firstly, the dynamic range of the track is too great due to the direct current gain as mentioned above. Secondly, the sampling rate is too high, resulting in far too much data being expressed in a small amount of space, which this expensive run-time effects on complicated processing algorithms, like empirical mode decomposition.

\begin{figure}[H]
  \centering
\begin{lstlisting}
snip.View(
  'logspectrum',
  frame_duration=.08,
  frame_shift=.02
)

\end{lstlisting}
  \includegraphics[width=\columnwidth]{./rawspec.png}
  \caption{Raw Spectrogram}
  \label{fig:rawspec}

\end{figure}

\section{Spectral Subtraction}

Spectral subtraction is a technique used to denoise signals with additive white noise (like found in this application). It is also, a very cheap algorithm with many modifications~\cite{specsub2008}, which makes it an ideal first pass on the data.

The sampled signal $y$ is modeled as the desired signal $x$ and background noise $b$. \[y[n] = x[n] + b[n]\]
At a single frame at point $p$ and length $L$,
\begin{align*}
  Y(pL, \omega) &= X(pL, \omega) + B(pL, \omega)\\
  |Y(pL, \omega)|^2 &= |X(pL, \omega)|^2 \\&+|B(pL, \omega)|^2 + |X(pL, \omega)*B(pL, \omega)|\\
\end{align*}

We can estimate the background noise, given sufficiently small frames, by subtracting the mean power spectrum from a segment of only noise. Using Welch's method~\cite{welch1976} we are able to estimate the mean power spectrum.

\begin{figure}[H]

\begin{lstlisting}
def _spectral_subtraction(self, other,
    frame_duration=.08, frame_shift=.02,
    wtype='boxcar', alpha=5.0, beta=.01):

  Frames = self._Frame(
    frame_duration, frame_shift).data
  power = other.power(
    frame_duration, frame_shift, wtype)
  window = signal.get_window(
    wtype, self.to_frame_count(frame_duration))

  spectrum = np.fft.fft(Frames * window)
  amplitude = np.abs(spectrum)
  phase = np.angle(spectrum)

  _ = (amplitude ** 2.0) - (power * alpha)
  _ = np.maximum(_, beta * amplitude ** 2.0)
  _ = np.sqrt(_)
  _ = _ * np.exp(phase*1j)

  return _
\end{lstlisting}
  \caption{Spectral Subtraction}
  \label{fig:subtractpy}

\end{figure}

Rather than the original spectral subtraction algorithm, \texttt{(Figure~\ref{fig:subtractpy})} implements the algorithm found in ~\cite{Berouti1979EnhancementOS}. This allows for adjustable $\alpha$ and $\beta$ parameters, used in tuning some audio artifacts consequent of spectral subtraction.

From \texttt{(Figure~\ref{fig:subtract})} it is much easier to see the vocalization section in the waveform. It is apparent that the spectrogram has less noise, but not necessarily in a useful way. This is due to the dynamic range and resolution problems mentioned above.

\begin{figure}[H]
  \centering

  \begin{comment}
\begin{lstlisting}
noise = snip[
  timedelta(seconds=0):
  timedelta(seconds=.8)]
clean = snip.subtract(noise)
clean.View()
clean.View('logspectrogram')
\end{lstlisting}
\end{comment}

  \includegraphics[width=\columnwidth]{./subwave.png}
  \includegraphics[width=\columnwidth]{./subspec.png}

  \caption{After Subtraction}
  \label{fig:subtract}

\end{figure}

\begin{figure}[H]
  \centering
  \begin{lstlisting}
noise = snip[
  timedelta(seconds=0):
  timedelta(seconds=.8)
]
clean = snip.subtract(noise)
down = clean.resample(40000)
down.View(
  'logspectrum',
  frame_duration=.08,
  frame_shift=.02
)
\end{lstlisting}
\includegraphics[width=\columnwidth]{./downspec.png}
  \caption{After Resamling}
  \label{fig:resample}

\end{figure}

Down sampling the data, as shown \texttt{(Figure~\ref{fig:resample})}, gives us the first visible pattern in the spectrogram. It is faint, due to far too high of dynamic range in the waveform.

\section{Empirical Mode Decomposition}

Empirical Mode Decomposition is used to address the variable gain found in this waveform, and allow us a more informative exploratory data analysis. Empirical mode decomposition expresses the current waveform as a summation of sine functions of learned mode. The results are stored, ordered by highest to lowest frequency. We can sum the first $k$ levels of the yield to capture the majority of data and audible effects, while ignoring the low order functions (that encode the gain).

This is a computationally expensive procedure, that benefits from the down sampling step.

\begin{figure}[H]
  \centering
  \begin{lstlisting}
centered = down.remove_dc(levels=13)
centered.View()
centered.View(
  'logspectrum',
  frame_duration=.08,
  frame_shift=.02
)
\end{lstlisting}
  \includegraphics[width=\columnwidth]{./centered.png}
  \includegraphics[width=\columnwidth]{./centeredspec.png}
  \caption{After EMD}
  \label{fig:emd}

\end{figure}

\section{Labeling}

With this level of granularity, we can correctly label our original dataset using both auditory and visual queues.

\begin{figure}[H]
  \centering
  \begin{lstlisting}
noise.label_src_as_noise()
centered[
  timedelta(seconds=0.88):
  timedelta(seconds=2.48)
].label_src_as_voice()
\end{lstlisting}

  \caption{Label Sections of Audio}
  \label{fig:labeling}
\end{figure}

\section{Results}

With the right parameters, this works very well to clean the data visually and audibly. Unfortunately, not all theses parameters have obvious or predictable trends. The goal of being able to with high precision label vocalization for later learned methods is definitely hit, and the ability to encode metadata enabling better audio track retrieval for human perception is on its way.

The code in its current form can be found here\footnote{https://github.com/probinso/Whales} with documentation coming soon. Once the datastore is setup in a shared location, there will be more opportunities for community contributions.

Finally, some of the parameters elected for this paper are not best fit, but better represent the challenges faced in this project. Actually a level of 5 and a resample of 10000 yield the audio files attached with the report.

\begin{comment}
\section{Prior Work}
\section{Methods}
\section{Materials}
\section{Results}
\section{Discussion}
\subsection{Study Assumptions}
\end{comment}
\bibliography{references.bib}{}
\bibliographystyle{plain}

\end{multicols}

\end{document}


\section{Clinical stratification} \label{clin}
% Note that this file describes only one implementation of the clinical stratification possible in the sm_sir code
\subsection{Stratification structure}
The ``clinical" stratification acts by replicating each of the two age-stratified sequential compartments representing infectious COVID-19 into three categories.
The three clinical categories are:
\begin{enumerate}
    \item Asymptomatic persons
    \item Symptomatic persons who are never notified as cases
    \item Symptomatic persons who are successfully detected and notified
\end{enumerate}
For each age category, a proportion of new active infections are assumed to remain asymptomatic throughout their infectious period (specified in Table \ref{tab:age_params}).
This proportion remains fixed over time throughout a model run.
It is assumed that asymptomatic persons are never detected and so do not contribute to notifications.
The remaining proportion constitutes the second and third categories, comprising all persons developing symptomatic COVID-19 during their infectious period.
The proportion of these symptomatic persons who progress to the third category varies with time and is described under the section on case detection (Section \ref{cdr}).
This approach differs from that presented in our previous COVID-19 modelling publications,
in that the earlier publications included additional stratification to distinguish those with detected COVID-19 according to disease severity.
In this analysis, mortality and health service burden are calculated through convolutions, as described below.
\begin{figure}[ht]
    \begin{center}
    \includegraphics[width=0.7\textwidth]{../../tex_descriptions/models/sm_sir/stratifications/clinical_strat.pdf}
    \end{center}
    \caption{Illustration of the clinical stratification. \small Depth of red shading of compartment qualitatively indicates infectiousness.}
    \label{fig:seeiir}
\end{figure}
\subsection{Modification to infectiousness}
Both the early and late stages of the post-stratification infectious COVID-19 compartment are assumed to have reduced infectiousness,
according to the asymptomatic infectiousness parameter (in Table to be added).
The late stage of the detected (third) stratum has reduced infectiousness to represent case isolation,
with these persons having their infectiousness reduced according to the isolation infectiousness parameter (in Table to be added).


\documentclass[10pt,makeidx]{beamer}

\mode<presentation>
{
 \usetheme{Boadilla}
\pagestyle{empty}

\setbeamerfont*{frametitle}{size=\normalsize,series=\bfseries}
\setbeamerfont*{block}{size=\normalsize,series=\bfseries}
%\setbeamertemplate{blocks}[rounded][shadow=true]
}

\usepackage{epsfig,epstopdf}
\usepackage{etex}
% \usepackage{helvet}
\usepackage{amsmath, amssymb}
\usepackage{color}
\usepackage{asymptote}
\usepackage{mathrsfs}
\usepackage{dsfont}
\usepackage{makeidx}
\usepackage{multido}
\usepackage{adjustbox}
\usepackage{cancel}

\usepackage{pst-sigsys,pst-plot,pstricks-add}
\usepackage{pst-pdf}

\usepackage[american voltages, american currents,siunitx]{circuitikz}
%\sisetup{load=derived} % loading \siemens

\makeatletter
% create the shape
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/interr/height 2}}{spst}{\ctikzvalof{bipoles/interr/height}}{\ctikzvalof{bipoles/interr/width}}{

    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}

% make the shape accessible with nice syntax
\def\pgf@circ@spst@path#1{\pgf@circ@bipole@path{spst}{#1}}
\tikzset{switch/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@spst@path, l=#1}}
\tikzset{spst/.style = {switch = #1}}
\makeatother

\definecolor{links}{HTML}{2A1B81}
\hypersetup{colorlinks,linkcolor=,urlcolor=links}

\def\nn{\nonumber}

\definecolor{links}{HTML}{2A1B81}
\hypersetup{colorlinks,linkcolor=,urlcolor=links}

\title[]{RLC Circuits}
\author[\textcolor{blue}{Systems and Circuits}]{\textcolor{darkblue}{Pablo M. Olmos} (olmos@tsc.uc3m.es)\\ \textcolor{darkblue}{Emilio Parrado} (emipar@tsc.uc3m.es)}
\institute{\textcolor{white}{UC3M}}

\definecolor{darkblue}{rgb}{0.0, 0.0, 0.40}
\setbeamercolor{title}{fg=darkblue}
\setbeamercolor{frametitle}{fg=darkblue}
\definecolor{darkgreen}{rgb}{0.0, 0.4, 0.0}%

\AtBeginSection[]
{
  \begin{frame}<beamer>{Index}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}

\begin{document}
\frame{
\titlepage
\thispagestyle{empty}
\begin{center}
\includegraphics[scale=0.05]{Figures/uc3m-logo.pdf}
\end{center}
}

\section{General solution of the Second-order  differential equation}

\frame{
\frametitle{Second order  linear differential equation with constant coefficients}
Compute $y(t)$ such that $y(t_0)=y_0$, $\frac{dy(t)}{dt}|_{t=t_0}=y_1$ if
%\begin{align}\nn
%A\frac{dx(t)}{dt}+Bx(t)=C
%\end{align}
%where $A$, $B$ and $C$ are constants.
%
\begin{align}\nn
\frac{d^2y(t)}{dt^2}+2\alpha\frac{dy(t)}{dt}+\omega_0^2 y(t)=\gamma
\end{align}
where  $\alpha$, $\omega_0^2$ are real constants.

}

\frame{
\frametitle{Second order  linear differential equation with constant coefficients}
Compute $y(t)$ such that $y(t_0)=y_0$, $\frac{dy(t)}{dt}|_{t=t_0}=y_1$ if
%\begin{align}\nn
%A\frac{dx(t)}{dt}+Bx(t)=C
%\end{align}
%where $A$, $B$ and $C$ are constants.
%
\begin{align}\nn
\frac{d^2y(t)}{dt^2}+2\alpha\frac{dy(t)}{dt}+\omega_0^2 y(t)=\gamma
\end{align}
where  $\alpha$, $\omega_0^2$ are real constants.

\begin{alertblock}{Characteristic equation:}
$s_1$ and $s_2$ are the roots of the equation
\begin{align*}
s^2+ 2\alpha s+\omega_0^2=0
\end{align*}
Thus
\begin{align*}
s_1=-\alpha+\sqrt{\alpha^2-\omega_0^2}\qquad s_2=-\alpha-\sqrt{\alpha^2-\omega_0^2}
\end{align*}
\end{alertblock}

}

\frame{
\frametitle{Case $\alpha>\omega_0$: $s_1$ and $s_2$ are negative real constants}

\begin{block}{}
\begin{align*}
y(t)=A_1 \text{e}^{s_1 (t-t_0)}+ A_2 \text{e}^{s_2 (t-t_0)}+\frac{\gamma}{\omega^2_0}\qquad t\geq t_0,
\end{align*}
where $A_1$ and $A_2$ can be found using the initial conditions.
\end{block}

}

\frame{
\frametitle{Exercise}

Let $x(t)= 3u(t)$ be the input signal to a system defined by the following input/output relationship:
\begin{align*}
\frac{d^2y(t)}{dt^2}+6\frac{dy(t)}{dt}+5y(t)=x(t),
\end{align*}
where $y(t)$ is the output signal. If we know that $y(0)=0$ and  $\frac{dy(t)}{dt}|_{t=0}=0$, compute and plot $y(t)$.

}

\frame{
\frametitle{Sol.}

For $t\geq 0$, the equation that gives the output is a second-order differential equation of the form
\begin{align*}
\frac{d^2y(t)}{dt^2}+6\frac{dy(t)}{dt}+5 y(t)=3\qquad t\geq 0
\end{align*}

\begin{alertblock}{}
\begin{align*}
s^2+ 6 s+5=0\Rightarrow s_1=-3+\sqrt{9-5}=-1, s_2=-3-\sqrt{2}=-5
\end{align*}
\end{alertblock}

\begin{exampleblock}{}
\begin{align*}
y(t)=A_1  \text{e}^{-t}+ A_2 \text{e}^{-5t}+\frac{3}{5}\qquad t\geq 0
\end{align*}
\end{exampleblock}

Using the initial conditions we find $A_1=\frac{-3}{5}$ and $A_2=\frac{3}{25}$.

}

\frame{

\begin{figure}
\centering\includegraphics[scale=0.4]{Figures/overdamped.eps}
\end{figure}

The response of this system to the unit step is said to be \emph{overdamped}.

}

\frame{
\frametitle{Case $\alpha<\omega_0$: $s_1$ and $s_2$ are complex}

\begin{align*}
s_1=-\alpha+j\sqrt{\omega_0^2-\alpha^2}\qquad s_2=-\alpha-j\sqrt{\omega_0^2-\alpha^2}
\end{align*}
Define $\omega_d\doteq \sqrt{\omega_0^2-\alpha^2}$.

\begin{block}{}
\begin{align*}
y(t)=B_1 \text{e}^{-\alpha (t-t_0)}\cos(\omega_d (t-t_0))+B_2 \text{e}^{-\alpha (t-t_0)}\sin(\omega_d (t-t_0))+\frac{\gamma}{\omega^2_0} \qquad t\geq t_0,
\end{align*}
where $B_1$ and $B_2$ can be found using the initial conditions.
\end{block}

\begin{alertblock}{$\alpha=0$}
Oscillation around $\gamma/\omega_0^2$!! The solution \textbf{does not} converge to a constant value in the limit $t\rightarrow\infty$!!!
\end{alertblock}

}

\frame{
\frametitle{Exercise}

Let $x(t)= 3u(t)$ be the input signal to a system defined by the following input/output relationship:
\begin{align*}
\frac{d^2y(t)}{dt^2}+\frac{dy(t)}{dt}+5 y(t)=x(t),
\end{align*}
where $y(t)$ is the output signal. If we know that $y(0)=0$ and  $\frac{dy(t)}{dt}|_{t=0}=0$, compute and plot $y(t)$.

}

\frame{
\frametitle{Sol.}

For $t\geq 0$, the equation that gives the output is a second-order differential equation of the form
\begin{align*}
\frac{d^2y(t)}{dt^2}+\frac{dy(t)}{dt}+5 y(t)=3\qquad t\geq 0
\end{align*}

\begin{alertblock}{}
\begin{align*}
s^2+  s+5=0\Rightarrow s_1=-0.5+j\sqrt{4.75}, s_2=-0.5-j\sqrt{4.75}
\end{align*}
\end{alertblock}

\begin{exampleblock}{}
\begin{align*}
y(t)=B_1 \text{e}^{-\frac{t}{2}}\cos(\sqrt{4.75} t)+B_2 \text{e}^{-\frac{t}{2}}\sin(\sqrt{4.75} t)+\frac{3}{5} \qquad t\geq 0
\end{align*}
\end{exampleblock}

Using the initial conditions we find $B_1=\frac{-3}{5}$ and $B_2=\frac{3}{10\sqrt{4.75}}$ (check!).

}

\frame{

\begin{figure}
\centering\includegraphics[scale=0.4]{Figures/underdamped.eps}
\end{figure}

The response of this system to the unit step is said to be \emph{underdamped}.

}

\frame{
\frametitle{Case $\alpha=\omega$: $s_1=s_2=-\alpha$}

\begin{block}{}
\begin{align*}
y(t)=(D_1+D_2 (t-t_0)) \text{e}^{-\alpha (t-t_0)} \qquad t\geq t_0,
\end{align*}
where $D_1$ and $D_2$ can be found using the initial conditions.
\end{block}

}

\frame{
\frametitle{Exercise}

Let $x(t)= 3u(t)$ be the input signal to a system defined by the following input/output relationship:
\begin{align*}
\frac{d^2y(t)}{dt^2}+2\sqrt{5}\frac{dy(t)}{dt}+5y(t)=x(t),
\end{align*}
where $y(t)$ is the output signal. If we know that $y(0)=0$ and  $\frac{dy(t)}{dt}|_{t=0}=0$, compute and plot $y(t)$.

}

\frame{
\frametitle{Sol.}

For $t\geq 0$, the equation that gives the output is a second-order differential equation of the form
\begin{align*}
\frac{d^2y(t)}{dt^2}+2\sqrt{5}\frac{dy(t)}{dt}+5 y(t)=3\qquad t\geq 0
\end{align*}

\begin{alertblock}{}
\begin{align*}
s^2+ 2\sqrt{5} s+5=0\Rightarrow s_1=s_2=-\sqrt{5}
\end{align*}
\end{alertblock}

\begin{exampleblock}{}
\begin{align*}
y(t)=(D_1+D_2 t) \text{e}^{-\sqrt{5} t} +\frac{3}{5}\qquad t\geq t_0
\end{align*}
\end{exampleblock}

Using the initial conditions we find $D_1=\frac{-3}{5}$ and $D_2=\frac{-3}{\sqrt{5}}$.

}

\frame{

\begin{figure}
\centering\includegraphics[scale=0.4]{Figures/critically_damped.eps}
\end{figure}

The response of this system to the unit step is said to be \emph{critically damped}.

}

\section{RLC circuits}

\frame{
\frametitle{Example}

\begin{center}
\begin{circuitikz}[] \draw[black]
(-2,0) to[short,i>=$i(t)$] (-2,2)
(-2,2) to[L=$L$] (0,2)
to[R=$R$] (2,2)
to[C=$C$] (2,0)
(2,2) to[short,-*] (5,2)
(2,0) to[short,-*] (5,0)
(2,0) to[short](-2,0)
(5,2) to[open,v<=$V_C(t)$] (5,0);
\end{circuitikz}
\end{center}

\begin{block}{}
If $i(0)=i_0$ and $\frac{\partial i(t)}{\partial t}|_{t=0}=i'_0$, determine the differential equation for the current $i(t)$ for $t\geq 0$.
\end{block}

}

\frame{
\frametitle{Sol.}

\begin{center}
\begin{circuitikz}[] \draw[black]
(-2,0) to[short,i>=$i(t)$] (-2,2)
(-2,2) to[L=$L$,v<=$v_L(t)$] (0,2)
to[R=$R$] (2,2)
to[C=$C$] (2,0)
(2,2) to[short,-*] (5,2)
(2,0) to[short,-*] (5,0)
(2,0) to[short](-2,0)
(5,2) to[open,v<=$V_C(t)$] (5,0);
\end{circuitikz}
\end{center}

 KVL in the loop:

\begin{align*}
v_L(t)+i(t)R+V_C(t)=0
\end{align*}

 We express all terms as a function of $i(t)$:

\begin{align*}
v_L(t)&=L\frac{\partial i(t)}{\partial t}\\
v_C(t)&=\frac{1}{C}\int_{-\infty}^{t} i(\tau) d\tau
\end{align*}

}

\frame{
Thus
\begin{align*}
L\frac{\partial i(t)}{\partial t}+i(t)R+\frac{1}{C}\int_{-\infty}^{t} i(\tau) d\tau=0
\end{align*}

This equation can be transformed into a second order differential equation by computing the time-derivative at both sides of the equation...

\begin{align*}
L\frac{\partial^2 i(t)}{\partial t^2}+\frac{\partial i(t)}{\partial t}R+\frac{1}{C}i(t)=0
\end{align*}

To find the solution for $i(t)$ $t\geq 0$ using our "recipe", we divide by $L$ so the coefficient for $\frac{\partial^2 i(t)}{\partial t^2}$ is one...

\begin{align*}
\frac{\partial^2 i(t)}{\partial t^2}+\frac{R}{L} \frac{\partial i(t)}{\partial t}+\frac{1}{LC}i(t)=0
\end{align*}

}

\frame{
\begin{block}{}
\begin{columns}
\begin{column}{0.4\textwidth}
\begin{align}\nn
\frac{d^2y(t)}{dt^2}+2\alpha\frac{dy(t)}{dt}+\omega_0^2 y(t)=\gamma,
\end{align}
\end{column}
\begin{column}{0.25\textwidth}
\begin{align*}
s^2+ 2\alpha s+\omega_0^2=0,
\end{align*}
\end{column}
\begin{column}{0.35\textwidth}
\begin{align*}
s_{1,2}=-\alpha\pm\sqrt{\alpha^2-\omega_0^2}
\end{align*}
\end{column}
\end{columns}
\end{block}

We identify terms

\begin{align*}
\frac{\partial^2 i(t)}{\partial t^2}+\frac{R}{L} \frac{\partial i(t)}{\partial t}+\frac{1}{LC}i(t)=0\quad \Rightarrow \omega_0^2=\frac{1}{LC}, 2\alpha=R/L.
\end{align*}

\begin{exampleblock}{$s_{1,2}=-\frac{R}{2L}\pm\sqrt{\frac{R^2}{4L^2}-\frac{1}{LC}}$}
\begin{itemize}
\item $R>2\sqrt{\frac{L}{C}}\rightarrow$ real (negative) roots. Overdamped solution.
\item $R<2\sqrt{\frac{L}{C}}\rightarrow$ complex roots. Underdamped solution.
\item $R=2\sqrt{\frac{L}{C}}\rightarrow$ 2 equal roots. Critically damped solution.
\item $R=0\rightarrow$ Oscillation.
\end{itemize}
\end{exampleblock}

}

\frame{
\frametitle{Example}

\begin{center}
\begin{circuitikz}[] \draw[black]
(-2,0) to[I,i>=$I_s$] (-2,3)
to[short](0,3)
to[cspst,l^=\mbox{t=0}] (1,3)
to[short](6,3)
(-1,3) to[ospst, l^ = \mbox{t = 0}] (-1,0)
(1,3) to[L=$L$,i>=$i_L(t)$] (1,0)
(4,3) to[C=$C$,v<=$v_0(t)$] (4,0)
(6,3) to[R=$R$] (6,0)
to [short] (-2,0);
\end{circuitikz}
\end{center}

\begin{block}{}
Determine the differential equation for the current $i_L(t)$ for $t\geq 0$.
\end{block}

\begin{alertblock}{}
Determine the differential equation for the voltage  $v_0(t)$ for $t\geq 0$.
\end{alertblock}

}

\frame{

\begin{center}
\begin{circuitikz}[] \draw[black]
(-2,0) to[I,i>=$I_s$] (-2,3)
to[short](0,3)
to[short] (1,3)
to[short](6,3)
(-1,3) to[ospst] (-1,0)
(1,3) to[L=$L$,i>=$i_L(t)$] (1,0)
(4,3) to[C=$C$,v<=$v_0(t)$,i>=$i_C(t)$] (4,0)
(6,3) to[R=$R$,i>=$i_R(t)$] (6,0)
to [short] (-2,0)
(3,0) node[ground] {};
\end{circuitikz}
\end{center}

\begin{align*}
\text{ KCL: } I_s=i_L(t)+i_C(t)+i_R(t)
\end{align*}

\begin{itemize}
\item Inductor: $v_0(t)=L\frac{\partial i_L(t)}{\partial t}$
\item Resistor: $i_R(t)=v_0(t)/R=\frac{L}{R}\frac{\partial i_L(t)}{\partial t}$
\item Capacitor: $i_C(t)=C\frac{\partial v_0(t)}{\partial t}=CL \frac{\partial^2 i_L(t)}{\partial^2 t} $

\end{itemize}

}

\frame{
\begin{block}{}
\begin{columns}
\begin{column}{0.4\textwidth}
\begin{align}\nn
\frac{d^2y(t)}{dt^2}+2\alpha\frac{dy(t)}{dt}+\omega_0^2 y(t)=\gamma,
\end{align}
\end{column}
\begin{column}{0.25\textwidth}
\begin{align*}
s^2+ 2\alpha s+\omega_0^2=0,
\end{align*}
\end{column}
\begin{column}{0.35\textwidth}
\begin{align*}
s_{1,2}=-\alpha\pm\sqrt{\alpha^2-\omega_0^2}
\end{align*}
\end{column}
\end{columns}
\end{block}

Therefore
\begin{align*}
&CL \frac{\partial^2 i_L(t)}{\partial^2 t} + \frac{L}{R}\frac{\partial i_L(t)}{\partial t}+i_L(t)=I_s\\\\
%&\Rightarrow \frac{\partial^2 i_L(t)}{\partial^2 t}+ \frac{1}{RC}\frac{\partial i_L(t)}{\partial t}+\frac{1}{CL} i_L(t)=\frac{I_s}{CL}\\
&\Rightarrow \omega_0^2=\frac{1}{LC}, 2\alpha=\frac{1}{RC}, \gamma=\frac{I_s}{CL}
\end{align*}

\begin{exampleblock}{$s_{1,2}=-\frac{1}{2RC}\pm\sqrt{\frac{1}{4(RC)^2}-\frac{1}{LC}}$}
\begin{itemize}
\item $R<\frac{1}{2}\sqrt{\frac{L}{C}}\rightarrow$ real (negative) roots. Overdamped solution.
\item $R>\frac{1}{2}\sqrt{\frac{L}{C}}\rightarrow$ complex roots. Underdamped solution.
\item $R=\frac{1}{2}\sqrt{\frac{L}{C}}\rightarrow$ 2 equal roots. Critically damped solution.
\item $R=\infty\rightarrow$ Oscillation.
\end{itemize}
\end{exampleblock}

}

\frame{
\frametitle{Auxiliary conditions}
We need $i_L(0^+)$ and $\frac{\partial i_L(t)}{\partial t}|_{t=0^+}$. If the circuit has been operating for a long time before the switch is open, then the equivalent circuit is

\begin{center}
\begin{circuitikz}[] \draw[black]
(-2,0) to[I,i>=$I_s$] (-2,3)
to[short](0,3)
to[open,*-*] (1,3)
to[short](6,3)
(-1,3) to[short] (-1,0)
(1,3) to[short] (1,0)
(4,3) to[open,*-*,v<=$v_0(t)$] (4,0)
(6,3) to[R=$R$,i>=$i_R(t)$] (6,0)
to [short] (-2,0);
\end{circuitikz}
\end{center}

Therefore, $i_L(0^-)=i_L(0^+)=0$ A and $v_0(0^-)=v_0(0^+)=0$ V.  Since $v_0(t)=l\frac{\partial i_L(t)}{\partial t}$, this means
\begin{align*}
\frac{\partial i_L(t)}{\partial t}|_{t=0^+}=0 \quad \text{A/s}
\end{align*}

}

\frame{

\begin{center}
\begin{circuitikz}[] \draw[black]
(-2,0) to[I,i>=$I_s$] (-2,3)
to[short](6,3)
(-1,3) to[ospst, l^ = \mbox{t = 0}] (-1,0)
(1,3) to[L=$L$,i>=$i_L(t)$] (1,0)
(4,3) to[C=$C$,v<=$v_0(t)$,i>=$i_C(t)$] (4,0)
(6,3) to[R=$R$,i>=$i_R(t)$] (6,0)
to [short] (-2,0)
(3,0) node[ground] {};
\end{circuitikz}
\end{center}

\begin{itemize}
\item If we already have the solution to $i_L(t)$, then $v_0(t)=L\frac{\partial i_L(t)}{\partial t}$.
\item We can directly obtain the differential equation for $v_0(t)$.
\end{itemize}

}

\frame{
\begin{center}
\begin{circuitikz}[] \draw[black]
(-2,0) to[I,i>=$I_s$] (-2,3)
to[short](6,3)
(-1,3) to[ospst, l^ = \mbox{t = 0}] (-1,0)
(1,3) to[L=$L$,i>=$i_L(t)$] (1,0)
(4,3) to[C=$C$,v<=$v_0(t)$,i>=$i_C(t)$] (4,0)
(6,3) to[R=$R$,i>=$i_R(t)$] (6,0)
to [short] (-2,0)
(3,0) node[ground] {};
\end{circuitikz}
\end{center}

\begin{align*}
\text{ KCL: } I_s=i_L(t)+i_C(t)+i_R(t)
\end{align*}

\begin{itemize}
\item Resistor: $i_R(t)=v_0(t)/R$
\item Capacitor: $i_c(t)=C\frac{\partial v_0(t)}{\partial t}$
\item Inductor: $i_L(t)=\frac{1}{L}\int_{-\infty}^{t}v_0(\tau)d\tau$
\end{itemize}

}

\frame{
Therefore
\begin{align*}
I_s=\frac{1}{L}\int_{-\infty}^{t}v_0(\tau)d\tau+C\frac{\partial v_0(t)}{\partial t}+\frac{1}{R}v_0(t)
\end{align*}

If we compute the time-derivative at both sides of the equation

\begin{align*}
\frac{\partial^2 v_0(t)}{\partial t^2}+\frac{1}{RC}\frac{\partial v_0(t)}{\partial t}\frac{1}{LC}v_0(t)=0
\end{align*}

\begin{exampleblock}{$s_{1,2}=-\frac{1}{2RC}\pm\sqrt{\frac{1}{4(RC)^2}-\frac{1}{LC}}$}
\begin{itemize}
\item $R<\frac{1}{2}\sqrt{\frac{L}{C}}\rightarrow$ real (negative) roots. Overdamped solution.
\item $R>\frac{1}{2}\sqrt{\frac{L}{C}}\rightarrow$ complex roots. Underdamped solution.
\item $R=\frac{1}{2}\sqrt{\frac{L}{C}}\rightarrow$ 2 equal roots. Critically damped solution.
\item $R=\infty\rightarrow$ Oscillation.
\end{itemize}
\end{exampleblock}

}

\section{RLC circuits as systems (filters)}

\frame{
\frametitle{RLC circuits as systems}
\begin{center}
\begin{circuitikz}[] \draw[color=red]
(-2,0) to[I,i>=$I_s$, color=red] (-2,3);
\draw[color=black] (-2,3)
to[short](6,3)
(-1,3) to[ospst, l^ = \mbox{t = $t_0$}] (-1,0)
(1,3)  to[R=$R$,i>=$i_R(t)$]  (1,0)
(4,3) to[C=$C$,v<=$v_0(t)$,i>=$i_C(t)$] (4,0);
\draw[color=blue]
(6,3) to[L=$L$,i>=$i_L(t)$, color=blue] (6,0);
\draw[color=black]
(6,3) to[L=$L$] (6,0)
(6,0)
to [short] (-2,0);
\end{circuitikz}
\end{center}

Differential equation for $i_L(t)$:

\begin{align*}
&\frac{\partial^2 i_L(t)}{\partial^2 t} + \frac{1}{RC}\frac{\partial i_L(t)}{\partial t}+\frac{1}{L}i_L(t)=\frac{ I_s}{LC} u(t-t_0)% \\\\
%&\Rightarrow \omega_0^2=\frac{1}{LC}, 2\alpha=\frac{1}{RC}, \gamma=\frac{I_s}{CL}
\end{align*}

with auxiliary conditions $i_L(t_0) = A$, $\frac{\partial i_L(t)}{\partial t}|_{t=t_0}=B$

We can consider {\color{red} $I_s u(t-t_0)$} as the {\color{red} input} and {\color{blue} $i_L(t)$} as the {\color{blue} output} of a system that is implemented by the RLC circuit. These systems are called \textbf{filters}.

}

\frame{
\frametitle{Filters}
\begin{alertblock}{}
The {\bf system} input/output relationship is given by the differential equation and the auxiliary conditions.
\end{alertblock}
\begin{center}
\begin{pspicture}[](6,2)
   \pssignal(0,1){x}{$I_su(t-t_0)$}
   \psblock(2,1){a}{Filter}
   %\psblock(4,1){b}{$h[n], H(z)$}
   \pssignal(4,1){y}{$i_L(t)$}
   %-----------------
   \psset{arrows=->}
   \ncline{x}{a}  \ncline{a}{y}  %\ncline{b}{y}
\end{pspicture}
\end{center}

We can characterize the system using the properties defined for systems in the first part of the course. In particular, we will discuss the linearity, time-invariance and causality properties of the filter.
}

\frame{
\frametitle{Linearity}
If we put an input current {\color{red} $I_1$} in the source, we will observe a current in the inductor {\color{blue} (system output) $i_1(t)$} such that:
\begin{align*}
&\frac{\partial^2 i_1(t)}{\partial^2 t} + \frac{1}{RC}\frac{\partial i_1(t)}{\partial t}+\frac{1}{L}i_1(t)=\frac{ I_1}{LC} u(t-t_0)% \\\\
%&\Rightarrow \omega_0^2=\frac{1}{LC}, 2\alpha=\frac{1}{RC}, \gamma=\frac{I_s}{CL}
\end{align*}
with auxiliary contidions $i_1(t_0) = A$, $\frac{\partial i_1(t)}{\partial t}|_{t=t_0}=B$

If we consider a different input {\color{red} $I_2$}, the new output current  {\color{green} $i_2(t)$} verifies
\begin{align*}
&\frac{\partial^2 i_2(t)}{\partial^2 t} + \frac{1}{RC}\frac{\partial i_2(t)}{\partial t}+\frac{1}{L}i_2(t)=\frac{ I_2}{LC} u(t-t_0)% \\\\
%&\Rightarrow \omega_0^2=\frac{1}{LC}, 2\alpha=\frac{1}{RC}, \gamma=\frac{I_s}{CL}
\end{align*}
with auxiliary conditions $i_2(t_0) = A$, $\frac{\partial i_2(t)}{\partial t}|_{t=t_0}=B$
}

\frame{
If we consider an input that is the linear combination of the two former inputs {\color{red}$I_3 = aI_1 + bI_2$} the new output {\color{blue} $i_3(t)$} is such that

\begin{align*}
\frac{(aI_1 + b I_2)}{LC}u(t-t_0)=&a\left\{ \frac{\partial^2 i_1(t)}{\partial^2 t} + \frac{1}{RC}\frac{\partial i_1(t)}{\partial t}+\frac{1}{L}i_1(t) \right \} + \\\\
& b\left\{\frac{\partial^2 i_2(t)}{\partial^2 t} + \frac{1}{RC}\frac{\partial i_2(t)}{\partial t}+\frac{1}{L}i_2(t)\right \}
\end{align*}
\begin{align*}
=\frac{\partial^2  (ai_1(t) +b i_2(t) )}{\partial^2 t} + \frac{1}{RC}\frac{\partial (ai_1(t) +b i_2(t) )}{\partial t}+\frac{1}{L}(ai_1(t) +b i_2(t) )
\end{align*}

Hence, the output is  $i_3(t) = a i_1(t) + b i_2(t)$.

But we have to see what happens with the auxiliary conditions.
}

\frame{
\frametitle{Filter linearity: auxiliary conditions}
The current {\color{blue} $i_3(t)$} must verify
\[
\begin{array}{ccc}  i_3(t_0) & = &A  \\ \frac{\partial i_3(t)}{\partial t}|_{t=t_0}& = & B\end{array} \Rightarrow \begin{array}{ccc}  ai_1(t_0) + bi_2(t_0) & = &A  \\ \frac{\partial (ai_1(t)+bi_2(t))}{\partial t}|_{t=t_0}& = & B \end{array}
\]

On the other hand
\[
\begin{array}{ccc}  ai_1(t_0) + bi_2(t_0) & = &aA + bA  \\ \frac{\partial (ai_1(t)+bi_2(t))}{\partial t}|_{t=t_0}& = & aB+bB \end{array}
\]

Putting all together

\[
\begin{array}{ccc}  A & = &(a + b)A  \\ B& = & (a+b)B \end{array}
\]
which has to be true for any $a$, $b$, hence  $A=B=0$.

\begin{exampleblock}{Linearity condition for a filter}
Null auxiliary conditions!
\end{exampleblock}
}

\frame{
\frametitle{Time Invariancy}
\begin{itemize}
\item $i_L(t)$ is the output when the input is  {\color{red}$I_s u(t-t_0)$}.

\item If we close the switch at $t_1>t_0$, we are essentially delaying the input: {\color{red}$I_s u(t-t_1)$}.

\item For this new input, we know the solution is automatically shifted to $t_1$ (the exponential solution will depend on $(t-t_1)$).

\item However, the auxiliary conditions have to be defined at $t_1$!!! Otherwise, the system is not time-invariant!

%\item Por tanto, las condiciones auxiliares tienen que poder desplazarse para que el filtro se comporte igual independientemente de cuándo accionemos el interruptor.
\end{itemize}

\begin{exampleblock}{Filter time-invariance condition}
Auxiliary conditions must be referred to the instant at which the input is activated (auxiliary conditions are initial conditions).
\end{exampleblock}

}

\frame{
\frametitle{Causality}
\begin{exampleblock}{Filter causality condition}
Auxiliary conditions are  {\bf null initial conditions}.
\end{exampleblock}

\begin{itemize}
\item This guarantees that the output signal $i_L(t)$ is zero as long as the input hasn't been activated.
\end{itemize}

}

%\frame{
%\frametitle{Respuesta al impulso}
%
%\begin{exampleblock}{Si un filtro es lineal e invariante con el tiempo:}
%\begin{itemize}
%\item Es causal: Por ser invariante tiene condiciones iniciales, por ser lineal estas condiciones han de ser nulas, luego se trata de {\bf reposo inicial}
%\item Podemos recuperar la respuesta al impulso {\bf derivando la respuesta al escalón}
%\end{itemize}
%\end{exampleblock}

\end{document}


The proposed \phic{} is based on set theory~\citep{jech2013set} and lambda calculus,
representing objects as sets of pairs and their internals as $\lambda$-terms.
The rest of the section contains formal definitions of
data, objects, attributes, abstraction, application, decoration, and dataization.

\subsection{Objects and Data}

\begin{eodefinition}\label{def:object}
An \textbf{object} is a set of ordered pairs $(a_i, v_i)$ such that
$a_i$ is an identifier, all $a_i$ are different, and $v_i$ is an object.
\end{eodefinition}

An identifier is either $\varphi$, $\rho$, or, by convention, a text without
spaces starting with a small-case English letter in typewriter font.

The object at \lref{book} may be represented as
\begin{equation}\label{eq:book}
\begin{split}
\ff{book} & = \left\{\begin{matrix*}[l]
  (\ff{isbn}, \emptyset) \\
\end{matrix*}\right\},
\end{split}
\end{equation}
where \ff{isbn} is an identifier and $\emptyset$ is an empty
set, which is a proper object, according to the Def.~\ref{def:object}.

\begin{eodefinition}\label{def:data}
An object may have properties of \textbf{data},
which is a computation platform dependable entity and is not
decomposable any further within the scope of \phic{}.
\end{eodefinition}

What exactly is data may depend on the
implementation platform, but most certainly would include
byte arrays, integers, floating-point numbers,
string literals, and boolean values.

The object at \lrefs{book2}{book2-end} may be represented as
\begin{equation}\label{eq:book2}
\begin{split}
\ff{book2} & = \left\{\begin{matrix*}[l]
  (\ff{isbn}, \emptyset) \\
  (\ff{title}, \ff{"Object Thinking"}) \\
  (\ff{price}, \ff{memory}) \\
\end{matrix*}\right\}, \\
\end{split}
\end{equation}
where \ff{isbn}, \ff{title}, and \ff{price} are identifiers,
\ff{memory} is an object defined somewhere else,
and the text in double quotes is data.

\subsection{Attributes}

\begin{eodefinition}\label{def:attribute}
In an object $x$, $a$ is a free \textbf{attribute}
iff $(a, \emptyset) \in x$; it is a bound attribute
iff $\exists (a, v)\in x$ and $v\not=\emptyset$.
\end{eodefinition}

In the Eq.~\ref{eq:book2}, identifiers \ff{isbn}, \ff{title}, and \ff{price}
are the attributes of the object \ff{book2}.
The attribute \ff{isbn} is free, while the other two are bound.

\begin{eodefinition}\label{def:dot}
If $x$ is an object and $\exists (a, v) \in x$, then $v$ may be referenced as $x.a$;
this referencing mechanism is called \textbf{dot notation}.
\end{eodefinition}

Both free and bound attributes of an object are accessible using
the dot notation. There is no such thing as
visibility restriction in \phic{}:
all attributes are visible to all objects outside of the one they belong to.

It is possible to chain attribute references using dot notation, for example
$\ff{book2}.\ff{price}.\ff{neg}$ is a valid expression, which means
``taking the attribute \ff{price} from the object \ff{book2} and then
taking the attribute \ff{neg} from it.''

\begin{eodefinition}\label{def:scope}
If $x(a_i, v_i)$ is an object, then $\hat{x}$, a set consisting of all $a_i$,
is its \textbf{scope} and the cardinality of $|\hat{x}|$ is
the \textbf{arity} of $x$.
\end{eodefinition}

For example, the scope of the object at the Eq.~\ref{eq:book2} consists of three identifiers:
\ff{isbn}, \ff{title}, and \ff{price}.

\subsection{Abstraction}

\begin{eodefinition}\label{def:abstraction}
An object $x$ is \textbf{abstract} iff at least one of its attributes is free,
i.e. $\exists (a, \emptyset)\in x$;
the process of creating such an object is called \textbf{abstraction}.
\end{eodefinition}

An alternative ``arrow notation'' may be used to denote an object $x$ in a more
compact way, where free attributes stay in the parentheses on the left side of the
mapping symbol $\mapsto$ and pairs,
which represent bound attributes, stay on the right side, in double-square brackets.
The Eq.~\ref{eq:book2} may be written as
\begin{equation}\label{eq:book2-compact}
\begin{split}
& \ff{book2}(\ff{isbn}) \mapsto \llbracket \br
& \quad \ff{title} \mapsto \ff{"Object Thinking"}, \br
& \quad \ff{price} \mapsto \ff{memory} \br
& \rrbracket. \\
\end{split}
\end{equation}

\subsection{Application}

\begin{eodefinition}\label{def:application}
If $x$ is an abstract object and $y$ is an object
  where $\hat{y}\subseteq\hat{x}$,
  then an \textbf{application} of $y$ to $x$ is
  a \textbf{copy} of $x$, a new object that consists of pairs $(a\in\hat{x},v)$ such that
  $v=y.a$ if $x.a=\emptyset$ and $v=x.a$ otherwise.
\end{eodefinition}

Application makes some free attributes of $x$ bound---by binding objects to them.
The produced object has exactly the same set of attributes, but some of them,
which were free before, become bound.

It is not expected that all free attributes turn into bound ones during application.
Some of them may remain free, which will lead
to creating a new abstract object. To the contrary,
if all free attributes are substituted with \emph{arguments} during copying,
a newly created object will be \emph{closed}.

Once set, bound attributes may not be reset.
This may be interpreted as \emph{immutability} property of objects.

Arrow notation may also be used to denote object copying,
where the names of the attributes, which remain free, stay in the brackets
on the left side of the mapping symbol $\mapsto$,
while objects $P$ provided as arguments stay on the right side,
in the brackets. For example, the object at \lref{point-copy} may be written as
\begin{equation}\label{eq:point}
\begin{split}
& \ff{point}(\ff{x} \mapsto \ff{5}, \ff{y} \mapsto \ff{-3}).\ff{distance}(\br
& \quad \ff{p} \mapsto \ff{point}(\ff{x} \mapsto \ff{13}, \ff{y} \mapsto \ff{3.9}) \br
& ),
\end{split}
\end{equation}
and may further be simplified since the order of parameters is obvious:
\begin{equation}
\begin{split}
\ff{point}(\ff{5}, \ff{-3}).\ff{distance}(\ff{point}(\ff{13}, \ff{3.9})).
\end{split}
\end{equation}

\subsection{Inner and Parent Objects}

\begin{eodefinition}\label{def:parent}
If an object $x$ is bound to an attribute of
an object $y$, then $x.\rho$ denotes $y$;
the object $x$ is \textbf{inner} object, while $y$ is its \textbf{parent};
an object, which is not bound to any attributes, is called \textbf{anonymous}.
\end{eodefinition}

For example, the object at \lrefs{book3}{book3-end}
has three inner objects bound to attributes \ff{title}, \ff{price}, and \ff{set-price}:
\begin{equation}\label{eq:book3}
\begin{split}
& \ff{book3}(\ff{isbn}) \mapsto \llbracket \br
& \quad \ff{title} \mapsto \ff{"Object Thinking"}, \br
& \quad \ff{price} \mapsto \ff{memory}, \br
& \quad \ff{set-price}(\ff{p}) \mapsto \llbracket \br
& \quad \quad \varphi \mapsto \rho.\ff{price}.\ff{write}(\ff{p}) \br
& \quad \rrbracket \br
& \rrbracket, \\
\end{split}
\end{equation}
where $\rho.\ff{price}$ refers to the attribute \ff{price}
of the parent object \ff{book3}. It is not always required to mention
$\rho$ explicitly, however it it may be present for the sake of
disambiguation.

Since the same object may be bound to more then one attribute,
the parent $\rho$ may depend on where the object
is bound.

\subsection{Decoration}

\begin{eodefinition}\label{def:decorator}
If $x$ and $y$ are objects and $x.\varphi = y$, then
  $\forall a (x.a = y.a)$ if $a \not\in \hat{x}$;
  this means that $x$ is \textbf{decorating} $y$.
\end{eodefinition}

Here, $\varphi$ is a special identifier denoting the object being decorated
within the scope of the decorator.

For example, the object at \lrefs{circle}{circle-end} would
be denoted by this formula:
\begin{equation}\label{eq:c-empty}
\begin{split}
& \ff{circle}(\ff{center}, \ff{radius}) \mapsto \llbracket \br
& \quad \varphi \mapsto \ff{center}, \br
& \quad \ff{is-inside}(\ff{p}) \mapsto \llbracket \br
& \quad \quad \varphi \mapsto \rho.\varphi.\ff{distance}(\ff{p}).\ff{leq}(\ff{radius}) \br
& \quad \rrbracket \br
& \rrbracket,
\end{split}
\end{equation}
while the application of it would look like:
\begin{equation}
\begin{split}
\ff{c} & \mapsto \ff{circle}(\ff{point}(\ff{-3}, \ff{9}), \ff{40}),
\end{split}
\end{equation}
producing:
\begin{equation}\label{eq:c-fin}
\begin{split}
& \ff{c} \mapsto \llbracket \br
& \quad \ff{center} \mapsto \ff{point}(\ff{-3}, \ff{9}), \br
& \quad \ff{radius} \mapsto \ff{40}, \br
& \quad \varphi \mapsto \ff{center}, \br
& \quad \ff{is-inside}(\ff{p}) \mapsto \llbracket \br
& \quad \quad \varphi \mapsto \rho.\ff{distance}(\ff{p}).\ff{leq}(\ff{radius}) \br
& \quad \rrbracket \br
& \rrbracket.
\end{split}
\end{equation}

Because of decoration, the expression
$\rho$.$\varphi$.\ff{distance} in the Eq.~\ref{eq:c-empty} is semantically equivalent to the expression
$\rho$.\ff{distance} in the Eq.~\ref{eq:c-fin}.

The following expression makes a new object \ff{is}, which represents
a sequence of object applications ending with a copy of \ff{leq}:
\begin{equation}\label{eq:is}
\begin{split}
& \ff{is} \mapsto \ff{c}.\ff{is-inside}(\ff{point}(\ff{1}, \ff{7})),
\end{split}
\end{equation}
producing:
\begin{equation}\label{eq:c-fin2}
\begin{split}
& \ff{c} \mapsto \llbracket \br
& \quad \ff{center} \mapsto \ff{point}(\ff{-3}, \ff{9}), \br
& \quad \ff{radius} \mapsto \ff{40}, \br
& \quad \varphi \mapsto \ff{center}, \br
& \quad \ff{is-inside} \mapsto \llbracket \br
& \quad \quad \ff{p} \mapsto \ff{point}(\ff{1}, \ff{7}), \br
& \quad \quad \varphi \mapsto \rho.\ff{distance}(\ff{p}).\ff{leq}(\ff{radius}) \br
& \quad \rrbracket \br
& \rrbracket.
\end{split}
\end{equation}

\subsection{Atoms}

\begin{eodefinition}\label{def:atom}
If $\lambda s.M$ is a function of one argument $s$ returning an object,
then it is an abstract object called an \textbf{atom}, $M$ is its $\lambda$-term,
and $s$ is its free attribute.
\end{eodefinition}

For example, the atom at \lref{sum-def} would be represented as
\begin{equation}
\begin{split}
& \ff{sum}(\ff{x}) \mapsto \lambda s . \sum\limits_{i=0}^{s[0].\ff{x}.\ff{size} - 1} s[0].\ff{x}.\ff{get}(i),
\end{split}
\end{equation}
where the function calculates an arithmetic sum of all items
in the array \ff{x} and returns the result as a data. The argument of
the function is a vector $s$ where the first element is the object under
consideration, the second element is its parent object, the third element
is the parent of the parent, and so on. Thus, $s[0]$ is the object
\ff{sum} itself, while $s[0].\ff{x}$ is its inner object \ff{x},
and $s[0].\ff{x}.\ff{get}(0)$ is the first element of it, if it is an array.
It is expected that the array has an attribute \ff{size} representing
the total number of elements in the array.

Atoms may have their $\lambda$-terms defined outside of \phic{} formal scope.
For example, the object at \lref{stdout} would be denoted as
\begin{equation}\label{def:stdout}
\begin{split}
& \ff{stdout}(\ff{text}) \mapsto \lambda s.M_\text{stdout},
\end{split}
\end{equation}
where $M_\text{stdout}$ is a $\lambda$-term defined externally.

\subsection{Locators}

\begin{eodefinition}\label{def:locator}
Object \textbf{locator} is a unique dot-separated not-empty
collection of identifiers prepended by either $\xi$, $\rho$, or $\Phi$.
\end{eodefinition}

Locators are used to avoid ambiguity when referencing objects.
For example, the Eq.~\ref{eq:c-fin} may be refined as
\begin{equation}
\begin{split}
& \ff{c} \mapsto \llbracket \br
& \quad \ff{center} \mapsto \Phi.\ff{point}(\Phi.\ff{-3}, \Phi.\ff{9}), \br
& \quad \ff{radius} \mapsto \Phi.\ff{40}, \br
& \quad \varphi \mapsto \xi.\ff{center}, \br
& \quad \ff{is-inside}(\ff{p}) \mapsto \llbracket \br
& \quad \quad \varphi \mapsto \rho.\ff{distance}(\xi.\ff{p}).\ff{leq}( \br
& \quad \quad \quad \rho.\ff{radius} \br
& \quad \quad ) \br
& \quad \rrbracket \br
& \rrbracket,
\end{split}
\end{equation}
where $\xi$ denotes the current abstract object
and $\Phi$ refers to the anonymous abstract ``root'' object.
Defining an object in a global scope
means binding it to the object $\Phi$, unless it is an anonymous
object, as the one at \lrefs{succ}{succ-end}.

The most precise and complete formula for the object in the
Eq.~\ref{eq:c-fin2} would also include attribute names for
the object application:
\begin{equation}
\begin{split}
& \ff{c} \mapsto \llbracket \br
& \quad \ff{center} \mapsto \Phi.\ff{point}( \br
& \quad \quad \ff{x} \mapsto \Phi.\ff{-3}, \br
& \quad \quad \ff{y} \mapsto \Phi.\ff{9} \br
& \quad ), \br
& \quad \ff{radius} \mapsto \Phi.\ff{40}, \br
& \quad \varphi \mapsto \xi.\ff{center}, \br
& \quad \ff{is-inside}(\ff{p}) \mapsto \llbracket \br
& \quad \quad \varphi \mapsto \xi.\rho.\ff{distance}(\ff{to} \mapsto \xi.\ff{p}).\ff{leq}( \br
& \quad \quad \quad \ff{other} \mapsto \xi.\rho.\ff{radius} \br
& \quad \quad ) \br
& \quad \rrbracket \br
& \rrbracket.
\end{split}
\end{equation}


\documentclass[a4paper,12pt]{article}

\begin{document}

\section*{The EMT potential in FAST.}

\subsection*{The energy}

The distance between atoms $i$ and $j$ is called $r_{ij}$.  The
weigthfunction $\Theta$ is defined as:
\begin{equation}
  \label{theta}
  \Theta(r) = {1 \over 1 + \exp\Bigl(\alpha_{cut} (r - r_{cut}) \Bigr)}
\end{equation}

The contributions to $\sigma_1$ and $\sigma_2$ for atom $i$ from all
atoms with atomic number $Z'$ are called $\sigma_{1,Z'}(i)$ and
$\sigma_{2,Z'}(i)$ respectively.

\begin{equation}
  \label{sigmaone}
  \sigma_{1,Z'}(i) = \sum_{j \in Z'} \Theta(r_{ij}) \exp\Bigl( -
  \eta_{2,Z'} r_{ij} + \eta_{2,Z'} s^{eq}_{Z'} \beta \Bigr)
\end{equation}
\begin{equation}
  \label{sigmatwo}
  \sigma_{2,Z'}(i) = \sum_{j \in Z'} \Theta(r_{ij}) \exp\left( -
  {\kappa_Z' \over \beta} r_{ij} + \kappa_{Z'} s^{eq}_{Z'}  \right)
\end{equation}

If both $i$ and $j$ are hydrogen:
\begin{equation}
  \label{sigmah}
  \sigma_H(i) = \sum_j \Theta(r_{ij}) \Bigl( \exp(-A_H r_{ij}) -
  \exp(-A_H r_{cut}) \Bigr)
\end{equation}

The total sigma1 and sigma2 are given by ($Z$ is the atomic number
of atom $i$, the sums go over all atomic numbers)
\begin{equation}
  \label{totsigmaone}
  \sigma_1(i) = \mbox{MAX}\Bigl[ 10^{-9}, \sum_{Z'} \chi(Z,Z')
  \sigma_{1,Z'}(i) \Bigr]
\end{equation}
\begin{equation}
  \label{totsigmatwo}
  \sigma_2(i) = \mbox{MAX}\Bigl[ 10^{-9}, \sum_{Z'} \chi(Z,Z')
  \sigma_{2,Z'}(i) \Bigr]
\end{equation}

The neutral-sphere radius $s$ is given by
\begin{equation}
  \label{s}
  s(i) = s^{eq}_Z - {1 \over \beta \eta_{2,Z}} \ln \left({ \sigma_1(i)
    \over 12 \gamma_1}\right)
\end{equation}

The cohesive energy $E_c$ and the atomic-sphere energy $E_{as}$:
\begin{equation}
  \label{Ec}
  E_c(i) = E^0_Z (\lambda_Z (s(i) - s^{eq}_Z) + 1)
  \exp \Bigl(-\lambda_Z (s(i) - s^{eq}_Z) \Bigl)
\end{equation}
\begin{equation}
  \label{Eas}
  E_{as} = 6 V^0_Z \exp \Bigr(-\kappa_Z (s(i) - s^{eq}_Z) \Bigl) -
  {1 \over 2} V^0_Z {\sigma_2(i) \over \gamma_2}
\end{equation}

\subsection*{Forces}
Real soon now \ldots

\subsection*{The stress tensor.}

The $\alpha,\beta$ component of the stress tensor of atom $i$ is
called $\sigma_{\alpha\beta}(i)$.  It is given by
\begin{equation}
  \label{stress}
  \sigma_{\alpha\beta}(i) = {1 \over v_i} \left( - {p_\alpha(i)
    p_\beta(i) \over m_i} + {1 \over 2} \sum_{j \neq i} {\partial
    E_{pot} \over \partial r_{ij}} \cdot {r_{ij,\alpha} r_{ij,\beta}
    \over r_{ij}} \right)
\end{equation}
where $p\alpha(i)$ is the $\alpha$ component of the momentum of atom
$i$, $r_{ij,\alpha}$ is the $\alpha$ component of the vector between
atoms $i$ and $j$, and $E_{pot} = E_c + E_{as}$.

\begin{equation}
  {\partial E_c(i) \over \partial s(i)} = - \lambda_Z E_c(i) + E^0_Z
  \lambda_Z \exp \Bigr( -\lambda_Z (s(i) - s^{eq}_Z) \Bigr)
\end{equation}
\begin{equation}
  {\partial s(i) \over \partial \sigma_1(i)} = - {1 \over \beta \eta_{2,Z}
    \sigma_1(i)}
\end{equation}
\begin{equation}
  {\partial E_{as}(i) \over \partial s(i)} = - 6 V^0_Z \kappa_Z \exp \Bigl(
  - \kappa_z (s(i) - s^{eq}_Z) \Bigr)
\end{equation}
\begin{equation}
  {\partial E_{as}(i) \over \partial \sigma_2(i)} = - {V^0_Z \over 2 \gamma_2}
\end{equation}
\begin{equation}
  {\partial \sigma_1(i) \over \partial r_{ij}} = \sum_{Z'} \chi(Z, Z')
  \sum_{j \in Z'} \Theta(r_{ij}) \Bigr( \alpha_{cut} \Theta(r_{ij}) -
  \eta_{2,Z'} - \alpha_{cut} \Bigl) \exp \Bigr( \eta_{2,Z'} r_{ij} +
  \eta_{2,Z'} s^{eq}_{Z'} \beta \Bigr)
\end{equation}
\begin{equation}
  {\partial \sigma_2(i) \over \partial r_{ij}} = \sum_{Z'} \chi(Z, Z')
  \sum_{j \in Z'} \Theta(r_{ij}) \Bigr( \alpha_{cut} \Theta(r_{ij}) -
  {\kappa_{Z'} \over \beta} - \alpha_{cut} \Bigl) \exp \Bigr(
  {\kappa_{Z'} \over \beta} r_{ij} +
  \kappa_{Z'} s^{eq}_{Z'} \Bigr)
\end{equation}

 Is has been used that ${\partial \Theta(r) \over \partial r} =
\alpha_{cut} \Theta(r) \bigr(\Theta(r) - 1\bigl)$.  Note that
$\partial E_{as}(i) \over \partial \sigma_2(i)$ only depends on $i$
through the atoms atomic number.  Now we get
\begin{equation}
  \label{ederiv}
  {\partial E_{pot}(i) \over \partial r_{ij}} = {\partial E_c(i) \over
    \partial s(i)} {\partial s(i) \over \partial \sigma_1(i)}
  {\partial \sigma_1(i) \over \partial r_{ij}} + {\partial E_{as}(i)
    \over \partial s(i)} {\partial s(i) \over \partial \sigma_1(i)}
  {\partial \sigma_1(i) \over \partial r_{ij}} + {\partial E_{as}(i)
    \over \sigma_2(i)} {\partial \sigma_2(i) \over \partial r_{ij}}
\end{equation}

It is important to notice that this is \emph{not} the quantity that
appears in equation \ref{stress}, since equation \ref{ederiv} gives
the change in the energy of atom $i$ when $r_{ij}$ is changed, whereas
${\partial E_{pot} \over \partial r_{ij}}$ is the change in the
energy of the \emph{total} system when $r_{ij}$ is changed.
\begin{equation}
  {\partial E_{pot} \over \partial r_{ij}} = {\partial E_{pot}(i) \over
    \partial r_{ij}} + {\partial E_{pot}(j) \over \partial r_{ij}}
\end{equation}
Note, however, that the term multiplying ${\partial E_{pot} \over
  \partial r_{ij}}$ in equation \ref{stress} is unchanged under the
interchange of $i$ and $j$.  This means that the contribution to the
stress for atom $i$ from ${\partial E_{pot}(j) \over \partial r_{ij}}$
is equal to a similar term (${\partial E_{pot}(j) \over \partial
  r_{ji}}$) in the stress of atom $j$, and thus only needs to be
calculated once.  But in the program, one cannot then make the
substitution ${1 \over 2} \sum_{j \neq i} \longrightarrow \sum_{j < i}$.

\end{document}


\chapter[Photoabsorption cross section at low energies]
{Photoabsorption cross section at low energies}

\section{Method}

The photoabsorption cross section,
$\sigma_{\gamma}(\omega)$, where $\omega$ is the photon energy , is used in
GEANT-4 package for description of X-ray transportation and ionization effects in
very thin absorbers.
For practical calculations it is convenient to use the
representation of the photoabsorption cross section as polinom of $\omega^{-1}$ as
was proposed in \cite{sandia}(Sandia table):

\[
\sigma_{\gamma}(\omega) = \sum_{k=1}^{4}a_{k}^{(i)}\omega^{-k} ,
\]

where the coefficients, $a_{k}^{(i)}$ are fitted with experimental data by the
least square method separately in each i-th energy interval. The interval borders
are equal as a rule to the corresponding photoabsorption edges.

Calculations of primary ionization and energy loss distributions produced by
relativistic charged particles in gaseous detectors based on original data
of Sandia table showed that there is clear disagreement with experimental data,
 especially for gas mixtures with xenon.

The special investigation was performed \cite{grich} for fitting of coefficients
$a_{k}^{(i)}$  in the energy range of $ 10 - 50 \ eV$ based on modern experimental
data from synchrotron radiation experiments. The elements usually used in
operation mixture of gaseous detectors were checked.

For hydrogen, fluorine, carbon, nitrogen and oxygen the data from the synchrotron
radiation experiments with molecular gases such as $N_2$, $O_2$, $CO_2$,
 $CH_4$, and $CF_4$ were used: \cite{lee73},\cite{lee77}. The noble gases were
checked using data given in the tables \cite{marr} and \cite{west}.

\section{Status of  this document}

18.11.98 created by V. Grichine .

\begin{thebibliography}{99}
\bibitem[Biggs90]{sandia} Biggs F., and Lighthill R.
{Preprint Sandia Laboratory, SAND 87-0070} (1990)
\bibitem[Grich94]{grich} Grichine V.M., Kostin A.P., Kotelnikov S.K. at el
{Bulletin of the Lebedev Institute no. 2-3, 34} (1994)
\bibitem[Lee73]{lee73} Lee L.C. at el
{J.Q.S.R.T., v. 13, p. 1023} (1973)
\bibitem[Lee77]{lee77} Lee L.C. at el
{Journ. of Chem. Phys., v. 67, p. 1237} (1977)
\bibitem[Marr76]{marr} Marr G.V. and West J.B.
{Atom. Data Nucl. Data Tabl., v. 18, p. 497} (1976)
\bibitem[West80]{west} West J.B. and Morton J.
{Atom. Data Nucl. Data Tabl., v. 30, p. 253} (1980)
\end{thebibliography}


\section{Background}
This section describes some existing technologies used in the system.

\subsection{Quorum Systems}
A variety of quorum systems have been used to manage replicated data /
storage in distributed systems. We briefly describe the original
quorum systems and its extension called Byzantine quorum
systems. Later, we construct a byzantine quorum system based on Web of
Trust.
The system defines two operations, {\sf read} and {\sf write}, between
a client and a set of servers called a quorum. A quorum system ($QS
\subseteq 2^U$) is a subset of the powerset of all servers ($U$), and
it satisfies a property:
\[
  \forall Q_1, Q_2 \in QS, Q_1 \cap Q_2 \neq \emptyset
\]
\hfill (intersection property)\\

With this property, it is guaranteed that the client always retrieves
the latest value from at least one server.

Melhi and Reiter \cite{Delhi:1} extend the property to handle
Byzantine failure:
\begin{align*}
  \forall Q_1, Q_2 \in QS, \forall B \in BF, Q_1 \cap Q_2 \nsubseteq B
\end{align*}
where $BF \subseteq 2^U$ and $\cup_{B \in BF} B$ is all Byzantine
failure nodes.
Especially when $|Q_1 \cap Q_2| \geq 2b+1$, $QS$ is called a $b$-masking
quorum system. When the client can be dishonet, signed messages are no
longer trustworthy therefore we rely on the quorum system to avoid
equivocation (aka double spending in blockchain terms).

\subsection{Web of Trust}
A web of trust is a directed graph $G = (V, E)$, where $V$ is a set of
nodes (each of which is a pair of unique ID and public key) and $E$ is a
set of trust relationship: when $(v_1, v_2) \in E$, $v1$ {\em trusts}
$v_2$,
i.e., the certificate of $v2$ includes a signature over its public key
with the private key of $v_1$. WoT was introduced by PGP to
authenticate certificates of peers without relying on central
authorities. We use the same mechanism to authenticate not only
end-users' certificates but quorum members' as well.

\subsection{Threshold Cryptosystems}
Threshold cryptosystems play important roles in this system. We use it
not just for fault-tolerance but for improving security.

Shamir's Shared Secret (SSS) \cite{shamir} is a major tool to
construct threshold cryptographic schemes. The system uses SSS for
both password authentication and DSA / ECDSA signature
schemes. Especially for the latter, the system uses a threshold
siganture scheme introduced by Gennaro et al.\ \cite{Gennaro}. For the
threshold password authentication, the system uses a simple DH key
exchange protocol with a similar setting to \cite{ford}.
See ~\ref{auth} for the details.
SSS uses a $t-1$ degree random polynomial on $\mathbb{Z}_q$
\[
  f(x) = \sum_{i=0}^{t-1}a_ix^i \bmod q
\]
Each {\em share} is $(i, f(i))_{i = 1..n}$. To reconstruct the shared
secret $f(0)$, calculate lagrange interpolate from $t$ responses out
of $n$
\[
    \lambda_j = \prod_{l \in \mathcal{T} \setminus \{j\}}
    i_l / (i_l - i_j) \bmod q
\]
then we get
\[
  f(0) = \sum_{j \in \mathcal{T}} f(j)\lambda_j
\]
where $\mathcal{T}$ is a subset of $\{1..n\}$ and $|\mathcal{T}| =
t$.

To construct a $(t, n)$ threshold scheme, we follow the quorum
threshold, i.e., $n = |Q|, t = n-b$.

For RSA signatures, it may seem straightforward to apply SSS to the
RSA signing process such as:
\[ S = M^{f(0)} = \prod_{i \in \mathcal{T}} M^{f(i)\lambda_i} \bmod N \]
however, since to calculate $\lambda_i$ we need the multiplicative
inverse in $\varphi(N)$ which must be kept as secret as the private
key, we cannot simply appy SSS to RSA signatures. Shoup \cite{shoup}
solved this problem by getting rid of multiplicative inverse all
together but it needs a special construction of the RSA parameters,
which makes it difficult to apply existing keys to the
method. Therefore we use a simple key hierachy to address this
issue. See \ref{thrsa} for the details.

For DSA and ECDSA, SSS has preferable properties due to its linearity:
\begin{align*}
f(0) + g(0) &= \sum_{i \in \mathcal{T}} (f(i) + g(i)) \lambda_i \\
f(0) \cdot g(0) &= \sum_{i \in \mathcal{T'}} (f(i) \cdot g(i)) \lambda_i
\end{align*}
where
\begin{align*}
  f(0) &= \sum_{i \in \mathcal{T}} f(i) \lambda_i \\
  g(0) &= \sum_{i \in \mathcal{T}} g(i) \lambda_i
\end{align*}
$\mathcal{T'}$ is a subset of $\{1..n\}$ and $|\mathcal{T'}| =
2t$. These properties make it possible to calculate the DSA / ECDSA
signature $(r, s)$ which invovles additions and multiplications of
shared variables, such that:
\begin{align*}
  r &= g^{k^{-1}} \bmod p \bmod q\\
  s &= k(x + mr) \bmod q
\end{align*}
from partial signatures $(r_i, v_i, s_i)$:
\begin{align*}
  r_i &= g^{a_i} \bmod p \\
  v_i &= k_ia_i \bmod q \\
  s_i &= k_i(x_i + mr) \bmod q
\end{align*}
where $x_i$ is the share of the private key for each node. $(a_i, k_i)$ is
generated randomly by each node. See \cite{Gennaro} for how to
construct $r$ from $(r_i, v_i)$.