\pageId{cmathml}

\newcommand{\ue}[1]{\upConversionExample{#1}}

SnuggleTeX can attempt to convert input LaTeX to Content MathML by first
creating \href[Enhanced Presentation MathML]{docs://pmathmlEnhancement} and
then processing that. In many ways, this part of the process is relatively
simple since most of the semantic structure has already been inferred (though
might not necessarily make any sense).

The following tables demonstrate the types of inputs that we support.

\subsection*{Supported Operators}

\begin{tabular}{|c|c|c|c|}
\hline
LaTeX operator & Application & Content MathML element & Live Example \\
\hline
\verb|+| & unary or n-ary & \verb|<plus/>| & \ue{\verb|x+1|} \\
\verb|-| & unary or binary & \verb|<minus/>| & \ue{\verb|-a-b|} \\
Any multiplication & n-ary & \verb|<times/>| & \ue{\verb|A\times 3x|} \\
Any division & binary & \verb|<divide/>| & \ue{\verb|1/2/{3\div 4}|} \\
\verb|\vee| & n-ary & \verb|<or/>| & \ue{\verb|A\vee B|} \\
\verb|\wedge| & n-ary & \verb|<and/>| & \ue{\verb|A\wedge B|} \\
\verb|\cup| & n-ary & \verb|<union/>| & \ue{\verb|A\cup B|} \\
\verb|\cap| & n-ary & \verb|<intersect/>| & \ue{\verb|A\cap B|} \\
\verb|\setminus| & binary & \verb|<setdiff/>| & \ue{\verb|A\setminus B\setminus C|} \\
\verb|\lnot| & unary (prefix) & \verb|<not/>| & \ue{\verb|\lnot \lnot A|} \\
\verb|!| & unary (postfix) & \verb|<factorial/>| & \ue{\verb|x!!|} \\
Any mix of relation operators & binary, applied in adjacent pairs & See below & \ue{\verb|1\leq x < y|} \\
\hline
\end{tabular}

\subsubsection*{Notes}

\begin{itemize}
\item
Operators may be left ``unapplied'', e.g. a raw input of \verb|+|
would result in \verb|<plus/>| with no enclosing
\verb|<apply/>|.

\ue{\verb|+|}

\item
Failures will be registered if an operator is used in an inappropriate
context.
\end{itemize}

\subsection*{Supported Relation Operators}

\begin{tabular}{|c|c|c|}
\hline
LaTeX operator & Content MathML element & Live Example \\
\hline
\verb|=| & \verb|<eq/>| & \ue{\verb|x=1|} \\
\verb|\not=| & \verb|<neq/>| & \ue{\verb|x\not=a|} \\
\verb|<| & \verb|<lt/>| & \ue{\verb|a<b|} \\
\verb|\not<| & \verb|<not>...<lt/>...</not>| & \ue{\verb|a\not<b|} \\
\verb|>| & \verb|<gt/>| & \ue{\verb|a>b|} \\
\verb|\not>| & \verb|<not>...<gt/>...</not>| & \ue{\verb|a\not>b|} \\
\verb|\leq| & \verb|<leq/>| & \ue{\verb|x\leq 1|} \\
\verb|\not\leq| & \verb|<not>...<leq/>...</not>| & \ue{\verb|x\not\leq 1|} \\
\verb|\geq| & \verb|<geq/>| & \ue{\verb|x\geq 1|} \\
\verb|\not\geq| & \verb|<not>...<geq/>...</not>| & \ue{\verb|x\not\geq 1|} \\
\verb|\equiv| & \verb|<equivalent/>| & \ue{\verb|a\equiv b|} \\
\verb|\not\equiv| & \verb|<not>...<equivalent/>...</not>| & \ue{\verb|a\not\equiv b|} \\
\verb|\approx| & \verb|<approx/>| & \ue{\verb|x\approx 1|} \\
\verb|\not\approx| & \verb|<not>...<approx/>...</not>| & \ue{\verb|x\not\approx 1|} \\
\verb|\mid| & \verb|<factorof/>| & \ue{\verb|a\mid b|} \\
\verb|\not\mid| & \verb|<not>...<factorof/>...</not>| & \ue{\verb|a\not\mid b|} \\
\verb|\in| & \verb|<in/>| & \ue{\verb|a\in A|} \\
\verb|\not\in| & \verb|<notin/>| & \ue{\verb|a\not\in A|} \\
\hline
\end{tabular}

\subsubsection*{Notes}

\begin{itemize}
\item
  Relation operators will be paired up earlier in the up-conversion
  process. Where there are two or more relations together, each pairing
  becomes an operand of an enclosing logical \verb|and| when
  converting to Content MathML. So a LaTeX input like \verb|1<x\leq 2| will
  result in the same output as \verb|(1<x) \land (x \leq 2)|.

\item
  Note that this pairing is still done for inputs like \verb|a=b=c|,
  even though they could have been converted to an $n$-ary application of
  the \verb|<eq/>| operator.
\end{itemize}

\subsection*{Supported Pre-defined Functions}

\begin{tabular}{|c|c|c|c|c|}
\hline
LaTeX function & Arity & Invertible & Content MathML element & Live Example \\
\hline
\verb|\sin| & unary & Yes & \verb|<sin/>| or \verb|<arcsin/>| & \ue{\verb|\sin x|} \\
\verb|\cos| & unary & Yes & \verb|<cos/>| or \verb|<arccos/>| & \ue{\verb|\cos^{-1} 0|} \\
\verb|\tan| & unary & Yes & \verb|<tan/>| or \verb|<arctan/>| & \ue{\verb|\tan\tan^{-1}x|} \\
\verb|\sec| & unary & Yes & \verb|<csc/>| or \verb|<arcsec/>| & \ue{\verb|\sec 0|} \\
\verb|\cot| & unary & Yes & \verb|<cot/>| or \verb|<arccot/>| & \ue{\verb|\cot x|} \\
\verb|\sinh| & unary & Yes & \verb|<sinh/>| or \verb|<arcsinh/>| & \ue{\verb|\sinh x|} \\
\verb|\cosh| & unary & Yes & \verb|<cosh/>| or \verb|<arccosh/>| & \ue{\verb|\cosh x|} \\
\verb|\tanh| & unary & Yes & \verb|<tanh/>| or \verb|<arctanh/>| & \ue{\verb|\tanh x|} \\
\verb|\sech| & unary & Yes & \verb|<sech/>| or \verb|<arcsech/>| & \ue{\verb|\sech^{-1}x|} \\
\verb|\csch| & unary & Yes & \verb|<csch/>| or \verb|<arccsch/>| & \ue{\verb|\csch x|} \\
\verb|\coth| & unary & Yes & \verb|<coth/>| or \verb|<arccoth/>| & \ue{\verb|\coth x|}  \\
\verb|\arcsin| & unary & No & \verb|<arcsin/>| & \ue{\verb|\arcsin x|} \\
\verb|\arccos| & unary & No & \verb|<arccos/>| & \ue{\verb|\arccos x|} \\
\verb|\arctan| & unary & No & \verb|<arctan/>| & \ue{\verb|\arctan x|} \\
\verb|\arcsec| & unary & No & \verb|<arcsec/>| & \ue{\verb|\arcsec x|} \\
\verb|\arccsc| & unary & No & \verb|<arccsc/>| & \ue{\verb|\arccsc x|} \\
\verb|\arccot| & unary & No & \verb|<arccot/>| & \ue{\verb|\arccot x|} \\
\verb|\arcsinh| & unary & No & \verb|<arcsinh/>| & \ue{\verb|\arcsinh x|} \\
\verb|\arccosh| & unary & No & \verb|<arccosh/>| & \ue{\verb|\arccosh x|} \\
\verb|\arctanh| & unary & No & \verb|<arctanh/>| & \ue{\verb|\arctanh x|} \\
\verb|\arcsech| & unary & No & \verb|<arcsech/>| & \ue{\verb|\arcsech x|} \\
\verb|\arccsch| & unary & No & \verb|<arccsch/>| & \ue{\verb|\arccsch x|} \\
\verb|\arccoth| & unary & No & \verb|<arccoth/>| & \ue{\verb|\arccoth x|} \\
\verb|\ln| & unary & No & \verb|<ln/>| & \ue{\verb|\ln x|} \\
\verb|\log| & unary & No & \verb|<log/>| & \ue{\verb|\log x|} \\
\verb|\exp| & unary & No & \verb|<exp/>| & \ue{\verb|\exp x|} \\
\verb|\det| & unary & No & \verb|<determinant/>| & \ue{\verb|\det A|} \\
\verb|\gcd| & n-ary & No & \verb|<gcd/>| & \ue{\verb|\gcd(x,y)|} \\
\verb|\lcm| & n-ary & No & \verb|<lcm/>| & \ue{\verb|\lcm(x,y)|} \\
\verb|\max| & n-ary & No & \verb|<max/>| & \ue{\verb|\max(1,2,3)|} \\
\verb|\min| & n-ary & No & \verb|<min/>| & \ue{\verb|\min A|} \\
\verb|\Re| & n-ary & No & \verb|<real/>| & \ue{\verb|\Re z|} \\
\verb|\Im| & n-ary & No & \verb|<imaginary/>| & \ue{\verb|\Im(1+3i)|} \\
\hline
\end{tabular}

\subsubsection*{Notes}

\begin{itemize}
\item
  For all functions, constructs like \verb|\cos^3 x| is
  interpreted as ``cosine $x$ raised to the power of $3$''.
  This behaviour is used for any power that is a
  number greater than or equal to $1$.

  \ue{\verb|\cos^2x+\sin^2x = 1|}

\item
  For functions listed as Invertible in the table above,
  the up-conversion process interprets constructs like
  \verb|\sin^{-1} x| as the ``inverse sin of $x$''
  and would result in \verb|<apply><arcsin/><ci>x</ci></apply>|.
  A failure will be noted if constructs like these are
  used on functions which do not support this.

  \ue{\verb|\sin^{-1}0 = 0|}

\item
  For the $\log$ function, an input like \verb|\log_a x|
  is interpreted as ``logarithm to base $a$ of $x$''.

  \ue{\verb|\log_{10}100 = 2|}
\end{itemize}

\subsection*{Supported Fixed Symbols}

\begin{tabular}{|c|c|c|}
\hline
LaTeX symbol & Content MathML interpretation & Live Example \\
\hline
\verb|\emptyset| & \verb|<emptyset/>| & \ue{\verb|A=\emptyset|} \\
\verb|\infty| & \verb|<infinity/>| & \ue{\verb|x<\infty|} \\
\hline
\end{tabular}

\subsection*{Configurable Symbols}

Some input symbols are not given pre-defined meanings and instead may
be configured, either via the custom \verb|\assumeSymbol| macro provided
as part of the \verb|snuggletex-upconversion| module, or via the Java API.

The following table shows examples of what is available:

\begin{tabular}{|c|c|c|}
\hline
LaTeX input & Content MathML interpretation & Live Example \\
\hline
\verb|\assumeSymbol{e}{exponentialNumber} $e$| & \verb|<exponentiale/>| & \ue{\verb|e|} \\
\verb|\assumeSymbol{e}{exponentialNumber} $e^x$| & Application of \verb|<exp/>| function & \ue{\verb|e|} \\
\verb|\assumeSymbol{i}{imaginaryNumber} $i$| & \verb|<imaginaryi/>| & \ue{\verb|i|} \\
\verb|\assumeSymbol{\pi}{constantPi} $\pi$| & \verb|<pi/>| & \ue{\verb|\pi|} \\
\verb|\assumeSymbol{\gamma}{eulerGamma} $\gamma$| & \verb|<eulergamma/>| & \ue{\verb|\gamma|} \\
\verb|\assumeSymbol{f}{function} $f(x)$| & Application of a function called \verb|f|, rather than a product & \ue{\verb|f(x)+a(x)|} \\
\hline
\end{tabular}

\subsubsection*{Notes}

\begin{itemize}
  \item
    The first argument of \verb|\assumeSymbol| is parsed in Math mode and may be an
    identifier, number of arbitrarily subscripted expression made out of identifiers and numbers.
    You will get a \verb|UAESY1| error if you try to use something too complicated here.

    \ue{\verb|\assumeSymbol{f_{n_k}}{function} $f_{n_k}(x)$|}

  \item
    Inverses and powers of assumed functions can be entered in a similar way to
    pre-defined functions:

    \ue{\verb|\assumeSymbol{f}{function} $f^{-1}(x)$|}
    \ue{\verb|\assumeSymbol{a}{function} $a^{2}(x)$|}

  \item
    This functionality was added in SnuggleTex 1.2.0.

\end{itemize}

\subsection*{Interpretation of Brackets}

SnuggleTeX inteprets brackets of various types according to the following
default rules:

\begin{tabular}{|c|c|c|}
\hline
LaTeX input & Default Content MathML intepretation & Live Example \\
\hline
\verb|(x)| & Round brackets treated as grouping only & \ue{\verb|(x)|} \\
\verb|(x,y)| & Round fence treated as \verb|<vector/>| & \ue{\verb|(x,y)|} \\
\verb|[x,y]| & Square fence treated as \verb|<list/>| & \ue{\verb|[x,y]|} \\
\verb|\{x,y\}| & Curly fence treated as \verb|<set/>| & \ue{\verb|\{x,y\}|} \\
\hline
\end{tabular}

From SnuggleTeX 1.2.0 onwards, this behaviour can be changed using the
\verb|\setUpConversionOption| command.  Here are some examples:

\begin{tabular}{|c|c|}
\hline
Live Example & Notes \\
\hline
\ue{\verb|\setUpConversionOption{roundBracketHandling}{list} $(x)$|} & Creates a list \\
\ue{\verb|\setUpConversionOption{roundFenceHandling}{set} $(1,2)$|} & Creates a set \\
\ue{\verb|\setUpConversionOption{squareFenceHandling}{vector} $[x]$|} & Creates a vector \\
\ue{\verb|\setUpConversionOption{curlyFenceHandling}{error} $[x]$|} & Treated as an error \\
\ue{\verb|\setUpConversionOption{squareFenceHandling}{grouping} $a[x]$|} & Treated as a grouping only \\
\hline
\end{tabular}

\subsection*{Other Supported Constructs}

\begin{itemize}

\item
  Powers are supported in the expected way. The special case of \verb|e^x|
  is normally treated as \verb|\exp x| if the symbol \verb|e| is assumed to be
  the exponential number.

  \ue{\verb|\assumeSymbol{e}{exponentialNumber} $e^{ab} = e^ae^b$|}
  \ue{\verb|\assumeSymbol{\alpha}{exponentialNumber} $\alpha^{x}$|}

\item
  Square and $n$th roots are supported using the familiar LaTeX
  constructs \verb|\sqrt{x}| and \verb|\sqrt[n]{x}|.

  \ue{\verb|\sqrt\sqrt{x} = \sqrt[4]{x}|}

\item
  Subscripted identifiers like \verb|x_1|, \verb|x_{1,2}|
  and \verb|a_{x_y}| are supported and are kept as presentation MathML wrapped
  inside a \verb|<ci/>| container element.

  \ue{\verb|A_{n,i}x_i|}

\item
  SnuggleTeX includes a custom macro called \verb|\units| that can be used
  to denote that its argument represent units. The result of up-converting
  this is a \verb|<csymbol/>| element.

  \ue{\verb|5\units{kg}|}

\end{itemize}


\section{Multiple Classifier System}\label{mcs}

For the Multiple Classifier System we used KNORAE, KNORAU, META-DES, OLA, Single Best and Static Selection. Each of these algorithms has the objective to select the best classifier in a set, in our evaluation, we are using a pool of 100 classifiers of the same base class.

The base classifier classes used are Perceptron and Decision Tree, in all ensemble algorithms we use the same base classifier configuration. For Perceptron we used no regularization, no early stopping, max of 1000 iterations and tolerance of $10^{-1}$. For Decision Tree, the split strategy is to select the most relevant feature with Gini Impurity as criterion. For ensemble algorithms, the KNORAE and KNORAU parameters were KNN to estimate the classifier competence using 7 neighbors, with no dynamic pruning and no indecision region. For META-DES, we are using Multinomial Naive Bayes as meta-classifier, 5 output profiles to estimate the competence using a KNN with 7 neighbors to decide the region of competence. And finally, static selection, we are choosing 50\% of the base classifiers. All parameters can be seen in Table \ref{table:mcs_params}.

\begin{table}[ht]
    \centering
    \renewcommand{\arraystretch}{1.8}
    \begin{tabular}{ p{5cm}p{3cm}|p{3cm}|p{3cm} }
        \toprule
        Model & \multicolumn{3}{c}{Parameters} \\
        \midrule
        Perceptron & max iterations \newline 1000 & tolerance $10^{-4}$ & \\
        Decision Tree & criterion Gini & spliter best & \\
        \midrule
        KNORAE and KNORAU & $k = 7$ & no prune & no indecision \\
        META-DES & Multinom. NB & $K_p = 5$ & $k = 7$ \\
        Static Selection & selection 50\% & & \\
        \bottomrule
        \end{tabular}
        \caption{%
        Parameters for Multiple Classifier System%
        }\label{table:mcs_params}
        \vspace{4ex}
\end{table}

In Table \ref{mcs_dt_table} is presented the MCS algorithms using Decision Tree classifier. We can observe a better mean result using META-DES in all metrics, except when comparing the Accuracy with KNORAE. Considering the mean and standard deviation, the results for KNORAE, KNORAU, OLA, Static Selection and META-DES are very close to the same interval. But we can observe that there is a bigger gap between OLA and Static Selection, and KNORAE, KNORAU and META-DES in Precision, Recall and F1. Comparing the Accuracy there is a smaller gap.

\begin{table}[!t]
    \centering
    \renewcommand{\arraystretch}{1.8}
    \begin{tabular}{ p{3cm}p{2.8cm}p{2.8cm}p{2.8cm}p{2.8cm} }
        \toprule
        Model & Precision & Recall & F1 Score & Accuracy \\
        \midrule
        KNORAE &            0.8602 (0.0517) & 0.8395 (0.0656) & 0.8469 (0.0455) & \textbf{0.8580 (0.0306)} \\
        KNORAU &            0.8377 (0.0557) & 0.8071 (0.0743) & 0.8181 (0.0495) & 0.8313 (0.0321) \\
        META-DES &          \textbf{0.8609 (0.0551)} & \textbf{0.8423 (0.0639)} & \textbf{0.8492 (0.0482)} & 0.8575 (0.0344) \\
        OLA &               0.8263 (0.0589) & 0.8104 (0.0667) & 0.8158 (0.0532) & 0.8306 (0.0387) \\
        Single Best &       0.7609 (0.0739) & 0.7356 (0.0994) & 0.7423 (0.0688) & 0.7629 (0.0447) \\
        Static Selection &  0.8424 (0.0579) & 0.8099 (0.0741) & 0.8213 (0.0492) & 0.8338 (0.0341) \\ [1ex]
        \bottomrule
        \end{tabular}
        \caption{%
        Result for Multiple Classifier System, Mean (Standard Deviation), using Decision Tree as main classifier with most relevant feature as split strategy and Gini Impurity as criterion. The best classifier for each metric is highlighted in bold%
        }\label{mcs_dt_table}
        \vspace{4ex}
\end{table}

\begin{table}[!t]
    \centering
    \renewcommand{\arraystretch}{1.8}
    \begin{tabular}{ p{3cm}p{2.8cm}p{2.8cm}p{2.8cm}p{2.8cm} }
        \toprule
        Model & Precision & Recall & F1 Score & Accuracy \\
        \midrule
        KNORAE &            0.8607 (0.0556) & \textbf{0.8368 (0.0678)} & \textbf{0.8452 (0.0471)} & \textbf{0.8570 (0.0273)} \\
        KNORAU &            0.8446 (0.0562) & 0.8148 (0.0581) & 0.8260 (0.0451) & 0.8386 (0.0301) \\
        META-DES &          \textbf{0.8748 (0.0559)} & 0.8167 (0.0700) & 0.8375 (0.0518) & 0.8525 (0.0335) \\
        OLA &               0.8418 (0.0580) & 0.8216 (0.0550) & 0.8282 (0.0413) & 0.8410 (0.0268) \\
        Single Best &       0.7913 (0.0753) & 0.7552 (0.1007) & 0.7644 (0.0688) & 0.7866 (0.0451) \\
        Static Selection &  0.8523 (0.0593) & 0.8158 (0.0717) & 0.8291 (0.0512) & 0.8438 (0.0329) \\ [1ex]
        \bottomrule
        \end{tabular}
        \caption{%
        Result for Multiple Classifier System, Mean (Standard Deviation), using Perceptron as main classifier using no regularization, no early stopping, max of 1000 iterations and tolerance of $10^{-1}$. The best classifier for each metric is highlighted in bold%
        }\label{mcs_perceptron_table}
        \vspace{4ex}
\end{table}

When using Perceptron as main classifier, Table \ref{mcs_perceptron_table}, we can observe that KNORAE have the best mean results in Recall, F1 and Accuracy but META-DES has a better Precision. When considering mean and standard deviation, the results of KNORAE, KNORAU, META-DES, Static Selection and OLA are in the same interval for all the metrics. The difference between KNORAE and META-DES is smaller in Precision, F1 and Accuracy but has a smaller Recall comparing to OLA.

The results for best classifier using Decision Tree has close results to the best classifier using Perceptron. Comparing KNORAE with Perceptron and META-DES with Decision Tree, the META-DES with Decision Tree has better results in all metrics, but again the difference between both is so small that do not exceed the confidence interval.

Evaluating Reinforcement Learning on Robocup Soccer Simulation 2D/chapters/results/mcs.tex


% !TeX root = ../libro.tex
% !TeX encoding = utf8
%
%*******************************************************
% Summary
%*******************************************************

\selectlanguage{english}
\chapter{Summary}
This project is about a very important result on differential topology. The main goal is to transmit how complex is the proof for a student, but been more comprehensible via Allen Hatcher's article \cite{arXiv:1312.3518}. Also, we will translate this problem to the computer scope, showing how difficult is to represent a surface correctly.\\
\\A typical problem of differential topology is known if it is possible to find a unique smooth structure for every topological surface (except diffeomorphisms). J. R. Munkres proved that result in his thesis in $1955$ but using some sophisticated analytical techniques. Allen Hatcher used ``The Kirby Torus Trick'' (a technique proposed by Kirby and Shiermann in $1960$) to proof the theorem for $2$-dimensional manifolds.\\
\\The initial main goals are to implement and design an efficient program to visualize homotopies, and proof the theorem as a corollary of the $2$ results cited on Allen Hatcher's article \cite{arXiv:1312.3518}. I think I have reached both goals and more because I found some interesting functionalities, like using partials of a defined function on the parametrization, and been able to visualize some characteristics of Morse functions (actually, only for ``Height'' function). However, it would have been interesting to have deepened more in Morse theory, but it would have required an exclusive project.\\

\section*{Mathematical part}
I will introduce some concepts and results about differential topology, principally from the subjects Topology II and Smooth Manifolds, and obviously Morse theory. After that, I enunciate the important results of this part, the ``facts'' (six facts). Those results are supposed by the author (Allen Hatcher) for the proof of the ``Handle Smoothing Theorem'' and theorems A and B (the $2$ main results whose corollary is the objective theorem). He proofs them at the end of his article.\\
\\Those facts need a large knowledge about Morse theory. To understand them, I used an article that concentrates some important results \cite{MorseTh1}. Also, it gives summarized proofs for almost all of them.\\
\\Then, I enunciate and extend the proof of the ``Handle Smoothing Theorem'', whose objective is to smooth one embedding incrementally, via finding isotopies (first on the origin, then on the segment $[0,1]$ and finally on the disk). It will help us to build a smooth structure starting from a base chart (topological chart, but being the only one it trivially defines a smooth structure) because we need a set of charts whose transition maps are smooth.\\
\\On the proof of that theorem, the author introduces the ``Torus trick'' (The Kirby Torus Trick), bringing up the structure of the surface to the Torus using an immersion to smooth the induced structure and bringing it back to the original surface (plus other steps). This together with Morse theory (specially, the ``facts'') are the key to build the entire proof of the theorems A and B because the rest needs only a correct connection.\\
\\Thanks to the previous theorem and the facts, I will enunciate and extend the proofs of theorems A and B (remember that in our case a manifold is a $2$-manifold):
\begin{itemize}
	\item \textbf{Theorem A}: Every manifold has a smooth structure.
	\item \textbf{Theorem B}: Every homeomorphism between smooth manifolds can be isotoped to a diffeomorphism.
\end{itemize}
For theorem A, using a triangulation of the open set of the transition map's preimage (supposing that is not smooth), we will be able to use the ``Handle Smoothing Theorem'' first on the vertex, then on the edges and finally on the interiors of the triangles. Therefore, we will have an isotopy of the main chart (whose have been affected by non-smooth transition map). Equivalently, we will have a chart with a smooth transition map with the previous charts. Then, by induction, we will define a smooth structure of the manifold, starting with a topological one.\\
\\Theorem B's proof is very similar to the proof of theorem A. We only need to translate chart smoothing for smoothing the homeomorphism, using the fact that exists a smooth triangulation on every smooth manifold.\\
\\Eventually, the central theorem of the project is a trivial corollary of theorems A and B.

\section*{Computational part}
Before explaining anything about this part, like the first part I will enunciate some useful concepts about $3$D visualization, especially OpenGL (Khronos Wiki \cite{KhronosWiki} was the main source in this topic).\\
\\After that, I begin with the development of tessellation study, in other words, how the program will subdivide the triangles to approximate better the surface. The first thing to do is select the correct definition of ``good surface approach'', under some threshold $\epsilon>0$.\\
\\Thanks to computer vision we know that the human vision perceives a surface through its geometry, edges, and textures. Because I use plain textures in this case and the charts defines a unique surface (only $1$ geometry element), we can reduce vision perception elements to edges and texture (how the light reacts to the surface). Abbreviating, the program will tessellate depending on the curvature (Gauss curvature, K, is the first characteristic of a surface that directly influences the light) and it will tessellate more on edges and areas with more light (dark areas will not be tessellated).\\
\\Also, I have implemented some typical techniques to improve the efficiency of the program, like adding tessellation distance (max distance to tessellate a triangle) or avoiding tessellation out of view frustum (out of the user's view). In some special cases we can also use an additional improvement, that prevent tessellate on hidden triangles. E. g. if we have a sphere, some triangles are visible on the front and others are not, on the back, then the program will not tessellate them.\\
\\Previously, I have studied more definitions, but the results were bad, because it was not able to detect critical areas like peaks (volume-based definition) or tessellates when it was not necessary (area-based definition).\\
\\In practice, before starting with tessellation study, it was needed to implement a program that pre-processes the charts (that defines the surface), giving as output a translation to GLSL language (used on the shaders) with additional functions, like the normal function of the charts and Gaussian curvature. For that, the program must recognize the expression trees of the functions and be able to derivate them (partial derivative respect to $x_i$, where $x_i$ is a function's variable). That GLSL code will be included in the shaders that will need it (tessellation shaders).\\
\\For the implementation of the ``processor'' I used a base code, provided in the subject Language Processors. It gave me an initial implementation that, after adapting it, can detect lexical, syntactical, and semantical errors.\\
\\In case of the visualizer, I used some example code that implements a basic shader for a simple $3$D scene (one object with one light, using Phong lighting). For its interface I used a free software library called Dear ImGui \cite{DearImGui}, with some addons for showing the light vector \cite{LVector} and a file selection dialog \cite{Dialog}, to select a parametrization.\\
\\The measures used to know if the program with tessellation works better than not using tessellation, have been the frames per second (how many frames have been calculated on one second) and the number of generated primitives. I want a program that visualizes the similar surface using less triangles than uniform approximation (with another initial mesh size), and generating more fps. This would mean that the program manages all the resources efficiently.\\
\\Because there are a lot of shading code that is executed many times (once per primitive or per vertex), it is required the best possible optimization. On Khronos Wiki \cite{KhronosWiki} there is some information about that. The more important thing is to avoid repeated calculations, like the inverse of a constant matrix (constant during rendering one frame). Apart of that, we can group some scalar calculations in a vector operation, reducing the number of operations (the number of ticks to resolve a vector operation is similar than a scalar operation, due to the GPU characteristics).\\

\section*{Conclusions}
After doing all the project, I can conclude that Allen Hatcher's article \cite{arXiv:1312.3518} provides a lot of results, which are so important in differential topology, supported by a large and interesting theory (Morse theory). It would be interesting going deeper into that theory, but it is very complex and will require a lot of time (it has content as for an own subject).\\
\\Respecting to the program, I realized how difficult is to correctly define a good approximation of a surface. Also, I have noticed that this program would be able to have more functionalities, like adding the possibility of using partials in the parametrization (implemented) and visualize Morse functions, and some characteristics (like critical points and, possibly, them indices).\\
\\There is a topic that I have not been able to study, because of the time. It is ``Transform feedback'', a functionality of OpenGL that allows render again the output mesh. It would add a lot of possibilities, including recursive tessellation (the originally thought algorithm). Logically, it will have a high negative impact on efficiency, but it should be studied carefully.\\
\\Also, we could modify the program to give as output a mesh that represents a surface with a certain number of primitives as goal. It would improve the performance of the program if we are treating with static objects (only surfaces, not homotopies), avoiding all the calculations for each vertex (calculate image through parameterization and the normal through the normal function of the parameterization).\\
\\It would be a good idea to implement the program with WebGL, to make it more portable and flexible.\\
\\These are the key words of the project:
\begin{itemize}
	\item Surface.
	\item Deepen.
	\item Comprehension.
	\item Visualization.
	\item Efficiency.
\end{itemize}

% Al finalizar el resumen en inglés, volvemos a seleccionar el idioma español para el documento
\selectlanguage{spanish}
\endinput


\section{Introduction}

We use automata to structure the combination of multiple neural networks.
Recurrent Neural Networks have been shown to correspond in computational (classification) power to deterministic finite automata~\cite{tino1998finite}.
While previous work had provided a translation from RNNs to DFAs, we show that this space can be seen as a spectrum.
By building systems that exist in between an RNN and a DFA we can gain the scalable power of RNN learning, but use DFAs at a high level to provide formal guarantees on the behavior of the system.

These synthesized controllers have strong formal guarantees, but were not competitive in performance with those built with machine learning techniques. We are now combining the two approaches to leverage the power of neural networks, as well as the safety properties of formal synthesis.

\subsection{Machine Learning for CPS}

Neural networks are used in building systems of autonomous vehicles, in both components such as vision systems, as well as top-level controllers that drive the car down the road.

End to end learning has been implemented previously in autonomous vehicles by Nvidia where a monolithic convolutional neural network was trained to map raw pixels from cameras to steering commands ~\cite{parallelforall}. This approach was shown to be successful in both simulation and real world tests.

Other autonomous car developers such as Drive.ai have used segmented deep learning neural networks to control their vehicles ~\cite{}. These researchers argue that incorrect decisions made by an end-to-end system can be difficult to correct since the selection making process of these algorithms cannot be intuitively understood. Techniques such as blacking out portions of camera images to select only the sections are used by the researchers to control the input the algorithm receives.

Previous work has combined multiple smaller neural networks to create systems with better properties than monolithic learners~\cite{masoudnia2014mixture,baldacchino2016variational}.
We are the first to propose using Mealy Machines as a combination framework for neural networks.

\subsection{Legibility}

As demonstrated in~\cite{DBLP:journals/corr/SzegedyZSBEGF13}, neural networks can be unreliable in the presence of small perturbations of the input.
As an example, with the manipulation of just a few pixels, a neural network can be fooled into thinking a stop sign is a speed limit sign.
These perturbations can be the result of random noise, or adversarial actors who aim to disrupt the safe behavior of the system.

In fact, in autonomous vehicles, further attacks are possible when the attacker has direct access to hardware.
As demonstrated in~\cite{DBLP:journals/iacr/Shoukry0TS15}, by non-intrusively attaching a small device in the wheel well of a car, the sensors that track the speed of the wheels can be completely controlled by an attacker.
Under unreliable sensor data, autonomous vehicles must continue to behave, as best as is possible, in a safe manner.
However, when using monolithic controllers, such as top-level neural networks for driving control, safely handling anomalous input remains a challenge.

We identify our contributions as follows:
\begin{enumerate}
\item A method of compositional construction of cyber-physical systems controllers with neural network components.
\item Using reactive program synthesis to build, and provide safety guarantees, for such systems.
\item An evaluation of this approach in the vehicle simulator TORCS.
\end{enumerate}


\documentclass{article}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage{cleveref}

\usepackage{color}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\Crefname{equation}{}{}
\crefname{equation}{}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator{\dn}{dn}
\DeclareMathOperator{\cn}{cn}
\DeclareMathOperator{\sn}{sn}

\newcommand*\C{\mathbb{C}}
\newcommand*\R{\mathbb{R}}
\def\bx{{\mathbf x}}
\def\bX{{\mathbf X}}
\def\bf{{\mathbf f}}
\def\bg{{\mathbf g}}
\def\bc{{\mathbf c}}
\def\by{{\mathbf y}}
\def\bxi{{\boldsymbol \xi}}
\def\bPhi{{\boldsymbol \Phi}}
\def\bSigma{{\boldsymbol \Sigma}}
\def\btheta{{\boldsymbol \theta}}
\def\bTheta{{\boldsymbol \Theta}}
\def\bC{{\mathbf C}}
\def\balpha{{\boldsymbol \alpha}}
\def\bB{{\mathbf B}}
\def\bigo{\mathcal{O}}

\newtheorem{remark}{Remark}
\newtheorem{lemma}{Lemma}
\newtheorem{theorem}{Theorem}

\title{Response to referees}
\author{Travis Askham, Manas Rachh}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\maketitle

In this document, we respond to the referees' comments
for the paper ``A boundary integral equation approach to computing
eigenvalues of the Stokes operator''.
We believe that the referees' suggestions improve the
quality of the paper and that we have been able to
address their concerns. Changes made to address these concerns
are marked in {\color{red} red} in the revised manuscript.

We have also marked in {\color{red} red} a couple of
changes around the explanation of the order of convergence
of the generalized Gaussian quadrature rule we used.
The rule is designed to be 16th order, i.e. it is designed
to integrate $p(y)\log|x-y| + q(y)$ for $p$ and
$q$ polynomials of degree up to 15. Our kernel is actually
smoother than $\log|x-y|$ (with leading order
singularity $|x-y|^2\log|x-y|$) and in our experience the
convergence rate is typically higher (20th order in
the example in the paper). In the revised text, we have clarified
that the rule is not designed to be 20th order but that this is
the behavior we observed.

\section{Reviewer 1}

A general concern of the first reviewer was the discussion
of what we originally called ``spurious double roots''.
We appreciate the reviewer pressing us on this issue, as it
has clarified the results of the paper.

To explain what happened originally, we computed the
roots using a rootfinding
utility in another software package, \texttt{chebfun}. In our
numerical experiments, we were puzzled that the output of the
utility consistently gave us pairs of roots which seemed to
be identical. Yet, they did not actually seem to correspond to
a double root of the Fredholm determinant in any meaningful sense
(indeed, the derivative of our interpolant was not particularly
close to zero for these points). We performed some other tests
(including checking whether there truly was a corresponding
two-dimensional eigenspace) and no other tests suggested a double
root existed. Thus, in the original submission, we made a note
suggesting that rounding errors may explain this strange behavior
and we described our ad hoc methods for determining true roots.
To confuse matters, we mentioned the existence of roots that
were computed and had large imaginary part as being part of
the same phenomenon (they are not).

It turns out that this behavior can be suppressed rather
simply. By default, the \texttt{roots}
utility in \texttt{chebfun} first divides the interval on
which the interpolant is defined into smaller intervals on which
the interpolant can be represented by a shorter Chebyshev series.
The roots on these subintervals can then be computed more efficiently.
However, the roots for neighboring intervals can be found twice
by this procedure and there is some internal processing to eliminate
double roots. This processing seems to fail in our case (perhaps because
we are using the complex roots mode, which is more experimental) and
we observe the fake double roots described above. Fortunately, the
subdivision procedure can be turned off. When this was done, such
roots disappeared (aside from double roots introduced by our
own splitting into subintervals). Once aware of this issue,
a much simpler procedure for identifying the roots which are actually
contained on a real subinterval can be employed.

We describe this simplified root finding procedure in the updated
manuscript. The eigenvalues/eigenvectors in the examples
did not change.

We respond to other comments from Reviewer 1 below. Original
reviewer comments in {\color{blue} blue}

\begin{itemize}
\item[1.] {\color{blue} In different parts of the paper the connection between the eigenvalue
problem of the Stokes operator and the biharmonic eigenvalue problem
1is addressed and utilized. Therefore for me it is strange that just in
the last section of the paper (“Conclusions”) this connection is elabo-
rated. It would be better that this elaboration is done somewhere at
the beginning of the paper and not in the end.}

We appreciate this suggestion and have moved this elaboration to
the introduction.

\item[2.] {\color{blue}
  In the abstract the Stokes operator is denoted as fourth-order operator.
This is unusual and in my opinion not the case (even if there is an
equivalence to a forth-order operator).}

We see how this could be confusing and have adjusted this phrasing.

\item[3.] {\color{blue} I would appreciate it if the following issue would be addressed in the
paper: under which weaker conditions (not analytic boundary, non-
simple eigenvalues) convergence of the discretization of the eigenvalues
can be proven. (Are there results concerning the convergence of the
eigenfunctions?)}

The question of addressing this problem under weaker assumptions of smoothness of the boundary
is a very interesting one. To the best of our knowledge, this
question hasn't even been addressed for the eigenvalues of the Laplacian.
We have a sketch of a proof of convergence for the eigenvalues and eigenfunctions
for the Laplace operator where we can show that the eigenvalues and eigenfunctions
converge at an algebraic rate (dependent on the smoothness of curves) for $C^{\ell}$,
with $\ell\geq 2$, boundaries. The procedure of using the Fredholm determinant as
stated does not work on Lipchitz boundaries, since the corresponding operators are
not second kind.

However, we feel that the discussion would be fairly technical and distract
from the main results of the paper --- demonstrating the use of Fredholm determinants
and second kind formulations for computing the Stokes operator eigenvalues and
eigenfunctions.  For this reason we feel that this analysis should be carried out in
a separate work and done for both the Laplace and Stokes cases.

We've included a sketch of the proof below.

The main estimate needed is to show that the error in computing
the Fredholm determinant at an eigenvalue of the Stokes operator
is directly proportional to the quadrature error in
evaluating the integral operator applied to the null vector (A proof sketch
of this result for the Laplace case is contained in~\cref{sec:appb}.
The red text in the appendix denotes results that need to be shown.).
Based on the second-kind nature of the operator from $C^{m,\alpha} \to C^{m,\alpha}$
for $m<\ell$ and $\alpha>0$ (when the boundary is $C^{\ell}$) one can show
that the resulting null vector must be at least in $C^{m,\alpha}$.
The quadrature error using Kress quadratures converges algebraically
when both the boundary and density being approximated are $C^{m,\alpha}$.

\item[4.] {\color{blue} In the paper it is not explicitly mentioned that
  both presented boundary integral equations may have non-trivial null-spaces
  for certain $k$ with ${\rm Im}(k) < 0$. These $k$s correspond to the eigenvalues of some
  related eigenvalue problems in the exterior domain. It is possible that
  these $k$s are also be detected by the root search method and that these
  eigenvalues may be some of those “spurious eigenvalues too far from
  real-valued” which are blamed to be caused by “noisy numerical determinant
  evaluation” but are actually caused by the used boundary integral formulation.}

Thank you for pointing this out. This is indeed the case, as can be seen
by the dependence of many of the results on ${\rm Im}(k) \geq 0$. We have
added a remark about this after Theorem 10 and updated the theorems and lemmas
as suggested in other comments below. These are indeed detected by the
root finding procedure, though they are easy to identify as
being distinct from the real-valued roots which correspond to
eigenvalues (the imaginary part of the real-valued roots is several
orders of magnitude smaller than the imaginary part of the
spurious roots we observed).

\item[5.] {\color{blue}
  In general it would be of interest which kind of spurious eigenvalues may
occur from a“noisy numerical determinant evaluation”. In the paper
only two kinds are specified, namely spurious eigenvalues with “large”
imaginary part (which may result also from the boundary integral for-
mulation itself as pointed out above) and spurious “double roots” on
the real line. Isn’t it possible that for example spurious single roots
occur on the real line?}

Again, thank you for pressing this point. We believe that this
is mostly resolved by the discussion above. In the case of a spurious
single root on the real line, we imagine that this could happen, though it
was not observed, i.e. one can imagine a pathological domain for which a
spurious root exists that is within, say, $10^{-7}$ of the real line.
Such a root would be hard to distinguish from a true root.
In all cases, we also computed the smallest singular
value of the BIE corresponding to the real part of a given root.
This singular value was found to be quite small. Because we believe
that the integral equation was well-resolved
by our discretization, this is rather convincing evidence that an
eigenvalue of the PDE has been found.

\item[6.] {\color{blue}
  For me it is not clear why with the suggested procedure spurious ``double roots''
  may be detected. What is actually the argument that this
  procedure detects spurious double roots?}

The original procedure was designed to test whether a root was
an eigenvalue in a manner independent of the interpolant we had
computed for the Fredholm determinant. Thus, we checked the several smallest
singular values to see if any eigenspaces of dimension larger
than one were associated
with the weird double roots. None were found. We thus chose what
seemed to be the better root in an ad hoc way. As noted above, this
procedure is no longer necessary when calling \texttt{roots} with
the subdivision procedure suppressed.

\item[7.] {\color{blue}In the caption of figure 5 the given interval for $k$
  does not match with the plots. Moreover, in each plot of figure
  5 two functions are given but in the caption only one function is described.}

Apologies about that. The caption for figure 5 has now been fixed. The two curves
correspond to the real and the imaginary part of the Fredholm determinant.

\item[8.] {\color{blue}Subsection 1.1 (”Relation to other work“) may
  lead to the false impression that boundary integral equations of the
  second kind combined with the proposed root finding method is the only
  profound and reasonable boundary integral equation approach for the Stokes
  eigenvalue problem. The authors seem not be aware of works which deal with
  boundary integral equation methods based on integral equations of the
  first kind (for several types of eigenvalue problems(Laplacian, Maxwell,
  fluid-solid interaction, plasmonics, ....)) which are well analyzed and for
  which a rigorous and comprehensive convergence theory is established.
  Such kind of an approach could be also applied to the Stokes eigen-
  value problem. Moreover, in these works instead of the root search for
  the determinant the contour integral method for nonlinear eigenvalue
  problem is used for which multiple and spurious eigenvalues seem not
  to be a problematic issue. In some way these alternatives should be
  briefly mentioned in the paper.}

  This comment is well taken.
  We did not mean to give this impression but had intended this section
  to be focused on methods specifically for the Stokes eigenvalue problem.
  We have added some references to applications treated using integral
  equation methods in the literature and reworked the section
  a little.

\item[9.] {\color{blue}
  I cannot follow the ”formal“ derivation of the fundamental solution from
  equation (8) to (10). Is it possible to describe the derivation in more
  detail? (It would be also good to mention the reference [7] between
  equation (8) and (10)).}

  We've added some more steps and added the suggested
  reference in that section.

\item[10.] {\color{blue}
  Lemma 4 only seems to hold for $k$ with ${\rm Im}(k) \geq 0$,
  see the asymptotic expansion of the Hankel function.}

  Thank you for pointing out this omission. It's been fixed
  in the revision.

\item[11.] {\color{blue} In the proof of Theorem 3 and 4 only the
  uniqueness of the solution is shown but not the existence.
  (The existence follow for example from the Fredholm theory.)}

  Thank you for pointing this out. We adjusted the
  phrasing of these.

\item[12.] {\color{blue}
  Theorem 8, 9 and 10 only seem to be valid for $k$ with
  ${\rm Im}(k) \geq 0$.}

  Again, thank you for this. This is certainly true for theorems
  8 and 10. We think that the demonstrated null vector in
  theorem 9 works for general $k$.

\end{itemize}

We also appreciate the reviewer alerting us to some typos, which have
been fixed.

\section{Reviewer 2}

Comments by the second reviewer. Original reviewer comments
in {\color{blue} blue}.

\begin{itemize}
\item[1.] {\color{blue} In the abstract and introduction the authors talk about the so-called pollution effect
with no reference to the Helmholtz problem or what high frequency regime means for
this problem. Thus unless the reader has experience with Helmholtz problems (may
not be the case for people interested in Stokes problems), they will not understand the
associated numerical challenges. This should be clarified.}

  We appreciate this suggestion and agree it may have been confusing.
  We have added a brief description of the phenomenon to the
  introduction.

\item[2.] {\color{blue} On page 3 line 31, what is meant by “current grid?”}

  Thank you for pointing out this vagueness. The current grid referred
  to the current boundary discretization. We have reworked this section
  in response to comments by the other reviewer and have dropped this more
  philosophical point altogether.

\item[3.] {\color{blue} On page 5 line 36, should $\exists \phi_0$ read $\exists \phi_0 \in X$?}

  Thank you for pointing this out. It's been fixed.

\item[4.] {\color{blue} On page 28 line 38, is the linear system $C_k^N$
  also discretized with generalized Gaussian quadrature?}

  Yes, this has been clarified in the revision.

\item[5.] {\color{blue} In Figure 6, a plot of $O(N \log N )$
  would be more helpful than $O(N )$ since that is the expected scaling.}

  Good point. This has been adjusted.

  \appendix
\input{../draft-01-stokes/appendix-b}
\end{itemize}

\end{document}


\chapter{Additional methodological details, data, and \\site
	descriptions}\label{dx:C}
\chaptermark{Additional methods and site descriptions}

This section provides additional, unpublished information regarding
methods or field observations that support the research presented in
the preceding chapters.

\section{\texorpdfstring{Equilibrium
		Δ\textsuperscript{13}CH\textsubscript{3}D versus
		temperature}{Calculated equilibrium Δ13CH3D versus temperature}}\label{calculated-equilibrium-ux3b413ch3d-versus-temperature}

\mrefs[B]{Figure}{fig:C:2} shows the calculated values of ln \emph{K}\textsubscript{eq} vs.\ temperature for the reaction:
\begin{equation}\label{eqn:C:exchange}
{}^{13}\text{CH}_4+ {}^{12}{\text{CH}}_3\text{D}\rightleftharpoons {}^{13}{\text{CH}}_3\text{D}+ {}^{12}{\text{CH}}_4
\end{equation}

\noindent A good fit to the curve is obtained with the expression:
\begin{equation}\label{eqn:C:equilibrium}
1000\ln K = \left( 1.68169 \times 10^{14} \right)\left( \frac{1}{T^{2}} \right)^{3} - \left( 1.40754 \times 10^{10} \right)\left( \frac{1}{T^{2}} \right)^{2} + \left( 6.72697 \times 10^{5} \right)\left( \frac{1}{T^{2}} \right) - 0.28671
\end{equation}
where temperature \emph{T} is in kelvin.

\input{figures/figC.2}

\section{Notes on analytical procedures}

\subsection{\texorpdfstring{Isolation of CH\textsubscript{4} using
		cryofocusing-preparative gas
		chromatography}{Isolation of CH4 using cryofocusing-preparative gas chromatography}}\label{isolation-of-ch4-using-cryofocusing-preparative-gas-chromatography}

\input{figures/figC.1}

\mrefs[]{Figure}{fig:C:1} shows a schematic of the methane preparation system used to
isolate CH\textsubscript{4} for measurement of
Δ\textsuperscript{13}CH\textsubscript{3}D by TILDAS at MIT from mid-2014
onwards \parencite{Wang++_2015_S,Inagaki++_2015_S,Wang++_2016_GCA,Lopes++_2016_JoDS,Whitehill++_2017_GCA}. The system consists of a
cryotrapping-preparative gas chromatography system interfaced with a
vacuum line and a helium supply. A software interface built using
National Instruments LabVIEW controls all pneumatically- and
electronically-actuated valves, pistons for dewars on cold traps, and
heating coils. Operation is mostly automatic and hands-free.
Preparation time is \textless{}45~minutes for a typical sample of
1--15~cm\textsuperscript{3} SATP CH\textsubscript{4} and
\textless{}200~cm\textsuperscript{3} air. Air blanks in the purified gas
are typically \textless{}0.10~cm\textsuperscript{3} SATP.

The retention time of methane on the PrepLine column depends on the amounts of both \ce{CH4} and ``air'' (\ce{O2}, \ce{Ar}, \ce{N2}, \ce{CO})
in the sample, as shown in \autoref{fig:C:GC}.

\input{figures/figC.GC}

\subsection{Correction of non-linearity in isotopologue concentration
	data}\label{correction-of-non-linearity-in-isotopologue-concentration-data-returned-by-tdlwintel}

Data retrieved from TDLWintel (Aerodyne Research, Inc., Billerica, Mass.)\footnote{For a history of the development of TDLWintel for applications with tunable diode and quantum cascade laser instruments, see \textcite{Horii++_1999_SPIE,Zahniser++_1995_PTRSA,Nelson++_2002_ApplPhysB,Nelson++_2004_SA-A}.} are in the form of number
densities (ND) that the software calculates from line parameters in the HITRAN database \parencite{Brown++_2013_JQSRT,Rothman++_2013_JQSRT}. For
all clumped isotopologue data collected in this thesis except those in
\autoref{dx:A}, the following correction scheme was applied.  Isotopologue/isotope ratios reported were calculated from the corrected number densities ($\mathrm{ND}_{6x}^\mathrm{corr}$).
\begin{equation}\label{eqn:C:correction}
\mathrm{ND}_{6x}^\mathrm{corr} = \mathrm{ND}_{6x}^\mathrm{meas} + D_{6x} \cdot \mathrm{ND}_{61}^\mathrm{meas} + H_{6x} \cdot \mathrm{ND}_{61}^\mathrm{meas} \cdot \left(1 - \frac{\mathrm{ND}_{61}^\mathrm{meas}/P_\mathrm{meas}}{\mathrm{ND}_{61}^\mathrm{pure}/P_\mathrm{target}} \right)~
\end{equation}
Here, $\mathrm{ND}_{6x}^\mathrm{meas}$ are the number densities returned by TDLWintel in the \texttt{STR} files, $P_\mathrm{meas}$ is the pressure of the sample in the cell, $P_\mathrm{target}}$ = \SI{1.0383}{\torr}, and $\mathrm{ND}_{61}^\mathrm{pure}$ (= \num{3.88e6}) is the number density of \ce{^{12}CH4} for a sample of pure methane at the target pressure.
Calibrated values for the correction factors $D$ and $H$ are listed in \autoref{tab:C:correctionfactors}.  Note that the $D$ and $H$ here are just variable names, and are not related to deuterium or hydrogen.  Numbering of isotopologues is from HITRAN.
\input{tables/tableC.1}

I have found this correction scheme to sufficiently correct the observed
non-linearity in δ\textsuperscript{13}CH\textsubscript{3}D vs.\ δ\textsuperscript{12}CH\textsubscript{3}D over a wide range of
δ\textsuperscript{12}CH\textsubscript{3}D values (from $-$600 to +400‰ vs.\ AL1) (the $D$ term), as well as any air that might make its way into the system (up to
10\%) (the $H$ term; the portion enclosed in parentheses represents an estimate of the percentage impurity in the methane sample).\footnote{The $D$ term
corrects the observation that measured Δ\textsuperscript{13}CH\textsubscript{3}D values are lower than their true values when δD of the sample
is lower than that of the reference gas (and vice versa).  The $H$ terms correct an observed elevation in all three δ-values when impurities (primarily air) are
present in the sample (important for the recycling technique used on small samples because air can accumulate in the sample due to small leaks in the TILDAS inlet system).}
Part of the reason for the nonlinearity is that the Voigt profile cannot accurately account for the tailing of one or more large \textsuperscript{12}CH\textsubscript{4} peaks
that are located immediately outside the wavelength region scanned by the laser.

\subsection{Calibration of isotopic composition of in-house standards
	(AL1)}\label{calibration-of-isotopic-composition-of-in-house-standards-al1}

%\input{tables/tableC.2}

The δ\textsuperscript{13}C and δD values we report have been calibrated
relative to PDB and SMOW, respectively, by measuring samples of NGS-1
(also known as NIST SRM 8559 and USGS-A) and NGS-3 (also known as NIST
SRM 8561 and USGS-C), which are natural gas standards with published
reference values for δ\textsuperscript{13}C and δD, as listed in \autoref{reporting-of-ux3b413c-and-ux3b4d-values} \parencite[supplementary materials in][]{Wang++_2015_S}. Samples of these natural gases were
included in a set of calibration samples distributed by the USGS to
various laboratories in the U.S. in July 2014. These samples were
contained in IsoTubes (Isotech Laboratories, Illinois, USA) at pressures
of \textasciitilde{}3 bar. We subsampled aliquots of these gases through
a septum adapter fitting (available from Isotech) using a 25~ml gastight
syringe (SGE Analytical Science), and introduced the aliquots into our
sample preparation system as described above.

Data shown in this thesis for δ\textsuperscript{13}C, δD, and
Δ\textsuperscript{13}CH\textsubscript{3}D assume that reference gas AL1
has the isotopic composition $-$34.5‰, $-$147.7‰, and $+$2.41 ± 0.07‰ (95\% CI)
respectively, consistent with \textcite{Wang++_2015_S} and with the values we
provided to the UCLA group \parencite{Young++_2016_IJMS}.\footnote{The values originally reported in \textcite{Ono++_2014_AC} are quite different in δD (by \textasciitilde{}20‰) for reasons as yet undetermined.  Anecdotal experience suggests that this is probably related to a historical problem of poorly-anchored δD values for GC-IRMS analyses of methane within the isotope community, with resultant differences in calibration between the several IRMS labs from which values for δD
of AL1 vs.\ SMOW were obtained.  I favor the revised values listed above for reasons of consistency with the NGS gases and the new USGS samples.}

\section{Miscellaneous unpublished information on selected sites}\label{miscellaneous-unpublished-information}

This section contains miscellaneous data and ruminations that do not yet have a proper home in the literature.
\clearpage

\subsection{\texorpdfstring{Additional field notes and thoughts on selected localities studied by \textcite{Wang++_2015_S}}{Additional field notes and thoughts on selected localities studied by Wang et al.\ (2015)}}\label{field-notes-and-thoughts-on-selected-localities}

\subsubsection{Lower Mystic Lake}\label{lower-mystic-lake}

The water sample from Lower Mystic Lake shown in \autoref{ch:2} was sampled from the water column at a depth of 18 mbll,
which is below the chemocline. It should be noted that the isotopic
composition of pore waters in Lower Mystic Lake sediments, at the
time(s) and depth(s) at which the methane was generated, may be or have
been significantly different than that of the water in the water column.
This is because prior to the implementation of water management
practices, Lower Mystic Lake was tidally-influenced, and the bottom waters were derived from seawater that flowed upriver along the bottom of the Mystic
River. Dams constructed in 1908 and 1966 slowed or stopped the influx of
seawater, and initiated a gradual reduction in the volume of anoxic and
sulfidic bottom waters in the lake; the reduction in bottom waters was
also accelerated by intentional removal of bottom waters by pumping and
treatment in the 1980s and 1990s \parencite{Duval+Ludlam_2001_IRHb,Ludlam+Duval_2001_LRM}. Therefore, even though the δD of Lower Mystic Lake water
at 18 mbll ($-$40.6 ± 1.0‰, 1\emph{s}) was similar to that of Upper Mystic
Lake ($-$39.2 ± 1.8‰, 1\emph{s}), the Lower Mystic Lake sediment pore
waters may have an isotopic signature that is closer to that of seawater
(\textasciitilde{}0‰). This trend is observed in other coastal
meromictic lakes in which seawater is trapped below the chemocline
\parencite{Jeffries++_1984_CJES}. Assuming a value of 0‰ for the associated
waters for methane generated in Lower Mystic Lake sediments would not
affect our conclusions; on the contrary, it would suggest that the field
of primary microbial methane could be constrained even more tightly than
\autoref{fig:2:2} indicates.

\subsubsection{CROMO}\label{cromo}

The water sample from the Coast Range Ophiolite Microbial Observatory (CROMO) for which the δD\textsubscript{water} value
is reported in \autoref{ch:2} was collected from the CSWold well. This well
is noted in publicly-available reports on water quality monitoring in
the area, but we do not presently have information on the depth(s) at
which the groundwater at CSWold is derived. However, the δD value of the
water is consistent with mixing between deep sedimentary-derived brines
and meteoric waters \parencite{Peters_1993_GCA}.

At CROMO, the δ\textsuperscript{13}C and δD data alone cannot
conclusively distinguish between thermogenic, abiogenic, and microbial
origins of the methane. Specifically, the CROMO gases are highly similar
in δ\textsuperscript{13}C and δD to the sample of natural gas from the
Utica Shale (\autoref{tab:2:S1} and \autoref{fig:2:1}), where the gases are
generally inferred to have been generated by thermogenic processes. The
Δ\textsuperscript{13}CH\textsubscript{3}D values at each field site are
very dissimilar, however, with the Utica Fm. gases having an apparent
temperature \textasciitilde{}160~°C and the CROMO gases having apparent
temperatures of 42 to 76~°C. Therefore, the clumped isotopic measurement
provides information that is complementary to, and independent of, the
bulk δ\textsuperscript{13}C and δD data, a conclusion that is not
obvious from previous studies.

I suggest that at CROMO, the isotopic composition of the gases
(δ\textsuperscript{13}C, δD, and
Δ\textsuperscript{13}CH\textsubscript{3}D) is inconsistent with a
significant contribution from thermogenic sources of methane.\footnote{Note that this is somewhat different from what was written by \textcite{Wang++_2015_S}.}
Furthermore, the C\textsubscript{1}/C\textsubscript{2} ratio (measured
using GC-FID) ranged from 360 to 1540 (\autoref{tab:2:S5}) for
samples of dissolved gases collected from 5 wells (including N-, CSW-,
and QV- wells) sampled in July 2014; these
C\textsubscript{1}/C\textsubscript{2} ratios are within the range
expected for microbial gases (\textgreater{}100), and outside the range
of values typically observed for thermogenic gases (\textless{}100).

If the framework presented in \autoref{fig:2:2} is correct, then a major source of
uncertainty in differentiating between the possible processes of methane
generation is the δD of the associated waters from which methane was
produced. Specifically, meteoric water in the vicinity of CROMO
generally has lower δD values ($-$70 to $-$50‰) \parencite{Peters_1993_GCA,Kendall+Coplen_2001_HP} than what was measured for water from the CSWold well
($-$33‰; \autoref{tab:2:S5}). Previous work on natural springs in the
vicinity of the McLaughlin mine suggested that groundwater in this
region can be best characterized as a two-component mixture consisting
of formation brines derived from the Great Valley Sequence mixed with
variable amounts of low-salinity meteoric water \parencite{Peters_1993_GCA}.
Parenthetically, I note that the
Δ\textsuperscript{13}CH\textsubscript{3}D-based temperatures for methane
at CROMO (42 to 76~°C) would suggest isotopic equilibration with water
that has a δD in the range of 0 to +20‰ (\autoref{fig:2:2}). This range is
consistent with the δD value (+11‰) of the most saline waters
({[}Cl\textsuperscript{\textminus}{]} \textasciitilde{} 580 mmol/kg) sampled by
\textcite{Peters_1993_GCA} from springs in the vicinity of CROMO. The apparent
temperatures of 42 to 76~°C for methane at CROMO are within the accepted
temperature limits of life (generally \textless{}80~°C, but up to 122~°C
for hyperthermophilic methanogens). Thus, based on the consistency of
the observed isotopic signatures with other geochemical parameters
(namely, {[}H\textsubscript{2}{]}, \autoref{fig:2:3}), I infer a
dominantly-microbial origin of the methane at CROMO originating from deep groundwater below the ophiolite body. Methanogenesis does not appear to occur to any appreciable extent in the shallow (meteoric) groundwaters.  More recent microbiological work showing a total absence of archaea, including methanogens, from 16S sequences of the CROMO waters  \parencite{Twing++_2017_FMicro} appears to support this conclusion.

\subsection{Methane isotopologue data on assorted samples}

\input{tables/tableC.3}

\subsubsection{Rice paddy, Sherrill, Arkansas, USA}\label{rice-paddy}
A sample of gas was collected by J.T. Bird from a paddy rice field in Sherrill, Arkansas, USA in June of 2014.  Bubbles of gas were released by gentle agitation of the submerged sediment, trapped in a funnel, and transferred to serum bottles containing several milliliters of 1~M NaOH added to inhibit microbial activity.  On the day of collection, air temperature was 93~°F and skies were cloudy.  Given that the daily lows had been steady at 70~°F for five days and the water on the field had been standing for ``a good two weeks'' (Sherrill local, via J.T. Bird, pers.\ comm.), estimated water temperatures are \textasciitilde{}75~°F or about 25~°C.

Analysis of methane in the sample (\autoref{tab:C:3}) yielded relatively low δ\textsuperscript{13}C and δD values ($-$56‰ and $-$336‰) typical of biologically-produced methane in wetlands.  The Δ\textsuperscript{13}CH\textsubscript{3}D value was anticlumped (ca.\ $-$0.5‰).  This is the lowest degree of \textsuperscript{13}C--D clumping we have observed in any natural methane sample aside from seep gases at The Cedars.

\subsubsection{Chimaera seep, Tekirova ophiolite, Turkey}
Four samples of gases collected by H.\ Hoşgörmez from the Chimaera seep (Yanartaş, meaning ``flaming rock'', near the Gulf of Antalya, eastern Mediterranean Sea; also the source of the first Olympic flame)   were sent to us by G.\ Etiope.  Samples arrived in glass vessels equipped with gas-tight stopcocks at both ends.

Analyses of methane in these samples yielded relatively high bulk δ\textsuperscript{13}C and δD values ($-$11‰ and $-$119‰, \autoref{tab:C:3}) consistent with those previously reported for the same site \parencite{Etiope++_2011_EPSL,Hosgormez++_2008_Gf,Hosgormez_2007_JAsES}.  The δ\textsuperscript{13}C values lie outside the typical range of known thermogenic methane (up to $-$20‰), and δD values are close to those required for D/H equilibrium with water of SMOW-like hydrogen-isotope composition at temperatures upwards of ca.\ 200~°C (\autoref{fig:3:5}).  The Δ\textsuperscript{13}CH\textsubscript{3}D data indicated apparent equilibrium temperatures averaging 153~°C.  These temperatures are much higher than the \textless50~°C temperatures at which abiotic methane was inferred by \textcite{Etiope++_2011_EPSL} to be synthesized here.  Recently-published data obtained by the UCLA group on several other samples taken at Chimaera yielded Δ\textsuperscript{13}CH\textsubscript{3}D values (ranging from +3.3 to +3.6‰) in general agreement with ours, as well as Δ\textsuperscript{12}CH\textsubscript{2}D\textsubscript{2} values that are at or near equilibrium at the same temperatures indicated by Δ\textsuperscript{13}CH\textsubscript{3}D \parencite{Young++_2017_GCA}.  These data indicate that methane carrying clumped isotopologue abundances similar to those of typical thermogenic gases probably comprises a large fraction of the Chimaera seep gas and that such gases may contribute more to the seepage flux than was previously suggested.

\section{Errata and corrigenda to published articles} \label{errata}

The following mistakes have been found in the two articles published from this thesis.
\begin{description}
	\item[\textcite{Wang++_2015_S}]  (\emph{i}) In Figure S4, the arrows denoting secondary isotope fractionation were labeled incorrectly; this is corrected in \autoref{fig:2:S4}.  (\emph{ii}) Several footnotes in Table S3 were incomplete or incorrectly labeled; this is fixed in \autoref{tab:2:S3}.  (\emph{iii}) Samples from the Powder River Basin were misstated as being from Wyoming.  These samples were actually taken from wellheads located in Montana, near the border with Wyoming (API well numbers 25-003-22076, 25-003-22192, and 25-003-22074, in order of appearance in \autoref{tab:2:S1}).  Also, well ``3CA34'' was completed in the Cook Coal as stated in the paper, but produces from the stratigraphically-higher Canyon Coal according to information on the Montana Board of Oil \& Gas Conservation website. \autoref{ch:2} contains the corrected information.  Several typographical errors have also been corrected.
	\item[\textcite{Wang++_2016_GCA}]  In Table 2, citations to the \citeauthor{Joelsson++_2014_CPL} papers were inadvertently switched.  \textcite{Joelsson++_2015_ACPD,Joelsson++_2016_ACP} should be cited for \ce{CH4}~+~OH and \textcite{Joelsson++_2014_CPL} for \ce{CH4}~+~Cl\@.  \autoref{tab:4:2} lists the correct references.
\end{description}

\section{Acknowledgments}
% \addcontentsline{toc}{section}{Acknowledgments}

Shuhei Ono and Bill Olszewski provided key assistance with the design,
construction, and troubleshooting of the Methane PrepLine.  Kyle Delwiche and Genming Luo are thanked for their help in the field at Lower Mystic Lake, and for insightful conversations.  Discussions with Matt Schrenk, Billy Brazelton, Katrina Twing, Mike Kubo, and Tori Hoehler helped form my views on the CROMO gases.  Dan Ritter provided the information regarding locations of wells in the Powder River Basin.  Jordan Bird graciously went out of his way to sample the Arkansas rice paddy (and take video footage!).  Giuseppe Etiope is thanked for sending us the samples from the Chimaera seep.


    \filetitle{convert}{Convert tseries object to a different frequency}{tseries/convert}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
Y = convert(X,NewFreq,...)
Y = convert(X,NewFreq,Range,...)
\end{verbatim}

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

\begin{itemize}
\item
  \texttt{X} {[} tseries {]} - Input tseries object that will be
  converted to a new frequency, \texttt{freq}, aggregating or
  intrapolating the data.
\item
  \texttt{NewFreq} {[} numeric \textbar{} char {]} - New frequency to
  which the input data will be converted: \texttt{1} or \texttt{'A'} for
  yearly, \texttt{2} or \texttt{'H'} for half-yearly, \texttt{4} or
  \texttt{'Q'} for quarterly, \texttt{6} or \texttt{'B'} for bi-monthly,
  and \texttt{12} or \texttt{'M'} for monthly.
\item
  \texttt{Range} {[} numeric {]} - Date range on which the input data
  will be converted.
\end{itemize}

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

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{Y} {[} tseries {]} - Output tseries created by converting
  \texttt{X} to the new frequency.
\end{itemize}

\paragraph{Options}\label{options}

\begin{itemize}
\item
  \texttt{'ignoreNaN='} {[} \texttt{true} \textbar{}
  \emph{\texttt{false}} {]} - Exclude NaNs from agreggation.
\item
  \texttt{'missing='} {[} numeric \textbar{} \emph{\texttt{NaN}}
  \textbar{} \texttt{'last'} {]} - Replace missing observations with
  this value.
\end{itemize}

\paragraph{Options for high- to low-frequency conversion
(aggregation)}\label{options-for-high--to-low-frequency-conversion-aggregation}

\begin{itemize}
\item
  \texttt{'method='} {[} function\_handle \textbar{} \texttt{'first'}
  \textbar{} \texttt{'last'} \textbar{} \emph{\texttt{@mean}} {]} -
  Method that will be used to aggregate the high frequency data.
\item
  \texttt{'select='} {[} numeric \textbar{} \emph{\texttt{Inf}} {]} -
  Select only these high-frequency observations within each
  low-frequency period; Inf means all observations will be used.
\end{itemize}

\paragraph{Options for low- to high-frequency conversion
(interpolation)}\label{options-for-low--to-high-frequency-conversion-interpolation}

\begin{itemize}
\item
  \texttt{'method='} {[} char \textbar{} \emph{\texttt{'cubic'}}
  \textbar{} \texttt{'quadsum'} \textbar{} \texttt{'quadavg'} {]} -
  Interpolation method; any option available in the built-in
  \texttt{interp1} function can be used.
\item
  \texttt{'position='} {[} \emph{\texttt{'centre'}} \textbar{}
  \texttt{'start'} \textbar{} \texttt{'end'} {]} - Position of the
  low-frequency date grid.
\end{itemize}

\paragraph{Description}\label{description}

The function handle that you pass in through the `method' option when
you aggregate the data (convert higher frequency to lower frequency)
should behave like the built-in functions \texttt{mean}, \texttt{sum}
etc. In other words, it is expected to accept two input arguments:

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  the data to be aggregated,
\item
  the dimension along which the aggregation is calculated.
\end{itemize}

The function will be called with the second input argument set to 1, as
the data are processed en block columnwise. If this call fails,
\texttt{convert} will attempt to call the function with just one input
argument, the data, but this is not a safe option under some
circumstances since dimension mismatch may occur.

\paragraph{Example}\label{example}


% Section 3
% 2021-08-19
% Alessandro Zanatta

\section{Case study}
\label{section:case-study}

The full models of the following examples are available on github \cite{CaseStudies}. All tools obtained the same results, the exception being Verifpal's model for the Needham-Schroeder-Lowe Public Key protocol.

\subsection{Diffie-Hellman key exchange}

We will examine three different models for the Diffie-Hellman key exchange protocol: anonymous, ephemeral and ephemeral with post-compromise of exponents. This allows us to explore many advanced features and modelling techniques of each tool. \Cref{fig:dh-key-exchange} shows a schematic representation of the protocol.

In the anonymous version we model an un-authenticated Diffie-Hellman, where no security property can hold as the adversary is free to perform a man-in-the-middle attack \cite{MITM-DH}.

In the ephemeral version we model a client-server Diffie-Hellman exchange in which the server's half key is authenticated (e.g. by an X.509 certificate). The server is willing to execute the protocol with any client, but the server is always authenticated.

Finally, we model a Diffie-Hellman with post-compromise of ephemeral keys. This is how Perfect Forward Secrecy \cite{PFS} is usually tested in the symbolic model. Of course, secrecy of the exchanged messages will not hold.

\begin{figure}[t]
    \setmscoptions
    \begin{msc}{}
        \setmscscale{.7}

        \declinst{client}{}{Client}
        \declinst{server}{}{Server}

        \action*{\parbox{3.5cm}{\centering
                Knows $g, p$\\
                $c \in \Z$\\
                $g_c := \modexp{g}{c}{p}$
            }}{client}

        \nextlevel[5]
        \mess{$g_c$}{client}{server}
        \nextlevel

        \action*{\parbox{3.5cm}{\centering
                Knows $g, p$\\
                $s \in \Z$\\
                $g_s := \modexp{g}{s}{p}$\\
                $\skey{c} := \modexp{g_c}{s}{p}$
            }}{server}

        \nextlevel[6]
        \mess{$g_s$}{server}{client}
        \nextlevel

        \action*{\parbox{3.5cm}{\centering
                $\key{cs} := \modexp{g_s}{c}{p}$
            }}{client}
        \nextlevel

    \end{msc}
    \centering
    \caption{Diffie-Hellman key exchange protocol}
    \label{fig:dh-key-exchange}
\end{figure}

\subsubsection{Implementation notes}

We will describe implementation details worth of note in the next paragraphs. Notice that we will use an incremental approach, describing only what was \textit{changed} between different versions.

\paragraph{Anonymous} The implementation of the anonymous version is straightforward. We use two particular constructs for Proverif and Tamarin to store keys: tables and persistent facts, respectively. Both serve the same purpose: store some permanent information (which is not, by default, available to the attacker). The first supports two operations: \textit{insert} and \textit{get}. The latter is, in essence, a \textit{fact} with the additional property of never being removed from the global state.

\paragraph{Ephemeral} In this version, the server half key needs to be authenticated\footnote{An additional requirement is that, while the half key cannot be mutated by the attacker, it must be available to it.}. In Verifpal there is a single (simple) way: guarded variables. Guarded variables (variables between square brackets) are not mutable by the attacker (but known by it). In Tamarin we model this with a simple private channel ruled by a passive attacker. This is done with the following multiset rewriting rule:

\lstset{language=tamarin}
\begin{lstlisting}
rule CertificateExchange:
    [ CertificateOut(x) ] --> [ CertificateIn(x), Out(x) ]
\end{lstlisting}

Finally, in Proverif we model this with a table, additionally making sure to output everything we insert into it. We could have also used a private channel, but that makes the verification of certain queries yield an inconclusive result.

\paragraph{Post-compromise} In Tamarin, we define the following rule (for both client and server):

\lstset{language=tamarin}
\begin{lstlisting}
rule RevealClientEphemeralKey:
    [ ClientEphemeralKey(c) ]
  --[ RevealedClientEphemeralKey(c) ]->
    [ Out(c) ]
\end{lstlisting}

This actually models a \textit{generic} compromise rule. We can exploit timepoints in security properties to assert that the compromise must happen \textbf{after} some other event (e.g. parties have exchanged a message), making this a post-compromise.

In Proverif, we define a process macro which simply outputs the ephemeral key in phase 1:

\lstset{language=proverif}
\begin{lstlisting}
let PostRevealClientEphemeralKey =
    phase 1;

    (* Get the client's ephemeral key and output it *)
    get ClientEphemeralKeyTable(c) in
    out(io, c);
    event PostRevealedClientEphemeralKeyTable(c);
    0.
\end{lstlisting}

\lstset{language=verifpal}
Modeling post-compromise in Verifpal requires using phases again. We can then use Verifpal's built-in construct for revealing terms: \lstinline{leaks x}.
\newpage
\begin{lstlisting}
phase [1]

principal Client [
    leaks c
]

principal Server [
    leaks s
]
\end{lstlisting}

\subsection{Needham-Schroeder Public Key protocol}
\label{sec:NSPK}

\begin{figure}[t]
    \setmscoptions
    \begin{msc}{}
        \setmscscale{.7}

        \declinst{alice}{}{Alice}
        \declinst{bob}{}{Bob}

        \action*{\parbox{3.5cm}{\centering
                Knows $\skey{A}, \pkey{A}$\\
                Knows $\pkey{B}$
            }}{alice}

        \action*{\parbox{3.5cm}{\centering
                Knows $\skey{B}, \pkey{B}$\\
                Knows $\pkey{A}$
            }}{bob}
        \nextlevel[4]

        \action*{\parbox{3.5cm}{\centering
                Generates $N_A$
            }}{alice}

        \nextlevel[3]
        \mess{$\enc{N_A, A}{\pkey{B}}$}{alice}{bob}
        \nextlevel

        \action*{\parbox{3.5cm}{\centering
                Generates $N_B$
            }}{bob}

        \nextlevel[3]
        \mess{$\enc{N_A, N_B}{\pkey{A}}$}{bob}{alice}
        \nextlevel[2]
        \mess{$\enc{N_B}{\pkey{B}}$}{alice}{bob}

    \end{msc}

    \centering
    \caption{Simplified Needham-Schroeder Public Key protocol}
    \label{fig:NSPK}
\end{figure}

The next case-study is the Needham-Schroeder Public Key protocol. Two versions are considered: the flawed version and the fixed one (by Lowe \cite{NSPK_LoweGavin}). A schematic representation of the flawed protocol is shown in \cref{fig:NSPK}, which assumes that clients already know each other's public keys. In the fixed version, message 2 is changed from $\enc{N_A, N_B}{\pkey{A}}$ to $\enc{B, N_A, N_B}{\pkey{A}}$.

\subsubsection{Implementation notes}

In order to re-discover the attack, we model the protocol in a way that allows the attacker to decide whom the honest initiator executes the protocol with. The responder, however, only wishes to engage with the honest initiator.

\newpage
\paragraph{Flawed}

In Proverif, to allow the behaviour described above, we let the attacker send the principals to the initiator at the start of its macro:

\lstset{language=proverif}
\begin{lstlisting}
let Initiator() =
(* Attacker sends communicating parties *)
in(io, (X: Principal, rUser: Principal));

(* We restrict them: X must be honest and they must be different *)
let iUser = isHonest(X, Alice, Bob) in
if iUser <> rUser then (* Protocol starts here *)
\end{lstlisting}

In Tamarin we follow a very similar approach, but we define the initiator to be always Alice (i.e. the attacker chooses \textit{only} the responder). Using the same strategy of Proverif would lead to a very complex protocol with termination issues.

In Verifpal the implementation is straightforward, with a single caveat: when pre-sharing public keys we need to guard only Alice key. This allows the attacker to mutate Bob's key to its own.

\lstset{language=verifpal}
\begin{lstlisting}
Alice -> Bob: [K_PA]
Bob -> Alice: K_PB
\end{lstlisting}

\paragraph{Fixed} No changes to the models were applied but the fix to the Needham-Schroeder Public Key protocol described at the start of \cref{sec:NSPK}.

\subsection{Results}
\begin{figure}[t]
    \centering
    \makebox[\textwidth][c]{\includegraphics{verifpal-nspk-trace}}
    \caption{Verifpal fixed NSPK attack trace.}
    \label{fig:verifpal-nspk-trace}
\end{figure}

All three tools returned the expected result:
\begin{itemize}
    \item{Diffie-Hellman
                \begin{itemize}
                    \item Anonymous: secrecy and authentication of both parties do not hold;
                    \item Ephemeral: secrecy of client messages and authentication of the server hold. Secrecy of server messages does not hold as the server is willing to initiate a run of the protocol with anybody, even the attacker;
                    \item Post-Compromise Ephemeral: secrecy of client messages no longer holds, but messages from the server are still authenticated.
                \end{itemize}
          }
    \item{Needham-Schroeder Public Key
                \begin{itemize}
                    \item Flawed: Secrecy of the nonces and authentication do not hold.
                    \item Fixed: Nonce secrecy and authentication of the initiator hold. However, as the initiator is willing to execute the protocol with anyone, authentication of the responder does not hold.
                \end{itemize}
          }
\end{itemize}

\lstset{language=verifpal}
There is an exception: Verifpal reports the fixed Needham-Schroeder Public Key  protocol as flawed and finds attack traces for both authentication and confidentiality queries.
Inspecting the tool's output shown in \cref{fig:verifpal-nspk-trace} carefully we can notice a strange result: in the penultimate line, the checked primitive \lstinline{ASSERT}\footnote{A checked primitive in Verifpal is a primitive that aborts execution of the protocol run when it fails. A question mark at the end of a primitive indicates that it is checked. The \lstinline{ASSERT} primitive simply checks that both arguments are actually the same term.} fails right after. In reality, an execution with a failed assertion should be immediately aborted, but Verifpal uses such executions to falsify queries.

Moreover, \textbf{this is not a bug} but the intended behaviour. In a mail on the Verifpal's mailing list we can find the Verifpal's author opinion (Nadim Kobeissi) on a similar problem: ``This analysis result appears to be completely correct to me. The ASSERT call occurs after Bob decrypts enca. So yes, the protocol does not finish its run, but Bob still manages to use the non-authentic enca before the protocol is aborted! Hence the result'' \cite{VerifpalMail}.

It does not seem like there is a way of changing this behaviour, but we can indeed confirm that Verifpal is reporting false traces by looking at the penultimate line: if it contains a checked primitive that obviously fails, then the attack trace is incorrect, otherwise there may be an attack. Notice that this does not mean that there is no attack trace for a certain property as the incorrect one might be masquerading a valid one.


\def\DevnagVersion{2.13}% Assignment 2 for CMSC723
% Finite State Machines

\documentclass[11pt]{article}
\usepackage{latexsym}
\usepackage{listings}
\usepackage{hyperref}
\usepackage[usenames,dvipsnames]{color}
\usepackage[pdftex]{graphicx}

%@modernhindi

\hypersetup{colorlinks=true,linkcolor=blue}

% \date{}
\begin{document}
\begin{center}
{\Large{\textbf{ Natural Language Processing:  }}}\\
\mbox{}\\
{\Large{Assignment 8: Machine Translation}}\\
% \mbox{}\\
% (\textsc{Not For Credit})\\
\mbox{}\\
{\large{Jordan Boyd-Graber}}\\
\mbox{}\\
{\large{Out: \textbf{10. November 2014}\\Due: \textbf{21. November 2014}}}\\
\end{center}

% \maketitle
\lstset{stringstyle=\ttfamily,language=Python,showstringspaces=False,tabsize=8,frameround=tttt,
		,keywordstyle=\color{Orange}\bfseries, stringstyle=\ttfamily\color{Green}
		,columns=fullflexible,identifierstyle=\ttfamily
		% , commentstyle=\itshape\color{Red}
}

\section*{Introduction} % (fold)
\label{sec:introduction}
As always, check out the Github repository with the course homework templates:

\url{git://github.com/ezubaric/cl1-hw.git}

The code for this homework is in the \texttt{hw8} directory.  The goal of this homework is for you to build a machine translation scoring function based on IBM Model 1.

\section*{Data}

The data are gzipped samples from \href{http://www.statmt.org/europarl/}{Europarl}.  And can be found in the GitHub directory with the code.

Also in the directory are two text files with lists of words.  These can help you monitor the progress of the algorithm to see if the lexical translation probabilities look like what they should.

\section*{What to Do}

You have been given a partial EM implementation of IBM Model 1 translating foreign (f) from English (e).\footnote{This is {\bf different} from what we initially discussed in class; we're applying the noisy-channel model here: $p(f|e) p(e)$, which translates into translating from English to foreign mathematically, even if the system is to translate from foreign to English.}  The maximization function is complete, but the expectation is not, nor is the function to score a complete translation pair.  You need to fill in two functions.

\subsection*{Generating Counts (20 points)}

The first function you need to fill in is \texttt{sentence\_counts}, which should return an iterator over english and foreign words pairs along with their expected count.  The expected count is the expected number of times that word pair was translated in the sentence, given by the equation
\begin{equation}
c(f|e;\vec{e}, \vec{f}) = \sum_{a} p(a|\vec{e}, \vec{f}) \sum_{j=1}^{l_f} \delta(f, f_j)(e, e_{a(j)}).
\end{equation}

\subsection*{Scoring (10 points)}

The second function you need to fill in is the noisy channel scoring method \texttt{translate\_score}, which is the translation probability (given by Model 1) times the probability of the English output under the language model.

\subsection*{Running the Model (10 points)}

Run the model and produce the lexical translation table for the development words.  Don't leave this until the last moment, because this can take a while.

\section*{How to solve the Problem}

Don't start using the big data immediately.  Start with the small data.  If you run a correct implementation on the toy data, you should get something like the following:

\begin{lstlisting}[float, label=example,caption=Successful output from running on toy data, frame=trBL,escapechar=*, numbers=left, numberstyle=\tiny, numberblanklines=false]
python ibm_trans.py 5 toy toy_test.txt
Corpus <__main__.ToyCorpus instance at 0x27d08c0>, 5 m1 iters
Model1 Iteration 0 ...
Sentence 0

blind:blind:0.250000 an:0.138889 hier:0.138889 von:0.138889
bist:0.111111 du:0.111111 nicht:0.111111 irish:du:0.166667
irisch:0.166667 kind:0.166667 mein:0.166667 wilest:0.166667
wo:0.166667 is:ist:0.181818 der:0.090909 fahrrad:0.090909
himmel:0.090909 mein:0.090909 nicht:0.090909 noch:0.090909
rosa:0.090909 siebte:0.090909 weit:0.090909 cries:auch:0.200000
der:0.200000 himmel:0.200000 weint:0.200000 wo:0.200000
are:du:0.206897 bist:0.120690 blind:0.120690 nicht:0.120690
irisch:0.086207 kind:0.086207 mein:0.086207 wilest:0.086207
wo:0.086207

done

...

========COMPUTING WORD TRANSLATIONS=======
balloons	99	0.203438
not	blind	0.028217
blind	blind	0.693760
jets	99	0.341654

LM Sentence 0
========COMPUTING SENTENCE TRANSLATIONS=======
ENGLISH:	 my bike cries 99 fighter jets
FOREIGN:	 mein fahrrad weint 99 dusenjaeger
SCORE:	 -30.100041

ENGLISH:	 the heaven is pink about now
FOREIGN:	 von hier an bleibe der himmel rosa
SCORE:	 -44.224041
\end{lstlisting}

\section*{What to turn in}

You will turn in your complete \texttt{ibm\_trans.py} file and the word translations for the supplied test file (devwords.txt) after three (3) iterations of EM.

\section*{Extra Credit (5 points)}

If you would like extra credit, add an additional function that computes the best alignment between a pair of sentences.

\section*{Questions}

\begin{enumerate}

\item \textit{My code is really slow; is it okay if I don't run my code on the entire dataset?  (by using the limit argument)}

Yes, but if your numbers look too far off from what is expected, you may lose points.

\item \textit{I'm getting probabilities greater than 1.0!}

The logprob function of \texttt{nltk}'s language model returns the negative log probability.

\item \textit{I can't get my translation probabilities to match.}

\begin{itemize}
\item One little thing that may cause a slight difference in computing
  the translation probability of sentences in the
  \texttt{translate\_score}: I add 0.001 to each of the inputs (to
  guard against zeros) while summing up across the foreign string.

\item You will need to add a \texttt{None} to the English sentence in the \texttt{translate\_score} function.  The assert is there to make sure it hasn't happened outside of the function.

\item Make sure you compute the \texttt{lm} probabilities conditioning the
  first word on the empty string (\texttt{''}).
\end{itemize}

\end{enumerate}

\end{document}


\section{Additional figures}
\label{sec:figures}

\subsection{Demographics}

\begin{figure}[H]
    \figuretitle{Old-age dependency ratio}
    \includegraphics[width=\textwidth]{../../out/figures/dependency_ratio.png}
    \caption{\textbf{Simulated old-age dependency ratio:} the dependency ratio is derived by simulating population dynamics based on adjusted conditional survival rates, starting from a stationary population distribution and calculating the ratio of the mass of retired households to the mass of working age households.}
    \label{fig:OADR}
\end{figure}

\subsection{Stationary equilibria}

\begin{figure}[H]
    \centering
    \figuretitle{Distributions by age}
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \includegraphics[width=\textwidth]{../../out/figures/aggregates_by_age_initial.png}
        \caption{Initial stationary equilibrium}
        \label{fig:aggregates_by_age_initial}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \includegraphics[width=\textwidth]{../../out/figures/aggregates_by_age_final.png}
        \caption{Final stationary equilibrium}
        \label{fig:aggregates_by_age_final}
    \end{subfigure}
    \caption{\textbf{Distribution by age:} Distribution of asset holdings and human capital level by age}
    \label{fig:aggregates_by_age}
\end{figure}

\subsection{Transitional dynamics}

\begin{figure}[H]
    \figuretitle{Transitional dynamics}
    \includegraphics[width=\textwidth]{../../out/figures/results_transition.png}
    \caption{Transition paths of aggregate variables}
    \label{fig:transition_aggregates}
\end{figure}