\documentclass{../csopractical}
\usepackage{pdffig}
\SVN    $Id: Practical3.tex 1325 2016-01-15 19:11:41Z sufrin $

\begin{document}
\begin{center}
\Large\bf Concurrent Programming Practical
\\
3: Hamming Numbers
\end{center}
%\maketitle

It is recommended that you read the material from the section of the course on
\emph{Message Passing} (using Channels) before you attempt this practical.

The aim of the practical is to  implement a dataflow network to generate
an ordered sequence of \textit{Hamming Numbers}, with no duplicates.
The (inductive) definition of the Hamming numbers is as follows:
%
\begin{itemize}
\item 1 is a Hamming number.
\item If $h$ is a Hamming number, then so are $2h$, $3h$ and $5h$.
\end{itemize}
%
Another way of thinking of the Hamming numbers is that they are those whose
only prime factors are 2, 3 and 5.

The illustration below shows a network that solves the problem. If you
have read the material suggested, it should be fairly obvious what the
various components are expected to do.  The component \SCALA{Merge} receives
two ordered streams, and merges them into a single ordered stream, without
repetitions.

\begin{center}
\pdffig[width=6cm]{hamming}
\end{center}

\subsubsection*{Your Task}
Implement the network.

You may make use of components from the package
\SCALA{io.threadcso.component} if you like (but note that
\SCALA{io.threadcso.component.merge} has a different behaviour from the
\SCALA{Merge} required here).  In some cases you will need to
implement your own components, especially to answer some of the questions
below.

If you implement the network with no buffering on any of the channels, you
will find that it deadlocks.  Explain precisely how this deadlock
arises: you should explain what state each component is in in the deadlocked
state.  You might need to adapt some of the components in order to understand
this behaviour.

Re-implement the network with sufficient buffering to enable it to find the value
of the 1000th Hamming number.  The declaration
\begin{scala}
val c = OneOneBuf[T](size)
\end{scala}
defines \SCALA{c} to be an asynchronous buffered channel, passing data of
type~\SCALA{T}, with capacity~\SCALA{size}.  Think about which channels
need to be buffered, and which can remain unbuffered.

{\bf Optional:} Modify the components so that all the processes terminate
cleanly once the 1000th Hamming number has been output.

\textbf{Just for fun:}
Generalize the construction of the network so that it generates
the sequence of ``Hamming-like'' numbers whose  factors are given as a
list of parameters to your program.

\subsubsection*{Reporting}

Your report should be in the form of a well-commented program, together with
brief answers to the above points.

%% You have already seen the design of a \texttt{Tee}-like
%% component. You are expected to design the remaining
%% components (\texttt{Merge, Buf, x2, x3, x5}) that will
%% enable you to explore the behaviour of the
%% network but you must decide for yourself how to
%% ``bootstrap'' the data flow in the network, and how and
%% where to ``tap'' the network so that the numbers can be
%% output to a channel from which they can be read and used.
%% In the diagram these details are hidden within the component named
%% \texttt{Hamming}.

%% Your report (which need not be very long) should explain your
%% code. In it you should also document the results of your investigation into the
%% following questions:
%% \begin{enumerate}\item[]
%% \begin{enumerate}\item[]
%% \begin{enumerate}
%% \item Does the network deadlock?
%% \item If so, then under what circumstances does it deadlock?
%% \item Could the deadlock either be avoided or postponed by changing the
%%       design of the network or by increasing the size of one or more
%%       of the buffers?
%% \item What is the largest Hamming number representable as a \SCALA{long}?
%% \item What is the 10000'th Hamming number?
%% \item Can any network component be modified, or can
%%       suitable components be added to the network, to ensure that all
%%       processes involved terminate cleanly after the largest representable
%%       Hamming number has been output?
%% \end{enumerate}
%% \end{enumerate}
%% \end{enumerate}

\vfill

\end{document}


\chapter{ISOCAM data deconvolution using Markov random field}

\section{Introduction}

The aim of image deconvolution is to estimate the original image $\bf x$ from its
observed image $\bf y$. The degradation model is described by the linear
relation:
\begin{eqnarray}
{\bf y = H x + n }
\label{eqn_lin}
\end{eqnarray}
where $\bf H$ is the Point Spread Function (PSF) matrix and $\bf n$ is
a white Gaussian additive noise.
In general, the information provided by the data alone and the forward model
(\ref{eqn_lin}) is not sufficient to
determine a solution with acceptable accuracy.
Consequently, some a priori information about the structure of $\bf x$ is needed
for recovery. Regularization is one method for adding constraints to the solution.
More details may be found in \cite{rest:demoment89}.
Many regularized solutions have been presented (see \cite{starck:sta94_1} and
\cite{rest:blancferaud96}).

\section{Regularization using Markov model}

\subsection{Introduction}

Let us briefly review the ingredients of the proposed regularization method.
The basic procedure uses a Markov random field as the prior model,
the relation (\ref{eqn_lin}) for image formation consisting typically of blur and superposition
of Gaussian noise, and Bayes formula to obtain the posterior distribution $P(\bf
x/y)$.

\subsubsection{Random Markov field}

A random sequence $\bf x$ is called a Markov random field if for each site $s$:
\begin{eqnarray}
P({\bf x}) > 0 && \forall {\bf x}\in \Omega
\end{eqnarray}
\begin{eqnarray}
P(x_s/x_t;t\in S-\{s\}) = P(x_s/x_t;t\in{{\cal V}_s})
\end{eqnarray}
where $\Omega$ represents all possible configurations and $S$ is the dimension of
the field $\bf x$.
At every site $s$ of the field $\bf x$, the conditional probability
depends on a neighborhood ${\cal V}_s$ which is defined by the neighbors $t$ of the
site $s$. Note that ${\cal V}_s$ increases with the order of the model.

\subsubsection{Examples of models}

The four-neighbor system is defined such as:

\begin{picture}(100,120)(0,0)
\put(50,0){\circle{5}}
\multiput(0,50)(100,0){2}{\circle{5}}
\put(50,50){\circle*{5}}
\put(55,55){site s}
\put(50,100){\circle{5}}
\put(150,55){4 NEIGHBOR MODEL}
\end{picture}

Because the edges of the image are not only parallel to the axes, there seems
to be need to include diagonal neighbor pixels.
Then, the four-neighbor model can be ameliorated such as:

\begin{picture}(100,120)(0,0)
\multiput(0,0)(50,0){3}{\circle{5}}
\multiput(0,50)(100,0){2}{\circle{5}}
\put(50,50){\circle*{5}}
\put(55,55){site s}
\multiput(0,100)(50,0){3}{\circle{5}}
\put(150,55){8 NEIGHBOR MODEL}
\end{picture}

\subsubsection{Gibbs distribution}

The prior distribution $P({\bf x})$ can be interpreted as a Gibbs energy.
Then, $\bf x$ is a Markov random field if
$P({\bf x})$ is a Gibbs distribution such as:
\begin{eqnarray}
P({\bf x}) = \frac{1}{Z}\exp(-U({\bf x}))
\end{eqnarray}
where $Z$ is a partition function and $U({\bf x})$ a prior energy such as:
\begin{eqnarray}
U({\bf x}) = \sum_{c \in {\cal C}} V_c(\bf x)
\end{eqnarray}
where $V_c(\bf x)$ are potentials functions and $c$ is a clique which is
defined as a pair of adjacent pixels.

\subsection{Potential function and line process}

In order to preserve edges,
the use of a {\it line process} was introduced by Geman and Geman \cite{rest:geman84}.
In practise, a line process is defined via a potential function $\phi$
which has particular properties (see \cite{rest:geman92}):

Suppose $\phi(u)$ has the following properties on $[0,+\infty[$:
\begin{itemize}
\item $\phi(0)=0$
\item $\phi(\sqrt u)$ concave
\item $\lim_{u \rightarrow +\infty} \phi(u)=1$
\end{itemize}

Then, there exists a function $\psi(l)$ defined on an interval [0,L] such as:
\begin{eqnarray}
\phi(u) = \inf_{0\leq l\leq L}(lu^2+\psi(l))
\label{mar_eqn_vdl}
\end{eqnarray}

and such that $\psi(l)$ has the properties:
\begin{itemize}
\item $\psi(0)=1$
\item $\psi(L)=0$
\item $\psi(l)$ strictly decreasing.
\end{itemize}

The line process is defined as the derivative of
$\phi(\sqrt u)$ such as:
\begin{eqnarray}
l = \phi'(\sqrt u)
\end{eqnarray}

\subsection{Posterior modelization}

In the context of Bayesian estimation, the posterior distribution
$P({\bf x/y})$ can be written as:
\begin{eqnarray}
P({\bf x/y}) \propto P({\bf y/x})P({\bf x})
\end{eqnarray}
where
\begin{eqnarray}
P({\bf y/x}) \propto \exp(-U({\bf y/x}))
\end{eqnarray}
and
\begin{eqnarray}
P({\bf x}) \propto \exp(-U({\bf x}))
\end{eqnarray}
Then, the posterior $P({\bf x/y})$ is also a Gibbs energy such as:
\begin{eqnarray}
U({\bf x/y}) = U({\bf y/x}) + U({\bf x})
\end{eqnarray}
The traditional choice in image restoration is:
\begin{eqnarray}
U({\bf y/x}) = \frac{\|{\bf y-Hx}\|^2}{2\sigma^2}
\end{eqnarray}
In the first order case, the prior $P({\bf x})$ is defined such as:
\begin{eqnarray}
U({\bf x}) = \sum_{cliques} \phi(x_r-x_s)
\end{eqnarray}
where $\phi$ is the potential function and $(x_s-x_r)$ is the difference
between the values $x_r$ and $x_s$ of the two neighbors inside the
clique $c$.
The solution is estimated by maximizing the posterior distribution
$P({\bf x/y})$.
Then, the energy $U({\bf x/y})$ must be minimized.
\begin{eqnarray}
U({\bf x/y}) = \frac{\|{\bf y-Hx}\|^2}{2\sigma^2}
               + \lambda \sum_{cliques} \phi(x_r-x_s)
\label{mar_eqn_cr}
\end{eqnarray}
where $\lambda$ is the regularizing parameter.

\section{Application}

\subsection{Minimization of the prior energy}

The difficulty is to minimize the non quadratic energy $U(\bf x)$.
From the work of Geman and Reynolds \cite{rest:geman92},
the minimization of $U(\bf x)$ is equivalent to minimizing $U(\bf x/l)$ such
as:
\begin{eqnarray}
\min_{\bf x}(U({\bf x})) = \min_{\bf x,l}(U({\bf x,l}))
\end{eqnarray}
where $\bf l$ is the vector of the line variables $l_c$.
According to equation (\ref{mar_eqn_vdl}), it follows that $U(\bf x/l)$ can
be written
as:
\begin{eqnarray}
U({\bf x,l}) = \sum_{cliques\,c} l_c (x_r-x_s)^2 + \psi(l_c)
\label{mar_mar_eqn_eg}
\end{eqnarray}
Note that the regularization becomes "half-quadratic" (see \cite{rest:blancferaud96})
by using equation (\ref{mar_mar_eqn_eg}):
\begin{itemize}
\item With $\bf l$ fixed, $U({\bf x,l})$ is quadratic in $\bf x$. The
minimization in $\bf x$ reduces to the resolution of a linear system.
\item With $\bf x$ fixed, the minimum $\hat l_c$ is given by the expression
$\hat l_c=\phi'(u)/2u$ where $u=(x_r-x_s)$.
\end{itemize}
We suppose that the variables $\hat l_c$ do not interact with each other.
In fact, these {\it line variables} map the discontinuities (or the edges) of
the image $\bf x$. $\hat l_c$ takes a value near zero at the edges and a
value $L$
in homogeneous areas.

\subsection{Line variables system}

For the first order Markov case, a line variable is labeled as an arrow
between two horizontal or vertical and adjacent pixels $(x_r,x_s)$.
Then, each arrow is associated with a first order clique.

\begin{picture}(100,120)(0,0)
\put(50,0){\circle{5}}
\multiput(0,50)(100,0){2}{\circle{5}}
\put(50,50){\circle*{5}}
\put(55,55){(x,y)}
\put(55,105){(x,y+1)}
\put(55,5){(x,y-1)}
\put(105,55){(x+1,y)}
\put(5,55){(x-1,y)}
\put(50,100){\circle{5}}
\put(50,95){\vector(0,-1){40}}
\put(50,45){\vector(0,-1){40}}
\put(95,50){\vector(-1,0){40}}
\put(45,50){\vector(-1,0){40}}
\put(150,55){FOUR-NEIGHBOR SYSTEM}
\end{picture}

The four neighbor system can be ameliorated by including diagonal adjacencies.

\begin{picture}(100,120)(0,0)
\multiput(0,0)(50,0){3}{\circle{5}}
\multiput(0,50)(100,0){2}{\circle{5}}
\put(50,50){\circle*{5}}
\multiput(0,100)(50,0){3}{\circle{5}}
\put(105,105){(x+1,y+1)}
\put(5,-5){(x-1,y-1)}
\put(105,-5){(x+1,y-1)}
\put(5,105){(x-1,y+1)}
\put(50,95){\vector(0,-1){40}}
\put(50,45){\vector(0,-1){40}}
\put(95,50){\vector(-1,0){40}}
\put(45,50){\vector(-1,0){40}}
\put(95,95){\vector(-1,-1){40}}
\put(45,45){\vector(-1,-1){40}}
\put(95,5){\vector(-1,1){40}}
\put(45,55){\vector(-1,1){40}}
\put(150,55){EIGHT-NEIGHBOR SYSTEM}
\end{picture}

\subsection{The potential function}

Concerning the choice of $\phi$, the following convex function proposed in
\cite{rest:brette96} is used:
\begin{eqnarray}
\phi_{\delta}(u) = |u/\delta| - \ln(1+|u/\delta|)
\label{mar_eqn_phi}
\end{eqnarray}
where $u=(x_r-x_s)$ and $\delta$ is a scaling parameter.
An example is given for $\delta=500$ in Figure~\ref{fig_mar_phi}. It shows
that $\phi$ is quadratic with $u<<\delta$ and linear with $u>>\delta$.
\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=mf_phi.ps,bbllx=2.5cm,bblly=13cm,bburx=19.5cm,bbury=25.5cm,width=14cm,height=14cm,clip=}
}}
\caption{}
\label{fig_mar_phi}
\end{figure}
The derivative is equal to
$\phi'_{\delta}(u)=u/\delta(|u|+\delta)$.
Note that updating the line variables is a simplified operation by using the following
formula:
\begin{eqnarray}
\hat l_c = \phi'_{\delta}(u)/2u = \frac{1}{2\delta}/(\delta + |u|)
\end{eqnarray}

