% === [ Type Recovery ] ========================================================

\section{Type Recovery}

% Key: many problems in binary analysis can be seen as subproblems of type analysis.

% binary analysis,

% floating-point stack
%    - track stack top (indirect calls/external calls)
% pointer analysis
%    - global memory region
%    - stack memory region
%    - heap memory region
% structures/arrays

The key concepts used in type recovery are \textit{type inference}, \textit{type propagation} and \textit{unification} \cite{mycroft_type_based_decompilation}; and their shared representation is \textit{type constraints} (e.g. upper and lower bounds in a primitive type lattice) associated with the variables determined through variable recovery (see section \ref{sec:variable_recovery}). The underlying theory is based on algorithm W \cite{milner_algorithmw}.

\begin{itemize}
	\item Type inference infers type constraints of variables (based on the values they may contain, their use in instructions and as function arguments).
	\item Type propagation propagates the type constraints between variables which interact (based on data flow analysis).
	\item Unification unifies the type constraints of the entire program, and may be seen as calculating the set of solutions (which may be empty) to the type constraint equations.
\end{itemize}

% === [ Subsections ] ==========================================================

\input{sections/4_type_recovery/1_type_inference}

% TODO: add type propagation and unification sections.
%\input{sections/4_type_recovery/2_type_propagation}
%\input{sections/4_type_recovery/3_unification}

% TODO: skip pointer analysis?
%\input{sections/4_type_recovery/4_pointer_analysis}


\section{Fisher information}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Set of equations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Depending on your choosed problem type, you will have a different set of equations.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Incompressible problems}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\trust solves Navier-Stokes equations with/without the heat equation for an incompressible fluid:

$$
\left\{
\begin{array}{c}
\nabla \cdot \vec u =0 \\
\displaystyle{\frac{\partial \vec u }{\partial t} + \textcolor{red}{\nabla \cdot (\vec u \otimes \vec u)} = \textcolor{blue}{\nabla \cdot (\nu \nabla \vec u)} - \nabla P^* } \\
\displaystyle{\frac{\partial T}{\partial t} + \textcolor{red}{\vec u \nabla T} = \textcolor{blue}{\nabla \cdot (\alpha \nabla T)} + \frac{Q}{\rho C_p}}
\end{array}
\right.
$$

where: $\displaystyle{P^*=\frac{P}{\rho} + g z}$, $Q$ is the heat source term, and:

\begin{itemize}
\item $\rho$: density,
\item $\mu$: dynamic viscosity,
\item $\displaystyle{\nu=\frac{\mu}{\rho}}$: kinematic viscosity,
\item $\vec g=g z$: gravity vector in cartesian coordinates,
\item $\displaystyle{\alpha=\frac{\lambda}{\rho C_p}}$: thermal diffusivity.
\item $C_p$: specific heat capacity at constant pressure,
\item $\lambda$: thermal conductivity,
\end{itemize}

\Note that \textcolor{red}{red} terms are convective terms and \textcolor{blue}{blue} terms are diffusive terms.\\

\begin{center}
\fbox{ \begin{minipage}[c]{0.98\textwidth}
\begin{alltt}
{\bf{Pb\_\textcolor{magenta}{Thermo}hydraulique\textcolor{darkblue}{\_Concentration}\hspace{-0.15cm}\textcolor{Greeen}{\_Turbulent} } } \textit{my\_problem}

...

{\bf{Read}} \textit{my\_problem}

\{

\hspace{1cm}    \textcolor{blue}{\# Navier Stokes equations with/without turbulent model \#}

\hspace{1cm}    {\bf{Navier\_Stokes$\overbrace{\mbox{\_Standard}}^{\mbox{\textcolor{Greeen}{\_Turbulent}}}$} }

\hspace{1cm}    \{

\hspace{2cm}        {\bf{Solveur\_Pression}} \textit{my\_solver} \{ ... \}

\hspace{2cm}        {\bf{Diffusion}} \{ ... \}

\hspace{2cm}        {\bf{Convection}} \{ ... \}

\hspace{2cm}        {\bf{Initial\_conditions}} \{ ... \}

\hspace{2cm}        {\bf{Boundary\_conditions}} \{ ... \}

\hspace{2cm}        {\bf{\textcolor{Greeen}{Modele\_turbulence \textit{modele} \{ ... \} } }}

\hspace{2cm}        {\bf{Sources}} \{ ... \}

\hspace{2cm}       ...

\hspace{1cm}    \}

\hspace{1cm}    \textcolor{blue}{\# Energy equation with/without turbulent model \#}

\hspace{1cm}    {\bf{\textcolor{magenta}{Convection\_Diffusion\_Temperature}\textcolor{Greeen}{\_Turbulent}}}

\hspace{1cm}    \textcolor{magenta}{\{}

\hspace{2cm}        \textcolor{magenta}{{\bf{Diffusion}} \{ ... \}}

\hspace{2cm}        \textcolor{magenta}{{\bf{Convection}} \{ ... \}}

\hspace{2cm}        \textcolor{magenta}{{\bf{Initial\_conditions}} \{ ... \}}

\hspace{2cm}        \textcolor{magenta}{{\bf{Boundary\_conditions}} \{ ... \}}

\hspace{2cm}        \textcolor{magenta}{{\bf{\textcolor{Greeen}{Modele\_turbulence Prandtl \{ ... \} } }}}

\hspace{2cm}        \textcolor{magenta}{{\bf{Sources}} \{ ... \}}

\hspace{2cm}        \textcolor{magenta}{...}

\hspace{1cm}    \textcolor{magenta}{\}}

\hspace{1cm}    \textcolor{blue}{\# Constituent transportation equations with/without turbulent model \#}

\hspace{1cm}    {\bf{\textcolor{darkblue}{Convection\_Diffusion\_Concentration}\textcolor{Greeen}{\_Turbulent}}}

\hspace{1cm}    \textcolor{darkblue}{\{}

\hspace{2cm}        \textcolor{darkblue}{{\bf{Diffusion}} \{ ... \}}

\hspace{2cm}        \textcolor{darkblue}{{\bf{Convection}} \{ ... \}}

\hspace{2cm}        \textcolor{darkblue}{{\bf{Initial\_conditions}} \{ ... \}}

\hspace{2cm}        \textcolor{darkblue}{{\bf{Boundary\_conditions}} \{ ... \}}

\hspace{2cm}        \textcolor{darkblue}{{\bf{\textcolor{Greeen}{Modele\_turbulence Schmidt \{ ... \} } }}}

\hspace{2cm}        \textcolor{darkblue}{{\bf{Sources}} \{ ... \}}

\hspace{2cm}        \textcolor{darkblue}{...}

\hspace{1cm}    \textcolor{darkblue}{\}}

\}
\end{alltt}
\end{minipage}}
\end{center}

For documentation, see:\\

\begin{longtable}{|c|c|c|c|c|}
\hline
Thermo & hydraulique & Concentration & Turbulent & Reference Manual\tabularnewline
\hline
\hline
            & \textbf{Pb\_hydraulique}  &
            &                           & \href{\REFERENCEMANUAL\#pbhydraulique}{doc} \tabularnewline
\hline
            & \textbf{Pb\_hydraulique}  & \textbf{\textcolor{darkblue}{\_Concentration}}
            &                           & \href{\REFERENCEMANUAL\#pbhydrauliqueconcentration}{doc} \tabularnewline
\hline
            & \textbf{Pb\_hydraulique}  &
            & \textbf{\textcolor{Greeen}{\_Turbulent}}      & TrioCFD Reference Manual \tabularnewline
\hline
            & \textbf{Pb\_hydraulique}  & \textbf{\textcolor{darkblue}{\_Concentration}}
            & \textbf{\textcolor{Greeen}{\_Turbulent}}      & TrioCFD Reference Manual \tabularnewline
\hline
\textbf{Pb\_\textcolor{magenta}{Thermo}}     & \textbf{hydraulique}  &
                        &                       & \href{\REFERENCEMANUAL\#pbthermohydraulique}{doc} \tabularnewline
\hline
\textbf{Pb\_\textcolor{magenta}{Thermo}}     & \textbf{hydraulique}  & \textbf{\textcolor{darkblue}{\_Concentration}}
                        &                       & \href{\REFERENCEMANUAL\#pbthermohydrauliqueconcentration}{doc} \tabularnewline
\hline
\textbf{Pb\_\textcolor{magenta}{Thermo}}     & \textbf{hydraulique}  &
                        & \textbf{\textcolor{Greeen}{\_Turbulent}}  & TrioCFD Reference Manual \tabularnewline
\hline
\textbf{Pb\_\textcolor{magenta}{Thermo}}     & \textbf{hydraulique}  & \textbf{\textcolor{darkblue}{\_Concentration}}
                        & \textbf{\textcolor{Greeen}{\_Turbulent}}  & TrioCFD Reference Manual \tabularnewline
\hline
\end{longtable}

\vspace{0.5cm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Quasi-compressible problem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\trust solves Navier-Stokes equations with/without heat equation for quasi-compressible fluid:

$$
\left\{
\begin{array}{c}
\displaystyle{\frac{\partial \rho }{\partial t} + \nabla \cdot (\rho \vec u) =0 }\\
\displaystyle{ \frac{\partial \rho \vec u}{\partial t} + \textcolor{red}{\nabla \cdot (\rho \vec u \vec u)} =  \textcolor{blue}{\nabla \cdot \left(\mu \nabla \vec u \right)} - \nabla P -\rho \vec g }\\
\displaystyle{ \rho C_p \left( \frac{\partial T}{\partial t} + \textcolor{red}{\vec u \nabla T} \right) = \textcolor{blue}{\nabla \cdot \left(\lambda \nabla T\right)} + \frac{dP_0}{dt} + Q }
\end{array}
\right.
$$

where: $P_0=\rho R T$, $Q$ is a heat source term, and:

\begin{itemize}
\item $\rho$: density,
\item $\mu$: dynamic viscosity,
\item $\vec g=g z$: gravity vector in cartesian coordinates,
\item $C_p$: specific heat capacity at constant pressure,
\item $\lambda$: thermal conductivity.
\end{itemize}

\Note that \textcolor{red}{red} terms are convective terms and \textcolor{blue}{blue} terms are diffusive terms.\\

\begin{center}
\fbox{ \begin{minipage}[c]{0.95\textwidth}
\begin{alltt}
{\bf{Pb\_Thermohydraulique\textcolor{Greeen}{\_Turbulent}\_QC} } \textit{my\_problem}

...

{\bf{Read}} \textit{my\_problem}

\{

\hspace{1cm}    \textcolor{blue}{\# Navier Stokes equations for quasi-compressible fluid under \#}

\hspace{1cm}    \textcolor{blue}{\# low Mach numbers with/without turbulent model \#}

\hspace{1cm}    {\bf{Navier\_Stokes\textcolor{Greeen}{\_Turbulent}\_QC}}

\hspace{1cm}    \{

\hspace{2cm}        {\bf{Solveur\_Pression}} \textit{my\_solver} \{ ... \}

\hspace{2cm}        {\bf{Diffusion}} \{ ... \}

\hspace{2cm}        {\bf{Convection}} \{ ... \}

\hspace{2cm}        {\bf{Initial\_conditions}} \{ ... \}

\hspace{2cm}        {\bf{Boundary\_conditions}} \{ ... \}

\hspace{2cm}        {\bf{\textcolor{Greeen}{Modele\_turbulence \textit{modele} \{ ... \} } }}

\hspace{2cm}        {\bf{Sources}} \{ ... \}

\hspace{2cm}       ...

\hspace{1cm}    \}

\hspace{1cm}    \textcolor{blue}{\# Energy equation for quasi-compressible fluid under low Mach \#}

\hspace{1cm}    \textcolor{blue}{\# numbers with/without turbulent model \#}

\hspace{1cm}    {\bf{Convection\_Diffusion\_Chaleur}\textcolor{Greeen}{\_Turbulent}\_QC}

\hspace{1cm}    \{

\hspace{2cm}        {\bf{Diffusion}} \{ ... \}

\hspace{2cm}        {\bf{Convection}} \{ ... \}

\hspace{2cm}        {\bf{Initial\_conditions}} \{ ... \}

\hspace{2cm}        {\bf{Boundary\_conditions}} \{ ... \}

\hspace{2cm}        {\bf{\textcolor{Greeen}{Modele\_turbulence Prandtl \{ ... \} } }}

\hspace{2cm}        {\bf{Sources}} \{ ... \}

\hspace{2cm}        ...

\hspace{1cm}    \}

\}
\end{alltt}
\end{minipage}}
\end{center}

For more information on QC problem, go \href{\REFERENCEMANUAL\#pbthermohydrauliqueqc}{there} and for turbulent QC problem see TrioCFD Reference Manual.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Conduction problem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
For this kind of problems, \trust solves the heat equation:
$$
\rho C_p \frac{\partial T}{\partial t} = \textcolor{blue}{\nabla \cdot \left(\lambda \nabla T\right)} + Q
$$
where:
\begin{itemize}
\item $\rho$: density,
\item $C_p$: specific heat capacity at constant pressure,
\item $\lambda$: thermal conductivity,
\item $Q$ is a heat source term.
\end{itemize}

\Note that term in \textcolor{blue}{blue} is the diffusive term.\\

In your data file, you will have:

\begin{center}
\fbox{ \begin{minipage}[c]{0.95\textwidth}
\begin{alltt}
{\bf{Pb\_Conduction} } \textit{my\_problem}

...

{\bf{Read}} \textit{my\_problem}

\{

\hspace{1cm}    \textcolor{blue}{\# Resolution of the heat equation \#}

\hspace{1cm}    {\bf{Conduction}}

\hspace{1cm}    \{

\hspace{2cm}        {\bf{Diffusion}} \{ ... \}

\hspace{2cm}        {\bf{Convection}} \{ ... \}

\hspace{2cm}        {\bf{Initial\_conditions}} \{ ... \}

\hspace{2cm}        {\bf{Boundary\_conditions}} \{ ... \}

\hspace{2cm}        {\bf{Sources}} \{ ... \}

\hspace{2cm}        ...

\hspace{1cm}    \}

\}
\end{alltt}
\end{minipage}}
\end{center}

For more information, see the \href{\REFERENCEMANUAL\#pbconduction}{\trustref Reference Manual}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Coupled problems}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
With \trust, we can couple problems. We will explain here the method for two problems
but you can couple as many problems as you want.\\

To couple two problems, we define two problems \textit{my\_problem\_1} and \textit{my\_problem\_2} each one associated to a separate domain \textit{my\_domain\_1} and \textit{my\_domain\_2}, and to a separate medium \textit{my\_medium\_1} and \textit{my\_medium\_2} (associated or not to the gravity).
\begin{center}
\fbox{ \begin{minipage}[c]{0.95\textwidth}
\begin{alltt}
{\bf{Dimension}} 2

{\bf{Pb_ThermoHydraulique_Turbulent}} \textit{my\_problem\_1}

{\bf{Pb_ThermoHydraulique_Turbulent}} \textit{my\_problem\_2}

{\bf{Domaine}} \textit{my\_domain\_1}

{\bf{Read\_file}} \textit{my\_mesh\_1.geo} ;

{\bf{Domaine}} \textit{my\_domain\_2}

{\bf{Read\_file}} \textit{my\_mesh\_2.geo} ;

{\bf{Fluide_Incompressible}} \textit{my\_medium\_1}

{\bf{Read}} \textit{my\_medium\_1} \{ ... \}

{\bf{Fluide_Incompressible}} \textit{my\_medium\_2}

{\bf{Read}} \textit{my\_medium\_2} \{ ... \}

{\bf{Associate}} \textit{my\_problem\_1} \textit{my\_domain\_1}

{\bf{Associate}} \textit{my\_problem\_1} \textit{my\_medium\_1}

{\bf{Associate}} \textit{my\_problem\_2} \textit{my\_domain\_2}

{\bf{Associate}} \textit{my\_problem\_2} \textit{my\_medium\_2}
\end{alltt}
\end{minipage}}
\end{center}

Then we define a coupled problem associated to a single time scheme like for example:
\begin{center}
\fbox{ \begin{minipage}[c]{0.95\textwidth}
\begin{alltt}
{\bf{Probleme\_Couple}} \textit{my\_coupled\_problem}

{\bf{VEFPreP1B}} \textit{my\_discretization}

{\bf{Scheme\_euler\_explicit}} \textit{my\_scheme}

{\bf{Read}} \textit{my\_scheme} \{ ... \}

{\bf{Associate}} \textit{my\_coupled\_problem} \textit{my\_problem\_1}

{\bf{Associate}} \textit{my\_coupled\_problem} \textit{my\_problem\_2}

{\bf{Associate}} \textit{my\_coupled\_problem} \textit{my\_scheme}
\end{alltt}
\end{minipage}}
\end{center}

Then we discretize and solve everything:
\begin{center}
\fbox{ \begin{minipage}[c]{0.95\textwidth}
\begin{alltt}
{\bf{Discretize}} \textit{my\_coupled\_problem} \textit{my\_discretization}

{\bf{Read}} \textit{my\_problem\_1} \{ ... \}

{\bf{Read}} \textit{my\_problem\_2} \{ ... \}

{\bf{Solve}} \textit{my\_coupled\_problem}

{\bf{End}}
\end{alltt}
\end{minipage}}
\end{center}

You can see the documentation of this kind of problem in the \href{\REFERENCEMANUAL\#coupledproblem}{\trustref Reference Manual}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Other problems}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\trust can also solve the following types of problems:
\begin{itemize}
%\item \href{\REFERENCEMANUAL\#problemeftdiscgen}{Front-Tracking problems},
%\item \href{\REFERENCEMANUAL\#pbphasefield}{Problems to solve local instantaneous incompressible-two-phase-flows},
\item \href{\REFERENCEMANUAL\#pbthermohydrauliqueconcentrationscalairespassifs}{Resolution of NAVIER STOKES/energy/multiple constituent transportation equations, with the additional passive scalar equations}, and
\item \href{\REFERENCEMANUAL\#chimie}{describe the chemical reactions}.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Pressure solvers}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Then you may indicate the choice of pressure solver (cf \href{\REFERENCEMANUAL\#solveursysbase}{\trustref Reference Manual}) using the following syntax:
    \begin{center}
    \fbox{ \begin{minipage}[c]{0.7\textwidth}
    \begin{alltt}
    {\bf{Solveur\_pression}}  \textit{my\_solver } \{ ... \}
    \end{alltt}
    \end{minipage}}
    \end{center}

The \textit{my\_solver} may be:

\begin{itemize}
\item \href{\REFERENCEMANUAL\#solvgcp}{\textbf{GCP}},
\item \href{\REFERENCEMANUAL\#petsc}{\textbf{Petsc} \textit{Petsc\_solver\_name}},
\item \href{\REFERENCEMANUAL\#cholesky}{\textbf{Cholesky}},
\item \href{\REFERENCEMANUAL\#gmres}{\textbf{Gmres}},
\item \href{\REFERENCEMANUAL\#gen}{\textbf{Gen}},
\item \href{\REFERENCEMANUAL\#optimal}{\textbf{Optimal}}.
%\item \textbf{Gmres} or \textbf{Gen} or \textbf{Optimal} (cf to the \href[page=DOCLINK_OTHER SOLVERS]{\REFERENCEMANUAL}{\trustref Reference Manual}).
\end{itemize}

Reminder: in CFD, a separate solver is used to solve the pressure. For more details, you can have a look at the section "Time and space schemes" of the \trust \& \textbf{TrioCFD} user slides.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Convection}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
There is no default convective scheme so you must choose one \href{\REFERENCEMANUAL\#blocconvection}{convection scheme}:
    \begin{center}
    \fbox{ \begin{minipage}[c]{0.5\textwidth}
    \begin{alltt}
    {\bf{convection}} \{ \textit{convective\_scheme} \}
    \end{alltt}
    \end{minipage}}
    \end{center}

You can use the following convective scheme, following the recommendations of the user training session (cf section "Time and space schemes" of the \trust \& \textbf{TrioCFD} user slides and the section "Recommendations for schemes") following your discretization type:
\begin{itemize}
\item \href{\REFERENCEMANUAL\#convectionamont}{\textbf{Amont}}
\item \href{\REFERENCEMANUAL\#convectionmuscl}{\textbf{Muscl}}
\item \href{\REFERENCEMANUAL\#convectionefstab}{\textbf{EF\_stab}}
\item for more, see the \href{\REFERENCEMANUAL\#blocconvection}{\trustref Reference Manual}.
\end{itemize}

\Note that there is no default convective scheme and if you don't want convection in your problem, you may use:

    \begin{center}
    \fbox{ \begin{minipage}[c]{0.5\textwidth}
    \begin{alltt}
    {\bf{convection \{ negligeable \} }}
    \end{alltt}
    \end{minipage}}
    \end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Diffusion}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
For the diffusive scheme, it is the same syntax:

    \begin{center}
    \fbox{ \begin{minipage}[c]{0.5\textwidth}
    \begin{alltt}
    {\bf{diffusion}} \{ [\textit{diffusive\_scheme}] \}
    \end{alltt}
    \end{minipage}}
    \end{center}

You can choose your scheme with the help of the \href{\REFERENCEMANUAL\#blocdiffusion}{\trustref Reference Manual}.\\

\Note that if you don't specify any diffusive scheme, the code automatically uses the standard diffusive scheme of order 2.
If you don't want diffusion in your problem, you may use:

    \begin{center}
    \fbox{ \begin{minipage}[c]{0.5\textwidth}
    \begin{alltt}
    {\bf{diffusion \{ negligeable \} }}
    \end{alltt}
    \end{minipage}}
    \end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Initial conditions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
For each equation, you \textbf{must} set initial conditions:
\begin{center}
\fbox{ \begin{minipage}[c]{0.5\textwidth}
\begin{alltt}
{\bf{initial\_conditions}} \{ ... \}
\end{alltt}
\end{minipage}}
\end{center}

To see the syntax of each available initial condition: cf \href{\REFERENCEMANUAL\#condinits}{\trustref Reference Manual}.
Here are the most used initial conditions:
\begin{itemize}
\item \textbf{Vitesse}     field\_type   \textit{bloc\_lecture\_champ}
\item \textbf{Temperature}  field\_type   \textit{bloc\_lecture\_champ}
\item \textbf{K\_eps}       field\_type   \textit{bloc\_lecture\_champ}
%\item \textbf{Flux\_Chaleur\_Turbulente}    field\_type   \textit{bloc\_lecture\_champ}
%\item \textbf{Fluctu\_Temperature}          field\_type   \textit{bloc\_lecture\_champ}
%\item for more, see the \href{\REFERENCEMANUAL\#condinits}{\trustref Reference Manual}.
\end{itemize}

We list here some "field\_type":
\begin{itemize}
\item \href{\REFERENCEMANUAL\#uniformfield}{\textbf{Uniform\_Field}}: for a uniform field,
\item \href{\REFERENCEMANUAL\#champfoncmed}{\textbf{Champ\_Fonc\_Med}}: to read a data field in a MED-format file .med at a specified time,
\item \href{\REFERENCEMANUAL\#fieldfunctxyz}{\textbf{Champ\_Fonc\_txyz}}: for a field which depends on time and space,
\item \href{\REFERENCEMANUAL\#champfoncfonctiontxyz}{\textbf{Champ\_Fonc\_Fonction\_txyz}}: for a field which is a function of another field and time and/or space coordinates,
\item \href{\REFERENCEMANUAL\#champfoncreprise}{\textbf{Champ\_Fonc\_Reprise}}: to read a data field in a saved file (.xyz or .sauv) at a specified time.
\item refer to the \href{\REFERENCEMANUAL\#fieldbase}{\trustref Reference Manual}.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Boundary conditions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Then you may specify your boundary conditions like:

    \begin{center}
    \fbox{ \begin{minipage}[c]{0.5\textwidth}
    \begin{alltt}
    {\bf{boundary\_conditions}} \{ ... \}
    \end{alltt}
    \end{minipage}}
    \end{center}

It is important to specify here that \textbf{TRUST will not accept any boundary conditions by default.}\\

You can find help for boundary conditions in the \href{\REFERENCEMANUAL\#condlimbase}{\trustref Reference Manual}.
Here is a list of the most used boundary conditions:
{\small{
\begin{itemize}
\item \href{\REFERENCEMANUAL\#frontiereouvertevitesseimposee}{\textbf{Bord Frontiere\_ouverte\_vitesse\_imposee}}    boundary\_field\_type \textit{bloc\_lecture\_champ}
%\item \textbf{Bord Frontiere\_ouverte\_rho\_u\_impose}      boundary\_field\_type \textit{bloc\_lecture\_champ}
\item \href{\REFERENCEMANUAL\#frontiereouvertepressionimposee}{\textbf{Bord Frontiere\_ouverte\_pression\_imposee}}   boundary\_field\_type \textit{bloc\_lecture\_champ}
%\item \textbf{Bord Frontiere\_ouverte\_gradient\_pression\_impose} boundary\_field\_type \textit{bloc\_lecture\_champ}
%\item \textbf{Bord Frontiere\_ouverte\_pression\_imposee\_Orlansky }
\item \href{\REFERENCEMANUAL\#paroifixe}{\textbf{Bord Paroi\_fixe}}
%\item \textbf{Bord Paroi\_decalee\_Robin \{ delta value \} }
\item \href{\REFERENCEMANUAL\#symetrie}{\textbf{Bord Symetrie}}
\item \href{\REFERENCEMANUAL\#periodic}{\textbf{Bord Periodique}}
%\item \textbf{Bord Paroi\_rugueuse} \{ \textbf{erugu} value \}
\item \href{\REFERENCEMANUAL\#frontiereouvertetemperatureimposee}{\textbf{Bord Frontiere\_ouverte\_temperature\_imposee}}                        boundary\_field\_type \textit{bloc\_lecture\_champ}
%\item \textbf{Bord Frontiere\_ouverte\_temperature\_imposee\_rayo\_semi\_transp}    boundary\_field\_type \textit{bloc\_lecture\_champ}
\item \href{\REFERENCEMANUAL\#frontiereouverte}{\textbf{Bord Frontiere\_ouverte T\_ext}}                       boundary\_field\_type \textit{bloc\_lecture\_champ}
%\item \textbf{Bord Frontiere\_ouverte\_rayo\_semi\_transp T\_Ext}   boundary\_field\_type \textit{bloc\_lecture\_champ}
%\item \textbf{Bord Frontiere\_ouverte\_rayo\_transp T\_Ext}         boundary\_field\_type \textit{bloc\_lecture\_champ}
\item \href{\REFERENCEMANUAL\#paroiadiabatique}{\textbf{Bord Paroi\_adiabatique}}
\item \href{\REFERENCEMANUAL\#paroifluximpose}{\textbf{Bord Paroi\_flux\_impose}}                             boundary\_field\_type \textit{bloc\_lecture\_champ}
%\item \textbf{Bord Paroi\_temperature\_imposee}                     boundary\_field\_type \textit{bloc\_lecture\_champ}
%\item \textbf{Bord Paroi\_echange\_externe\_impose H\_imp}          boundary\_field\_type \textit{bloc\_lecture\_champ}  \textbf{T\_ext}   boundary\_field\_type \textit{bloc\_lecture\_champ}
%\item \textbf{Bord Frontiere\_ouverte\_concentration\_imposee}      boundary\_field\_type \textit{bloc\_lecture\_champ\_front}
%\item \textbf{Bord Frontiere\_ouverte C\_ext}                       boundary\_field\_type \textit{bloc\_lecture\_champ\_front}
%\item \textbf{Bord Frontiere\_ouverte\_K\_Eps\_impose}              boundary\_field\_type \textit{bloc\_lecture\_champ\_front}
%\item \textbf{Bord Frontiere\_ouverte K\_Eps\_ext}                  boundary\_field\_type \textit{bloc\_lecture\_champ\_front}
%\item \textbf{Bord Paroi}
\item for more, see the \href{\REFERENCEMANUAL\#condlimbase}{\trustref Reference Manual}.
\end{itemize}
}}

To choose your "boundary\_field\_type" parameters, refer to the \href{\REFERENCEMANUAL\#frontfieldbase}{\trustref Reference Manual}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Turbulence models (in TrioCFD)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
User can add a turbulence model to his simulation using the keyword:
\begin{center}
\fbox{ \begin{minipage}[c]{0.7\textwidth}
\begin{alltt}
{\bf{Modele\_turbulence}} \textit{my\_model} \{ ... \}
\end{alltt}
\end{minipage}}
\end{center}

where \textit{my\_model} can be:
\begin{itemize}
\item \href{\REFERENCEMANUAL\#longueurmelange}{\textbf{Longueur\_Melange}}: RANS model based on mixing length modelling,
\item \href{\REFERENCEMANUAL\#sousmaille}{\textbf{Sous\_maille}}: LES model which uses a structure sub-grid function model,
%\item \textbf{Sous\_maille\_Smago}
%\item \textbf{Sous\_maille\_wale}
\item \href{\REFERENCEMANUAL\#kepsilon}{\textbf{K\_epsilon}}: for RANS turbulence model (k-$\varepsilon$),
%\item \textbf{K\_epsilon\_2\_Couches}
\item for more, see the \href{\REFERENCEMANUAL\#modeleturbulencehydderiv}{\trustref Reference Manual}.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Source terms}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
To introduce a source term into an equation, add the following line into the block defining the equation. The list of source keyword is described below.
\begin{center}
\fbox{ \begin{minipage}[c]{0.5\textwidth}
\begin{alltt}
{\bf{Sources}}  \textit{ \{ source\_keyword \}}
\end{alltt}
\end{minipage}}
\end{center}

To introduce several source terms into the same equation, the blocks corresponding to the various terms need to be separated by a comma:
\begin{center}
\fbox{ \begin{minipage}[c]{0.7\textwidth}
\begin{alltt}
{\bf{Sources}}  \textit{ \{ source\_keyword1 , source\_keyword2 , ...\}}
\end{alltt}
\end{minipage}}
\end{center}

\begin{itemize}
\item \href{\REFERENCEMANUAL\#pertechargereguliere}{\textbf{Perte\_Charge\_Reguliere}} type\_perte\_charge bloc\_definition\_pertes\_charges
%\item \textbf{Perte\_Charge\_Isotrope} \{ ... \}
\item \href{\REFERENCEMANUAL\#pertechargesinguliere}{\textbf{Perte\_Charge\_Singuliere}} \textbf{KX | KY | KZ} coefficient\_value \{ ... \}
%\item \textbf{Source\_Qdm}   field\_type   field\_description
\item \href{\REFERENCEMANUAL\#canalperio}{\textbf{Canal\_perio}} \{ ... \}
%\item \textbf{Source\_Robin} N boundary\_name\_1  ... boundary\_name\_N
\item \href{\REFERENCEMANUAL\#boussinesqtemperature}{\textbf{Boussinesq\_temperature}} \{ ... \}: $\rho(T)=\rho(T_0)(1-\beta_{th}(T-T_0))$
\item \href{\REFERENCEMANUAL\#boussinesqconcentration}{\textbf{Boussinesq\_concentration}} \{ ... \}
%\item \textbf{Source\_Th\_TdivU }
\item \href{\REFERENCEMANUAL\#puissancethermique}{\textbf{Puissance\_thermique}} field\_type   bloc\_lecture\_champ
%\item \textbf{Source\_Robin\_Scalaire  ...}
%\item \textbf{Source\_Generique} field\_type   bloc\_lecture\_champ
\item \href{\REFERENCEMANUAL\#sourcebase}{documentation for hydraulic source terms and for scalar source terms}.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Post-processing}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Before post-processing fields, during a run, \trust creates several files which contain information about the calculation, the convergence, fluxes, balances... (see part \ref{post} for more information).\\

Several keywords can be used to create a post-processing block, into a problem. First, you can create a single post-processing task (\href{\REFERENCEMANUAL\#postraitement}{\textbf{Post\_processing}} keyword). Generally, in this block, results will be printed with a specified format at a specified time period.
\begin{center}
\fbox{ \begin{minipage}[c]{0.5\textwidth}
\begin{alltt}
{\bf{Post\_processing }}

\{

\hspace{1cm}    \textit{Postraitement\_definition}

\}
\end{alltt}
\end{minipage}}
\end{center}

But you can also create a list of post-processings with \href{\REFERENCEMANUAL\#postraitements}{\textbf{Post\_processings}} keyword (named with Post\_name1, Post\_name2, etc...), in order to print results into several formats or with different time periods, or into different results files:
\begin{center}
\fbox{ \begin{minipage}[c]{0.6\textwidth}
\begin{alltt}
{\bf{Post\_processings }}

\{

\hspace{1cm}  \textit{Post\_name1  \{ Postraitement\_definition \} }

\hspace{1cm}  \textit{Post\_name2  \{ Postraitement\_definition \} }

\hspace{1cm} ...

\}
\end{alltt}
\end{minipage}}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Field names}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{itemize}
\item \textcolor{darkblue}{\textbf{Existing \& predefined fields}}

You can post-process predefined fields and already existing fields.
Here is a list of post-processable fields, but it is not the only ones.

\small
\input{fieldnames.tex}
\normalsize

\begin{remark}
Physical properties (conductivity, diffusivity,...) can also be interrogated.
\end{remark}

\textbf{The name of the fields and components available for post-processing is displayed in the error file after the following message: "Reading of fields to be postprocessed". Of course, this list depends of the problem being solved.}

For more information, you can see the \href{\REFERENCEMANUAL\#champsapost}{\trustref Reference Manual}.
%\vspace{1cm}

\item \textcolor{darkblue}{\textbf{Creating new fields}}

The \href{\REFERENCEMANUAL\#definitionchamps}{\textbf{Definition\_champs}} keyword is used to create new or more complex fields for advanced post-processing.

\begin{center}
\fbox{ \begin{minipage}[c]{0.8\textwidth}
\begin{alltt}
{\bf{Definition\_champs}} \{ \textit{field\_name\_post} {\bf{\textit{field\_type}}} \{ ... \} \}
\end{alltt}
\end{minipage}}
\end{center}

%%%    \begin{center}
%%%    \fbox{ \begin{minipage}[c]{0.7\textwidth}
%%%    \begin{alltt}
%%%    {\bf{Definition\_champs}} \{

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{refChamp}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Interpolation}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Gradient}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Divergence}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Moyenne}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Ecart\_Type}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Correlation}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Transformation}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Extraction}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Reduction\_0D}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Morceau\_Equation}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Predefini}} \{ ... \}]

%%%    \hspace{1cm}    [{\textit{field\_name\_post}} {\bf{Tparoi\_VEF}} \{ ... \}]

%%%    \}

%%%    \end{alltt}
%%%    \end{minipage}}
%%%    \end{center}

\textit{field\_name\_post} is the name of the new created field and \textbf{\textit{field\_type}} is one of the following possible type:
\begin{itemize}
\item \href{\REFERENCEMANUAL\#refchamp}{\textbf{refChamp}}
\item \href{\REFERENCEMANUAL\#reduction0d}{\textbf{Reduction\_0D}} using for example the \textbf{min}, \textbf{max} or \textbf{somme} methods.
\item \href{\REFERENCEMANUAL\#transformation}{\textbf{Transformation}}
%\item Interpolation
%\item \textbf{Gradient}
%\item Divergence
%\item Moyenne
%\item Ecart\_Type
%\item Correlation
%\item Extraction
%\item Morceau\_Equation
%\item Predefini
%\item Tparoi\_VEF
\item for details and other keywords, see the \href{\REFERENCEMANUAL\#definitionchamps}{\trustref Reference Manual}.
\end{itemize}

\Note that you can combine several \textbf{\textit{field\_type}} keywords to create your field and then use your new fields to create other ones.\\

Here is an example of new field named \textit{max\_temperature}:

\begin{center}
\fbox{ \begin{minipage}[c]{0.9\textwidth}
\begin{alltt}
{\bf{Read}} \textit{my\_problem} \{

\hspace{0.5cm}    ...

\hspace{0.5cm}    {\bf{Postraitement}} \{

\hspace{1cm}        {\bf{Definition\_champs}} \{

\hspace{1.5cm}            \textcolor{blue}{\# Creation of a 0D field: maximal temperature of the domain \#}

\hspace{1.5cm}            \textit{max\_temperature} {\bf{Reduction\_0D}} \{

\hspace{2cm}            {\bf{methode max}}

\hspace{2cm}            {\bf{source refChamp}} \{ {\bf{Pb\_champ}} \textit{my\_problem} {\bf{temperature}} \}

\hspace{1.5cm}            \}

\hspace{1cm}        \}

\hspace{1cm}        {\bf{Probes}} \{

\hspace{1.5cm}            \textcolor{blue}{\# Print max(temperature) into the datafile\_TMAX.son file \#}

\hspace{1.5cm}            \textit{tmax} \textit{max\_temperature} {\bf{periode}} 0.01 {\bf{point}} 1 0. 0.

\hspace{1cm}        \}

\hspace{1cm}        {\bf{Champs dt\_post}} 1.0 \{ ... \}

\hspace{0.5cm}        \}

\}
\end{alltt}
\end{minipage}}
\end{center}

You can find other examples in the \trust \& \textbf{TrioCFD} user slides in the section "Post processing description".
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Post-processing blocks}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
There are three methods to post-process in \trust: using probes, fields or making statistics.

\begin{itemize}
\item \textcolor{darkblue}{\textbf{Probes}}\\
Probes refer to sensors that allow a value or several points of the domain to be monitored over time.
The probes are a set of points defined:
\begin{itemize}
\item one by one: \href{\REFERENCEMANUAL\#points}{\textbf{Points}} keyword or
\item by a set of points evenly distributed over a straight segment: \href{\REFERENCEMANUAL\#segment}{\textbf{Segment}} keyword or
\item arranged according to a layout: \href{\REFERENCEMANUAL\#plan}{\textbf{Plan}} keyword or
\item arranged according to a parallelepiped: \href{\REFERENCEMANUAL\#volume}{\textbf{Volume}} keyword.
\end{itemize}

Here is an example of 2D \textbf{Probes} block:
    \begin{center}
    \fbox{ \begin{minipage}[c]{0.92\textwidth}
    \begin{alltt}
    {\bf{Probes}} \{

        \hspace{0.2cm}     \textit{pressure\_probe} \textit{[loc]} {\bf{pressure Periode}} 0.5 {\bf{Points}}      3  1.  0.   1.   1.   1.   2.

        \hspace{0.2cm}     \textit{velocity\_probe} \textit{[loc]} {\bf{velocity Periode}} 0.5 {\bf{Segment}}     10  1.  0.      1.   4.

    \}
    \end{alltt}
    \end{minipage}}
    \end{center}
where the use of \textit{"loc"} option allow to specify the wanted location of the probes. The available values are \textbf{"grav"} for gravity center of the element, \textbf{"nodes"} for faces and \textbf{"som"} for vertices. There is not default location. If the point does not coincide with a calculation node, the value is extrapolated linearly according to neighbouring node values.

For complete syntax, see the \href{\REFERENCEMANUAL\#corpspostraitement}{\trustref Reference Manual}, also for \href{\REFERENCEMANUAL\#sondes}{all options}.

%%    \begin{center}
%%    \fbox{ \begin{minipage}[c]{1\textwidth}
%%    \begin{alltt}
%%    {\bf{Probes}} \{

%%    \hspace{1cm}    [nom\_sonde [type] field\_name {\bf{Periode}} dts

%%        \hspace{1.5cm} | {\bf{Points}}      {\bf{position\_like}} nom\_sonde

%%        \hspace{1.5cm} | {\bf{Points}}      n x1 y1 [z1] x2 y2 [z2] .... xn yn [zn]]

%%    \hspace{1cm}    [nom\_sonde [type] field\_name {\bf{Periode}} dts

%%        \hspace{1.5cm} | {\bf{Segment}}     {\bf{position\_like}} nom\_sonde

%%        \hspace{1.5cm} | {\bf{Segment}}     ns x1 y1 [z1] x2 y2 [z2]]

%%    \hspace{1cm}    [nom\_sonde [type] field\_name {\bf{Periode}} dts

%%        \hspace{1.5cm} | {\bf{Segmentpoints}}       {\bf{position\_like}} nom\_sonde

%%        \hspace{1.5cm} | {\bf{Segmentpoints}}       ns x1 y1 [z1] x2 y2 [z2] .... xn yn [zn]]

%%    \hspace{1cm}    [nom\_sonde [type] field\_name {\bf{Periode}} dts

%%        \hspace{1.5cm} | {\bf{Plan}}    {\bf{position\_like}} nom\_sonde

%%        \hspace{1.5cm} | {\bf{Plan}}    ns1 ns2  x1 y1 [z1] x2 y2 [z2] x3 y3 [z3]]

%%    \hspace{1cm}    [nom\_sonde [type] field\_name {\bf{Periode}} dts

%%        \hspace{1.5cm} | {\bf{Volume}}      {\bf{position\_like}} nom\_sonde

%%        \hspace{1.5cm} | {\bf{Volume}}      ns1 ns2 ns3  x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4]

%%    \hspace{1cm}    [nom\_sonde [type] field\_name {\bf{Periode}} dts

%%        \hspace{1.5cm} | {\bf{Circle}}      {\bf{position\_like}} nom\_sonde

%%        \hspace{1.5cm} | {\bf{Circle}}      n x0 y0 [z0 dir] r teta1 teta2]

%%    \hspace{1cm}    [nom\_sonde [type] field\_name {\bf{Periode}} dts {\bf{Numero\_elem\_sur\_maitre}} integer

%%    \}
%%    \end{alltt}
%%    \end{minipage}}
%%    \end{center}

\item \textcolor{darkblue}{\textbf{Fields}}\\
This keyword allows to post-process fields on the whole domain, specifying the name of the backup file, its format, the post-processing time step and the name (and location) of the post-processed fields.

Here is an example of \href{\REFERENCEMANUAL\#champsposts}{\textbf{Fields}} block:
    \begin{center}
    \fbox{ \begin{minipage}[c]{0.5\textwidth}
    \begin{alltt}
    {\bf{Fichier}} \textit{results}

    {\bf{Format lata}}

    {\bf{Fields}} {\bf{dt\_post}} 1.  \{

        \hspace{1cm}     {\bf{velocity   [faces] [som] [elem]}}

        \hspace{1cm}    {\bf{pressure   [elem] [som]}}

        \hspace{1cm}    {\bf{temperature [elem] [som] }}

    \}
    \end{alltt}
    \end{minipage}}
    \end{center}

where \textbf{"faces"} , \textbf{"elem"} and \textbf{"som"} are keywords allowed to specify the location of the field.\\

\Note that \underline{when you don't specify the location of the field}, the default value is \textbf{"som"} for values at the vertices. So fields are post-processed at the vertices of the mesh.\\

To visualize your post-processed fields, you can use open source softwares like: \href{https://wci.llnl.gov/simulation/computer-codes/visit}{VisIt} (included in \trust package) for lata files, or for med files: \href{http://www.salome-platform.org}{Salom\'e} or \href{http://www.paraview.org}{Paraview}.\\

You can see the \href{\REFERENCEMANUAL\#corpspostraitement}{complete syntax} and \href{\REFERENCEMANUAL\#champsposts}{all options} in the \href{\REFERENCEMANUAL}{\trustref Reference Manual}.

\item \textcolor{darkblue}{\textbf{Statistics}}\\
Using this keyword, you will compute statistics on your unknows. You must specify the begining and ending time for the statistics, the post-processing time step, the statistic method, the name (and location) of your post-processed field.

Here is an example of \href{\REFERENCEMANUAL\#statsposts}{\textbf{Statistiques}} block:
    \begin{center}
    \fbox{ \begin{minipage}[c]{0.7\textwidth}
    \begin{alltt}
    {\bf{Statistiques dt\_post}} 0.1 \{

        \hspace{1cm}  {\bf{t\_deb}} 1. {\bf{t\_fin}} 5.

        \hspace{1cm}  {\bf{moyenne  velocity [faces] [elem] [som]}}

        \hspace{1cm}  {\bf{ecart\_type pressure [elem] [som]}}

        \hspace{1cm}  {\bf{correlation pressure velocity [elem] [som] }}

    \}
    \end{alltt}
    \end{minipage}}
    \end{center}

%%    {\bf{Statistiques\_en\_serie Dt\_integr}} dtst \{
%%        \hspace{1cm}  {\bf{t\_deb}} value {\bf{t\_fin}} value
%%        \hspace{1cm}  [{\textit{stat}}  field\_name] [location]
%%        \hspace{1cm}  ...
%%    \}

This block will write at every \textbf{dt\_post} the average of the velocity $\overline{V(t)}$:
\[
\overline{V(t)}=\left\{ \begin{array}{ll}
0 & ,\mbox{ for }t\leq t\mbox{\_}deb\\
\frac{1}{t-t\mbox{\_}deb}{\displaystyle \int_{t\mbox{\_}deb}^{t}V(t)dt} & ,\mbox{ for }t\mbox{\_}deb<t\leq t\mbox{\_}fin\\
\frac{1}{t\mbox{\_}fin-t\mbox{\_}deb}{\displaystyle \int_{t\mbox{\_}deb}^{t\mbox{\_}fin}V(t)dt} & ,\mbox{ for }t>t\mbox{\_}fin
\end{array}\right.
\]

the standard deviation of the pressure $\left\langle P(t)\right\rangle$:
\[
\left\langle P(t)\right\rangle=\left\{ \begin{array}{ll}
0 & ,\mbox{ for }t\leq t\mbox{\_}deb\\
\frac{1}{t-t\mbox{\_}deb}{\displaystyle \sqrt{\int_{t\mbox{\_}deb}^{t}\left[P(t)-\overline{P(t)}\right]^{2}dt}} & ,\mbox{ for }t\mbox{\_}deb<t\leq t\mbox{\_}fin\\
\frac{1}{t\mbox{\_}fin-t\mbox{\_}deb}{\displaystyle \sqrt{\int_{t\mbox{\_}deb}^{t\mbox{\_}fin}\left[P(t)-\overline{P(t)}\right]^{2}dt}} & ,\mbox{ for }t>t\mbox{\_}fin
\end{array}\right.
\]

and correlation between the pressure and the velocity $\left\langle P(t).V(t)\right\rangle$ like:
\[
\left\langle P(t).V(t)\right\rangle=\left\{ \begin{array}{ll}
0 & ,\mbox{ for }t\leq t\mbox{\_}deb\\
\frac{1}{t-t\mbox{\_}deb}{\displaystyle \int_{t\mbox{\_}deb}^{t}\left[P(t)-\overline{P(t)}\right]\cdot\left[V(t)-\overline{V(t)}\right]dt} & ,\mbox{ for }t\mbox{\_}deb<t\leq t\mbox{\_}fin\\
\frac{1}{t\mbox{\_}fin-t\mbox{\_}deb}{\displaystyle \int_{t\mbox{\_}deb}^{t\mbox{\_}fin}\left[P(t)-\overline{P(t)}\right]\cdot\left[V(t)-\overline{V(t)}\right]dt} & ,\mbox{ for }t>t\mbox{\_}fin
\end{array}\right.
\]

\begin{remark}
Statistical fields can be plotted with probes with the keyword "operator\_field\_name" like for example: Moyenne\_Vitesse or Ecart\_Type\_Pression or Correlation\_Vitesse\_Vitesse. For that, it is mandatory to have the statistical calculation of this fields defined with the keyword \textbf{Statistiques}.\\
\end{remark}

For the complete syntax, see the \trustref Reference Manual \href{\REFERENCEMANUAL\#corpspostraitement}{here}, and for all options see the \href{\REFERENCEMANUAL\#statsposts}{\trustref Reference Manual}.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Post-process location}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
You can use location keywords to specify where you want to post-process your fields in order to avoid interpolations on your post-processed fields.\\

%For example, in VDF, pressure field is computed at the vertices so if we put \textbf{"elem"} keyword, the post-processed field will be taken at the center of the element so it won't be interpolated. If we use \textbf{"faces"} keyword for VDF pressure, we will get interpolated field.

For the \textbf{VDF} discretization, you can see the Figure \ref{fig_VDF} and here is a table with a reminder of the computation location of the fields in the \textbf{VDF} discretization:

%\begin{longtable}[h!]{|c|c|c|c|c|}
%\hline
%\textbf{Names}              & \textbf{Keyword}                  & \textbf{Location}     & \textbf{Probes}   & \textbf{Fields}   \\ \hline
%\hline
%Pressure                    & \textbf{pressure}                 & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%Velocity                    & \textbf{velocity}                 & faces center              & \textbf{nodes}    & \textbf{faces}    \\ \hline
%Temperature                 & \textbf{temperature}              & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%\hline
%Density $\rho$              & \textbf{masse\_volumique}         & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%Cinematic viscosity $\nu$   & \textbf{viscosite\_cinematique}   & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%Dynamic viscosity $\mu$     & \textbf{viscosite\_dynamique}     & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%\hline
%K                           & \textbf{k}                        & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%eps                         & \textbf{eps}                      & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%$y^+$                       & \textbf{y\_plus}                  & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%$u^*$                       & \textbf{u\_star}                  & faces center              & \textbf{nodes}    & \textbf{faces}    \\ \hline
%Turbulent viscosity         & \textbf{viscosite\_turbulente}    & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%\end{longtable}

\begin{longtable}[h!]{|c|c|c|c|c|}
\hline
\textbf{Names}              & \textbf{Keyword}                  & \textbf{Location}     \\ \hline
\hline
Pressure                    & \textbf{pressure}                 & element gravity center    \\ \hline
Velocity                    & \textbf{velocity}                 & faces center              \\ \hline
Temperature                 & \textbf{temperature}              & element gravity center    \\ \hline
\hline
Density $\rho$              & \textbf{masse\_volumique}         & element gravity center    \\ \hline
Kinematic viscosity $\nu$   & \textbf{viscosite\_cinematique}   & element gravity center    \\ \hline
Dynamic viscosity $\mu$     & \textbf{viscosite\_dynamique}     & element gravity center    \\ \hline
\hline
K                           & \textbf{k}                        & element gravity center    \\ \hline
eps                         & \textbf{eps}                      & element gravity center    \\ \hline
$y^+$                       & \textbf{y\_plus}                  & element gravity center    \\ \hline
$u^*$                       & \textbf{u\_star}                  & faces center              \\ \hline
Turbulent viscosity         & \textbf{viscosite\_turbulente}    & element gravity center    \\ \hline
\end{longtable}

For the \textbf{VEFPreP1B} discretization, you can see the Figure \ref{fig_VEF} and \ref{fig_VEF_pressure_loc}. Here is a table with a reminder of the computation location of the fields in \textbf{VEFPreP1B} discretization:

\begin{longtable}[h!]{|c|c|c|c|c|}
\hline
\textbf{Names}              & \textbf{Keyword}                  & \textbf{Location}     \\ \hline
\hline
                            &                                   & element gravity center    \\
Pressure                    & \textbf{pressure}                 & vertices                  \\ \hline
%                            &                                   & faces center (for 3D)     \\ \hline
Velocity                    & \textbf{velocity}                 & faces center              \\ \hline
Temperature                 & \textbf{temperature}              & faces center              \\ \hline
\hline
Density $\rho$              & \textbf{masse\_volumique}         & element gravity center    \\ \hline
Kinematic viscosity $\nu$   & \textbf{viscosite\_cinematique}   & element gravity center    \\ \hline
Dynamic viscosity $\mu$     & \textbf{viscosite\_dynamique}     & element gravity center    \\ \hline
\hline
K                           & \textbf{k}                        & faces center              \\ \hline
eps                         & \textbf{eps}                      & faces center              \\ \hline
$y^+$                       & \textbf{y\_plus}                  & element gravity center    \\ \hline
$u^*$                       & \textbf{u\_star}                  & faces center              \\ \hline
Turbulent viscosity         & \textbf{viscosite\_turbulente}    & element gravity center    \\ \hline
\end{longtable}

%\begin{longtable}[h!]{|c|c|c|c|c|}
%\hline
%\textbf{Names}              & \textbf{Keyword}                  & \textbf{Location}     & \textbf{Probes}   & \textbf{Fields}   \\ \hline
%\hline
%                            &                                   & P0: element gravity center    & \textbf{grav} & \textbf{elem}     \\
%Pressure                    & \textbf{pressure}                 & P1: vertices              & \textbf{som}      & \textbf{som}      \\
%                            &                                   & Pa: faces center (for 3D) & \textbf{nodes}    & \textbf{faces}    \\ \hline
%Velocity                    & \textbf{velocity}                 & faces center              & \textbf{nodes}    & \textbf{faces}    \\ \hline
%Temperature                 & \textbf{temperature}              & faces center              & \textbf{nodes}    & \textbf{faces}    \\ \hline
%\hline
%Density $\rho$              & \textbf{masse\_volumique}         & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%Cinematic viscosity $\nu$   & \textbf{viscosite\_cinematique}   & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%Dynamic viscosity $\mu$     & \textbf{viscosite\_dynamique}     & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%\hline
%K                           & \textbf{k}                        & faces center              & \textbf{nodes}    & \textbf{faces}    \\ \hline
%eps                         & \textbf{eps}                      & faces center              & \textbf{nodes}    & \textbf{faces}    \\ \hline
%$y^+$                       & \textbf{y\_plus}                  & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%$u^*$                       & \textbf{u\_star}                  & faces center              & \textbf{nodes}    & \textbf{faces}    \\ \hline
%Turbulent viscosity         & \textbf{viscosite\_turbulente}    & element gravity center    & \textbf{grav}     & \textbf{elem}     \\ \hline
%\end{longtable}

\textbf{Be careful}, if you are in P0+P1 discretization (default option) and you post-process the pressure field at the element (or at the vertices), you will have an \textbf{interpolation} because the field is computed at the element \textbf{and} at the vertices. \\
%There is no distinction between the two fields and the code will interpolate to have pressure at the element or at the vertices.\\
%This is the same in P0+P1+Pa.


\vsssub
\subsubsection{~$S_{ice}$: Damping by sea ice (Liu et al.)} \label{sec:ICE2}
\vsssub

\opthead{IC2}{\ws/NRL}{E. Rogers, S. Zieger, F. Ardhuin}

\noindent
This method for representing the dissipation of wave energy by wave-ice interaction is based on the papers
by \cite{art:LMC88}, \cite{art:LHV91} and \cite{art:Aea15}. The main input ice parameters
is the ice thickness (in meters) that can vary spatially and temporally and is the forcing field  ${C_{ice,1}}$.

This is a model for attenuation by a
sea ice cover, derived on the assumption that dissipation is caused by
friction in the boundary layer below the ice,
with the ice modeled as a continuous thin elastic plate. The original form by  \cite{art:LMC88} is activated by
setting the {\code IC2} namelist {\F SIC2} parameter {\code IC2DISPER = .TRUE.}. That form
 assumes that the boundary layer is always laminar but it uses an eddy viscosity ${\nu}$ that can vary spatially
and is the forcing field ${C_{ice,2}}$.

 {\code IC2} and {\code IS2} share
the optional use of the \cite{art:LMC88} dispersion relation for unbroken ice,
\begin{equation}
\sigma^2 =  \left(gk_{ice} + B k_{ice}^5\right)  / \left(1/\tanh ( k_{ice}H) +\frac{\rho_{ice}  h k_{ice}} {\rho_{w} }\right),
\end{equation}
\begin{equation}
c_g =  (g+(5 + 4 k_{ice} M)Bk_{ice}^5)/(2\sigma(1+k_{ice}M)^2).
\end{equation}

\noindent
$B$ and $M$ quantify the effects of, respectively, ice bending due to waves and ice inertia.
The group velocity under the ice, derived from the same relation, is used in the module {\code W3SIS2MD} and computed in
{\code W3DISPMD}.  See \citet{art:LMC88} for details.

For {\code IC2}, the dispersion relation is defined by

\begin{equation}\label{eq:ice1}
  {\sigma}^2 = ({gk_r} + {Bk_r^5})/(\coth({k_r}{h_w}) + {k_r}{M}),
\end{equation}
\begin{equation}\label{eq:ice2}
  {c_g} = (g + (5 + 4{k_r}{M}){B}{k_r^5})/(2{\sigma}(1+{k_r}{M})^2),
\end{equation}
\begin{equation}\label{eq:ice3}
  {\alpha} = (\sqrt{{\nu\sigma}}{k_r)}/({c_g}\sqrt{2}(1+{k_r}{M})).
\end{equation}

\noindent
In our notation, $h_w$ is water depth and $h_i$ is ice thickness.  The
variables $B$ and $M$ quantify the effects of the bending of the ice and
inertia of the ice, respectively. Both of these variables depend on $h_i$
\citep[see][]{art:LMC88, art:LHV91}.

This equation is only solved when ICEDISP=TRUE in the {\F MISC} namelist. Otherwise, $k_{ice}=k$, just like in open water.
Note that the effect of $k_{ice}$ is not passed back to the main program.
% I temporarily removed text "...is limited to wave breaking and dissipation..." : is this true? Or did the author mean to say "ice breaking and dissipation"?

 \cite{art:SAG16} improved {\code IC2} by adding a better alternative to the eddy viscosity representation of dissipation.
They distinguish between laminar and
turbulent regimes, allowing this is activated by setting  {\code IC2DISPER = .FALSE.}.
In that case the dissipation goes from a laminar form using the molecular viscosity multiplied by an
empirical adjustment factor {\code IC2VISC} to a turbulent form, amplified by a factor {\code IC2TURB}, for Reynolds numbers
above a user-defined threshold {\code IC2REYNOLDS}. This transition is smoothed over a range {\code IC2SMOOTH} to take into
account the random nature of the wave field. In the turbulent regime, the friction factor
is estimated from a user-specified under-ice roughness length {\code IC2ROUGH}, expected to be of the order of $10^{-4}$~m.
Possibility has also been added to perform a heuristic reduction of the dissipation
rate when the floe diameters are much shorter than the ocean wave
wavelength \citep[see][for details]{Aea18}. It relies on the hypothesis that, in these conditions, ice floes follow at least partly
the horizontal motion and it is thus logical to reduce the relative velocity
between the ice and the water from which the dissipation rate is estimated.
This reduction is controlled by the factor called $r_D$ in \cite{Aea18} which value can be set through the namelist parameter {\code IC2DMAX}.
Reduction of the dissipation rate occures for waves longer than $D_{\max}/r_D$ ($D_{\max}$
being the maximum floe size), and there is no reduction for maximum floe diameters of the order of
the wavelength or more.

The parameter {\code IC2TURBS} is an ad hoc enhancement of turbulent dissipation in the Southern hemisphere
that was introduced for test purposes to investigate sources of bias. This will be deprecated in future versions. It now appears
that combining IC2 with ineleastic dissipation in IS2 can provide good results for dominant waves in both hemispheres \citep{Aea18}.

A full description of the original form of {\code IC2} can be found in \cite{rep:RO13}.
It is applied in \cite{art:LKS15}. A concise summary of the present code is given
in \cite{rep:RPLA18}. A description of the improvement of the dissipation mechanism
of {\code IC2} can be found in Appendix B of \cite{art:SAG16}, where it is used.


\section{Mutable Records}
We build mutable records in addition to our preceding operators. A record simply needs labels and the possiblity to (mutably) select a
field from a record. Since we want to ensure mutability, we want our selection operator to take as input a reference to our record and
to return as output a reference to the selected field; references can be assigned and evaluated (thanks to the $:=$, $*=$ and $eval$
operators) and this is what does guarantee mutability:

\begin{verbatim}
class (RefSt ref st s) => Record r ref st s where
  type Label r :: * -> *
  (<=) :: ref s r -> Label r a -> ref s a
\end{verbatim}

Before Giuseppe's PhD/Monads/ObjectiveMonad/MonadicObjects prev/trunk/tex v2/mutable_records.tex


\documentclass{article}
\usepackage[utf8]{inputenc}

\title{%
  \Huge Ramanujan's Square \\
  \LARGE Detailed Analysis\\
  \Large A DV2136 Proposal}

\author{by\\
\Large Afzal (h1810003) \\
\Large Prannaya Gupta (h1810124) \\
\Large Yap Yuan Xi (h1810166) \\
}

\date{\Large 14 August 2019}

\usepackage{natbib}
\usepackage{graphicx}

\begin{document}

\maketitle

\section{Introduction}

\subsection{Magic Squares}
    A magic square is a square whose column and rows give the same sum. The first Magic Square was created in China. Magic Squares are very fun to solve. In this project, we will be solving a 4 by 4 magic square.
    \subsubsection{Pan-diagonals}
            In this kind of Magic Square, the one of its diagonals adds up to the same sum as the sum of its rows and columns
    \subsubsection{Bi-diagonals}
        In this kind of Magic Square, the sum of both its diagonals both add up to the same sum as the sum of its rows and columns
    \subsubsection{Rectangle}
        These kind of Magic Squares have a different amount of numbers in one dimension than the other\\
        \textbf{Note: These Squares cannot be Pan-diagonal or Bi-diagonal}\\
        Example:
        \def\arraystretch{2}
        \begin{center}
            \begin{tabular}{|c|c|c|c|}
                \hline
                62 & 44 & 23 & 01 \\
                \hline
                03 & 61 & 02 & 64 \\
                \hline
                38 & 28 & 39 & 25 \\
                \hline
                27 & 37 & 26 & 40 \\
                \hline
                22 & 04 & 63 & 41 \\
                \hline
                43 & 21 & 42 & 24 \\
                \hline
            \end{tabular}
        \end{center}
    \subsubsection{Non-Repeating}
            These kind of Magic Squares have no numbers that can be found in 2 boxes
\subsection{Srinivasa Ramanujan}
    Magic squares are squares where the rows and columns have the same sum. This magic squares has more than that, it has many other ways to get the same sum. This is known as Srinivasa Ramanujan's Magic Square.
    Notice that the top row makes up his birthday, 22 December 1887.

\section{The Problem}
% Table showing the numbers in the square
\begin{center}
    \begin{tabular}{|c|c|c|c|}
        \hline
        22 & 12 & 18 & 87 \\
        \hline
        88 & 17 & 09 & 25 \\
        \hline
        10 & 24 & 89 & 16 \\
        \hline
        19 & 86 & 23 & 11 \\
        \hline
    \end{tabular}
\end{center}
\space
This, as we noticed, is a bi-diagonal, non-repeating square unless input otherwise.
Is there formula/method to generate the magic squares from any given birthday?

\newpage
\section{Solution}
After looking at it for a while, we noticed that some of the numbers are pretty similar. Although the numbers were scattered we noticed that numbers above 80 appeared in 4 squares and are pretty similar to the year he was born in, 87. We realised that by using his birthday as base, we expressed the entire square in terms of it.\\
After trying a few combinations between the numbers around 20 in the magic square, we realised the following\\

\begin{center}
Letting D be day, M be month, C be century and Y be year of the birthday,\\
We expressed the table as shown below\\

\def\arraystretch{2}
\begin{tabular}{|c|c|c|c|}
    \hline
    D + 0 & M + 0 & C + 0 & Y + 0 \\
    \hline
    Y + 1 & C - 1 & M - 3 & D + 3 \\
    \hline
    M - 2 & D + 2 & Y + 2 & C - 2 \\
    \hline
    C + 1 & Y - 1 & D + 1 & M - 1 \\
    \hline
\end{tabular}
\end{center}

\section{Extensions/ Generalisations}
    \subsection{Another Form}
        Is there another method to generate squares with the same properties?

    \subsubsection{Variation 1: Diagonal}
        Letting D,M,C,Y be the day, month, century and year of the birthday respectively. \\
        Let start with the diagonal. \\
        \def\arraystretch{2}
        \begin{center}
            \begin{tabular}{|c|c|c|c|}
                \hline
                D + 0 & Y + 2 & M - 1 & C - 1 \\
                \hline
                C - 2 & M + 0 & Y - 1 & D + 3 \\
                \hline
                Y + 1 & D + 1 & C + 0 & M - 2 \\
                \hline
                M + 1 & C - 3 & D + 2 & Y + 0 \\
                \hline
            \end{tabular}
        \end{center}
    \subsubsection{Variation 2: Box}
        Letting D,M,C,Y be the day, month, century and year of the birthday respectively. \\
        Let start with the Upper Left 2 by 2 square. \\
        \def\arraystretch{2}
        \begin{center}
            \begin{tabular}{|c|c|c|c|}
                \hline
                C - 2 & M + 1 & D + 2 & Y - 1 \\
                \hline
                Y + 1 & D + 0 & M + 0 & C - 1 \\
                \hline
                M - 1 & C + 0 & Y + 0 & D + 1 \\
                \hline
                D + 2 & Y - 1 & C - 2 & M + 1 \\
                \hline
            \end{tabular}
        \end{center}

    \subsubsection{Variation 3: Column}
        Letting D,M,C,Y be the day, month, century and year of the birthday respectively. \\
        Let start with the Left most Column. \\

        \def\arraystretch{2}
        \begin{center}
            \begin{tabular}{|c|c|c|c|}
                \hline
                D + 0 & C + 2 & Y - 1 & M - 1 \\
                \hline
                M + 0 & Y - 2 & C - 1 & D + 3 \\
                \hline
                C + 0 & D + 2 & M + 1 & Y - 3 \\
                \hline
                Y + 0 & M - 2 & D + 1 & C + 1 \\
                \hline
            \end{tabular}
        \end{center}

    \subsection{Method of making these squares}
        Looking at the above Variations. We believe that there is a method in the creation of these kinds of squares.

        This is the method we found while creating the squares

        \begin{enumerate}
            \item Set the beginning (Column, Row etc.)
            \item Set each box to base of one of the four given variables
            \item Set one number to differ
            \item Using that number set the others, keeping the beginning unchanged
            \item Check if it all add up and make changes if necessary.
        \end{enumerate}
\end{document}


\subsection{part c}
Now we design feedforward controller to make staedy state error zero.
$$
\lim_{s\to0} \dfrac{s+1}{s^2-2s+4} = 4 \to F(s) = 4
$$
With this controller staedy state is zero and with lead controller (that we have digened in part d) we achive requirements.
\newpage
\begin{itemize}
	\item all figures from siso toolbox
	\begin{figure}[H]
		\caption{All figures from siso toolbox}
		\centering
		\includegraphics[width=16cm]{../Figure/Q1/Q1_c/siso_all.png}
	\end{figure}
	\newpage
	\item root locus with lead and feedforward controller
	\begin{figure}[H]
		\caption{root locus}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_c/rlocus.png}
	\end{figure}
	\item step response for closeloop system with lead and feedforward controller
	\begin{figure}[H]
		\caption{step response for closeloop system}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_c/feedback_step.png}
	\end{figure}
	\item closeloop bode (magnitude) with lead and feedforward controller
	\begin{figure}[H]
		\caption{closeloop bode (magnitude)}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_c/feedback_bode.png}
	\end{figure}
	\item openloop bode (magnitude) with lead and feedforward controller
	\begin{figure}[H]
		\caption{openloop bode (magnitude)}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_c/openloop_bode.png}
	\end{figure}
	\item sensitivity function with lead and feedforward controller
	\begin{figure}[H]
		\caption{sensitivity function}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_c/s_bode.png}
	\end{figure}
	\item complementary sensitivity function with lead and feedforward controller
	\begin{figure}[H]
		\caption{complementary sensitivity function}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_c/t_bode.png}
	\end{figure}
\end{itemize}


\section{Classifiers}

\subsection{Metrics to use}
\begin{frame}
 \frametitle{Which metrics to use ?}
 46 metrics correlated with bug density:
 \begin{itemize}
  \item Program size. 26 metrics\\
  (lines of codes, comments, blank, semicolons, functions, preprocessor)
  \item Cyclomatic complexity. 11 metrics
  \item Halstead metrics. 9 metrics
 \end{itemize}
\end{frame}
% TODO liste complete en annexe
% Program size: cout lines of code, blank lines, comments, functions, classes, semicolons.
% Program size: count, average, ration, etc,

\begin{frame}
 \frametitle{Halstead metrics}
 Halstead metrics: set of metrics based on the number of operands and number of operators.\\
 Based on
 \begin{center}
  \begin{tabular}{ll}
   $\eta_1$ & = The number of distinct operators\\
   $\eta_2$ & = The number of distinct operands\\
   $N_1$ & = The total number of operators\\
   $N_2$ & = The total number of operands\\
  \end{tabular}
 \end{center}
 \begin{exampleblock}{Some halstead metrics}
  \begin{itemize}
   \item Program vocabulary = $\eta = \eta_1 + \eta_2$
   \item Program length = $N = N_1 + N_2$
   \item Volume = $N \times \text{log}_2\eta$
   \item Difficulty = $\frac{\eta_1}{2} \times \frac{N_2}{\eta_2}$
  \end{itemize}
 \end{exampleblock}
\end{frame}

\subsection{Results without new metrics}
\begin{frame}
 \frametitle{Tried classifiers}
 \begin{itemize}
  \item Naive Bayes (NB)
  \item Bayesian networks (BayesNet)
  \item Decision trees (DecTree)
  \item Logistic regression (Logistic)
 \end{itemize}
\end{frame}
%TODO montrer la gueule que ça a

\begin{frame}
 \frametitle{Results without new metrics}
 \framesubtitle{Terminology}
 $$PD = \text{Probability of detection} = \frac{\text{true positives}}{\text{true positives + false negatives}} . 100\%$$
 \vspace{0.1cm}
 $$PF = \text{Probability of false alarms} = \frac{\text{false positives}}{\text{true negatives + false positives}} . 100\%$$
 \vspace{0.1cm}
 $$Bal = Balance = 100 - \frac{\sqrt{(0-PF)^2 + (100-PD)^2}}{\sqrt{2}}$$
 \begin{center}
  \begin{tabular}{ll}
   log : & metrics at a logarithmic scale
  \end{tabular}
 \end{center}
 \small note: the difference between the highest and the second highest value can be statistically not significant. See numbers in bold. \normalsize
\end{frame}
%Probability of detection is the probability that a ARB-prone module will be classified as ARB-prone
%Probability of false alamrs is the probability that a non-ARB-prone module is erroneously identified as ARB-prone
%A classifier with a high PD can also have a high PF (imagine a classifier that always answer 'yes') So balance is a trade-off

\begin{frame}
 \frametitle{Results without new metrics}
 \framesubtitle{Linux}
 \begin{center}
 \begin{tabular}{lrrr}
  \hspace{0.2cm} Classifier & PD & PF & Bal\\
  \hline
  NB & 60.13 & 12.46 & \textbf{69.24}\\
  NB + log &  \textbf{92.33} & \textbf{37.09} & \textbf{72.28}\\
  BayesNet & 3.72 & 1.85 & 31.91\\
  BayesNet + log & 5.34 & 1.95 & 33.06\\
  DectTree & 0.00 & 0.03 & 29.30\\
  DectTree + log & 0.00 & 0.00 & 29.30\\
  Logistic & 1.00 & 0.63 & 30.01\\
  Logistic + log & 3.84 & 0.62 & 32.01\\
  \hline
 \end{tabular}
 \end{center}
\end{frame}

\begin{frame}
 \frametitle{Results without new metrics}
 \framesubtitle{MySQL}
 \begin{center}
 \begin{tabular}{lrrr}
  \hspace{0.2cm} Classifier & PD & PF & Bal\\
  \hline
  NB & 49.14 & 10.46 & 63.02\\
  NB + log &  \textbf{88.30} & \textbf{34.67} & \textbf{73.53}\\
  BayesNet & 44.57 & 8.65 & 60.26\\
  BayesNet + log & 44.50 & 8.65 & 60.21\\
  DectTree & 11.21 & 2.64 & 37.17\\
  DectTree + log & 11.28 & 2.65 & 37.22\\
  Logistic & 22.93 & 4.46 & 45.40\\
  Logistic + log & 25.07 & 5.13 & 46.88\\
  \hline
 \end{tabular}
 \end{center}
\end{frame}

\begin{frame}
 \frametitle{Results without new metrics}
 \framesubtitle{CARDAMOM}
 \begin{center}
 \begin{tabular}{lrrr}
  \hspace{0.2cm} Classifier & PD & PF & Bal\\
  \hline
  NB & 0.00 & 7.18 & 29.08\\
  NB + log &  \textbf{54.50} & \textbf{25.15} & \textbf{53.25}\\
  BayesNet & 0.00 & 0.00 & 29.30\\
  BayesNet + log & 0.00 & 0.00 & 29.30\\
  DectTree & 0.00 & 0.00 & 29.30\\
  DectTree + log & 0.00 & 0.00 & 29.30\\
  Logistic & 0.00 & 1.21 & 29.30\\
  Logistic + log & 0.00 & 0.65 & 29.30\\
  \hline
 \end{tabular}
 \end{center}
\end{frame}

\begin{frame}
 \frametitle{Results without new metrics}
 \begin{center}
  $\Longrightarrow$ \alert{Select the Naive Bayes classifier with metrics at a logarithmic scale.}
 \end{center}
 \vspace{1cm}
 High probability of detection but high probability of false alarm.
 Still useful for Verification \& Validation process:
 \begin{center}
  \alert{avoids to inspect the files classified as non-ARB !}
 \end{center}
\end{frame}


\subsection{Stability on non-smooth objectives}
\label{sec:stability}

\begin{figure}
%	%\begin{minipage}{0.61\textwidth}
\centering
%% \vspace{-2.25em}
  \includegraphics[width=\linewidth]{experiment_results/clipping_example.pdf}
% \vspace{-0.75em}
\caption{A variation of the LSTM architecture in \citep{zhu2016trained} exhibits exploding gradients.
The proposed adaptive gradient clipping threshold (blue) stabilizes the training loss.}
\label{fig:stability}
%\end{minipage}
\end{figure}

The process of training neural networks is inherently non-stationary, with the landscape abruptly switching from flat to steep areas.
In particular, the objective functions of RNNs with hidden units can exhibit occasional but very steep slopes \citep{pascanu2013difficulty,szegedy2013intriguing}.
To deal with this issue, gradient clipping has been established in literature as a standard tool to stabilize the training using such objectives \citep{pascanu2013difficulty,Goodfellow-et-al-2016,gehring2017convolutional}.
%When that happens, the smoothed statistics from our measurement functions might not be representative.
%So, it is not always safe to assume that the smoothed statistics from our measurement functions so far will accurately represent the objective with abruptly large gradient in the next step.

We use \emph{adaptive gradient clipping} heuristics as a very natural addition to our basic tuner.
However, the classic tradeoff between adaptivity and stability applies:
setting a clipping threshold that is too low can hurt performance;
setting it to be high, can compromise stability.
\tuner, keeps running estimates of extremal gradient magnitude squares, $h_{max}$ and $h_{min}$ in order to estimate a generalized condition number.
We posit that $\sqrt{h_{max}}$ is an ideal gradient norm threshold for adaptive clipping.
In order to ensure robustness to extreme gradient spikes, like the ones in Figure~\ref{fig:stability}, we also limit the growth rate of the envelope $h_{max}$ in Algorithm~\ref{alg:curv_func} as follows:
\begin{equation}
 h_{max}
 \leftarrow
 \beta \cdot h_{max}
 	+ (1-\beta) \cdot \textrm{min}\left\{
 		h_{max,t}, 100 \cdot h_{max}
 	\right\}
\end{equation}
Our heuristics follows along the lines of classic recipes like~\cite{pascanu2013difficulty}. However, instead of using the average gradient norm to clip, it uses a running estimate of the maximum norm $h_{\max}$. In Figure~\ref{fig:stability}, we demonstrate the mechanism of our heuristic by presenting an example of an LSTM that exhibits the 'exploding gradient' issue. The proposed adaptive clipping can stabilize the training process using \tuner and prevent large catastrophic loss spikes.
\label{sec:infl_clip}
\begin{figure}
\centering
\begin{tabular}{c@{\hspace{0.0em}} c}
	\includegraphics[width=0.49\linewidth]{experiment_results/ptb/clip_cmp.pdf} &
	\includegraphics[width=0.49\linewidth]{experiment_results/resnet/cifar10_clip_cmp.pdf}
\end{tabular}
\caption{Training losses on PTB LSTM (left) and CIFAR10 ResNet (right) for YellowFin with and without adaptive clipping.}
\label{fig:infl_clip}
\end{figure}

%\begin{table*}
%\begin{minipage}{0.61\textwidth}
%\centering
%% \vspace{-2.25em}
%  \includegraphics[width=0.95\linewidth]{experiment_results/clipping_example.pdf}
% \vspace{-0.75em}
%\captionof{figure}{A variation of the LSTM architecture in \citep{zhu2016trained} exhibits exploding gradients.
%The proposed adaptive gradient clipping threshold (blue) stabilizes the training loss.}
%\label{fig:stability}
%\end{minipage}
%\begin{minipage}{0.01\textwidth}
%	 \
%\end{minipage}
%\begin{minipage}{0.37\textwidth}
%\centering
%%\small
%\vspace{0.5em}
%\begin{tabular} {@{\hspace{0.2em}}c | c | c @{\hspace{0.2em}}}
%\toprule
%	& Loss & BLEU4 \\
%\midrule
%\midrule
%	Default w/o clip. & \multicolumn{2}{c}{diverge} \\ [0.3em]
%	Default w/ clip. & 2.86 & 30.75 \\ [0.3em]
%	YF & \textbf{2.75} & \textbf{31.59} \\
%\bottomrule
%\end{tabular}
%\vspace{2.25em}
%\captionof{table}{German-English translation validation performance using convolutional seq-to-seq learning.}
%\label{tab:conv_seq}
%\end{minipage}
%%\vspace{-0.75em}
%\end{table*}

%Section~\ref{sec:oracles} describes the core measurement functions for \tuner tuner. To support its tuning rule, \tuner calculates smoothed, rough approximations of curvature ranges, a distance from a local minimum and gradient variance.
%Neural network objectives can involve arbitrary non-linearities, and large Lipschitz constants \citep{szegedy2013intriguing}.
%Furthermore, the process of training them is inherently non-stationary, with the landscape abruptly switching from flat to steep areas.
%The process of training neural networks is inherently non-stationary, with the landscape abruptly switching from flat to steep areas.
%In particular, the objective functions of RNNs with hidden units can exhibit occasional but very steep slopes \citep{pascanu2013difficulty,szegedy2013intriguing}.
%%When that happens, the smoothed statistics from our measurement functions might not be representative.
%%So, it is not always safe to assume that the smoothed statistics from our measurement functions so far will accurately represent the objective with abruptly large gradient in the next step.
%To deal with this issue, we use \emph{adaptive gradient clipping} heuristics as a very natural addition to our basic tuner. It is discussed with extensive details in Appendix~\ref{sec:adapt_clip}.
%In Figure~\ref{fig:stability} in Appendix~\ref{sec:adapt_clip}, we present an example of an LSTM that exhibits the 'exploding gradient' issue. The proposed adaptive clipping can stabilize the training process using \tuner and prevent large catastrophic loss spikes.
%\begin{table}
%\centering
%\begin{tabular} { c | c | c | c}
%\toprule
%	& Default w/o clip. & Default w/ clip. & YF \\
%\midrule
%\midrule
%	Validation loss & diverge & 2.86 & 2.75 \\
%	Validation BLEU4 & diverge & 30.75 & 31.59 \\
%\bottomrule
%\end{tabular}
%\caption{German-English translation performance using convolutional sequence to sequence learning.}
%\label{tab:conv_seq}
%\end{table}

\begin{wrapfigure}[10]{r}{0.48\linewidth}
%asdfad
\hspace{-0.75em}
\begin{minipage}{\linewidth}
%%\begin{table}[h]
%\centering
\small
%\hspace{-1em}
\vspace{-0.75em}
\begin{tabular} {@{\hspace{0.1em}}c@{\hspace{0.3em}} | @{\hspace{0.35em}}c@{\hspace{0.4em}}c @{\hspace{0.1em}}}
\toprule
	& Loss & BLEU4 \\
\midrule
\midrule
	Default w/o clip. & \multicolumn{2}{c}{diverge} \\ [0.3em]
	Default w/ clip. & 2.86 & 30.75 \\ [0.3em]
	YF & \textbf{2.75} & \textbf{31.59} \\
\bottomrule
\end{tabular}
%\hspace{-1em}
\captionof{table}{German-English translation validation metrics using convolutional seq-to-seq model.}
%\vspace{2.25em}
\label{tab:conv_seq}
\end{minipage}
\end{wrapfigure}
We validate the proposed adaptive clipping on the convolutional sequence to sequence learning model \citep{gehring2017convolutional} for IWSLT 2014 German-English translation. The default optimizer~\citep{gehring2017convolutional} uses learning rate $0.25$ and Nesterov's momentum $0.99$, diverging to loss overflow due to 'exploding gradient'. It requires, as in~\citet{gehring2017convolutional}, strict manually set gradient norm threshold $0.1$ to stabilize.
%We train the model for 120 epochs and report the best validation loss, as well as the best validation BLEU4 score.
%We follow the default optimizer setting in~\citep{gehring2017convolutional}, where manually set strict clipping is applied before performing SGD with learning rate $0.25$ and Nesterov's momentum set to $0.99$.
%The optimizer diverges when the clipping is removed.
In Table~\ref{tab:conv_seq}, we can see YellowFin, with adaptive clipping, outperforms the default optimizer using manually set clipping, with 0.84 higher validation BLEU4 after 120 epochs.
To further demonstrate the practical applicability of our gradient clipping heuristics, in Figure~\ref{fig:infl_clip}, we demonstrate that the adaptive clipping does not hurt performance on models that do not exhibit instabilities without clipping. Specifically, for both PTB LSTM and CIFAR10 ResNet, the difference between \tuner with and without adaptive clipping diminishes quickly.
%Thinking fast and slow approach:
%- slow layer, the basic tuner we described
%- fast layer: applies clipping based on the statistics estimated
%- *and* we don’t let the estimates grow too quickly

%%%%%%%%%%%%%%%%%%% latest backup version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%\begin{table*}
%%\begin{minipage}{0.61\textwidth}
%%\centering
%%% \vspace{-2.25em}
%%  \includegraphics[width=0.95\linewidth]{experiment_results/clipping_example.pdf}
%% \vspace{-0.75em}
%%\captionof{figure}{A variation of the LSTM architecture in \citep{zhu2016trained} exhibits exploding gradients.
%%The proposed adaptive gradient clipping threshold (blue) stabilizes the training loss.}
%%\label{fig:stability}
%%\end{minipage}
%%\begin{minipage}{0.01\textwidth}
%%	 \
%%\end{minipage}
%%\begin{minipage}{0.37\textwidth}
%%\centering
%%%\small
%%\vspace{0.5em}
%%\begin{tabular} {@{\hspace{0.2em}}c | c | c @{\hspace{0.2em}}}
%%\toprule
%%	& Loss & BLEU4 \\
%%\midrule
%%\midrule
%%	Default w/o clip. & \multicolumn{2}{c}{diverge} \\ [0.3em]
%%	Default w/ clip. & 2.86 & 30.75 \\ [0.3em]
%%	YF & \textbf{2.75} & \textbf{31.59} \\
%%\bottomrule
%%\end{tabular}
%%\vspace{2.25em}
%%\captionof{table}{German-English translation validation performance using convolutional seq-to-seq learning.}
%%\label{tab:conv_seq}
%%\end{minipage}
%%%\vspace{-0.75em}
%%\end{table*}
%
%%Section~\ref{sec:oracles} describes the core measurement functions for \tuner tuner. To support its tuning rule, \tuner calculates smoothed, rough approximations of curvature ranges, a distance from a local minimum and gradient variance.
%%Neural network objectives can involve arbitrary non-linearities, and large Lipschitz constants \citep{szegedy2013intriguing}.
%%Furthermore, the process of training them is inherently non-stationary, with the landscape abruptly switching from flat to steep areas.
%The process of training neural networks is inherently non-stationary, with the landscape abruptly switching from flat to steep areas.
%In particular, the objective functions of RNNs with hidden units can exhibit occasional but very steep slopes \citep{pascanu2013difficulty,szegedy2013intriguing}.
%%When that happens, the smoothed statistics from our measurement functions might not be representative.
%%So, it is not always safe to assume that the smoothed statistics from our measurement functions so far will accurately represent the objective with abruptly large gradient in the next step.
%To deal with this issue, we use \emph{adaptive gradient clipping} heuristics as a very natural addition to our basic tuner. It is discussed with extensive details in Appendix~\ref{sec:adapt_clip}.
%In Figure~\ref{fig:stability} in Appendix~\ref{sec:adapt_clip}, we present an example of an LSTM that exhibits the 'exploding gradient' issue. The proposed adaptive clipping can stabilize the training process using \tuner and prevent large catastrophic loss spikes.
%%\begin{table}
%%\centering
%%\begin{tabular} { c | c | c | c}
%%\toprule
%%	& Default w/o clip. & Default w/ clip. & YF \\
%%\midrule
%%\midrule
%%	Validation loss & diverge & 2.86 & 2.75 \\
%%	Validation BLEU4 & diverge & 30.75 & 31.59 \\
%%\bottomrule
%%\end{tabular}
%%\caption{German-English translation performance using convolutional sequence to sequence learning.}
%%\label{tab:conv_seq}
%%\end{table}
%
%\begin{wrapfigure}[10]{r}{0.48\linewidth}
%%asdfad
%\hspace{-0.75em}
%\begin{minipage}{\linewidth}
%%%\begin{table}[h]
%%\centering
%\small
%%\hspace{-1em}
%\vspace{-0.75em}
%\begin{tabular} {@{\hspace{0.1em}}c@{\hspace{0.3em}} | @{\hspace{0.35em}}c@{\hspace{0.4em}}c @{\hspace{0.1em}}}
%\toprule
%	& Loss & BLEU4 \\
%\midrule
%\midrule
%	Default w/o clip. & \multicolumn{2}{c}{diverge} \\ [0.3em]
%	Default w/ clip. & 2.86 & 30.75 \\ [0.3em]
%	YF & \textbf{2.75} & \textbf{31.59} \\
%\bottomrule
%\end{tabular}
%%\hspace{-1em}
%\captionof{table}{German-English translation validation metrics using convolutional seq-to-seq model.}
%%\vspace{2.25em}
%\label{tab:conv_seq}
%\end{minipage}
%\end{wrapfigure}
%We validate the proposed adaptive clipping on the convolutional sequence to sequence learning model \citep{gehring2017convolutional} for IWSLT 2014 German-English translation. The default optimizer~\citep{gehring2017convolutional} uses learning rate $0.25$ and Nesterov's momentum $0.99$, diverging to loss overflow due to 'exploding gradient'. It requires, as in~\citet{gehring2017convolutional}, strict manually set gradient norm threshold $0.1$ to stabilize.
%%We train the model for 120 epochs and report the best validation loss, as well as the best validation BLEU4 score.
%%We follow the default optimizer setting in~\citep{gehring2017convolutional}, where manually set strict clipping is applied before performing SGD with learning rate $0.25$ and Nesterov's momentum set to $0.99$.
%%The optimizer diverges when the clipping is removed.
%In Table~\ref{tab:conv_seq}, we can see YellowFin, with adaptive clipping, outperforms the default optimizer using manually set clipping, with 0.84 higher validation BLEU4 after 120 epochs.
%%Thinking fast and slow approach:
%%- slow layer, the basic tuner we described
%%- fast layer: applies clipping based on the statistics estimated
%%- *and* we don’t let the estimates grow too quickly
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\begin{table}[t]
%\begin{minipage}{0.62\textwidth}
%\centering
%  \includegraphics[width=\linewidth]{experiment_results/clipping_example.pdf}
% \vspace{-1.5em}
%\captionof{figure}{A variation of the LSTM architecture in \citep{zhu2016trained} exhibits exploding gradients.
%The proposed adaptive gradient clipping threshold (blue) stabilizes the training loss.}
%\label{fig:stability}
%\end{minipage}
%\begin{minipage}{0.02\textwidth}
%	 \
%\end{minipage}
%\begin{minipage}{0.35\textwidth}
%\centering
%\small
%\vspace{1.5em}
%\begin{tabular} {@{\hspace{0.2em}}c | c | c @{\hspace{0.2em}}}
%\toprule
%	& Loss & BLEU4 \\
%\midrule
%\midrule
%	Default w/o clip. & \multicolumn{2}{c}{diverge} \\ [0.3em]
%	Default w/ clip. & 2.86 & 30.75 \\ [0.3em]
%	YF & \textbf{2.75} & \textbf{31.59} \\
%\bottomrule
%\end{tabular}
%\vspace{1em}
%\caption{German-English translation validation performance using convolutional seq-to-seq learning.}
%\label{tab:conv_seq}
%\end{minipage}
%\end{table}
%
%
%Section~\ref{sec:sync_tuner} describes the core of the \tuner tuner.
%It uses the basic tuning rules extracted from a noisy quadratic model.
%To engineer our implementation on arbitrary objectives, we calculate smoothed, rough approximations of curvature ranges, a distance from a local minimum and gradient variance.
%However, certain neural network objectives can involve arbitrary non-linearities, and large Lipschitz constants \citep{szegedy2013intriguing}.
%Furthermore, the process of training them is inherently non-stationary, with the landscape abruptly switching from flat to steep areas.
%In particular, the objective functions associated with RNNs   with hidden units can exhibit occasional but very steep slopes \citep{pascanu2013difficulty}.
%So, it is not always safe to assume that the statistics we calculated so far will accurately represent the objective function in the next step.
%
%In Figure~\ref{fig:stability}, we present such an example of an LSTM that exhibits this 'exploding gradient' issue.
%To deal with this issue, we propose a very natural addition to our basic tuner, that performs {\em adaptive gradient clipping}.
%Gradient clipping has been established in literature as a standard---almost necessary---tool for training such objectives \citep{pascanu2013difficulty,Goodfellow-et-al-2016,gehring2017convolutional}.
%However, the classic tradeoff between adaptivity and stability applies:
%setting a clipping threshold that is too low can hurt performance;
%setting it to be high, can compromise stability.
%\tuner, keeps running estimates of extremal gradient magnitude squares, $h_{max}$ and $h_{min}$ in order to estimate a generalized condition number.
%We posit that $\sqrt{h_{max}}$ is an ideal gradient norm threshold for adaptive clipping.
%In order to ensure robustness to extreme gradient spikes, like the ones in Figure~\ref{fig:stability}, we also limit the growth rate of the envelope $h_{max}$ in Algorithm~\ref{alg:curv_func} as follows:
%\begin{equation}
% h_{max}
% \leftarrow
% \beta \cdot h_{max}
% 	+ (1-\beta) \cdot \textrm{min}\left\{
% 		h_{max,t}, 100 \cdot h_{max}
% 	\right\}
%\end{equation}
%%\begin{table}
%%\centering
%%\begin{tabular} { c | c | c | c}
%%\toprule
%%	& Default w/o clip. & Default w/ clip. & YF \\
%%\midrule
%%\midrule
%%	Validation loss & diverge & 2.86 & 2.75 \\
%%	Validation BLEU4 & diverge & 30.75 & 31.59 \\
%%\bottomrule
%%\end{tabular}
%%\caption{German-English translation performance using convolutional sequence to sequence learning.}
%%\label{tab:conv_seq}
%%\end{table}
%
%We demonstrate the performance of YellowFin with adaptive clipping on the IWSLT 2014 German-English translation task using the convolutional sequence to sequence learning model of \citep{gehring2017convolutional}. We train the model for 120 epochs and report the best validation loss, as well as the best validation BLEU4 score. We follow the default optimizer setting in~\citep{gehring2017convolutional}, where manually set strict clipping is applied before performing SGD with learning rate $0.25$ and Nesterov's momentum set to $0.99$. The optimizer diverges when the clipping is removed. In Table~\ref{tab:conv_seq}, we can see YellowFin, with adaptive clipping, can outperform the default optimizer with manually set clipping in both validation loss and BLEU4 score.
%Our proposed adaptive clipping helps stabilize difficult objectives, without sacrificing performance.
%In Appendix~\ref{sec:infl_clip} we demonstrate that on models that do not exhibit instabilities, our clipping does not hurt performance.
%
%%Thinking fast and slow approach:
%%- slow layer, the basic tuner we described
%%- fast layer: applies clipping based on the statistics estimated
%%- *and* we don’t let the estimates grow too quickly
%


\subsection{Operators}

\subsubsection{Unary Operators}
The following unary operations are allowed on $\SecretBit$, $\SecretI$.
\begin{verbatim}
     !
\end{verbatim}
This operation inverts all bits (or just the one bit in the $\SecretBit$ case)
of its argument. There is no $!$ operation like in C on integers. If you want to
check whether all bits are zero in Rust, you need to use an equality operation.

\subsubsection{Binary Operators}
The following operations are allowed between $\SecretI$ and $\ints$
types:
\begin{verbatim}
     +   -   *   /
     ^   &   |
\end{verbatim}
The output is of type $\SecretI$ if any of the two operands are
$\SecretI$s, otherwise the output type is a $\ints$.

~\\

\noindent
The following operations are allowed between $\SecretModp$ and $\ClearModp$
types:
\begin{verbatim}
     +   -   *
\end{verbatim}
The output is of type $\SecretModp$ if any of the two operands are
$\SecretModp$s, otherwise the output type is a $\ClearModp$.

~\\
\noindent
The following operations are allowed between $\SecretModp$ and $\ClearModp$
types:
\begin{verbatim}
     /
\end{verbatim}
The output is of type $\SecretModp$ if the first operand is
$\SecretModp$s, otherwise the output type is a $\ClearModp$.
     {\bf Note:} The second operand must be a $\ClearModp$ or a \verb|ConstI32| at present.

~ \\

\noindent
The following operations are allowed between $\ClearModp$ and $\ints$ types:
\begin{verbatim}
    %   <<   >>  ^  &  |
\end{verbatim}
The operations are performed by lifting the $\ClearModp$ values to
the integers (in the range $[0,\ldots,p)$) and then performing
the operation over the integers.  The output is of type $\ClearModp$

~ \\

\noindent
The following operations are allowed between $\SecretBit$ types:
\begin{verbatim}
     ^   &   |
\end{verbatim}
The output is of type $\SecretBit$

~\\

\noindent
The following operations are allowed between $\ints$ types:
\begin{verbatim}
     ==    !=
     <   >   <=  >=
\end{verbatim}
The output is of type $\ints$/$\bool$ and therefore allows branching
on the resulting condition etc.

~ \\

\noindent
Between an $\SecretI$, $\SecretModp$ or $\ClearModp$ and an immediate operand (an \verb|ConstU32|)
you can execute shift-left and shift-right operations. These operators also exist if both operands
are $\ints$.
\begin{verbatim}
     <<    >>
\end{verbatim}
As in
\begin{lstlisting}
   let sb = sa << ConstU32::<3>;
\end{lstlisting}
For integers, the small example needs to use $\mathsf{black\_box}$
as otherwise the optimizer will optimize the shift and just store
the end result.
\begin{lstlisting}
   let a = black_box(2);
   let b = black_box(1);
   let c = a << b
\end{lstlisting}