\subsection{The prior energy formula}

\subsubsection{Four neighbor system}

In the case of the four nearest neighbors, the prior energy is defined as:
\begin{eqnarray}
U({\bf x}) = \sum_{vertical\, cliques} \phi_{\delta}(I_{y,x}-I_{y+1,x}) +
\sum_{horizontal\, cliques} \phi_{\delta}(I_{y,x}- I_{y,x+1})
\label{mar_eqn_e}
\end{eqnarray}
where $I_{y,x}$ is the pixel intensity in image $I$ at row $y$ and column $x$.

\subsubsection{Eight neighbor system}

By adding the following expressions to the terms in equation (\ref{mar_eqn_e}), we
obtain the energy $U({\bf x})$ of the eight neighbor system:
\begin{eqnarray}
\sum_{diagonal\, cliques} \phi_{\delta}(I_{y,x}- I_{y+1,x+1})
\end{eqnarray}
and
\begin{eqnarray}
\sum_{diagonal\, cliques} \phi_{\delta}(I_{y,x}- I_{y-1,x+1})
\end{eqnarray}

\subsection{Deterministic algorithm}

Instead of using a stochastic approach, we use a single site update algorithm
\cite{rest:brette96} in order
to minimize the half-quadratic criterion (\ref{mar_eqn_cr}).
The solution is computed by visiting the entire set of pixels in a determined
fashion (checkerboard) to update each value $x_{ij}$ of the estimated solution
$\bf x$ at row $i$ and column $j$.
We know that the energy $U(\bf x)$ is quadratic as a function of $x_{ij}$.
Its minimum value is reached at $m_{ij}$:
\begin{eqnarray}
m_{ij} = x_{ij} + \frac{[{\bf H^ty}]_{ij} - [{\bf H^tHx}]_{ij} - 2\sigma^2\lambda
\sum l_c(x_{ij}-x_c)}{[{\bf H^tH}]_{ij,ij} + 2\sigma^2\lambda\sum l_c}
\label{mar_eqn_corr}
\end{eqnarray}
where the sums extend to the neighborhood of the currently visited pixel $x_{ij}$.
The algorithm is initialized with an image where all pixels are equal to zero.

\subsection{Parameter estimation}

\subsubsection{Scaling parameter $\delta$}

This parameter allows to fix the threshold under which the smoothness of the
solution is preserved and above which discontinuities or edges stay in the
estimated solution.
The value $\delta$ is estimated from the observed image $\bf y$ by looking at the
evolution of edges between adjacent pixels. In fact, one method of selecting
$\delta$
would be to determine the global maximal difference between two adjacent pixels
for all possible cliques of the observed image.
If $\delta$ is too high, then the estimated solution will be smooth.

\subsubsection{Regularizing parameter $\lambda$}

This parameter balances fidelity to the prior constraints and fidelity to the
data. In every experiment, $\lambda$ is empirically tuned to obtain
visually good results. In fact, since appropriate values for $\delta$ are more or
less estimated, the value for $\lambda$ is not an evident choice.
However, if $\lambda$ is too high, the solution is over-regularized and if
$\lambda$ is too small, the solution is not stabilized.

\section{Use of the program im\_dec\_markov}

\begin{center}
 USAGE: ${\bf im\_dec\_markov}$ option image\_in psf\_in image\_out
\end{center}
where options are:
\begin{itemize}
\item {\bf [-b]} \\
If this option is set, the support of the image is dilated by using I\_MIRROR to
obtain a solution with the same support. By default, we use I\_CONT.
\item {\bf [-d delta]} \\
Scaling parameter $\delta$. This parameter must be strictly positive.
Default is 1 (See Parameter estimation section)
\item {\bf [-e epsilon]} \\
Convergence parameter. Default is 0.001
\item {\bf [-g sigma]} \\
Gaussian Noise standard deviation. Default is automatically estimated.
\item {\bf [-i number\_of\_iterations]} \\
Maximum number of iterations. Default is 500
\item {\bf [-l lambda]} \\
Regularizing parameter $\lambda$. This parameter must be strictly positive.
Default is 1 (See Parameter estimation section)
\item {\bf [-o omega]} \\
Over-relaxation coefficient such as: $1\leq omega<2$. Omega is used to allow faster
convergence. Default is 1
\item {\bf [-r residual\_file\_name]} \\
If this option is set, the residual is written to
the file of name {\em residual\_file\_name}. By default, the
residual is not written. The residual is equal to the difference between
the input image and the solution convolved by the PSF.

The maximum of the PSF must be at the center of its support.
So, dimensions of the PSF support must be odd.
\end{itemize}
\noindent

{\bf Example:}
\begin{itemize}
\item im\_dec\_markov -d 100 -i 100 -l 10 -r residu.fits
image\_in.fits psf\_in.fits ima\_out.fits \\
deconvolves an image with $\delta=100$ and $\lambda=10$, assuming
a Gaussian noise (its standard deviation is automatically estimated).
\end{itemize}

For each iteration, the following informations will be printed:

...

It 95 D=90674.9 M=537432 V=628106 Ec=75.5482 Fx=9.38398e+07 min=1224.23 max=13732.2

It 96 D=90676.3 M=537430 V=628107 Ec=70.6314 Fx=9.38399e+07 min=1224.23 max=13731.7

It 97 D=90677.5 M=537429 V=628107 Ec=66.1543 Fx=9.38398e+07 min=1224.23 max=13731.3

It 98 D=90678.7 M=537429 V=628107 Ec=61.8843 Fx=9.38399e+07 min=1224.23 max=13730.8

It 99 D=90679.9 M=537428 V=628107 Ec=57.978 Fx=9.38399e+07 min=1224.23 max=13730.4

where D=$U({\bf y/x})$, M=$U({\bf x})$ and V=$U({\bf x/y})$
so V=D+M according to equation (\ref{mar_eqn_cr}).

Ec is the correction energy compared
to the convergence parameter (epsilon).

Fx is the flux of the estimated
solution $\bf \hat x$.

Minimum and maximum of the restored image are also printed.

\newpage

\section{Data Simulation}

The original image (the object) is a simulated HST Wide field camera image of
a distant cluster
of galaxies (see Figure~\ref{fig_convol1}).
We used a Gaussian PSF (see Figure~\ref{fig_psf}) which has the following properties:
\begin{itemize}
\item{Support = 11 x 11 pixels}
\item{  Min = 2.00418e-08}
\item{  Max = 0.0980603}
\item{  Mean = 0.0082643}
\item{  sigma = 0.0183551}
\item{  Flux = 0.999981}
\item{  Energy = 0.0490302}
\end{itemize}
\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=mf_psf.ps,bbllx=2.5cm,bblly=13cm,bburx=19.5cm,bbury=25.5cm,width=16cm,height=16cm,clip=}
}}
\caption{Point Spread Function (PSF)}
\label{fig_psf}
\end{figure}

The image (see Figure~\ref{fig_convol1}) was blurred with the Gaussian PSF, and Gaussian noise ($\sigma=20$) was
added.
\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=mf_simu256.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
\psfig{figure=mf_data256.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
}}
\caption{Left: the original image, Right: the blurred image.}
\label{fig_convol1}
\end{figure}

\section{Results}

\subsection{Visual comparisons}

The proposed deconvolution method using a Markov model is compared to the
basic Richardson-Lucy (RL)
algorithm in
Figure~\ref{fig_lucy} and to the regularized RL method in Figure~\ref{fig_mr}.
\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=mf_Lresultd4.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
\psfig{figure=mf_D100L10.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
}}
\caption{Left: Deconvolution with RL method, Right: Deconvolution with
Markov model ($\delta=100$ and $\lambda=10$)}
\label{fig_lucy}
\end{figure}
\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=mf_Lresultd8.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
\psfig{figure=mf_D100L10.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
}}
\caption{Left: Deconvolution with regularized RL method, Right: Deconvolution with
Markov model ($\delta=100$ and $\lambda=10$)}
\label{fig_mr}
\end{figure}

\subsection{Flux linearity}

The simulated HST image in Figure~\ref{fig_convol1} provides enough sources
to test
the flux linearity. The procedure followed was to detect all sources
respectively
in the observed image and also in the image restored by the proposed
regularization method.
Then, the flux of each source before and after deconvolution is
displayed in Figure~\ref{fig_flux}.

\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=fx256.ps,bbllx=1.5cm,bblly=13cm,bburx=20.5cm,bbury=25.5cm,width=15cm,height=15cm,clip=}
}}
\caption{FLUX LINEARITY TEST}
\label{fig_flux}
\end{figure}

\section{Conclusion}

The problem of image deconvolution has been considered in the context of the
regularization theory. An example of regularized method is proposed.
The approach we have taken involves constraints in the estimated solution
that are locally due to the Markov
neighbor system. Nevertheless, the choice of parameters $\delta$ and $\lambda$
is global. Then, it could be interesting to introduce
local parameters to open up new experimental directions.


\documentclass[10pt]{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fullpage}
\usepackage{amssymb}
\usepackage{amsmath}

\linespread{1.18}
\pagenumbering{gobble}

%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Title & Heading %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%

\title{\huge\textbf{HW2: Problem 1}}
\author{\textit{Mehran Shakerinava}}
\date{October 2019}

\begin{document}

\maketitle

\noindent
For brevity, I'll write $\mathbb{E}_{x\sim p_\theta (X|y)}$ as $\mathbb{E}_{x|y}$.\\
\textit{The following result forms the basis of the solutions to this problem:}

\begin{equation*}
\begin{aligned}
\mathbb{E}_{a_t|s_t} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \right] &= \int \pi_\theta(a_t|s_t) \nabla_\theta \log \pi_\theta(a_t|s_t) da_t \\
&= \int \pi_\theta(a_t|s_t) \frac {\nabla_\theta \pi_\theta(a_t|s_t)}{\pi_\theta(a_t|s_t)} da_t \\
&= \int \nabla_\theta \pi_\theta(a_t|s_t) da_t \\
&= \nabla_\theta \int \pi_\theta(a_t|s_t) da_t \\
&= \nabla_\theta 1 \\
&= 0
\end{aligned}
\end{equation*}

\section*{Part A}

\begin{equation*}
\begin{aligned}
\mathbb{E}_{\tau}\left[ \nabla_\theta \log \pi_\theta(a_t|s_t) b(s_t) \right] &= \mathbb{E}_{s_t, a_t} \left[ \mathbb{E}_{\tau/s_t, a_t|s_t, a_t} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) b(s_t) \right] \right] \\
&= \mathbb{E}_{s_t, a_t} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) b(s_t) \right] \\
&= \mathbb{E}_{s_t} \left[ \mathbb{E}_{a_t|s_t} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) b(s_t) \right] \right] \\
&= \mathbb{E}_{s_t} \left[ b(s_t) \mathbb{E}_{a_t|s_t} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \right] \right] \\
&= 0
\end{aligned}
\end{equation*}

\section*{Part B}

\subsection*{a)}
Because of the Markov property, given $s_t$, the distribution of states and actions after time $t$ is independent of states and actions before time $t$. This implies that $\nabla_\theta \log \pi_\theta(a_t|s_t) b(s_t)$, which is a function of $s_t$ and $a_t$, is independent of $(s_1, a_1, ..., a_{t-1})$ given $s_t$, and thus, conditioning on $(s_1, a_1, ..., a_{t-1}, s_t)$ is equivalent to conditioning only on $s_t$.

\subsection*{b)}
\begin{equation*}
\begin{aligned}
\mathbb{E}_{\tau}\left[ \nabla_\theta \log \pi_\theta(a_t|s_t) b(s_t) \right] &= \mathbb{E}_{s_{1:t}, a_{1:t-1}} \left[ \mathbb{E}_{s_{t+1:T}, a_{t:T} | s_{1:t}, a_{1:t-1}} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) b(s_t) \right] \right] \\
&= \mathbb{E}_{s_{1:t}, a_{1:t-1}} \left[ \mathbb{E}_{s_{t+1:T}, a_{t:T} | s_t} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) b(s_t) \right] \right] \\
&= \mathbb{E}_{s_{1:t}, a_{1:t-1}} \left[ \mathbb{E}_{a_t | s_t} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) b(s_t) \right] \right] \\
&= \mathbb{E}_{s_{1:t}, a_{1:t-1}} \left[ b(s_t) \mathbb{E}_{a_t | s_t} \left[ \nabla_\theta \log \pi_\theta(a_t|s_t) \right] \right] \\
&= 0
\end{aligned}
\end{equation*}

\end{document}


\documentclass[11pt,english]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{float}

\begin{document}

% Define document title and author
\title{Modeling Object Behavior Near Black Holes}
\author{
  Carl Cortright\\
  \texttt{SID: 104731007 Recitation Number: 212 Section Number: 130}
  \and
  Samuel Coyle\\
  \texttt{SID: 105477414 Recitation Number: 243 Section Number: 140}
  \and
  Nelson Botsford\\
  \texttt{SID: 103627718 Recitation Number: 243 Section Number 140}
}
\maketitle

\section*{Introduction}

The study of black holes has classically been restricted to the field of theoretical physics, but lately with movies like Interstellar and Gravity the science has begun to capture the public imagination. While it is impossible to model the inner workings of a black hole beyond the event horizon, we can use differential equations to model the paths of object moving near a black hole, including their relativistic properties. In this report, we analyze the path of an astronaut (Matthew McConaughey) as he descends towards the event horizon from our perspective on a ship whose mission is to seed humanity\textquotesingle s new home planet. Before we lost contact, we were able to model the path of the astronaut with the following differential equation.

\begin{center}
$\frac{dx}{dt} = (\frac{1}{x(t)} - 1) \frac{1}{\sqrt{x(t)}}$
\end{center}

\section*{Understanding the Astronaut\textquotesingle s Path}

To better understand the path of the astronaut, we must first classify the differential equation as autonomous, non-linear, homogeneous, and separable. The astronaut\textquotesingle s speed is the derivative of his position, and the equation is autonomous/homogeneous, meaning that his speed is entirely dependent on his proximity from the center of the black hole.

As mentioned earlier, the speed of the astronaut is the time derivative of position, meaning the differential equation given is the speed of the astronaut as he approaches the black hole. If we have the position of the astronaut, then we are also able to measure his velocity, making it trivial to find his initial velocity.

\begin{center}
$x(0) = 2$,  $v_o = (\frac{1}{2} - 1)\frac{1}{\sqrt{2}} = \frac{-1}{2\sqrt{2}} = -\sqrt{2}$
\end{center}

\section*{Analyzing Existence and Uniqueness of Solution Curves}

Before we decide to use our model as a model for the astronaut\textquotesingle s path, we must first verify that it produces sufficiently unique solutions in proximity of where we want to do our analysis. A useful theorem for defining existence and uniqueness of solutions is Picard\textquotesingle s Theorem which states that the derivative is continuous on a specific rectangle and the second partial derivative with respect to the dependent variable is continuous on that same rectangle, then there exists a unique solution within some interval on the rectangle. Using Picard\textquotesingle s, we first need to find the second partial with respect to x:

\begin{center}
  $\frac{\partial v}{\partial x} = \frac{d}{dx} (\frac{1}{x(t)} - 1) \frac{1}{\sqrt{x(t)}} = \frac{3}{2x^\frac{5}{2}} - \frac{1}{2x^\frac{3}{2}}$
\end{center}

Using this derivative, we are able to tell that there will be a unique solution on any rectangle where all values of x are greater than 0.

\section*{Positions that Result in no Translation}

Using the equation of the velocity of the velocity given we find that there may be positions where the astronaut will stop moving away or towards the event horizon. These two points where the astronaut will be at equilibrium are x=1 and the limit as x approaches infinity. This makes sense because at the event horizon the astronaut will no longer be moving towards it and as the astronaut gets farther and farther the black hole will have diminishing effect on the astronaut. Unfortunately for the astronaut they will never escape the black hole because for any x value greater than one there is a nonzero velocity.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{DirectionField.jpg}
  \caption{The direction field for equation 1.}
  \label{fig:dirfield1}
\end{figure}

\section*{Finding the Path of the Astronaut}

Our most promising option for finding solutions to this differential equation is numerical computation. Analytical solutions are desirable, but in this case it is not worth trying to find one. Instead we can find use various step sizes to compute the following approximations.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{EulerPlots.jpg}
  \caption{Numerical approximations using Euler\textquotesingle s method starting at x=2.}
  \label{fig:euler1}
\end{figure}

Considering that the plots for step sizes of 0.01 and 0.1are indistinguishable, a step size of 0.1 is enough to give us an accurate approximation without wasting computational resources.

\section*{Long Term Results}

We know that this equation has a unique solution when the starting value of x > 0 as shown in the equation shown below:

\begin{center}
  $\lim_{x\to1} (\frac{1}{x(t)} - 1) \frac{1}{\sqrt{x(t)}} = 0$
\end{center}

The limit as t approaches infinity is 0 meaning that from the space station the astronaut will never actually reach the event horizon only approach it. We also know that the long term behavior is independent of the initial condition. This is made clear by the graph shown below.

\begin{figure}[H]
  \includegraphics[width=\linewidth]{InitialValuePlots.jpg}
  \caption{Numerical approximations using Euler\textquotesingle s method starting at various different starting points .}
  \label{fig:euler2}
\end{figure}

Regardless of the starting position of the astronaut he will approach an x value of 1. The one exception to this is at a starting position at infinity, where the gravity of the black hole has no effect on him. Both our direction field analysis and our analysis of numerical solutions of this equation agree that our astronaut will approach the event horizon asymptotically.

\section*{Conclusion}

Our astronaut will never reach the event horizon of the black hole, at least from the perspective of observers on the space station. Instead he will approach it, quickly at first, but he will soon slow down and be doomed to spend an eternity gravitating towards the event horizon.

% Your document ends here!
\end{document}


\section{Background \& Methodology}

\subsection{CNRS Benchmark}

The CNRS benchmark \cite{tiberga_results_2020} consists of three
\textit{Phases} and
eight \textit{Steps} in total. Each step is a well-defined subproblem for
systematically assessing \gls{MSR} software capabilities and pinpointing
the source of discrepancies between software. Phase 0 consists of
single-physics problems in fluid dynamics, neutronics, and temperature,
respectively. Phase 1 consists of coupled, steady-state eigenvalue problems.
Lastly, Phase 2 consists of a coupled, transient scenario. Table
\ref{table:benchmark} provides brief descriptions of each step, except for the
last transient case as it is still a work in progress at the time of writing.

The domain geometry is a 2m by 2m square cavity filled with LiF-BeF$_2$-UF$_4$
molten salt at an initial temperature of 900K \cite{tiberga_results_2020}.
Standard vacuum boundary conditions apply for neutron flux along the
boundaries, with homogeneous boundary conditions for delayed neutron
precursors. No-slip boundary conditions apply for flow in the cavity, except
the top boundary when the subproblem imposes forced convection via lid-driven
cavity flow. For temperature, all boundaries are insulated and we simulate salt
cooling with the following volumetric heat sink equation:
%
\begin{align}
    q'''(\vec{r}) &= \gamma \left(900 - T(\vec{r})\right), \label{eq:heat}
    \intertext{where}
    q''' &= \mbox{volumetric heat sink [W$\cdot$m$^{-3}$],}
    \nonumber \\
    \gamma &= \mbox{heat transfer coefficient [W$\cdot$m$^{-3}\cdot$K$^{-1}$],}
    \nonumber \\
    T(\vec{r}) &= \mbox{temperature at point $(\vec{r})$ [K].} \nonumber
\end{align}

Tiberga et al. \cite{tiberga_results_2020} used Serpent 2
\cite{leppanen_serpent_2014} with the JEFF-3.1 library
\cite{koning_jeff-31_2006} to generate multigroup neutronics data for the
LiF-BeF$_2$-UF$_4$ salt in the domain at 900K. They condensed the neutronics
data into six energy groups and eight precursor groups. Their paper contains
all relevant data \cite{tiberga_results_2020}. The benchmark prescribes the
following equations to govern the temperature dependence in the cross sections
and the neutron diffusion coefficients:
%
\begin{align}
    \Sigma_i (T) &= \Sigma_i(T_{ref})
    \frac{\rho_{fuel}(T)}{\rho_{fuel}(T_{ref})}, \\
    D (T) &= D(T_{ref})
    \frac{\rho_{fuel}(T_{ref})}{\rho_{fuel}(T)},
    \intertext{where}
    \Sigma_i &= \mbox{relevant macroscopic cross section [cm${-1}$],}
    \nonumber \\
    D &= \mbox{neutron diffusion coefficient [cm$^2\cdot$s$^{-1}$],}
    \nonumber \\
    \rho_{fuel} &= \mbox{density of the fuel salt [kg$\cdot$m$^{-3}$],}
    \nonumber \\
    T_{ref} &= \mbox{reference temperature} = 900\mbox{ K}. \nonumber
\end{align}

The benchmark also prescribes for incompressible Navier-Stokes and the
Boussinesq approximation for buoyancy when evaluating the salt flow in the
domain but places no restrictions on the type of neutronics model.

\begin{table*}[t!]
	\caption{Description of each benchmark subproblem.}
	\centering
	\small
	\setlength\tabcolsep{2.5pt}
	\begin{tabular}{p{33mm} p{65mm} l p{40mm}<{\centering}}
		\toprule
		Step & Description & Input parameters & Observables \\
		\midrule
		Step 0.1: Velocity field & Solve for the steady-state incompressible
		flow solution from lid-driven cavity flow. &
		$\begin{aligned}[t]
		    U_{lid} &= 0.5 \mbox{ m$\cdot$s$^{-1}$}
        \end{aligned}$
        & $(u_x, u_y)$ along AA' and BB'; \\
        \midrule
        Step 0.2: Neutronics & Solve for the fission rate density
        $\sum^G_i \Sigma_{f,i} \phi_i(\vec{r})$ and reactivity $\rho$
        in a static, isothermal fuel configuration. &
		$\begin{aligned}[t]
		    U_{lid} &= 0 \mbox{ m$\cdot$s$^{-1}$} \\
		    T &= 900 \mbox{ K} \\
		    P &= 1 \mbox{ GW}
        \end{aligned}$
        & $\sum^G_i \Sigma_{f,i} \phi_i(\vec{r})$ along AA'; \newline
        $\rho$; \\
        \midrule
        Step 0.3: Temperature & Solve for the temperature distribution $T$
        arising from the velocity field $(u_x, u_y)_{s_{0.1}}$ and fission heat
        generation $Q_{s_{0.2}}$ from Steps
        0.1 and 0.2, respectively, and a volumetric heat sink (Equation
        \ref{eq:heat}). &
		$\begin{aligned}[t]
		    (u_x, u_y) &= (u_x, u_y)_{s_{0.1}} \\
		    Q &= Q_{s_{0.2}} \\
		    \gamma &= 10^6 \mbox{ W$\cdot$m$^{-3}\cdot$K$^{-1}$}
        \end{aligned}$
        & $T$ along AA' and BB'; \\
        \midrule
        Step 1.1: Circulating fuel & Solve for the delayed neutron source
        distribution $\sum_j \lambda_j C_j$ and reactivity $\rho$ in a
        non-static, isothermal fuel configuration. &
		$\begin{aligned}[t]
		    (u_x, u_y) &= (u_x, u_y)_{s_{0.1}} \\
		    T &= 900 \mbox{ K} \\
		    P &= 1 \mbox{ GW}
        \end{aligned}$
        & $\sum_j \lambda_j C_j$ along AA' and BB'; \newline $\rho -
        \rho_{s_{0.2}}$; \\
        \midrule
        Step 1.2: Power coupling & Solve for the temperature distribution $T$,
        reactivity $\rho$, and fission rate density
        $\sum^G_i \Sigma_{f,i} \phi_i(\vec{r})$ under the fixed velocity field
        from Step 0.1. &
		$\begin{aligned}[t]
		    (u_x, u_y) &= (u_x, u_y)_{s_{0.1}} \\
		    P &= 1 \mbox{ GW} \\
		    \gamma &= 10^6 \mbox{ W$\cdot$m$^{-3}\cdot$K$^{-1}$}
        \end{aligned}$
        & $T$ along AA' and BB'; \newline $\rho - \rho_{s_{1.1}}$; \newline
        $\sum^G_i \Sigma_{f,i} \phi_i(\vec{r}) -
        \left[\sum^G_i \Sigma_{f,i} \phi_i(\vec{r})\right]_{s_{0.2}}$; \\
        \midrule
        Step 1.3: Buoyancy & Solve for the velocity components $(u_x, u_y)$,
        temperature distribution $T$, delayed neutron source
        distribution $\sum_j \lambda_j C_j$, and
        reactivity $\rho$ in a fully coupled system. &
		$\begin{aligned}[t]
		    P &= 1 \mbox{ GW} \\
		    U_{lid} &= 0 \mbox{ m$\cdot$s$^{-1}$} \\
		    \gamma &= 10^6 \mbox{ W$\cdot$m$^{-3}\cdot$K$^{-1}$}
        \end{aligned}$
        & $(u_x, u_y)$ along AA' and BB'; \newline $T$ along AA' and BB';
        \newline $\sum_j \lambda_j C_j$ along AA' and BB'; \newline
        $\rho - \rho_{s_{0.2}}$; \\
        \midrule
        Step 1.4: Full coupling & Solve for the
        reactivity $\rho$ in a fully coupled system with external
        momentum-driven flow and buoyancy effects and various permutations of
        $P$ and $U_{lid}$ values.  &
		$\begin{aligned}[t]
		    \gamma &= 10^6 \mbox{ W$\cdot$m$^{-3}\cdot$K$^{-1}$} \\
		    P &= [0, 1] \mbox{ GW} \\
		    U_{lid} &= [0, 0.5] \mbox{ m$\cdot$s$^{-1}$}
        \end{aligned}$
        & $\rho - \rho_{s_{0.2}}$; \\
		\bottomrule
	\end{tabular}
	\label{table:benchmark}
\end{table*}
%
\begin{figure}[H]
  \centering
  \includegraphics[width=0.75\columnwidth]{domain}
  \caption{The CNRS benchmark problem domain. The benchmark compares pointwise
  observable data along the centerlines AA' and BB'. Retrieved from
  \cite{tiberga_results_2020}.}
  \label{fig:domain}
\end{figure}

\subsection{Moltres}

Moltres \cite{lindsay_introduction_2018} is an open-source, \gls{MOOSE}-based
application designed for multi-physics simulations of \glspl{MSR}. Moltres
depends on the
\gls{MOOSE} finite element framework for its meshing and parallel, nonlinear
NEWTON-based solver capabilities, and standard physics modules such as the
Navier-Stokes module \cite{peterson_overview_2017} in \gls{MOOSE}.

Moltres solves the multigroup neutron diffusion equation for an arbitrary
number of energy and precursor groups. For this study, we coupled Moltres'
neutronics capabilities with \gls{MOOSE}'s incompressible Navier-Stokes
capabilities \cite{peterson_overview_2017} to
model precursor drift and thermal-hydraulics.

For this study, we discretized the problem domain into a 200 by 200 structured
mesh, resulting in uniform mesh elements of dimensions 1cm by 1cm. We
approximated most of the relevant variables, i.e., neutron fluxes, velocity
components, pressure, and temperature, using first-order Lagrange shape
functions. The only exception is the precursor concentration variables, which
we approximated using zeroth-order monomial shape functions and solved using
the Discontinuous Galerkin finite element method to eliminate spurious
numerical oscillations from the high Schmidt number flow. As for the
high Reynolds number flow, we stabilized the incompressible Navier-Stokes
equations using the streamline upwind Petrov-Galerkin and pressure-stabilizing
Petrov-Galerkin stabilization methods \cite{peterson_overview_2017} provided in
\gls{MOOSE}.


\section{Basics of Reinforcement Learning}
\label{sec:reinforcement_learning}

\begin{frame}{The Reinforcement Learning Framework}
\begin{figure}[t]
	\centering
	\begin{tikzpicture}[node distance = 6em, auto, thick]
		\onslide<2->{%
			\node at (4, 0) (Environment) {\includegraphics[width=3cm]{Images/environment}};
			\node at (4, 2) {\LARGE Environment};
			\node at (4, -2) {\LARGE $\calP$, $\calR$};
		}

		\onslide<3->{%
			\node at (-4, 0) (Agent) {\includegraphics[width=3cm]{Images/agent}};
			\node at (-4, 2) {\LARGE Agent};
			\node at (-4, -2) {\LARGE $\pi$};
		}

		\onslide<4->{%
		\draw [->, line width=5pt, Blue] (Environment) to [bend right=35] (Agent);
		\node at (0, 2.5) {\Large State $S_t$};
		}

		\onslide<5|handout:0>{%
		\node[draw=SteelBlue, circle, line width=3pt, minimum size=1cm] at (-4, -2) {};
		}

		\onslide<6->{%
		\draw [->, line width=5pt, SteelBlue] (Agent) to [bend right=35] (Environment);
		\node at (0, -2.5) {\Large Action $A_t$};
		}

		\onslide<7|handout:0>{%
		\node[draw=SteelBlue, circle, line width=3pt, minimum size=1cm] at (3.56, -2) {};
		}

		\onslide<8|handout:0>{%
		\node[draw=SteelBlue, circle, line width=3pt, minimum size=1cm] at (4.42, -2) {};
		}

		\onslide<9->{%
		\draw [->, line width=5pt, LightSteelBlue] (Environment) to (Agent);
		\node at (0, 0.5) {\Large Reward $R_{t+1}$};
		}
	\end{tikzpicture}
\end{figure}
\end{frame}

\begin{frame}{Mathematical Formulation}
	\onslide<1->{%
	\textbf{State-value function}
		\begin{equation*}
			V_\pi(s) = \E[\pi]{\sum_{t=0}^{\infty} \gamma^t R_{t+1} \Big| S_0 = s}
		\end{equation*}
	}

	\onslide<2->{%
	\textbf{Action-value function}
		\begin{equation*}
			Q_\pi(s, a) = \E[\pi]{\sum_{t=0}^{\infty} \gamma^t R_{t+1} \Big| S_0 = s, A_0 = a}
		\end{equation*}
	}

	\onslide<3->{
	\textbf{Optimal value functions}
		\begin{equation*}
			V_*(s) = \max_\pi V_\pi(s) \;\;\;\;\; Q_*(s, a) = \max_\pi Q_\pi(s, a)
		\end{equation*}
	}

	\onslide<4->{
	\textbf{Optimal policy}
		\begin{equation*}
			\pi_* \;\text{s.t.}\; V_{\pi_*} (s) = V_*(s),\; \forall s \in \S
		\end{equation*}
	}
\end{frame}

\begin{frame}{Taxonomy of RL Algorithms}
\begin{figure}[t]
	\centering
	\begin{tikzpicture}[node distance = 6em, auto, thick]

		\onslide<1->{%
			\node [draw=LightSteelBlue, circle, line width=5pt, minimum size=2cm] at (-4, 0) (Model) {\Large $\calP$, $\calR$};
			\node at (-4, 1.5) {\Large Model};
		}

		\onslide<2->{%
			\node [draw=SteelBlue, circle, line width=5pt, minimum size=2cm] at (-0, 0) (Value) {\Large $V_*$, $Q_*$};
			\node at (0, 1.5) {\Large Value Functions};
			\draw [->, line width=5pt, LightGray] (Model) to (Value);
		}

		\onslide<3->{%
			\node [draw=Blue, circle, line width=5pt, minimum size=2cm] at (4, 0) (Policy) {\Large $\pi_*$};
			\node at (4, 1.5) {\Large Policy};
			\draw [->, line width=5pt, LightGray] (Value) to (Policy);
		}

		\onslide<4->{%
			\node [draw=LightSteelBlue, circle, line width=5pt, minimum size=2cm] at (-4, -3) (ApproxModel) {\Large $\widehat{\calP}$, $\widehat{\calR}$};
			\node at (-4, -4.5) {\Large Model-Based};
			\draw [dashed, line width=5pt, LightGray] (ApproxModel) to (Model);
		}

		\onslide<5->{%
			\node [draw=SteelBlue, circle, line width=5pt, minimum size=2cm] at (0, -3) (ApproxValue) {\Large $\widehat{V}$, $\widehat{Q}$};
			\node at (0, -4.5) {\Large Value-Based};
			\draw [dashed, line width=5pt, LightGray] (ApproxValue) to (Value);
		}

		\onslide<6->{%
			\node [draw=Blue, circle, line width=5pt, minimum size=2cm] at (4, -3) (ApproxPolicy) {\Large $\widehat{\pi}$};
			\node at (4, -4.5) {\Large Policy-Based};
			\draw [dashed, line width=5pt, LightGray] (ApproxPolicy) to (Policy);
		}
	\end{tikzpicture}
\end{figure}
\end{frame}


\lab{Algorithms}{Conformal Maps}{Conformal Maps}

\objective{To become familiar with some of the basic properties of conformal maps and some of their basic applications.}

The analysis of complex valued functions has been called ``one of the most beautiful and useful fields of mathematics.''  Conformal maps are special functions in complex analysis that have proven to be very useful in several applications, especially those that model physical phenomena.

We begin by examining some maps on the complex plane.  Let
\[
f(z) = \frac{3z - 4}{z - 2}
\]
and
\[
g(z) = z^2 - 2
\]
What happens if we map the box $[0,1]\times[0,i]$ under these mappings?
\newpage
Looking at $g(z)$, we see the box turn into a sort of curved triangle.  On the other hand, if we look at $f(z)$, it seems like there is even more distortion than in the case of $g(z)$.
\begin{figure}
\begin{center}
\includegraphics[scale=0.5]{map1}
\caption{The box $[0,1]\times[0,i]$ under g(z).  The vertical axis is the imaginary line and the horizontal axis is the real line.}
\end{center}
\end{figure}

\begin{figure}
\begin{center}
\includegraphics[scale=0.5]{map2}
\caption{bla bla bla}
\end{center}
\end{figure}

There is a fundamental difference between these two mappings.  Though in both cases the shape is significantly distorted, in the case of $f(z)$ the angles where two sides meet are preserved, whereas $g(z)$ distorts not only the shape of the lines but also the angles where they meet.  Maps that preserve angles, as in the case of $f(z)$, are called conformal.

\begin{figure}
\begin{center}
\includegraphics[scale=0.33]{map3}
\includegraphics[scale=0.33]{map4}
%\includegraphics[scale=0.33]{./Applications_Labs/ConfMaps/map5}
\caption{Some more conformal maps}
\end{center}
\end{figure}

\begin{problem}
Write a Python script that transform a shape on the complex plane using the the conformal maps that we have used in the examples.  What do you expect will happen to the unit circle on the complex plane under these transformations?  Do your predictions match the results?  Try this for several shapes.
\end{problem}

The theory of conformal mappings is highly developed and well studied.  Here we only scratch the surface and comment on an important theorem for applications that will be useful in later volumes.

\section*{The Schwarz-Christoffel Transformation}
This transformation is very useful in applications of complex analysis.  Once again, the theory behind this is very rich, and we only state a theorem and look at some simple implications here.

\begin{theorem}  Let $P$ be a polygon on the complex plane having consecutive corners at $z_1, z_2, ..., z_n$ with corresponding right turn angles $\theta_1, \theta_2,...\theta_n$.  Then there exists a function that is a one to one conformal map from the upper half plane onto the interior of $P$ of the form:
\[
f(z) = A\int_0^z (\zeta - x_1)^{\frac{\theta_1}{\pi}}..(\zeta - x_{n-1})^{\frac{\theta_{n-1}}{\pi}}d\zeta + B
\]
Where $\theta_i$ represents the angle made by adjacent sides of the polygon and $x_i \in \mathbb{R}$.
\end{theorem}

We omit the proof here.  Consider the power of this theorem - we are able to map the upper half of the complex plane onto a polygon of our choosing.  This is very powerful for finding the numerical solutions to differential equations that model physical systems.  It turns out that a conformal mapping retains sufficient structure of a domain so that a solution in a transformed domain will be the same as the solution in the original domain.  This fact along with the theorem allows us to take problems which may be very difficult to solve in one domain and transform the domain to a polygonal domain of our choosing where a solution is much easier to find.  We give an example of such a transformation using built in Python functions:

\begin{example}
We will give an example showing how to find a Schwarz-Christoffel transform.  Suppose we wish to transform the upper half plane onto the triangle with corners at $0, i,$ and $1$.  We choose $x_1 = -1$ and $x_2 = 1$.  Starting from the upper corner, we have $\theta_1 = \theta_2 = \frac{-3\pi}{4}$ and $\theta_3 = \frac{-\pi}{2}$.  Using theorem 36.1, we have an expression for our mapping:
\begin{align*}
f(z) &= A\int_0^z(\zeta + 1)^{\frac{-3}{4}}(\zeta - 1)^{\frac{-3}{4}}d\zeta + B \\
	 &= A\int_0^z(\zeta^2 - 1)^{\frac{-3}{4}}d\zeta + B
\end{align*}

\end{example}

\begin{problem}
Find the conformal map that transforms the upper half plane to the strip $|Re(z) < 1|, Im(z) > 0$.  Display the result in a meaningful way.
\end{problem}


\chapter{Dimensionality}

    \begin{definition*}[Dimensionality]
        Given a formula $P$, the coalescence proof search produces a proof in an $n$-dimensional petri net.
        Equivalently, an additively stratified sequent proof $\vdash P$ has $n$ terms at the bottom before any contractions are applied.
        The dimensionality of $P$ is then defined $\dim(P) \defeq n$.
    \end{definition*}

    \begin{example*}
        Borrowing the proof from Example~\ref{example:add-strat-proof}, it has dimensionality 2 since the tree concludes with $\vdash P, P$ before any contractions.
        \begin{prooftree}
            \AxiomC{}
            \RightLabel{$ax$}\UnaryInfC{$\vdash a, \neg a$}
            \RightLabel{$\vee$}\UnaryInfC{$\vdash a \vee \neg a, \neg a$}
            \RightLabel{$\vee$}\UnaryInfC{$\vdash a \vee \neg a, a \vee \neg a$}
            \AxiomC{}
            \RightLabel{$\top$}\UnaryInfC{$\vdash \top$}
            \RightLabel{$w$}\UnaryInfC{$\vdash \top, a \vee \neg a$}
            \RightLabel{$\wedge$}\BinaryInfC{$\vdash (a \vee \neg a) \wedge \top, a \vee \neg a$}
            \AxiomC{}
            \RightLabel{$\top$}\UnaryInfC{$\vdash \top$}
            \RightLabel{$w$}\UnaryInfC{$\vdash \top, (a \vee \neg a) \wedge \top$}
            \RightLabel{$\wedge$}\BinaryInfC{$\vdash (a \vee \neg a) \wedge \top, (a \vee \neg a) \wedge \top$}
            \RightLabel{$c$}\UnaryInfC{$\vdash (a \vee \neg a) \wedge \top$}
        \end{prooftree}
    \end{example*}

    \begin{definition}[Classes of Formulae]\label{sec-ctr:formulae-classes}
        Let $D^i$ be the subclasses of formulae defined as:
        \begin{align*}
            D^1 \quad &\defeq \quad \top \,|\, D^1 \wedge D^1 \,|\, D^* \vee D^1 \\
            D^2 \quad &\defeq \quad D^{i \geq 2} \vee D^2 \,|\, P \vee \neg P \,|\, \ldots
        \end{align*}
        where $D^* \defeq \bigcup_{i \in \mathbb{N}} D_i$, such that $D^n$ is the class of all formulae provable in n dimensions.

        \textit{This definition will be revised later.}
    \end{definition}

    \begin{remark*}[Satisfiability vs Provability]
        For any formula $P$, there exist four distinct classes: \textit{true, false, satisfiably true, satisfiably false}, where satisfiable differs by finding a particular assignment of values to each variable.
        Coalescence searches for a proof of $P$ in \textit{true}, whereas the SAT problem addresses a proof of $P$ in \textit{true}.
    \end{remark*}

    \begin{proposition*}[Bounds on Dimensionality]
        Given a formula $P$, the following provides a bound its dimensionality:
        \begin{equation*}
            P \in D^n \implies n+1 \leq vars(P)
        \end{equation*}
        Justification is left unaddressed here as the current construction does not emit a `nice' proof.
    \end{proposition*}

    \begin{remark*}
        These methods do not lend themselves to `nice' properties.
        It is possible that in the general case, \textit{finding an exact value for the dimensionality of a given formula $P$ may be equivalent to finding a proof of $P$}, but it remains to be proven.
        Instead, a natural optimisation is applied to the algorithm as follows, giving rise to a different set of classes of dimensionality and more pleasing properties.
    \end{remark*}

    \begin{definition*}[$\top$-substitution]
         Given a sequent expressing a proof of $Q$, i.e. $\vdash Q, Q, \ldots Q$, the formula $P$ may be equivalently expressed $P[Q \seteq \top]$.
    \end{definition*}

    \begin{example*}
        Consider the formula $P \defeq (a \vee \neg a) \wedge (b \vee \neg b)$.
        The sequent proof $\vdash P$ is large and has dimensionality 3 as follows:
        \begin{center}
            \begin{tabular}{@{}l@{}}
                \begin{varwidth}{\linewidth}
                    \begin{scprooftree}{0.40}
                        \AxiomC{$ \vdash a , a , \neg a $}
                        \UnaryInfC{$ \vdash a , ( a \vee \neg a ) , \neg a $}
                        \AxiomC{$ \vdash a , \neg a , b $}
                        \UnaryInfC{$ \vdash a , \neg a , ( b \vee \neg b ) $}
                        \BinaryInfC{$ \vdash a , \neg a , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) $}
                        \UnaryInfC{$ \vdash a , ( a \vee \neg a ) , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) $}
                        \AxiomC{$ \vdash a , \neg a , b $}
                        \UnaryInfC{$ \vdash a , \neg a , ( b \vee \neg b ) $}
                        \UnaryInfC{$ \vdash a , ( a \vee \neg a ) , ( b \vee \neg b ) $}
                        \AxiomC{$ \vdash a , b , \neg b $}
                        \UnaryInfC{$ \vdash a , b , ( b \vee \neg b ) $}
                        \UnaryInfC{$ \vdash a , ( b \vee \neg b ) , ( b \vee \neg b ) $}
                        \BinaryInfC{$ \vdash a , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( b \vee \neg b ) $}
                        \BinaryInfC{$ \vdash a , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) $}
                        \UnaryInfC{$ \vdash ( a \vee \neg a ) , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) $}
                        \AxiomC{$ \vdash a , \neg a , b $}
                        \UnaryInfC{$ \vdash a , \neg a , ( b \vee \neg b ) $}
                        \UnaryInfC{$ \vdash a , ( a \vee \neg a ) , ( b \vee \neg b ) $}
                        \AxiomC{$ \vdash a , b , \neg b $}
                        \UnaryInfC{$ \vdash a , b , ( b \vee \neg b ) $}
                        \UnaryInfC{$ \vdash a , ( b \vee \neg b ) , ( b \vee \neg b ) $}
                        \BinaryInfC{$ \vdash a , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( b \vee \neg b ) $}
                        \UnaryInfC{$ \vdash ( a \vee \neg a ) , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( b \vee \neg b ) $}
                        \AxiomC{$ \vdash a , b , \neg b $}
                        \UnaryInfC{$ \vdash a \vee \neg a , b, \neg b $}
                        \AxiomC{$ \vdash b , b , \neg b $}
                        \UnaryInfC{$ \vdash b \vee \neg b , b , \neg b $}
                        \BinaryInfC{$ \vdash ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , b , \neg b $}
                        \UnaryInfC{$ \vdash ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , b , ( b \vee \neg b ) $}
                        \UnaryInfC{$ \vdash ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( b \vee \neg b ) , ( b \vee \neg b ) $}
                        \BinaryInfC{$ \vdash ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( b \vee \neg b ) $}
                        \BinaryInfC{$ \vdash ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) , ( ( a \vee \neg a ) \wedge ( b \vee \neg b ) ) $}
                    \end{scprooftree}
                \end{varwidth}
            \end{tabular}
        \end{center}

        Using substitutions of $\top$ for provable subformulae, the proof $\vdash P$ becomes much more manageable:

        \begin{center}
            \begin{tabular}{@{}l@{}}
                $ A := ( a \vee \neg a ) $
                \begin{varwidth}{\linewidth}
                    \begin{prooftree}
                        \AxiomC{$ \vdash a , \neg a $}
                        \UnaryInfC{$ \vdash a , ( a \vee \neg a ) $}
                        \UnaryInfC{$ \vdash ( a \vee \neg a ) , ( a \vee \neg a ) $}
                    \end{prooftree}
                \end{varwidth}\\ \\

                $ B := ( b \vee \neg b ) $
                \begin{varwidth}{\linewidth}
                    \begin{prooftree}
                        \AxiomC{$ \vdash b , \neg b $}
                        \UnaryInfC{$ \vdash b , ( b \vee \neg b ) $}
                        \UnaryInfC{$ \vdash ( b \vee \neg b ) , ( b \vee \neg b ) $}
                    \end{prooftree}
                \end{varwidth}\\ \\

                \begin{varwidth}{\linewidth}
                    \begin{prooftree}
                        \AxiomC{$ \vdash A , A $}
                        \AxiomC{$ \vdash A , B $}
                        \BinaryInfC{$ \vdash A , ( A \wedge B ) $}
                        \AxiomC{$ \vdash A , B $}
                        \AxiomC{$ \vdash B , B $}
                        \BinaryInfC{$ \vdash B , ( A \wedge B ) $}
                        \BinaryInfC{$ \vdash ( A \wedge B ) , ( A \wedge B ) $}
                    \end{prooftree}
                \end{varwidth}\\
            \end{tabular}
        \end{center}

        While the final step need only be performed with dimensionality 1, the prior steps require dimensionality 2, giving the full formula a dimensionality of 2.
    \end{example*}

    \begin{remark*}
        It is now important to reexamine the coalescence algorithm.

        Storing a token as a \texttt{Tuple} gives an inefficient algorithm due to the implicit ordering.
        By commutativity, given a token $(a_1 \ldots a_n)$, there exist up to $n!$ permutations of $a_i$'s and thus $n!$ equivalences per token.

        Instead, order is abstracted over and a token is stored as a \texttt{Multiset}.
        This gives the storage optimisation exploiting the symmetry of petri nets that expresses commutativity of terms in a sequent.
        There are now only $n$ equivalences per token.

        This may be taken a step further.
        Consider a token stored as a \texttt{Set} which expresses idempotency of terms in a sequent $\vdash P, P \equiv \, \vdash P$.
        This forms a canonical representation of tokens --- the only token equivalent to $T \in \texttt{Set}$ is T itself.
    \end{remark*}

    \begin{examples}
        Consider again the formula $(a \vee \neg a) \wedge (b \vee \neg b)$, with a proofs as follow, but instead tracing the values of tokens.

        Where tokens are member of the category \texttt{Tuple}, so as to demonstrate the exponential blow-up, both the `minimal' (black) and `saturated' (grey) proofs are as follows:
        \input{proofnet-example-tuple} where $\rightsquigarrow$ is an application of weakening.
        This is notable as this will be the point coalescence will reach for $n \seteq 2$ and a suitably intelligent method for extending dimensions will maintain the proof search so far.
        Both `minimal' and `saturated' proofs are included as each represent the deterministic versus non-deterministic searches --- proof search versus validation.

        Where tokens are now members of \texttt{Multiset}, the proof of the full formula follows:
        \input{proofnet-example-multiset}
        The above remains tedious and unnatural.
        Proofs of each of $a \vee \neg a$ and $b \vee \neg b$ are constructed in two steps, while the remaining steps are to prove the conjunction of these (proven) subformulae.
        Instead, consider the tokens as members of \texttt{Set} as follows:

        \input{proofnet-example-set}

        Equivalently with symbols:
        \input{proofnet-example-set-symbols}
        This is finally deemed a `satisfying' proof --- dimensionality is extracted as the largest set required in the proof, a nicer algebra of dimensionality may be constructed and there is some essence of justification for the correctness of this $\top$-substitution --- all through changing the datatype of tokens.
    \end{examples}

    \begin{remark}
        In essence, allowing for efficient substitution of a $\top$ term for proven subformulae allows the coalescence algorithm to run without restricting the output to additively stratified proofs.
        A proof may be reconstructed including substitutions, where each subproof substituted is itself additively stratified, but now there are contractions for the conclusion of a subproof on top of weakenings for the axioms of a `superproof'.
    \end{remark}

    \begin{definition*}[Classes of Formulae]
        With this new concept of coalescence, dimensionality and proof search, the definitions in~\ref{sec-ctr:formulae-classes} are revisited and revised.
        Let $\mathcal{D}^i$ be defined as the subclasses of formulae:
        \begin{align*}
            \mathcal{D}^1 \quad \defeq \quad &\top \quad | \quad \mathcal{D}^1 \wedge \mathcal{D}^1 \quad | \quad \mathcal{D}^* \vee \mathcal{D}^1 \\
            \mathcal{D}^2 \quad \defeq \quad &P \vee \neg P \quad | \quad \mathcal{D}^2 \vee \mathcal{D}^{i \geq 2} \quad | \quad \mathcal{D}^2 \wedge \mathcal{D}^{i \leq 2} \\
            \mathcal{D}^3 \quad \defeq \quad &(P \wedge Q) \vee (P \wedge \neg Q) \vee (\neg P \wedge Q) \vee (\neg P \wedge \neg Q) \\
                                       \quad &| \quad \mathcal{D}^3 \vee \mathcal{D}^{i \geq 3} \quad | \quad \mathcal{D}^3 \wedge \mathcal{D}^{i \leq 3}
        \end{align*}
        where $\mathcal{D}^* \defeq \bigcup_{i \in \mathbb{N}} \mathcal{D}^i$, $P \in \mathcal{D}^*$, such that $\mathcal{D}^n$ is the class of all formulae provable in exactly n dimensions.
    \end{definition*}

    \begin{corollary}\label{cory:dimensionality-algebra}
        For $P \in \mathcal{D}^i, Q \in \mathcal{D}^j$, the following statements hold:
        \begin{equation*}
            P \vee Q \in \mathcal{D}^{\min{i, j}}
            \qquad
            P \wedge Q \in \mathcal{D}^{\max{i, j}}
        \end{equation*}
        In fact, for $P \in \mathcal{D}^n$ in $v$ variables, $n \leq v + 1$.
    \end{corollary}

    \begin{definition*}[Assignments]
        Given $n$ variables $a_1 \ldots a_n$, then the conjunction of each combination of atoms (with or without negation) is called an \textit{assignment} of boolean values to these variables.
        For $n$ variables, there exist $2^n$ possible \textit{assignments}, each analogous to one of:
        \begin{align*}
            (a_1 \seteq \textit{True} \quad &\ldots \quad a_n \seteq \textit{True}) \\
            (a_1 \seteq \textit{False}, \, a_2 \seteq \textit{True} \quad &\ldots \quad a_n \seteq \textit{True}) \\
            &\ldots \\
            (a_1 \seteq \textit{False} \quad &\ldots \quad a_{n-1} \seteq \textit{False}, \, a_n \seteq \textit{True}) \\
            (a_1 \seteq \textit{False} \quad &\ldots \quad a_n \seteq \textit{False})
        \end{align*}

        An assignment $\Delta$ is found in \textit{DNF} terms as $\delta_j \defeq a_1 \wedge \ldots \wedge a_n$ and can therefore be seen as satisfiably true for a unique assignment of values to each $a_i$.
    \end{definition*}

    \begin{proposition}[Dimensionality Bound of Disjunctive Normal Form]\label{propn:dimensionality-bounds}
        Let $\textit{DNF}^n$ denote the set of all formulae in $n$ variables in disjunctive normal form.
        That is, $P \in \textit{DNF}^n \implies P = \bigvee_{j = 1 .. 2^n} (\bigwedge_{i = 1 .. n} a_i)$ the disjunction of $2^n$ conjunctions, each a unique assignment of $n$ variables.
        Then the following statement holds:
        \begin{equation*}
            P \in \textit{DNF}^n \implies P \in \mathcal{D}^{n+1}
        \end{equation*}
    \end{proposition}

    Two proofs of this statement are presented.
    The former may be most intuitive to follow and hold the fewest edge-cases, but breaks away from how proof search and calculation of dimensionality is performed in the coalescence algorithm.
    To this end, the latter is also included which stays truer to the methods used.

    \begin{proof}[Sequent Tree Proof]
        Working from the bottom of the proof tree upwards, suppose there exists a proof of $Q \seteq \bigvee_j \delta_j \in \textit{DNF}^n$.
        Let this be written as the sequent $\vdash Q \ldots_m Q$ for some $m$ --- the proof seeks to show $m = n+1$.
        Suppose $\Delta_i \seteq a_1 \ldots a_n$ the `all true' assignment with associated conjunction $\delta_i$, then any one of these $Q$ must have been derived as follows:
        \begin{prooftree}
            \AxiomC{}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m-1} Q, a_1$}
            \AxiomC{$\ldots_n$}
            \AxiomC{}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m-1} Q, a_n$}
            \doubleLine\TrinaryInfC{$\vdash Q \ldots_{m-1} Q, \delta_i$}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_m Q$}
        \end{prooftree}

        Without loss of generality, focus on the rightmost subtree and recurse, then second-rightmost subtree and recurse:
        \begin{scprooftree}{0.7}
            \AxiomC{}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m-3} Q, a_1, a_{n-1}, a_n$}
            \AxiomC{$\ldots_n$}
            \AxiomC{}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m-3} Q, a_n, a_{n-1}, a_n$}
            \doubleLine\TrinaryInfC{$\vdash Q \ldots_{m-3} Q, \delta_i, a_{n-1}, a_n$}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m-2} Q, a_1, a_n$}
            \AxiomC{$\ldots_n$}
            \AxiomC{}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m-2} Q, a_n, a_n$}
            \doubleLine\TrinaryInfC{$\vdash Q \ldots_{m-2} Q, \delta_i, a_n$}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m-1} Q, a_n$}
        \end{scprooftree}

        Then, by induction on $n$, the process may be repeated until there exists a sequent containing atoms for each $a_i \in \delta_i$ as seen in the upper left here:
        \begin{prooftree}
            \AxiomC{}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m-n} Q, a_1, a_2 \ldots_{n-1} a_n$}
            \AxiomC{$\ldots_n$}
            \AxiomC{}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m-n} Q, a_n, a_2 \ldots_{n-1} a_n$}
            \doubleLine\TrinaryInfC{$\vdash Q \ldots_{m-n} Q, \delta_i, a_n$}
            \doubleLine\UnaryInfC{$\vdash Q \ldots_{m+1-n} Q, a_2 \ldots_{n-1} a_n$}
        \end{prooftree}

        Now, every other branch in as many steps will have \textit{at most} as many unique atoms as the above, if not less.
        For the sequent $\vdash Q \ldots_{m-n} Q, a_1 \ldots_n a_n$ to reach the top $\vdash \top$, all that is required is a single $\neg a_i$.
        This similarly applies for all other leaves.

        This means the sequent $\vdash a_i, a_1 \ldots a_n$ (accompanied by $n^n$ other sequents, most simpler than this `worst-case') is sufficient to provide a proof of $Q$.
        Therefore, $m = n + 1$ as required and the proof is complete.
    \end{proof}

    \begin{remark*}
        This bounds the exponential blowup of \textit{DNF} formulae as $\mathcal{O}(n^n$) --- an exceptionally poor worst-case,
    \end{remark*}

    \begin{proof}[ALL Proof]
        By induction on the number of variables $n$.

        Let the base case be $n \seteq 1$ and the proof is trivial --- the sequent proof $\vdash a \vee \neg a$ requires 2 dimensions and the hypothesis holds.

        Suppose the inductive hypothesis holds up to $n - 1$ variables --- in $i$ dimensions where $i \leq n$ and all \textit{DNF}-terms in $v$ variables where $i - 1 \equiv v < n$ such that:
        \begin{equation*}
            \forall \, i \leq n \,:\, P \in \textit{DNF}^{i} \implies P \in \mathcal{D}^{i}
        \end{equation*}
        It is now sufficient to show the hypothesis continues to hold for up to $n$ variables:
        \begin{equation*}
            \forall \, Q \in \textit{DNF}^n :  Q \in \mathcal{D}^{n+1}
        \end{equation*}

        Let $a_n$ be fresh in $P$ and $a_1 \ldots a_{n-1}$ be used.
        Write $P \defeq \bigvee_j \delta_j \quad \forall \, j \in 1 \ldots 2^{n-1}, \, \forall j \in 1 \ldots n-1$ where each $\delta_j$ is the $j$'th assignment of variables $a_1 \ldots a_{n-1}$.
        Now construct $Q$ as follows:
        \begin{equation*}
            Q \seteq Q_{l} \vee Q_{r} \seteq (\bigvee_j \delta_j \wedge a_n) \vee (\bigvee_j \delta_j \wedge \neg a_n) \in \textit{DNF}^n
        \end{equation*}
        where $Q$ is the simplest $\textit{DNF}^n$ extension of $P$.
        Each $\delta_j$ is of course not provable by itself.
        Since the $P$ term has been deconstructed, $P$ provable only in $n$ dimensions or greater and therefore the conditions for the inductive hypothesis have been broken (by contrapositive as the dimensionality is too high), $Q$ is therefore not provable in $n$ dimensions.

        Choose an assignment in $Q$ --- without loss of generality, choose $\Delta_Q \seteq a_1 \ldots a_n$ the `all true' assignment and the associated $d_Q$ conjunction.
        Since $Q$ not provable in $n$ dimensions, extend the proof to $n+1$ dimensions --- on the left, the leaf sequents of $Q_l$ may be weakened from $\vdash \Gamma$ all atomic terms to $\vdash \Gamma, \neg a_n$ giving at least $n + 1$ dimensionality as required (if the formula can now be proven of course).

        Let $a_i$ be as in the decided assignment $\Delta_Q$.
        There exist a sufficient number of sequents containing assignments $\Delta_i$ for $P$ of $n-1$ variables (and thus $n-1$ sequent terms) $\vdash a_j, \Delta_i, a_i$ such that $a_j \in \Delta_Q$ and $\neg a_i \in \Delta_i$.
        By applying the steps made in $\vdash P$, each $\vdash a_j, \Delta_i, a_i$ can produce a sequent proof down to $\vdash a_j, \delta_i \ldots_n \delta_i$ for any given $a_j \in \Delta$, so construct for all of them.
        By applying the $\wedge$ rule across all these subtrees, this produces $\vdash \delta_j \wedge a_n, \delta_i \ldots_n \delta_i \,\, \equiv \,\, \vdash Q_l, \delta_i \ldots_n \delta_i \,\, \equiv \,\, \vdash Q, \delta_i \ldots_n \delta_i$.

        Tediously, from here the proof can be grown up to the following sequents:
        \begin{equation*}\label{eqn:proof-omission}
            \vdash Q \ldots_n Q, \delta_i \qquad \vdash Q \ldots_n Q, a_n \text{\, for \,} a_n \in \Delta_Q \tag{+}
        \end{equation*}

        Reducing across subtrees by the $\wedge$ rule yields $\vdash Q \ldots_n Q, \delta_i \wedge a_n$.
        Finally, the $\vee$ rule may be applied up the formula syntax tree to yield $\vdash Q \ldots_{n} Q, Q \equiv \, \vdash Q \ldots_{n+1} Q \implies Q \in \mathcal{D}^{n+1}$, where $Q \in \textit{DNF}^n$ as required.
    \end{proof}

    \begin{remark}\label{remark:proof-subtleties}
        The latter proof omits the subtleties and specifics of deriving the results in~\eqref{eqn:proof-omission}.
        This is considered tedious and does not aid to a clear representation of the intermediate steps but remains to be formally proven, should such a thing be desirable.
    \end{remark}

    \begin{proposition*}
        Building on the above, the dimensionality of any given formula can be predicted by examining the most variables in a disjunctive normal form subformula:
        \begin{equation*}
            P \in \mathcal{D}^{n+1} \iff \exists \, Q \in P \,:\, Q \in DNF^{n}
        \end{equation*}
    \end{proposition*}

    \begin{proof}
        It can be trivially seen that by combining the results in Corollary~\ref{cory:dimensionality-algebra} and Proposition~\ref{propn:dimensionality-bounds} that the statement is true.

        $(\impliedby)$
        The reverse implication is given exactly by Proposition~\ref{propn:dimensionality-bounds}.

        $(\implies)$
        Suppose $P \in \mathcal{D}^{n+1}$.
        Then, one of the following is true:

        \begin{enumerate}
            \item
            $P \equiv (L \wedge R)$  where there exist proofs for each of $L, R$ and by Corollary~\ref{cory:dimensionality-algebra}, without loss of generality, $L \in \mathcal{D}^{n+1}$.
            Then, the proof recurses on $L$.

            \item
            $P \equiv (L \vee R)$ where there exist proofs for each of $L, R$ and by Corollary~\ref{cory:dimensionality-algebra} $L, R \in \mathcal{D}^{n+1}$.
            Then, the proof recurses on both $L$ and $R$.

            \item
            $P \equiv (L \vee R)$ where there do not exist proofs for both $L, R$.
            Therefore, if there is a proof of $P$, then $P \in \textit{DNF}$ and $P \in \mathcal{D}^{n+1} \implies P \in \textit{DNF}^n$ as required.
        \end{enumerate}
    \end{proof}


\documentclass{article}

\usepackage[letterpaper]{geometry}

\usepackage{siunitx}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{scrextend}
\usepackage{microtype}
\usepackage{mathrsfs}
\usepackage{booktabs}

\theoremstyle{remark}
\newtheorem{example}{Example}[section]
\newtheorem*{solution}{Solution}

\begin{document}

\section{Fundamentals in Quantitative Design}
\subsection{Power and Energy}
When energy gets consumed due to transistor switching, it's called \textbf{dynamic energy}, defined as the following:
\[
    E_{dynamic} = \frac{1}{2} C V^2
\]
where \(C\) is the capacitive load, \(V\) is the voltage.

There is also \textbf{dynamic power}, defined as follows:
\[
    P_{dynamic} = \frac{1}{2} C V^2 f
\]
where \(f\) is frequency.

When power is consumed due to transistor leakage current, it's called \textbf{static power}, which has the following equation:
\[
    P_{static} = CV
\]

In general, power usage by a processor is the combination of dynamic and static power. When no calculation is being done, it's purely static power, which cannot be removed without disabling the circuit by \textbf{power gating}.

\subsection{Dependability}
Generally, there are two ways dependability can be measured:

\begin{itemize}
    \item \textbf{Module reliability:} Measure of how long a module runs before failure, hence it's usually named the Mean Time To Failure (MTTF). The inverse is the rate of failure, defined by failures per billion of hours (FIT).
          \begin{itemize}
              \item Interruptions are measured as Mean Time to Repair (MTTR)
              \item Combined together, it forms the Mean Time Between Failure \[MTBF = MTTR + MTTF\]
          \end{itemize}
    \item \textbf{Module availability:} Measure of how available the module is, defined by the following formula: \[
              \frac{MTTF}{MTTF+MTTR}
          \]
\end{itemize}

\begin{example}
    Assume a disk subsystem with the following components and MTTF:\@

    \centering
    \begin{tabular}{ c c c }
        \toprule
        Count & Component    & MTTF                \\
        \midrule
        10    & Disks        & \SI{1000000}{\hour} \\
        1     & Controller   & \SI{500000}{\hour}  \\
        1     & Power supply & \SI{200000}{\hour}  \\
        1     & Fan          & \SI{200000}{\hour}  \\
        1     & Cable        & \SI{1000000}{\hour} \\
        \bottomrule
    \end{tabular}
    \begin{solution}
        \begin{align*}
            \text{Failure rate}_{\text{system}} & = \frac{10}{1000000} + \frac{1}{500000} + \frac{1}{200000}+ \frac{1}{200000}+ \frac{1}{1000000} \\
                                                & = \frac{10+2+5+5+1}{1000000} = \frac{23}{1000000} = \frac{23000}{1000000000}
        \end{align*}
        which is \(23000\) FIT.\@ The MTTF will be the reciprocal which is:
        \[
            \text{MTTF}_{\text{system}} = \frac{1000000000}{23000} = 43500 \si{\hour} \approx 5 \text{years}
        \]
    \end{solution}
\end{example}

\subsection{Measuring Performance}
Performance is usually defined by response time and throughput. Response time is how fast a processor can execute a program, while throughput is how many tasks the processor can run in one unit of time.

Using response time as the main metric, Amdahl's law can be used to give the theoretical speedup in latency of a program.
\[
    S = \frac{T_B}{T_A} = \frac{1}{\left(1-p\right) + \frac{p}{s}}
\]
where \(S\) is the speedup, \(p\) is the portion of the program that gets enhanced and \(s\) is the speedup of the enhanced portion.

It could be extended to apply to multiple different programs by replacing execution time with the geometric mean of all programs:
\[
    \sqrt[i]{R_1 R_2 R_3 \ldots R_i}
\]

\section{Floating Point Numbers}
The floating point format we will be using in this class is the IEEE754 format.

\subsection{Representation}
Floating point numbers are represented with a sign bit \(s\), a mantissa/significand \(M\) and an exponent \(E\), which is used like so
\[
    {\left(1\right)}^s \times M \times 2^E
\]
%TODO: Finish up
%TODO: Rounding, Memory, Disk, RAID, Caching, Virtual Memory, Address Translation
\newpage
\section{Instruction Set Architectures}
\subsection{Memory Ordering}
Most modern computer are byte addressed, with the following terms being the most often used one:
\begin{itemize}
    \item \textbf{Byte:} 8 bits
    \item \textbf{Halfword:} 16 bits
    \item \textbf{Word:} 32 bit
    \item \textbf{Doubleword:} 64 bit
\end{itemize}
Multi-byte objects have two standards for ordering Little Endian (Least significant byte comes first) and Big Endian (Most significant byte comes first). A word-sized example is \verb"0xA0B0C0D". The following will be the result:

\begin{table}[!htbp]
    \centering
    \begin{tabular}{ c c c }
        \toprule
        Address                 & Little Endian           & Big Endian              \\
        \midrule
        \verb"0"  & \verb"0D"  & \verb"0A"  \\
        \verb"1"  & \verb"0C"  & \verb"0B"  \\
        \verb"2"  & \verb"0B"  & \verb"0C" \\
        \verb"3" & \verb"0A" & \verb"0D" \\
        \bottomrule
    \end{tabular}
\end{table}

Multi-byte objects must be aligned properly to prevent issues. Alignment is when an object of size \(s\) is stored at address \(A\) fulfils \(A \mod s = 0\).

A structure must start and end at a multiple of the largest element \(K\). In addition, every element must be aligned according to the following rules:

\begin{table}[!htbp]
    \centering
    \begin{tabular}{ c c c }
        \toprule
        \multicolumn{3}{c}{x86}                                                              \\
        \midrule
        Size (bytes) & Windows                                     & Linux                   \\
        \midrule
        1            & \multicolumn{2}{c}{No restrictions}                                   \\
        2            & \multicolumn{2}{c}{Lowest bit must be 0}                              \\
        4*           & \multicolumn{2}{c}{Lowest bits must be 00}                            \\
        8            & Lowest bits must be 000                     & Lowest bits must be 00  \\
        12           & \multicolumn{2}{c}{Lowest bits must be 00}                            \\
        \midrule
        \multicolumn{3}{c}{x86--64}                                                          \\
        \midrule
        8*           & \multicolumn{2}{c}{Lowest bits must be 000}                           \\
        16           & N/A                                         & Lowest bits must be 000 \\
        \bottomrule
    \end{tabular}
\end{table}

To efficiently repack a structure, start with the largest elements then go down.
\subsection{Addressing Modes}
The names of all existing addressing modes are presented in the following table. The term \(d\) is defined to be the data that's being accessed by the instruction.
\begin{table}[!htbp]
    \centering
    \begin{tabular}{ c c c }
        \toprule
        Mode Name         & pseudo-assembly         & RTL Meaning                                        \\
        \midrule
        Register          & \verb"ADD R4, R1" & \(R4 \leftarrow R4 + R1\)                          \\
        Immediate         & \verb"ADD R4, #1" & \(R4 \leftarrow R4 + 1\)                           \\
        Register Indirect & \verb"ADD R4, (R1)" & \(R4 \leftarrow R4 + [R1]\)                        \\
        Displacement      & \verb"ADD R4, 100(R1)" & \(R4 \leftarrow R4 + [100 + R1]\)                  \\
        Scaled            & \verb"ADD R4, 100(R1)[R2]" & \(R4 \leftarrow R4 + [100 + R1 + R2 \times d]\)    \\
        Direct/Absolute   & \verb"ADD R4, (1000)" & \(R4 \leftarrow R4 + [1000]\)                      \\
        Memory Indirect   & \verb"ADD R4, @(R1)" & \(R4 \leftarrow R4 +[[R1]]\)                       \\
        Auto Increment    & \verb"ADD R4, (R1)+" & \(R4 \leftarrow R4 + [R1], R1 \leftarrow R1 + d \) \\
        Auto Decrement    & \verb"ADD R4, -(R1)" & \(R1 \leftarrow R1 - d, R4 \leftarrow R4 + [R1]\)  \\
        \bottomrule
    \end{tabular}
\end{table}

\section{Pipelining}

Pipelining is done by separating an instruction into it's individual stages, which for MIPS is the Fetch, Decode, Execute, Memory Access and finally Writeback stages.

The pipeline is limited by the slowest stage. Whatever that stage is will be defined as the time for a single cycle of the processor. There is also propagation delay and setup time of flip-flops to take into account, which add to the total full cycle time of a pipelined processor.

Some equations to use are written out here, with \(T\) being the cycle time and \(N\) being the stages of a pipeline.
\begin{itemize}
    \item \textbf{Unpipelined instruction time:} \(T + T_{ovh}\)
    \item Following are all pipelined equations
    \item \textbf{Balanced time per stage:} \(T/N + T_{ovh}\)
    \item \textbf{Unbalanced time per stage:} \(T_{slowest}\)
    \item \textbf{Cycles per instruction:} \(N\)
    \item \textbf{Total instruction time:} \(T_{slowest} * N + N T_{slowest}\)
    \item \textbf{Clock speed:} Inverse of time per stage.
    \item \textbf{Speedup:} Unpipelined instruction time divided by pipelined instruction time
\end{itemize}

\subsection{Hazards}
There are several problems that may add issues for your pipeline. They are called hazards, and there are 3 of them.
\begin{itemize}
    \item \textbf{Structural hazards:} Hardware is unable to do both instructions.
          \begin{itemize}
              \item CPU has single memory bus for data and instructions. MEM and IF conflicts.
          \end{itemize}
    \item \textbf{Data hazards:} Consecutive instructions rely on the same registers as results or source of their data.
          \begin{itemize}
              \item ADD writes to R1, which is needed for SUB in next instruction. ADD might be at WB when sub is at ID.\@
              \item Can be solved by adding pipeline stalls.
              \item Also by forwarding.
          \end{itemize}
    \item \textbf{Control hazards:} Branch may cause PC to change a lot, making the instructions in the rest of the pipeline wrong.
          \begin{itemize}
              \item Can be solved by discarding instructions after the branch or to stop fetching instructions after branch is found.
              \item Take the branch not taken until proven otherwise, where we dump the pipeline.
              \item Assume branch is taken until proven otherwise, inverse of previous.
              \item Can fill certain number of instructions after branch with instructions that will run either way (e.g. NOP).
          \end{itemize}
\end{itemize}

\subsection{Dynamic Branch Prediction}
Instead of doing the same thing all the time, we could be smart and ``learn'' from past experience instead. Prediction is not perfect, so we might make mistakes now and again.

One way of doing prediction is by storing a branch prediction table which stores lowest few bits of branch instruction, each storing a bit that says whether branch was recently taken or not. If wrong, flip bit.

Prediction bits can be increased to 2 bits with the values being level of confidence.

\subsection{Extending Pipeline}
Floating point units are generally slower than integer units. One way to solve it is to add separate execution units for floating point addition, combined FP/INT multiply and divide, then allowing those execution units to stall on structural hazards, repeating cycles until they complete.

A better solution is to add pipelining to FP units (except divide) and allowing multiple separate operations to execute.

\subsection{Instruction Level Parallelism}
Instruction level parallelism is the idea of overlapping execution of different instructions. Pipelining instructions is one way to do it, with superscalar architectures adding another way to do it.

An idea to improve ILP is by allowing the processor to execute code out of order, as long as it eventually produces the same result. This is done through scheduling; Dynamic and Static. Dynamic scheduling is done by the CPU while Static scheduling is done by the programmer or compiler.

\subsection{Loop Unrolling}
Loop unrolling allows processors to take advantage of pipelining by the processor making the loop take bigger steps then rescheduling to reduce the number of stalls.

This however has downsides, such as increased code size since more instructions are written down and increased register pressure do to an increased number of live variables.

\subsection{Advanced Branch Prediction}
Branches might not happen in isolation, and can be predicted based on previous branches. A Correlating Branch Predictor takes advantage of this fact and makes a decision based on \(m\) previous branches.

For example, \(m=2\). We then have a 2 bit branch predictor for each possible combination of \(m\): (untaken, untaken), (untaken, taken), (taken, untaken), (taken, taken).

Correlating Branch Predictors are usually defined in the \((m, n)\) notation, so to calculate the number of bits used by the predictor: \(2^m \times n \times \text{address entries}\)

Tournament predictors combine global and local predictors, where global predictors use the behaviour of other branches and current branch while local predictors use just the current branch. Similar to the 2 bit local predictor, which one to use is based on the value.
\subsection{Tomasulo's Algorithm}
Look at slides
\subsection{Speculative Execution}

\subsection{VLIW}

\subsection{Multithreading}

\end{document}


%-------------------------------------------------------------------------------
% Contexts
%-------------------------------------------------------------------------------

\subsection{Contexts}

Contexts map (DeBruijn) variables to types.

\newcommand{\Ctx}{\ \mathtt{ctx}}
\bigskip
\framebox{$\Gamma\Ctx$}
\bigskip

$$
\begin{array}{cc}
\infer{\cdot\Ctx}{} &
\infer{\Gamma,A\Ctx}{\Gamma\Ctx & \CheckTy[\cdot]{A}{\Type}}
\end{array}
$$


\chapter{Minima Times Determination}
\label{Chapter_minima_det}
In order to obtain precise time of minima in eclipsing binary systems we need to define function that will fit minima shape with best precision.
There is to different approaches for eclipsing binary LC fit: (i) finding parameters of LC that will describe physical processes of binary star system or (ii) phenomenological (mathematical) modelling of observed data variations.

There is also a possibility to fit LC minima with simple functions or use Kwee and van Woerden method.
Individual approach requires narrow shape minima. Each branch of such minima must be fitted with some linear fit and time of minima will be found
at the intersection of lines.

In this work we prefer to use phenomenological fitting methods or use simple function fitting, because we have a large number of eclipsing binary systems in Kepler EB catalogue. It is not possible to find each system's physical parameters in every case or it can take much longer time. All this methods are described below.

\section{Kwee and van Woerden Method}
Based on assumption that the set of data points around the minimum can be represented by the curve that is strictly
symmetric with respect to the true minimum epoch $T_{0}$. Then an even function of time $\tau=T-T_{0}$ can be chosen to
fit the observations in sense of least-squares method. However the function itself is not evaluated. Instead a preliminary
minimum time $T_{1}$ is estimated and $2K$ magnitudes (equation \ref{eq:kwee_m}) spaced at equal time intervals $\Delta$ symmetrically to $T_{1}$ are formed by linear interpolation between the observations.  Then $S(T_{1})$ is computed.
\begin{equation} \label{eq:kwee_m}
m_{\pm k} = m(T_{1}\pm k \Delta), ~~~ k=(1,K)
\end{equation}

\begin{equation} \label{eq:kwee_S}
S(T_{1}) = \sum_{k=1}^{K}(m_{k}-m_{-k})^2
\end{equation}

The procedure is repeated twice by shifting assumed minimum time by~ $\pm \Delta/2$ ~yielding $S(T_{1}+\Delta/2)$ ~and~ $S(T_{1}-\Delta/2)$.
The three values of $S$ define a parabola~ $S(T)=aT^2+bT+c$ ~with minimum at~ $T_{KW}=-b/2a$ ~which is considered to represent the
true minimum time $T_{0}$. The mean error of minimum epoch is estimated by

\begin{equation} \label{eq:kwee_err}
\sigma_{KW} =\sqrt{\frac{4ac-b^2}{4a^2(Z-1)}}
\end{equation}
where $Z$ is the number of independent magnitude pairs. For~ $2K=N$  ($N$ is a number of observations) the authors take  $Z=N/4$ ~if observations are not equally spaced in time ~\citep{kwee1956, brainhorst1973}.

Main disadvantage of this method is that we must have symmetrical shape of minimum and error of such method are unrealistically small.

\section{Simple Function Methods}

\subsection{Fitting with Gauss and Lorentzian Functions}
The main advantage of this two functions is their simplicity and ability to get coordinates of centre ($x_{c}$) after fitting light curve.
With another more complex functions that are discussed below we must to derivate it before we can find $x_{c}$.

Gaussian function:
\begin{equation}\label{eq:gaus}
F(t)= A\cdot \exp(-\frac{(t - x_{c})^2}{2\sigma^2})
\end{equation}

Lorentzian function:
\begin{equation}\label{eq:lorentz}
F(t)= A \frac{w^2}{w^2 + (t - x_{c})^2}
\end{equation}
where $A$ is the amplitude, $t$ is the time, $w$ is the half-width at half-maximum, $\sigma$ is the standard deviation and $x_{c}$ is the coordinates of centre.

Functions perform good fit when EB minima has shape similar to normal distribution. In case of narrow minima such functions have a slightly larger error. Also, function perform good fit when we fit only minima part but not all light curve.

\subsection{Fitting with Polynomial Function}
Polynomial function is fitted to light curve in a time interval $2 \Delta t$, symmetric with respect
to the estimated minima time. The times of minima are then found using
the calculated first derivatives, and the resulting list is processed again in
subsequent iterations. Two choices must be carefully made:
\begin{enumerate}
\item The optimal value of $\Delta t$: evidently, $\Delta t$ should comprise only those data
that contribute to the minimum event being considered, and should exclude
data beyond the flection point. The time interval $\Delta t$ should by all
means be sufficiently large to avoid small-number statistics, and the fitted
parameters must be reasonably stable when omitting data points near the
edges of the interval $2 \Delta t$
\item The degree of the polynomial: parabolic fits are to be avoided, since they
force symmetry to the data. Polynomials of third degree work well if data
curves have a slight asymmetry, but for more extreme skewness, fourth- or
fifth-degree polynomials may be used. The order of the polynomial should
be appropriate in relation to the number of data points: though the formal
goodness of fit may appear to increase with increasing polynomial degree,
one should avoid high orders when dealing with sparse data.
\end{enumerate}

The choices are very much dictated by the data, perhaps most of all by the
observational precision, and by the time resolution.
The safest approach, probably, is to carry out a statistical investigation with a range of $\Delta t$ and polynomial
degrees 3-5 for every reference phase of every variable studied, and to select the
best-fit combination of reference phase, interval and polynomial degree for that
particular variable.

But the solution really depends on the chosen interval
and on the number of data, we should keep in mind the rule of thumb that the order
of the polynome should respect the number of fitted points \citep{Sterken2005basic}.

\section{Phenomenological Methods}
\label{phenom}
\input{phenom}

\section{Template Method}
This method is based on assumptions described in \cite{Pribula2012, Pribulla2008}.
%Another method is describer in \cite{Pribula2012, Pribulla2008}.
For each EB, the fitting templates $T(x)$ is prepared to obtain the time of minimum
for any sufficiently long photometric sequence. In such way, not only the minima part of LC, but also other LC segments where
the brightness sufficiently changes can be used. The template LC can be produced as the average obtained over the whole
available observations, or as a phenomenological model as mentioned in Section \ref{phenom}.

Due to the differences in filter transparencies and wavelength response of different used detectors,
LC template must be formed for each filter separately and the fitting LC will be scaled to match the observations.
It is also noted that small nightly shifts effects of the LCs observed even with the same
instrument. Sometimes the LC shows slight but systematic slopes. These slopes are, very probably, caused by scattered
light combined with drifting of the targets on the CCD due to imperfect tracking of the telescope.
In order to obtain good fits of the template $T(x)$ to the observed LCs (and accurate timings), authors constructed the following
fitting function (see \cite{Pribulla2008}):

\begin{equation}\label{eq:dwarf1}
F(x) = A+Bx+CT(x-D)
\end{equation}
where $T(x)$ is a LC template, $A,B$ and $C$ describe shifting,
scaling and \textquote{slanting} of the LC template, and $D$ is shift in time to get exact time of minima. Fixing of the
parameters are judged according to the appearance of individual LCs.