\section{RAVEN Mathematical Background}
\label{sec:mathBackground}
\subsection{System and Control Model}
\label{sub:controlAndSystem}
The first step is the derivation of the mathematical model representing, with a high
level of abstraction, the plant and control system model. Let $\overline{\theta}\left ( t
\right )$ be a vector describing the system status in the phase space, characterized
by the following governing equation:
\begin{equation}
\label{eq:dThetaOverDT}
\frac{\partial \overline{\theta} }{\partial t}=\overline{H}\left (  \overline{\theta}\left ( t \right ),t \right )
\end{equation}
In Equation above, the assumption of time differentiability of the trajectory equation $\overline{H}\left (  \overline{\theta}\left ( t \right ),t \right )$ in the phase space has been taken. This assumption is not fully correct and generally required and it is used here, without missing of generality, for compactness of the notation.
\\It can now be performed an arbitrary decomposition of the phase space:
\begin{equation}
\label{eq:thetaDecomposition}
  \overline{\theta} = \left (\frac{\overline{x}}{\overline{v}}  \right )
\end{equation}
The decomposition is made in such a way that $\overline{x}$ represent the unknowns
solved by a system code (such as RELAP5-3D~\cite{RELAP5userManual},
RELAP7~\cite{relap7FY12}, etc.) while $\overline{v}$ are the variables directly
controlled by the control system (e.g., automatic mitigation systems, operator actions,
etc.).
\\The governing equation can be now cast in the following system of equations:
\begin{equation}
\label{eq:governingEquations}
\left\{\begin{matrix}
\frac{\partial \overline{x} }{\partial t} = \overline{F}\left (  \overline{x}, \overline{v}, t \right )  \\
\frac{\partial \overline{v} }{\partial t} = \overline{V}\left (  \overline{x}, \overline{v}, t \right )
\end{matrix}\right.
\end{equation}
Consequentially to this splitting, $\overline{x}$ contains the state variables of the
phase space that are continuous while $\overline{v}$ contains discrete state
variables that are usually handled by the control system (consequentially, named
\textbf{control variables}). It can be noticed that the
function  $ \overline{V}\left (  \overline{x}, \overline{v}, t \right )$, representing the
control system, does not depend on the  knowledge of the complete status of the
system but on a restricted subset that can be named \textbf{monitored variables} $\overline{C}$:

\begin{equation}
\label{eq:controlVars}
\left\{\begin{matrix}
\frac{\partial \overline{x} }{\partial t} = \overline{F}\left (  \overline{x}, \overline{v}, t \right )  \\
 \overline{C} =  \overline{G}(\overline{x},t)     \\
\frac{\partial \overline{v} }{\partial t} = \overline{V}\left (  \overline{x}, \overline{v}, t \right )
\end{matrix}\right.
\end{equation}
where $\overline{C}$ is a vector of smaller dimensionality than $\overline{x}$ and,
therefore, more convenient to handle.
\\As it can be noticed, the standard nomenclature of \textit{signals} (monitored variables) and \textit{status} (control variables) is not adopted. Two principal reasons
justify this decision:
\begin{itemize}
  \item The definition of signals is tight to the definition of the
  control logic for each component and, therefore, relative rather than absolute in the
  overall system analysis. For example, it is possible the the \textit{signals} for a
  component represent \textit{status} of another one, determining an in-unique
  definition.
  \item The standard nomenclature becomes meaningless when this derivation is
  applied to Uncertainty Quantification (UQ).
\end{itemize}

\subsubsection{Splitting Approach for the Simulation of the Control System}
Equation~\ref{eq:controlVars} represents a fully coupled system of Partial Differential
Equations (PDEs). To solve this system, an  \textit{operator splitting} approach
is employed. This method is preferable in this context for several reasons, among which the following:
\begin{itemize}
  \item In reality, the control system (automatic mitigation systems, operator actions,
  etc.) is always characterized by an intrinsic delay
  \item The reaction of the control system might make the system ``move'' among
  different discrete states; therefore, numerical errors will be always of first order
  unless the discontinuity is explicitly treated.
\end{itemize}
Employing the \textit{operator splitting} approach, Equation ~\ref{eq:controlVars}  can be
cast as follows:
\begin{equation}
\label{eq:operatorSplitting}
\left\{\begin{matrix}
\frac{\partial \overline{x} }{\partial t} = \overline{F}\left (  \overline{x},\overline{v}_{t_{i-1}}, t \right )  & \\
\overline{C} =  \overline{G}(\overline{x},t)  & t_{i-1} \leq t \leq  t_{i} =  t_{i-1} + \Delta  t_{i}\\
\frac{\partial \overline{v} }{\partial t} = \overline{V}\left (  \overline{x}, \overline{v}_{t_{i-1}}, t \right ) &
\end{matrix}\right.
\end{equation}
Hence, the system of equations in solved decomposing it into simpler sub-problems that are treated individually
using specialized numerical algorithms.

\subsubsection{Definition of the Monitored Variable Space}
The contraction of the information from the $\overline{x}$ space to the $\overline{C}$ space is a crucial step.
Since $\overline{C}$ represents an arbitrary middle step, it is needed to define a set of rules that make this
choice unique. $\overline{C}$ is chosen such that:
\begin{itemize}
  \item The solution of  $ \left.\begin{matrix} \frac{\partial \overline{v} }{\partial t}
  \end{matrix}\right| =\overline{V}\left (  \overline{x},\overline{v}_{t_{i-1}}, t \right )$
  can be carried along without any knowledge of the solution algorithm of
   $ \left.\begin{matrix}
  \frac{\partial \overline{x} }{\partial t} =  \end{matrix}\right| \overline{F}\left (
  \overline{x},\overline{v}_{t_{i-1}}, t \right )
  $. This requirement determines the minimum information contraction from  $\overline{x}$ to
  $\overline{C}$.
  \item All actions represented by $\overline{C} = \overline{G}(\overline{x},t)$ require knowledge of the
  solution algorithm of
  $ \left.\begin{matrix}
  \frac{\partial \overline{x} }{\partial t} =  \end{matrix}\right| \overline{F}\left (
  \overline{x},\overline{v}_{t_{i-1}}, t \right )  $. This requirement determines  the maximum  information contraction from  $\overline{x}$ to  $\overline{C}$.
\end{itemize}
The intersection of the two sub-spaces defined above create a minimal unique set.
\subsubsection{Definition of the Auxiliary Variable Space}
In the previous sections, it has been determined that the needed information to model the dynamic system
is contained in the solution vectors $\overline{x}$ and $\overline{v}$. Even if $\overline{x}$ and $\overline{v}$
are sufficient to assess the system status at every point in time, it can result in an unpractical way to model
the eventual control system.
Let's suppose to model a component of a particular system that presents different behavior depending on
other systems or operation behaviors. In order to define the status of this component in every point in time, the
whole history of the system needs to be tracked. In order to remove these inefficiency, a set of auxiliary variables
$\overline{a}$ can be introduced. These variables are the ones that in the analysis of stochastic dynamics
are artificially added into the phase space to a non-Markovian system to obtain back a Markovian behavior. In this
way only the previous time-step information is needed to determine the status of the system.
\\ Adding this additional system of variables, Equation ~\ref{eq:operatorSplitting} can be casted as follows:

\begin{equation}
\label{eq:auxiliaryVariables}
\left\{\begin{matrix}
\frac{\partial \overline{x} }{\partial t} = \overline{F}\left (  \overline{x},\overline{v}_{t_{i-1}}, t \right )  & \\
\overline{C} =  \overline{G}(\overline{x},t)  & t_{i-1} \leq t \leq  t_{i} =  t_{i-1} + \Delta  t_{i}\: \\
\frac{\partial \overline{a} }{\partial t} = \overline{A}\left (  \overline{x},\overline{C},\overline{a},\overline{v}_{t_{i-1}}, t \right ) \\
\frac{\partial \overline{v} }{\partial t} = \overline{V}\left (  \overline{C},\overline{a}, \overline{v}_{t_{i-1}}, t \right )  &
\end{matrix}\right.
\end{equation}

\subsection{Dynamic Systems Stochastic Modeling}
%
\subsubsection{General system of equations and variable classification}
\label{subsub:generalSystemOfEqAndVarsClassification}
In Section ~\ref{sub:controlAndSystem}, the derivation of the governing equations for a controllable system
have been reported. In this section, the mathematical framework of the modeling of dynamic stochastic systems,
under uncertainties, is derived.
\\ Dynamic stochastic systems are the ones whose dynamic is characterized by intrinsic randomness. Random
behaviors, although present in nature, are often artificially introduced into physical models to account for the
incapability of fully modeling part of the nature of the system behavior and/or of the phenomena bounding the
physical problem.
\\The distinction between variables that are artificially considered aleatory and the ones intrinsically aleatory
corresponds with the classical definition of epistemic and aleatory uncertainties. From a
system simulation point of view it is more relevant how these variables, the sources of aleatory behavior, change
in time.
Possible examples of random elements are:
\begin{itemize}
 \item random variability of parameters (e.g., uncertainty in physical parameters)
 \item presence of noise (background noise due to intrinsically stochastic behaviors or lack of detail in the
 simulation)
 \item Uncertainty in the initial and boundary conditions
 \item Random failure of components
 \item aging effects.
\end{itemize}
Before introducing the mathematical models for uncertainty,  it can beneficial to recall
Equation ~\ref{eq:dThetaOverDT}, adding the initial conditions:
\begin{equation}
\label{eq:dThetaOverDTWithBoundary}
\left\{\begin{matrix}
\frac{\partial  \overline{\theta}\left ( t \right )}{\partial t}=\overline{H}\left (  \overline{\theta}\left ( t \right ),t \right ) \\
 \overline{\theta}\left ( t_{0} \right ) = \overline{\theta}_{0}
\end{matrix}\right.
\end{equation}
At this point, each source of uncertainty or stochastic behavior is considered and progressively added in
Equation ~\ref{eq:dThetaOverDTWithBoundary}.
For the scope of this derivation, it is convenient to split the phase space into \textit{continuous} (e.g.,temperature,
pressure, hentalpy, etc.) and discrete (e.g.,status of components, such as operational and failure states) variables
as follows:
\begin{itemize}
 \item $ \overline{\theta}^{c} \in \Phi \subseteq \mathbb{R}^{C}$, the set of continuous variables
 \item $ \overline{\theta}^{d} \in \Psi \subseteq \mathbb{N}^{D}$, the set of discrete variables
 \item $\overline{\theta}(t) = \overline{\theta}^{c} \oplus \overline{\theta}^{d}$.
\end{itemize}
Consequentially, Equation ~\ref{eq:dThetaOverDTWithBoundary} assumes the following form:
\begin{equation}
\label{eq:systemThetaContAndDescrete}
\left\{\begin{matrix}
\frac{\partial  \overline{\theta}^{c}\left ( t \right )}{\partial t}=f\left ( \overline{\theta}^{c},\overline{\theta}^{d},t \right ) \\
\frac{\partial  \overline{\theta}^{d}\left ( t \right )}{\partial t}=g\left ( \overline{\theta}^{c},\overline{\theta}^{d},t \right )\\
 \overline{\theta}^{c}\left ( t_{0} \right ) = \overline{\theta}^{c}_{0}\\
 \overline{\theta}^{d}\left ( t_{0} \right ) = \overline{\theta}^{d}_{0}
\end{matrix}\right.
\end{equation}
Note that the time derivative operator has been also used for the time discontinuous variables, even
if this is allowed only introducing complex extension of the time derivative operator. In this context, the $\frac{\partial  }{\partial t}$ on the discontinuous space is employed for simplifying the notation only.

\subsubsection{Probabilistic Nature of the Parameters Characterizing the Equation}
As shown in Equation ~\ref{eq:systemThetaContAndDescreteStaz}, The first stochastic behaviors to be introduced are the
uncertainties associated with the:
\begin{itemize}
  \item initial conditions (i.e. $\overline{\theta}^{c}$ and $\overline{\theta}^{d}$ at time $t_{0}$), and
  \item parameters characteristic of  $f\left ( \overline{\theta}^{c},\overline{\theta}^{d},t \right )$ and $g\left ( \overline{\theta}^{c},\overline{\theta}^{d},t \right )$.
\end{itemize}

\begin{equation}
\label{eq:systemThetaContAndDescreteStaz}
\left\{\begin{matrix}
\frac{\partial  \overline{\theta}^{c}\left ( t \right )}{\partial t}=f\left ( \overline{\theta}^{c},\overline{\theta}^{d}, \overline{\alpha}_{staz} ,      t \right ) \\
\frac{\partial  \overline{\theta}^{d}\left ( t \right )}{\partial t}=g\left ( \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},t \right )\\
\Pi \left ( \overline{\theta}^{c},t_{0} \right ) \sim pdf\left ( \overline{\theta}^{c}_{0}|,\sigma_{c}^{2} \right )\\
\Pi \left ( \overline{\theta}^{d},t_{0} \right ) \sim pdf\left ( \overline{\theta}^{d}_{0}|,\sigma_{d}^{2} \right ) \\
\overline{\alpha}_{staz}\left ( t \right )=\overline{\alpha}_{staz}\left ( t_{0} \right ) \sim pdf\left ( \overline{\alpha}_{staz}^{0}|, \sigma_{staz}^{2} \right )
\end{matrix}\right.
\end{equation}
In Equation ~\ref{eq:systemThetaContAndDescreteStaz}, $\Pi \left ( \overline{\theta}^{c},t_{0} \right )$ indicates the
probability distribution of $\overline{\theta}^{c}$ at the initial time $t=t_{0}$ while
$pdf\left ( \mu|, \sigma^{2} \right )$ represents a generic probability distribution function having mean value
$\mu$ and sigma $\sigma$.The term $\overline{\alpha}_{staz}$ is the vector of parameters affected by
uncertainty but not varying over time.
\\As already mentioned, Equation ~\ref{eq:systemThetaContAndDescreteStaz} considers uncertainties whose values
do not change during the dynamic evolution of the system. This set of uncertainties accounts for most of the
common source of aleatory behaviors. Examples of this kind of uncertainties are:
\begin{itemize}
  \item \textit{Uncertainty associated with the heat conduction coefficient}:  This value is known (but uncertain) and has no physical reason to change during the simulation;
  \item \textit{Uncertainty on failure temperature for a pipe}: This value is usually characterized by a probability distribution function but once the value has been set (like through random sampling) it will not change during the simulation.
\end{itemize}
From a modeling perspective, all the probabilistic behaviors connected to $\Pi \left ( \overline{\theta}^{c},t_{0}
\right ) $, $\Pi \left ( \overline{\theta}^{d},t_{0} \right )$ and $\overline{\alpha}_{staz}(t)$ can be modeled without
changing the dimensionality of the phase space (hence, no alteration of the solution algorithm is required), simply performing sampling of the input space. In addition, the Markovian assumption is still preserved.

\subsubsection{Variables Subject to Random Motion}
The next aleatory component to be accounted for is the set of parameters that continuously change over time (i.e. $\overline{\alpha}_{brow}$).
In other words,  these parameters are referred as if they behave like a \textit{Brownian motion}.
While what commonly is indicated as \textit{Brownian motion} has not impact at the character
the space and time scales (characteristic of a physical system), there are parameters that have (or \textbf{appear}
to have) such behavior. The  \textit{Brownian motion} characteristic of some variables can be completely
synthetic, due to the lack of modeling details in the simulation model.
\\For instance, two examples of these randomly varying variables are:
\begin{itemize}
  \item \textit{Cumulative damage growth in material}. Experimental data and models representing this
  phenomenon show large uncertainties. There is also an intrinsic natural stochasticity driving
  the accumulation of the damage (natural Brownian motion);
  \item \textit{Heat conductivity in the fuel gap during heating of fuel}. During some transients there are
  situations where the fuel is in contact with the clad while in others where there is the presence of a gap. While in
  nature this is a discontinuous transition, it is not usually possible to model in such a way, especially if vibrations
  of the fuel lead to high frequency oscillations. In this case, it would be helpful to introduce directly into the
  simulation a random noise characterizing the thermal conductivity when these transitions occur (synthetic
  Brownian motion).
\end{itemize}
The system of Equations~\ref{eq:systemThetaContAndDescreteStaz} can be rewritten in the following form:

\begin{equation}
\label{eq:systemThetaContAndDescreteStazAndBrow}
\left\{\begin{matrix}
\frac{\partial  \overline{\theta}^{c}\left ( t \right )}{\partial t}=f\left ( \overline{\theta}^{c},\overline{\theta}^{d}, \overline{\alpha}_{staz} ,\overline{\alpha}_{brow},      t \right ) \\
\frac{\partial  \overline{\theta}^{d}\left ( t \right )}{\partial t}=g\left ( \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )\\
\frac{\partial \overline{\alpha}_{brow} }{\partial t}=b\left ( \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )\Gamma \left ( t \right )
\\
\Pi \left ( \overline{\theta}^{c},t_{0} \right ) \sim pdf\left ( \overline{\theta}^{c}_{0}|,\sigma_{c}^{2} \right )\\
\Pi \left ( \overline{\theta}^{d},t_{0} \right ) \sim pdf\left ( \overline{\theta}^{d}_{0}|,\sigma_{d}^{2} \right ) \\
\overline{\alpha}_{staz}\left ( t \right )=\overline{\alpha}_{staz}\left ( t_{0} \right ) \sim pdf\left ( \overline{\alpha}_{staz}^{0}|, \sigma_{staz}^{2} \right ) \\
\overline{\alpha}_{brow}\left ( t_{0} \right ) \sim  \overline{\alpha}_{brow}^{0} \Gamma \left ( t_{0} \right )
\end{matrix}\right.
\end{equation}
where $\Gamma \left ( t \right )$ is 0-mean random noise and $\overline{\alpha}_{brow}$ is the set of parameters subject to \textit{Brownian motion}.
\\Clearly, the equation referring to the time change of the parameters subject to the \textit{Brownian motion} should be interpreted in the \textbf{Ito} sense [C. Gardiner, Stochastic Methods, Springer (2009)].

\subsubsection{Discontinuously and Stochastically varying variables}
The last and probably most difficult step is the introduction of parameters that are neither constant during the simulation nor continuously vary over time. As an example, consider a valve that, provided set of operating conditions, opens or closes. If this set of conditions is reached n times during the simulation, the probability of the valve correctly operating should be sampled n times. It is also foreseeable that the history of failure/success of the valve will impact future probability of failure/success.  In this case the time evolution of such parameters (discontinuously stochastic changing parameters  $\overline{\alpha}_{DS}$) is governed by the following equation:

\begin{equation}
\label{eq:systemDiscAndStochVaryVars}
\frac{\partial  \overline{\alpha }_{DS}\left ( t \right )}{\partial t}=  \overline{\delta}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right ) \times \overline{V}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right ) \times \overline{p}\left ( \int_{t_{0}}^{t}  S\left ( \overline{\theta}\left ( t^{'} \right ),t^{'} \right )dt^{'} \right )
\end{equation}
where:
\begin{itemize}
  \item The function $\overline{\delta}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},
  \overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )$ is the delta of Dirac of the instant on which the
  transition need to be evaluated (control logic signaling to the valve to open/close).
  \item The term $\overline{p}\left ( \int_{t_{0}}^{t}  S\left ( \overline{\theta}\left ( t^{'} \right ),t^{'} \right )\right )
  = \overline{p}\left ( \int_{t_{0}}^{t}  \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},
  \overline{\alpha}_{staz},\overline{\alpha}_{brow},t dt\right )$ represents the transition probability
  between different states (in case of the valve: open/close). Note that the time integral of the
  parameter history accounts for the memory of the component via the kernel $S\left ( \overline{\theta}\left ( t^{'}
  \right ),t^{'} \right )$.
  \item The term $\overline{V}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},
  \overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )$ is the rate of change of $\overline{\alpha }_{DS}$.
  For a discrete parameter, it is defined as the value of the instantaneous $\overline{\alpha }_{DS}$ change.
\end{itemize}
The introduction of the history dependency introduced in the term $\overline{p}$ determines that the system cannot be considered
Markovian if ``countermeasures'' are not taken. In order to make the system return to be Markovian, the phase space needs to be
expanded (i.e., increase its dimensionality): the time at which the
parameters changed status and their corresponding values $\left \{  \left (\overline{\alpha}_{DS}, t \right )_{i} \right \} = \left \{  \overline{\alpha}_{DS}, t_{i} \right \} = \overline{\overline{\alpha}}_{DS}, \overline{t}\, \left ( for\, i=1,...,n \right )$.
\\Equation~\ref{eq:systemDiscAndStochVaryVars} now assumes the form:
\begin{equation}
\label{eq:systemDiscAndStochVaryVarsExpanded}
\begin{matrix}
\frac{\partial  \overline{\alpha }_{DS}\left ( t \right )}{\partial t}=  \overline{\delta}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right ) \times \overline{V}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right ) \times \overline{p}\left ( \overline{\overline{\alpha}}_{DS},\overline{t},\overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t  \right ) \\ \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \! \!
for \, t\geq t_{n}
\end{matrix}
\end{equation}
This formulation introduces a phase space that is continuously growing over time $n \rightarrow \infty$. In this respect, it is useful to introduce and discuss possible assumptions:
\begin{enumerate}
  \item The memory of the past is not affected by the time distance; in this case:
  \begin{equation}
   \overline{p}\left ( \overline{\overline{\alpha}}_{DS},\overline{t},\overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t  \right ) =  \overline{p}\left ( \overline{\overline{\alpha}}_{DS},\overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t  \right )
  \end{equation}
  The dimensionality of the phase space is still growing during the simulation since more and more sampling is
  performed, but the time integral is removed from the transition probability. A simple example of this situation is
  a component activated on demand in which failure is a function of all previous sampling, but not of when the
  component was sampled or in which sequence the outcome occurred.
  \item  The number of samples is determined before the simulation itself takes place (e.g.,$n$ times) In this case
  the different $\overline{\alpha}_{DS_{i}}$ could be treated explicitly as $\overline{\alpha}_{staz}$   while
  $\overline{t}$ would still remain a variable to be added to the phase space (if simplification 1 is not valid) but of
  fixed dimension. In this case $\overline{t}$ still needs to be computed and its expression is:
  \begin{equation}
   \overline{t} \left ( t \right ) = \int_{t_{0}}^{t} \overline{t}  \, \overline{\delta }\left ( \overline{\alpha }_{DS},
   \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )  dt
  \end{equation}
  The transition probability becomes:
  \begin{equation}
     \overline{p}\left ( \int_{t_{0}}^{t} dt\, S\left ( \overline{t} \right ), \overline{\alpha}_{DS}, \overline{\theta}^{c},
     \overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )
  \end{equation}
  For example, this is the case of a component that is sampled a fixed number of times for a given simulation
  while the contribution of the history to the transition probability might decay exponentially over time. This
  approximation might eliminate the memory from the system by adding n variables to the phase space $t_{i} \, \,
  (for \, \, i=1,...,n)$ thus restoring the Markovian characteristic.
  \item Another possible approximation alternative to the previous one is that the memory of the system (here
  explicitly represented by $ \int_{t_{0}}^{t}  \overline{\alpha }_{DS} dt$) is limited
  only to a fixed number of steps back in the past. In this case $n$ is always bounded. Therefore, adding  $\left \{
  \overline{\alpha}_{DS_{i}},t_{i} \right \}, \left ( for\: i=1,...,n \right )$ would possibly preserve the system
  Markovian properties of the system. This approximation allows for eliminating the memory from the system by
  expanding the phase space $2n$ variables. From a software implementation point of view, this is the most
  complex  situation since without any simplification we would have to deal with a system that is never reducible
  to a Markovian one and therefore forced to use the whole history of the system to forecast its evolution at each
  time step.
\end{enumerate}
Assumption 1 limits this cost by restraining it to the set of values assumed by the
variable but would still lead to very difficult to deal with situation. Assumption 2 would
require an expansion of phase space to introduce the time at which the transitions
happens but the value that the parameter will assume at each sampling could be
treated as initial condition. Assumption 3 would instead require the expansion of the
phase space for both the time and the values of the
transitioning variables.
\\Based on the this simplifications, the system of
Equations~\ref{eq:systemThetaContAndDescreteStazAndBrow}, accounting also for $ \overline{\alpha}_{DS}$ can be cast into the form:
\begin{equation}
\label{eq:fullSystem}
\begin{split}
\left\{\begin{matrix}
\frac{\partial  \overline{\theta}^{c}\left ( t \right )}{\partial t}=f\left ( \overline{\theta}^{c},\overline{\theta}^{d}, \overline{\alpha}_{staz} ,\overline{\alpha}_{brow},      t \right ) \\
\frac{\partial  \overline{\theta}^{d}\left ( t \right )}{\partial t}=g\left ( \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )\\
\frac{\partial \overline{\alpha}_{brow} }{\partial t}=b\left ( \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )\Gamma \left ( t \right ) \\
\frac{\partial  \overline{\alpha }_{DS}\left ( t \right )}{\partial t}=  \overline{\delta}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right ) \times \overline{V}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right ) \times
\\ \times  \overline{p}\left ( \int_{t_{0}}^{t}  dt\;   \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},
  \overline{ \alpha}_{staz},\overline{\alpha}_{brow},t \right )
\\
\Pi \left ( \overline{\theta}^{c},t_{0} \right ) \sim pdf\left ( \overline{\theta}^{c}_{0}|,\sigma_{c}^{2} \right )\\
\Pi \left ( \overline{\theta}^{d},t_{0} \right ) \sim pdf\left ( \overline{\theta}^{d}_{0}|,\sigma_{d}^{2} \right ) \\
\overline{\alpha}_{staz}\left ( t \right )=\overline{\alpha}_{staz}\left ( t_{0} \right ) \sim pdf\left ( \overline{\alpha}_{staz}^{0}|, \sigma_{staz}^{2} \right ) \\
\overline{\alpha}_{brow}\left ( t_{0} \right ) \sim  \overline{\alpha}_{brow}^{0} \Gamma \left ( t_{0} \right ) \\
\overline{\alpha}_{DS} \left ( t_{0} \right ) = \overline{\alpha}_{DS} ^{0}
\end{matrix}\right.
\end{split}
\end{equation}
Introducing the Simplifications \textbf{1} and \textbf{3} ( the most
appropriated in this context), Equation ~\ref{eq:fullSystem} becomes:
\begin{equation}
\label{eq:fullSystemApprox1-3}
\begin{split}
\left\{\begin{matrix}
\frac{\partial  \overline{\theta}^{c}\left ( t \right )}{\partial t}=f\left ( \overline{\theta}^{c},\overline{\theta}^{d}, \overline{\alpha}_{staz} ,\overline{\alpha}_{brow},      t \right ) \\
\frac{\partial  \overline{\theta}^{d}\left ( t \right )}{\partial t}=g\left ( \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )\\
\frac{\partial \overline{\alpha}_{brow} }{\partial t}=b\left ( \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )\Gamma \left ( t \right ) \\
\frac{\partial  \overline{\alpha }_{DS}\left ( t \right )}{\partial t}=  \overline{\delta}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right ) \times \overline{V}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right ) \times
\\ \times  \overline{p}\left ( \overline{\alpha }_{DS}, \overline{\theta}^{c},\overline{\theta}^{d},\overline{\alpha}_{staz},\overline{\alpha}_{brow},t \right )
\\
\Pi \left ( \overline{\theta}^{c},t_{0} \right ) \sim pdf\left ( \overline{\theta}^{c}_{0}|,\sigma_{c}^{2} \right )\\
\Pi \left ( \overline{\theta}^{d},t_{0} \right ) \sim pdf\left ( \overline{\theta}^{d}_{0}|,\sigma_{d}^{2} \right ) \\
\overline{\alpha}_{staz}\left ( t \right )=\overline{\alpha}_{staz}\left ( t_{0} \right ) \sim pdf\left ( \overline{\alpha}_{staz}^{0}|, \sigma_{staz}^{2} \right ) \\
\overline{\alpha}_{brow}\left ( t_{0} \right ) \sim  \overline{\alpha}_{brow}^{0} \Gamma \left ( t_{0} \right ) \\
\overline{\alpha}_{DS} \left ( t_{0} \right ) = \overline{\alpha}_{DS} ^{0}
\end{matrix}\right.
\end{split}
\end{equation}
This dissertation does not cover all the possible phenomena, but it
provides a sufficient mathematical framework for extrapolating toward cases that are not explicitly treated.
\\ Given the presence of all these sources of stochastic behaviors, every
exploration of the uncertainties (through sampling strategies) only
represents a possible trajectory of the system in the phase space. Hence,
it is much more informative the assessment of the probability of a
particular response, rather than the response itself.
\\The explanation of these concepts is demanded to next section.
%
%
% Formulation of the equation set in a statistical framework
%
%
\subsection{Formulation of the equation set in a statistical framework}
Based on the premises reported in the previous sections and assuming
that at least one of the simplifications mentioned in
Section~\ref{subsub:generalSystemOfEqAndVarsClassification} is applicable (i.e. the system can be
casted as Markovian), it is needed to investigate the system evolution
in terms of its probability density function in the global phase space
$\overline{\theta}$ via the Chapman-Kolmogorov
equation~\cite{ProbReactoDynamicsDevooght}.
\\The integral form of the Chapman-Kolmogorov is the following:
\begin{equation}
\label{eq:chapKolmogIntegralForm}
\begin{matrix}
\Pi \left (\overline{\theta}_{3},t_{3}|\overline{\theta}_{1},t_{1}  \right ) = \int
d\overline{\theta}_{2} \Pi\left (\overline{\theta}_{2},t_{2}|
\overline{\theta}_{1},t_{1}  \right )   \Pi\left (\overline{\theta}_{3},t_{3}|
\overline{\theta}_{2},t_{2}  \right )   &
where \: \:   t_{1} < t_{2} < t_{3}
\end{matrix}
\end{equation}
while its differential form is:
\begin{equation}
\label{eq:chapKolmogDiffForm}
\frac{\partial \Pi \left (\overline{\theta},t|\overline{\theta}_{0},t_{0}  \right )  }{\partial t} =
\mathcal{L}_{CK}\left (   \Pi \left (\overline{\theta},t|\overline{\theta}_{0},t_{0}  \right ) \right )
\end{equation}
The transition from the integral to the differential form is possible under the following assumptions:
\begin{equation}
\label{eq:chapKolmogAssump1}
\lim_{\Delta t \to 0} \frac{1}{\Delta t}  \int_{|
\overline{\theta}_{2}-\overline{\theta}_{1}|<\varepsilon }   \Pi \left
(\overline{\theta}_{2},t+\Delta t|\overline{\theta}_{1},t  \right )
d\overline{\theta}_{2} = 0
\end{equation}

\begin{equation}
\label{eq:chapKolmogAssump2}
\lim_{\Delta t \to 0} \frac{1}{\Delta t} \Pi \left (\overline{\theta}_{2},t+\Delta t|
\overline{\theta}_{1},t  \right ) = W\left ( \overline{\theta}_{2}|
\overline{\theta}_{1},t \right )
\end{equation}

\begin{equation}
\label{eq:chapKolmogAssump3}
\lim_{\Delta t \to 0} \frac{1}{\Delta t}  \int_{|
\overline{\theta}_{2}-\overline{\theta}_{1}|<\varepsilon }
\left ( \overline{\theta}_{2,i} - \overline{\theta}_{1,i} \right )
\Pi \left (\overline{\theta}_{2},t+\Delta t|\overline{\theta}_{1},t  \right )
d\overline{\theta}_{2} = A_{i}\left ( \overline{\theta}_{1},t \right ) +
\mathcal{O}\left ( \varepsilon \right )
\end{equation}

\begin{equation}
\label{eq:chapKolmogAssump4}
\lim_{\Delta t \to 0} \frac{1}{\Delta t}  \int_{|
\overline{\theta}_{2}-\overline{\theta}_{1}|<\varepsilon }
\left ( \overline{\theta}_{2,i} - \overline{\theta}_{1,i} \right ) \left (
\overline{\theta}_{2,j} - \overline{\theta}_{1,j} \right )
\Pi \left (\overline{\theta}_{2},t+\Delta t|\overline{\theta}_{1},t  \right )
d\overline{\theta}_{2} = B_{i,j}\left ( \overline{\theta}_{1},t \right ) +
\mathcal{O}\left ( \varepsilon \right )
\end{equation}

The first condition guarantees the continuity of $\Pi \left (\overline{\theta},t|\overline{\theta}_{0},t_{0}  \right )$, while the other three force the finite existence of three parameters.
Equation 25 can be furthermore decomposed into the continuous and discrete components:

\begin{equation}
\label{eq:chapKolmogIntegralFormContDisct}
\left\{\begin{matrix}
\Pi \left (\overline{\theta}_{3}^{c},t_{3}|\overline{\theta}_{1}^{c},t_{1}  \right )
= \int \Pi \left (\overline{\theta}_{2}^{c},t_{2}|\overline{\theta}_{1}^{c},t_{1}
\right ) \Pi \left (\overline{\theta}_{3}^{c},t_{3}|\overline{\theta}_{2}^{c},t_{2}
\right ) d\overline{\theta}_{2}^{c}
\\
\Pi \left (\overline{\theta}_{3}^{d},t_{3}|\overline{\theta}_{1}^{d},t_{1}  \right )
= \int \Pi \left (\overline{\theta}_{2}^{d},t_{2}|\overline{\theta}_{1}^{d},t_{1}
\right ) \Pi \left (\overline{\theta}_{3}^{d},t_{3}|\overline{\theta}_{2}^{d},t_{2}
\right ) d\overline{\theta}_{2}^{d}
\end{matrix}\right.
\: \: \: where \:\:   t_{1}<t_{2}<t_{3}
\end{equation}

and its differential form is as follows:
\begin{equation}
\label{eq:chapKolmogDiffFormContDisct}
\left\{\begin{matrix}
\frac{\partial \Pi \left (\overline{\theta}^{c},t|\overline{\theta}_{0}^{c},t_{0}
\right ) }{\partial t} = \mathcal{L}_{CK}^{c}  \left (     \Pi \left
(\overline{\theta}^{c},t|\overline{\theta}_{0}^{c},t_{0} \right ),
\overline{\theta}^{d},\overline{\alpha}_{brow},\overline{\alpha}_{staz},
\overline{\alpha}_{DS},t  \right )
\\
\frac{\partial \Pi \left (\overline{\theta}^{d},t|\overline{\theta}_{0}^{d},t_{0}
\right ) }{\partial t} = \mathcal{L}_{CK}^{d}  \left (     \Pi \left
(\overline{\theta}^{d},t|\overline{\theta}_{0}^{d},t_{0} \right ),
\overline{\theta}^{c},t  \right )
\end{matrix}\right.
\end{equation}
where:
\begin{itemize}
 \item  $\Pi \left (\overline{\theta}^{c},t|\overline{\theta}_{0}^{c},t_{0} \right
 )$ of the system to be in state $\overline{\theta}^{c}$ at time $t$ given that
 the system was in $\overline{\theta}^{c}_{0}$ at time $t_{0}$;
 \item $\Pi \left (\overline{\theta}^{d},t|\overline{\theta}_{0}^{d},t_{0} \right
 )$ of the system to be in state $\overline{\theta}^{d}$ at time $t$ given
 that the system was in $\overline{\theta}^{d}_{0}$ at time $t_{0}$;
 \item $\mathcal{L}_{CK}^{c} \left ( \cdot  \right )$ and
 $\mathcal{L}_{CK}^{d} \left ( \cdot  \right )$  are specific Chapman-
 Kolmogorov operators that will be described in the following section.
\end{itemize}
%
%
% The Chapman-Kolmogorov Equation
%
%
% COPY FROM HERE
%
\subsection{The Chapman-Kolmogorov Equation}
\label{sec:ChapmanKolmogorov }
The system of equations~\ref{eq:thetaDecomposition}, written in integral
form, can be solved in a differential form through the Chapman-Kolmogorov (C-K)
operator~\cite{ProbReactoDynamicsDevooght}:

\begin{equation}
\label{eq:CK}
\begin{matrix}
\frac{\partial \Pi \left (\overline{\theta}^{c},t|\overline{\theta}_{0}^{c},t_{0}
\right ) }{\partial t} = - \sum_i \frac{\partial }{\partial \overline{\theta}_{i}^{c}} \left ( A_{i}\left (  \overline{\theta}^{c}, \overline{\theta}^{d}, t\right ) \Pi \left (\overline{\theta}^{c},t|\overline{\theta}_{0}^{c},t_{0}
\right )  \right ) +
\\
+ \frac{1}{2}\sum_{i,j} \frac{\partial^2 }{\partial \overline{\theta}^{c}_{i} \partial \overline{\theta}^{c}_{j}}\left ( B_{i,j}\left (  \overline{\theta}^{c}, \overline{\theta}^{d}, t\right ) \Pi \left (\overline{\theta}^{c},t|\overline{\theta}_{0}^{c},t_{0}
\right )  \right ) +
\\
+ \int \left (  W\left ( \overline{\theta}^{c}|
\overline{\theta}^{'c},\overline{\theta}^{d},t \right )\Pi \left (\overline{\theta}^{'c},t|\overline{\theta}_{0}^{c},t_{0}
\right ) - W\left ( \overline{\theta}^{'c}|
\overline{\theta}^{c},\overline{\theta}^{d},t \right )\Pi \left (\overline{\theta}^{c},t|\overline{\theta}_{0}^{c},t_{0}
\right )  \right )d\overline{\theta}^{'c}
\end{matrix}
\end{equation}

\begin{equation}
\frac{\partial \Pi \left (\overline{\theta}^{d},t|\overline{\theta}_{0}^{d},t_{0}
\right ) }{\partial t} =
\sum_{i} W\left ( \overline{\theta}^{d}|
\overline{\theta}^{d}_{i},\overline{\theta}^{c},t \right ) \Pi \left (\overline{\theta}^{d}_{i},t|\overline{\theta}^{d},t_{0}
\right ) - W\left ( \overline{\theta}^{d}_{i}|
\overline{\theta}^{d},\overline{\theta}^{c},t \right ) \Pi \left (\overline{\theta}^{d},t|\overline{\theta}^{d}_{0},t_{0}
\right )
\end{equation}
where:
\begin{equation}
\begin{matrix}
A_{i}\left ( \overline{\theta}, t \right ) = \left\{\begin{matrix}
0 & \: \: if  \: \: \overline{\theta}_{i} \in \overline{\theta}^{d}
\\
f\left ( \overline{\theta}^{c},\overline{\theta}^{d},\alpha_{staz},\alpha_{brow},t \right ) +\frac{1}{2}\frac{\partial b\left ( \overline{\theta}^{c},t \right )}{\partial \overline{\theta}^{c}}Qb\left ( \overline{\theta}^{c},t \right ) \: \: & if  \: \: \overline{\theta}_{i} \notin \overline{\theta}^{d}
\end{matrix}\right.
\\
B_{i,j}\left ( \overline{\theta}, t \right ) = \left\{\begin{matrix}
0 & \: \: if  \: \: \overline{\theta}_{i} \: \: or \: \: \overline{\theta}_{j}  \in \overline{\theta}^{d}
\\
b\left ( \overline{\theta}^{c},t \right )Qb^{T}\left (  \overline{\theta}^{c},t \right ) \: \: & \: \: if  \: \: \overline{\theta}_{i} \: \: or \: \: \overline{\theta}_{j}  \notin \overline{\theta}^{d}
\end{matrix}\right.
\end{matrix}
\end{equation}
This system of equations is composed of four main terms that identify four different types of processes:
\begin{itemize}
  \item Drift process
  \item Diffusion process
  \item Jumps in continuous space
  \item Jumps in discrete space (component state transitions).
\end{itemize}
 These four processes are described in the following sub-sections.
%
%
% Drift process
%
%
\subsubsection{Drift Process}
\label{sec:CKDrift}
The drift process is defined by the Lioville’s equation:
\begin{equation}
\label{eq:lioville}
  \frac{\partial \, \Pi \left (\overline{\theta}^{c},t|\overline{\theta}^{c}_{0},t_{0}  \right ) }{\partial t} = \sum_{i}\frac{\partial }{\partial \overline{\theta}^{c}_{i}}\left ( A_{i}\left ( \overline{\theta}^{c},\overline{\theta}^{d},t \right ) \Pi \left (\overline{\theta}^{c},t|\overline{\theta}^{c}_{0},t_{0}  \right ) \right )
\end{equation}
It is important to note that this equation describes a completely deterministic motion, indicated by the equation:
\begin{equation}
\label{eq:determLioville}
   \frac{\partial \, \overline{\theta}^{c}\left ( t \right ) }{\partial t} = A_{i}\left ( \overline{\theta}^{c},\overline{\theta}^{d},t \right )
\end{equation}
If $\overline{\theta}^{c} \left (\overline{\theta}^{c}_{0},\overline{\theta}^{d},t  \right )$ is the solution of Equation ~\ref{eq:determLioville}, then then the solution of the Lioville's equation is:
\begin{equation}
\label{eq:solLioville}
\Pi \left (\overline{\theta}^{c},t|\overline{\theta}^{c}_{0},t_{0}  \right ) = \delta\left ( \overline{\theta}^{c} - \overline{\theta}^{c}\left ( \overline{\theta}^{c}_{0},\overline{\theta}^{d},t \right ) \right )
\end{equation}
provided the initial condition:
\begin{equation}
\label{eq:solLiovilleInitCond}
\Pi \left (\overline{\theta}^{c},t|\overline{\theta}^{c}_{0},t_{0}  \right ) = \delta\left ( \overline{\theta}^{c} - \overline{\theta}^{c}_{0} \right )
\end{equation}
%
%
% Diffusion process
%
%
\subsubsection{Diffusion Process}
\label{subsec:CKDiffusion}
This process is described by the Fokker-Plank equation:
\begin{equation}
\begin{matrix}
\frac{\partial \, \Pi \left (\overline{\theta}^{c},t|\overline{\theta}^{c}_{0},t_{0}  \right ) }{\partial t} =
\sum_{i}\frac{\partial }{\partial \overline{\theta}^{c}_{i}}\left ( A_{i}\left ( \overline{\theta}^{c},\overline{\theta}^{d},t \right ) \Pi \left (\overline{\theta}^{c},t|\overline{\theta}^{c}_{0},t_{0}  \right ) \right ) +
\\
+ \frac{1}{2}\sum_{i,j} \frac{\partial^2 }{\partial \overline{\theta}^{c}_{i} \partial \overline{\theta}^{c}_{j}}\left ( B_{i,j}\left (  \overline{\theta}^{c}, \overline{\theta}^{d}, t\right ) \Pi \left (\overline{\theta}^{c},t|\overline{\theta}_{0}^{c},t_{0}
\right )  \right )
\end{matrix}
\end{equation}
where $A_{i}\left ( \overline{\theta}^{c},\overline{\theta}^{d},t \right )$ is the drift vector and $B_{i,j}\left (  \overline{\theta}^{c}, \overline{\theta}^{d}, t\right ) $  is the diffusion matrix.
\\Provided the initial condition in Equation ~\ref{eq:solLiovilleInitCond}, the Fokker-Plank equation describes a system moving with drift whose velocity is
 $A\left ( \overline{\theta}^{c},\overline{\theta}^{d},t \right )$ on which is imposed a Gaussian fluctuation with covariance matrix $B\left (  \overline{\theta}^{c}, \overline{\theta}^{d}, t\right ) $.
%
%
% Jumps in continuous space
%
%
\subsubsection{Jumps in Continuous Space }
\label{subsec:CKJumpsCont}
This process is described by the Master equation:
\begin{equation}
\frac{\partial \, \Pi \left (\overline{\theta}^{c},t|\overline{\theta}^{c}_{0},t_{0}  \right ) }{\partial t} =  \int \left (  W\left ( \overline{\theta}^{c}|
\overline{\theta}^{'c},\overline{\theta}^{d},t \right )\Pi \left (\overline{\theta}^{'c},t|\overline{\theta}_{0}^{c},t_{0}
\right ) - W\left ( \overline{\theta}^{'c}|
\overline{\theta}^{c},\overline{\theta}^{d},t \right )\Pi \left (\overline{\theta}^{c},t|\overline{\theta}_{0}^{c},t_{0}
\right )  \right )d\overline{\theta}^{'c}
\end{equation}
Provided the initial condition  in Equation ~\ref{eq:solLiovilleInitCond}, it describes a process characterized by
straight lines interspersed with discontinuous jumps whose distribution is given by $W\left ( \overline{\theta}^{c}|
\overline{\theta}^{'c},\overline{\theta}^{d},t \right )$

%
%
% Jumps in discrete space
%
%
\subsubsection{Jumps in Discrete Space}
\label{subsec:CKJumpsDiscrete}
Transitions in the discrete space can occur in terms of jumps, then the formulation of
\begin{equation}
\frac{\partial \, \Pi \left (\overline{\theta}^{d},t|\overline{\theta}^{d}_{0},t_{0}  \right ) }{\partial t} =
\mathcal{L}_{CK}^{d}\left ( \Pi \left (\overline{\theta}^{d},t|\overline{\theta}_{0}^{d},t_{0}
\right )  \right )
\end{equation}
is similar to the Master equation, recasted for a discrete phase space:
\begin{equation}
\frac{\partial \, \Pi \left (\overline{\theta}^{d},t|\overline{\theta}^{d}_{0},t_{0}  \right ) }{\partial t} =  \sum_{i} \left (  W\left ( \overline{\theta}^{d}|
\overline{\theta}^{d}_{i},\overline{\theta}^{c},t \right )\Pi \left (\overline{\theta}^{d}_{i},t|\overline{\theta}^{d}_{0},t_{0}
\right ) - W\left ( \overline{\theta}^{d}_{i}|
\overline{\theta}^{d},\overline{\theta}^{c},t \right )\Pi \left (\overline{\theta}^{d},t|\overline{\theta}_{0}^{d},t_{0}
\right )  \right )
\end{equation}


%---------------------------Shape and Size---------------------------
\section{Shape and Size\label{s:hex-shape-and-size}}

Let $R$ be the relative size squared as defined in \S\ref{s:hex-relative-size-squared}
and $S$ be the shape as defined in \S\ref{s:hex-shape}.
The ``shape and size'' metric is the the product of these two numbers:
\[
  q = RS
\]

\hexmetrictable{shape and size}%
{$1$}%                                        Dimension
{$[0.2,1]$}%                                  Acceptable range
{$[0,1]$}%                                    Normal range
{$[0,1]$}%                                    Full range
{Dependent on $\overline{V}$}%                Cube
{\cite{knu:03}}%                              Citation
{v\_hex\_shape\_and\_size}%                   Verdict function name


\documentclass{article}
%include polycode.fmt
%
\begin{document}

Semigroups, semigroupoids... are there more semithings?

\subsection{Group, Semigroup, Monoid}

Let's start "from the beginning". Groups is 19th century thing.  A \emph{group}
is a set $G$ with a binary operation $\bullet$, identity element $e$ and
inverse element $a^{-1}$ for each $a \in G$.
With an obvious laws you can imagine relating these.

If we remove \emph{identity} element from a group, "obviously" we get a \emph{semigroup}.
Because if there's \emph{any} element $x \in G$, we can recover the identity
element by $e = x \bullet x^{-1}$.

So what's a semigroup with identity element? For sometimes it were just that,
until we started call it \emph{monoid}. Go figure, naming is hard, not only in
programming, but also in mathematics.\foonote{\url{https://math.stackexchange.com/questions/156952/why-the-terminology-monoid}}

\subsection{Category, Groupoid, Semigroupoid}

You are hopefully familiar with a concept of a category.
I repeat a definition here:

\textbf{Definition} (Awodey 1.1)
A \emph{category} consist of the following data
\begin{itemize}
\item Objects: $A, B, C, \ldots$
\item Arrows: $f, g, h, \ldots$

\item For each arrow $f$, there are given objects

\begin{equation*}
\mathrm{dom}(f), \qquad \mathrm{cod}(f)
\end{equation*}

called the \emph{domain} and \emph{codomain} of $f$. We write

\begin{equation*}
f : A \to B
\end{equation*}

to indicate that $A = \mathrm{dom}(f)$ and $B = \mathrm{cod}(f)$.

\item Given arrows $f : A \to B$ and $g : B \to C$, that is, with

\begin{equation*}
\mathrm{cod}(f) = \mathrm{dom}(g)
\end{equation*}

there is given an arrow

\begin{equation*}
g \circ f : A \to C
\end{equation*}

called the \emph{composite} of $f$ and $g$.

\item For each object $A$, there is given an arrow

\begin{equation*}
1_A : A \to A
\end{equation*}

called the \emph{identity arrow} of $A$.

\item Associativity:

\begin{equation*}
h \circ (g \circ f) = (h \circ g) \circ f
\end{equation*}

for all $f : A \to B$, $g : B \to C$, $h : C \to D$.

\item Unit:

\begin{equation*}
f \circ 1_A = f = 1_B \circ f
\end{equation*}

for all $f : A \to B$.
\end{itemize}

If you think hard (or read a book), you'll learn that a single object
category is a monoid: category arrows are monoid elements, and the
laws work out.

The group analogue is called \emph{groupoid}. In addition to
category data, we require that for each arrow $f : A \to B$ there is an inverse arrow $f^{-1} : B \to A$,
such that $f \circ f^{-1} = 1_B$ and $f^{-1} \circ f = 1_A$.
Or more succinctly: that each arrow is an isomorphism.

But we can also remove stuff: if we remove identity arrows,
and unit law we get \emph{semigroupoid}.

\textbf{Definition}
A \emph{semigroupoid} consist of the following data
\begin{itemize}
\item Objects: $A, B, C, \ldots$
\item Arrows: $f, g, h, \ldots$

\item For each arrow $f$, there are given objects

\begin{equation*}
\mathrm{dom}(f), \qquad \mathrm{cod}(f)
\end{equation*}

called the \emph{domain} and \emph{codomain} of $f$. We write

\begin{equation*}
f : A \to B
\end{equation*}

to indicate that $A = \mathrm{dom}(f)$ and $B = \mathrm{cod}(f)$.

\item Given arrows $f : A \to B$ and $g : B \to C$, that is, with

\begin{equation*}
\mathrm{cod}(f) = \mathrm{dom}(g)
\end{equation*}

there is given an arrow

\begin{equation*}
g \circ f : A \to C
\end{equation*}

called the \emph{composite} of $f$ and $g$.

\item Associativity:

\begin{equation*}
h \circ (g \circ f) = (h \circ g) \circ f
\end{equation*}

for all $f : A \to B$, $g : B \to C$, $h : C \to D$.

\end{itemize}

A reader probably ask themselves: are there interesting, not-contrived
examples of semigroupoids, which aren't also categories?
There are. If poset (set with partial order) is
an example of category, then a set with strict order\footnote{\url{http://mathworld.wolfram.com/StrictOrder.html}, I not dare to call the set with strict order a soset},
is an example of semigroupoid.

As a concrete example, natural numbers with an unique arrow between $n$ and $m$ when $n < m$ is a semigroupoid.

\begin{equation}
0 < 1 < 2 < 3 < 4 < \cdots
\end{equation}

There are no identity arrow, as $n \not< n$, but associativity works out:
if $n < m$ and $m < p$ then $n < p$. Let's call this semigroupoid $\mathbf{LT}$.

Finally, a plot twist. \href{https://ncatlab.org/nlab/show/semicategory}{nLab} calls semigroupoids semicategories,
and don't even mention a semigroupoid as an alternative name!

\subsection{Functors, Semifunctors...}

Recall a definition of functor.

\textbf{Definition} (Awodey 1.2)
A \emph{functor}

\begin{equation*}
F : \mathbf{C} \to \mathbf{D}
\end{equation*}

between categories $\mathbf{C}$ and $\mathbf{D}$ is a mapping of objects
to objects and arrows to arrows, in such a way that
\begin{itemize}
\item $F (f : A \to B) = F(f) : F(A) \to F(B)$,
\item $F(1_A) = 1_{F(A)}$,
\item $F(g \circ f) = F(g) \circ F(f)$.
\end{itemize}
That is, $F$ preserves domains and codomains, identity arrows,
and composition. A functor $F : \mathbf{C} \to \mathbf{D}$ thus gives
a sort of "picture" -- perhaps distorted -- of $\mathbf{C}$ in $\mathbf{D}$.

Functors preserve identities, but semigroupoids don't have identities to be preserved.
We need a weaker concept:

\textbf{Definition}
A \emph{semifunctor}

\begin{equation*}
F : \mathbf{C} \to \mathbf{D}
\end{equation*}

between semigroupoids $\mathbf{C}$ and $\mathbf{D}$ is a mapping of objects
to objects and arrows to arrows, in such a way that
\begin{itemize}
\item $F (f : A \to B) = F(f) : F(A) \to F(B)$,
\item $F(g \circ f) = F(g) \circ F(f)$.
\end{itemize}
That is, $F$ preserves domains and codomains,
and composition. A functor $F : \mathbf{C} \to \mathbf{D}$ thus gives
a sort of "picture" -- perhaps distorted -- of $\mathbf{C}$ in $\mathbf{D}$.

An identity functor is obviously a semifunctor, also a successor functor $S : \mathbf{N} \to \mathbf{N}$
is a semifunctor $\mathbf{LT} \to \mathbf{LT}$.

In Haskell, that would be silly to define a class for (endo)semifunctors:

\begin{code}
-- semimap f . semimap g = semimap (f . g)
class Semifunctor f where
    semimap :: (a -> b) -> f a -> f b
\end{code}

It's the |Functor| type-class without an identity law.
On the other hand, something like

\begin{code}
data Mag a b t where
    Map   :: (x -> t) -> Mag a b x -> Mag a b t
    One   :: a -> Mag a b b

instance Semifunctor (Mag a b) where
    fmap f (Map g x) = Map (f . g) x
    fmap f x         = Map f x
\end{code}

would be valid.

\subsection{Semimonad?}

Now as we have semifunctors, would it make sense to ask whether
endosemifunctors can form a monad

\textbf{Semimonad}
A \emph{semimonad} on semigroupoid $C$ consists of
\begin{itemize}
\item an endosemifunctor $T : C \to C$
\item semi natural transformation $\eta : 1_C \to T$ (|return|)
\item semi natural transformation $\mu : T^2 \to T$  (|join|)
\item Associativity (as semi natural transformations $T^3 \to T$)

\begin{equation}
\mu \circ T \mu = \mu \circ \mu T
\end{equation}

\item Identity (as semi natural transformations  $T \to T$)

\begin{equation}
\mu \circ T\eta = \mu \circ \eta T = 1_T
\end{equation}
\end{itemize}

Looks a lot like monad, but for semifunctors. I have an example: the $S$ semifunctor
is a semimonad. Feels like (I didn't check) that all strictly monotonic functions would fit.
We need to find some more structured semigroupoid than $\mathbf{LT}$ to find more interesting semimonads, but I haven't yet.

I end with a catchy phrase:

\emph{A semimonad is a monoid (!) in the category of endosemifunctors.}

What would be a semigroup in the category of endofunctors\footnote{in Haskell we call it |Bind|, at least now (or |Apply| for different semigroup)}, or
a semigroup in the category of endosemifunctors?

Naming is hard.

\subsection{References: More on the theory of semi-functors}

There's a paper \emph{The theory of semi-functors} by
Raymond Hoofman \url{https://doi.org/10.1017/S096012950000013X}.

\end{document}


\section{Conclusions and Discussion}

In the experiment, the moment of inertia is found by measuring the angular acceleration of the turntable in different cases.

By plotting and fitting the relation between $k\pi$ and $ t $, we found the $\beta$ for each situation of the instrument.
For we used MATLAB to do the fitting work, the uncertainty of the fitting curve can be easily seen as $\pm 5\%$.

By comparing the calculated value of the difference of $I_A$ and $I_B$, we can use the experiment to judge whether the parallel axis theorem holds.

The calculated value of $I$ is $md^2 =  165.8 g \times  (4.7560 cm - 6.0120cm )^2 + 165.8 g \times  (4.7610 cm - 6.0200cm )^2  = 0.0052436 kg\times m^2 $ and the value derived from the experiment is $ I_{A3B4} -I_{A1B2} =0.0055  kg\times m^2 -   0.0044  kg\times m^2 = 0.0011 kg\times m^2 $.
The relative uncertainty is $$ \frac{ 0.0055  kg\times m^2 - 0.0052436 kg \times m^2}{0.0055  kg\times m^2} = 4.66 \% $$

Thus, the parallel axis theorem holds very well.

The g


\subsection{Bootstrapping}

If we have a sample of \(n\), we can create bootstrap samples by drawing with replacement for other sets with \(n\) members.


\documentclass[11pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{bm}

\newcommand{\e}{\epsilon}
\newcommand{\dl}{\delta}
\newcommand{\dij}{\delta_{ij}}
\newcommand{\1}{\bm{1}}
\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\uu}[1]{\underline{\underline{#1}}}
\newcommand{\un}[1]{\underline{#1}}

\title{Lecture 5: Isotropic tensors and related integrals}
\begin{document}
\maketitle

Our objective here is to exploit the index notation and symmetry of the problem to solve certain integrals that would have been cumbersome otherwise. These include

\begin{itemize}
  \item Integrals involving normal vectors over a sphere
  \item Integrals in $D$ dimensions
  \item Attraction between induced dipoles - linear approximation
  \item Attraction between induced dipoles - general case
  \item Moment of inertia
\end{itemize}

To begin with, we note the isotropic tensors of various orders
\begin{itemize}
  \item Zeroth order - any scalar
  \item First order - Null vector
  \item Second order - $\dl_{ij}$
  \item Third order - $\e_{ijk}$ (pseudo tensor)
  \item Fourth order - constructed using $\dl_{ij}$
\end{itemize}

It is also possible to construct a fourth order tensor using $\e_{ijk}\e_{klm}$ where two indices have been contracted. However, it is easily shown that this can be written as a combination of $\dl$'s. Let

$$\e_{ijm}\e_{mkl} = c_1\dl_{ij}\dl_{kl} + c_2\dl_{ik}\dl_{jl} + c_3\dl_{il}\dl_{jk}$$

Using the fact that interchanging $i$ and $j$ changes the sign of the LHS, we get $c_1=0$. Exploiting the properties of cyclic permutations being equal gives us $c_2=-c_3$. Setting $i=j$, we can obtain $c_2=1, c_3=-1$ which finally gives us the important identity

$$\e_{ijk}\e_{mkl} = \dl_{ik}\dl_{jl} - \dl_{il}\dl_{jk}$$

In fact, any isotropic tensor of order $2n$ can be expressed as an \textit{n-tuple} of $\dl$'s. Such a combination will have a total of $\frac{2n!}{2^n n!}$ number of terms. All such even order tensors are true tensors while all odd order tensors are pseudo tensors because they will contain a $\e_{ijk}$.

\section{Some integrals for the normal over a unit sphere}

Let $\un{n}$ be a unit normal and $d\Omega$ be the solid angle given by $d\Omega = \sin\theta d\theta d\phi$ (it is a small area element of a unit sphere). Now let's evaluate the integral

$$\int \un{n}\un{n}d\Omega$$

We might represent the normal vector in spherical polar coordinates but that will lead to a long-winded integral. Instead, we note that the integral is a second order tensor with no special preference for any direction. Hence it must be proportional to $\dl_{ij}$

$$\int n_i n_j d\Omega = c \dl_{ij}$$

Contract both sides with $\dl_{ij}$. We get

$$\int n_i n_i d\Omega = \int d\Omega = 3c$$

Since $\int d\Omega$ is just the surface area of a unit sphere, we get $c = 4\pi / 3$. Hence,

$$\int \un{n}\un{n}d\Omega = \frac{4\pi}{3} \dl_{ij}$$

What about $\int n_i d\Omega$ ? Since it also doesn't't have a preferred direction, it must be isotropic. However, its a vector and we know that the only isotropic vector is the Null vector. Hence $c=0$ for this case. What about $\int n_i n_j n_k d\Omega$ ? This is a true third order tensor, but there is no true third order isotropic tensor and hence $c=0$ for this case as well. Let's evaluate

$$\int n_in_jn_kn_l d\Omega$$

Since, its a fourth order isotropic tensor, we must have
$$
\int n_in_jn_kn_l d\Omega = c_1\dl_{ij}\dl_{kl} + c_2\dl_{ik}\dl_{jl} + c_3\dl_{il}\dl_{jk}
$$

Isotropy of the left hand side dictates that $c_1=c_2=c_3=c$ and the value of $c$ can be determined by contracting both sides with $\dl_{ij}\dl_{kl}$. This gives us $c=4\pi/15$ and hence
$$
\int n_in_jn_kn_l d\Omega = \frac{4\pi}{15}(\dl_{ij}\dl_{kl} + \dl_{ik}\dl_{jl} + \dl_{il}\dl_{jk})
$$

\subsection{Integrals in D dimensions}
What if we want to calculate $\int n_in_j d\Omega$ in $D$ dimensions? As before, we contract both sides with $\dl_{ij}$ and obtain
$$
\int d\Omega = C\cdot D
$$
where the LHS is the surface area of a D-dimensional hypersphere. Let's denote it as $\Omega(D)$, then $C=\Omega(D)/D$

\section{Applications}

\subsection{Dipole interaction in a weak field}
We know that the induced dipole moment is $D(DE/kT)$ where D is the intrinsic dipole moment and $(DE/kT)$ is a biasing factor that accounts for the thermal fluctuations in the orientation of the dipole. Let $\un{p}$ be the direction of the dipole vector and $D$ be its magnitude. Let $\un{1}_E$ be the direction of the electric field of the other dipole and $E$ be its magnitude. Then the probability density of the orientation of the second molecule as a function of $(\theta, \phi)$ will be
$$
P(\theta, \phi) \propto e^{DE(\un{p}\cdot \un{1}_E)/kT}
$$

Let the proportionality constant be $N$. Then,
$$
P(\theta, \phi) = N e^{DE(\un{p}\cdot \un{1}_E)/kT}
$$

Using the fact that the integral of probability density over all possible orientations must be 1, we can obtain the value of $N$. All possible orientations in this case sample all points on a unit sphere. Therefore,
$$
\int N e^{DE(\un{p}\cdot \un{1}_E)/kT} d\Omega = 1
$$
which gives
$$
N=\frac{1}{\int e^{DE(\un{p}\cdot \un{1}_E)/kT} d\Omega}
$$

Using this in the expression for the probability, we get
$$
P(\theta, \phi) = \frac{e^{DE(\un{p}\cdot \un{1}_E)/kT}}{\int e^{DE(\un{p}\cdot \un{1}_E)/kT} d\Omega}
$$

If $E=0$, we obtain $P=1/4\pi$ which is a constant. Hence the dipole has equal probability of being in any possible orientation. Now, the induced dipole moment will be the integral of intrinsic dipole moment times the probability density over all orientations - the unit sphere
$$
\text{\footnotesize{Induced dipole moment}} = \int \text{\footnotesize{Intrinsic dipole moment $\cdot$ probability density}}
$$
Therefore, induced dipole moment $\un{P_{ind}}$
$$
\un{P}_{ind} = \frac{\int D \un{p}e^{DE(\un{p}\cdot \un{1}_E)/kT}d\Omega}{\int e^{DE(\un{p}\cdot \un{1}_E)/kT}d\Omega}
$$

If the field is weak, the coefficient of the exponential is small and we can use the Taylor expansion. Considering only the linear terms, we get
$$
\un{P}_{ind} = D\frac{\int \un{p}(1 + DE(\un{p}\cdot \un{1}_E)/kT)d\Omega}{\int (1+DE(\un{p}\cdot \un{1}_E)/kT)d\Omega}
$$

Now, using the fact that$\un{E}$ is constant and $\int n_i d\Omega = 0$, the first term in the numerator and second term in the denominator vanish, leaving us with
$$
\un{P}_{ind} = D\frac{\int \frac{D E}{k T} \un{1}_i(p_ip_j)d\Omega}{4\pi}
$$

which is a familiar integral resulting in the answer
$$
\un{P}_{ind} = \frac{1}{3}\frac{D^2 E}{k T} \un{1}_E
$$

\subsection{Moment of Inertia}

The scalar moment of inertia is a property that depends on one's choice of the axis of rotation. The tensorial moment of inertia, however, depends only on the body (its mass and mass distribution). Let $\un{1}_p$ be the unit vector along the axis of rotation and $\un{X}$ be the position vector for some point within the volume occupied by the body. Then, scalar moment of inertia can be written as
$$
I = \int \rho dV (\un{X}-(\un{X}\cdot \un{1}_p)\un{1}_p)^2
$$
Or in index notation
$$
I = \un{1}_{p_i}\un{1}_{p_j} \underbrace{\int \rho dV (r^2 \dl_{ij} - x_i x_j)}_{\text{This is moment of inertia tensor}}
$$

As an example, we can write the moment of inertia tensor for a sphere as
$$
\int \rho dV (r^2 \dl_{ij} - x_i x_j) = C \dl_{ij}
$$
Contracting both sides with $\dl_{ij}$, we easily get the familiar moment of inertia of the sphere $2/5 MR^2$.

Suppose we have a solid of revolution, such as a spheroid. Once we fix the coordinate system, we can define the direction of anisotropy, say $q_i$. Clearly the moment of inertia tensor will not just be proportional to $\dij$ because the body is not isotropic anymore. We must incorporate the anisotropy in our ansatz. Anisotropy is given by a direction - a vector $q_i$. In order to be proportional to a second order tensor, we must construct a second order tensor using just $q_i$, for which the simplest recipe is a dyadic product $q_i q_j$.
$$
I_{ij} = \int \rho dV (r^2 \dl_{ij} - x_i x_j) = F_1 \dij + F_2 q_i q_j
$$

Here, $F_1$ and $F_2$ are functions of the aspect ratio such that if aspect ratio becomes 1, $F_2$ vanishes and we get the result for a sphere. Note that the presence of $\dij$ is necessary here. In order to solve this equation, we contract once with $\dij$ and once with $q_iq_j$ and get two equations which can be solved for $F_1$ and $F_2$. More importantly, we can recast the above expression as
$$
I_{ij}= \underbrace{F_1(\dij - q_iq_j)}_{\text{Axial M.o.I}}+\underbrace{(F_1 + F_2)(q_iq_j)}_{\text{Equatorial M.o.I}}
$$

Here $q_iq_j$ denotes the component of $I_{ij}$ associated with the axial moment of inertia while $\dij - q_iq_j$ denotes the equatorial component. ($\dij - q_iq_j$ can be written as $x_i - q_iq_jx_j$ which emphasizes the subtraction of component of \un{x} along \un{q} from \un{x})

If instead of the spheroid, we had an ellipsoid (given by $\frac{x^2}{A^2}+\frac{y^2}{B^2}+\frac{z^2}{C^2} = 1$) which is aligned with the coordinate directions, we can write
$$
I_{ij} = \int \rho dV (r^2 \dl_{ij} - x_i x_j) = F_1 q_i q_j + F_2 r_i r_j + F_3 s_is_j
$$
 where \un{q}, \un{r}, \un{s} are the unit vectors along the axes of the ellipsoid and also along the coordinate axes. In this case we did not require $\dij$ because it comes out as a special case if $F_1=F_2=F_3=F$. In that case $I_{ij}=F( q_i q_j + r_i r_j + s_i s_j) = F(\un{1}_{1_i}\un{1}_{1_j} + \un{1}_{2_i}\un{1}_{2_j} + \un{1}_{3_i}\un{1}_{3_j}) = F\dij$
\section{Appendix}

\subsection{Area of a D-dimensional hypersphere}

\subsection{Dipole interaction in strong field in D-dimensions}
In this case, the linearization of the exponential is not a valid simplification and in general we must consider all powers in the power series expansion of the biasing factor $e^{DE(\un{p}\cdot \un{1}_E)/kT}$. To start with, we align the first dipole along a coordinate axis and consider all possible orientations of the other dipole. This eliminates the $\phi$ dependence (azimuthal dependence) of the probability density (or energy) and allows us to easily calculate the normalization constant. Then we expand the exponential whose general term consists of an integral involving $n$ normals over the unit sphere
$$
\int p_1 p_{i_1} p_{i_2} p_{i_3}...p_{i_{n}} d\Omega
$$

where $p_1$ denotes the direction of the first dipole. The integral is zero if $n$ is even and hence we consider only odd $n$ i.e. we take $n = 2n'+1$. Now we get an integral of $2n+2$ normals over the unit sphere.
$$
\int p_1 p_{i_1} p_{i_2} p_{i_3}...p_{i_{2n+1}} d\Omega
$$
If we can solve the general integral over the $2n$ normals
$$
\int p_{i_1} p_{i_2} p_{i_3}...p_{i_{2n}} d\Omega
$$
then we can obtain the required result by replacing $n$ with $2n+1$. To attempt a solution by method of induction, we assume a solution for $2n-1$ normals and use to prove the case for $2n$ normals. Doing this leads us to the following integral
$$
\int x_{i_1} x_{i_2} x_{i_3}...x_{i_{2n-1}} n_{i_{2n}} d\Omega
$$
where $\un{x}=r\un{n}$ and they are both equal at the surface of the unit sphere. Writing it in this form allows us to use divergence theorem to convert this surface integral into a volume integral as follows
$$
\int x_{i_1} x_{i_2} x_{i_3}...x_{i_{2n-1}} n_{i_{2n}} d\Omega = \int \pd{(x_{i_1} x_{i_2} x_{i_3}...x_{i_{2n-1}})}{x_{i_{2n}}} dV
$$
Henceforth, we just have to apply the product rule and use the assumed form for $2n-1$ to prove the result for $2n$ normals. One critical step here is to note the application of the general form of divergence theorem. In general one can write
$$
\int A_{i_1 i_2...i_n j}n_j dS = \int \pd{A_{i_1 i_2...i_n j}}{x_j}dV
$$

This identity would have helped us convert the above surface integral into volume integral. However, we note that the use of this form of divergence theorem requires that one index be contracted ($j$ in this case) but we don't have any contracting index in our surface integral. To overcome this problem consider that we fix all but indices of the surface integral. The integrand then behaves as a vector. Let that vector be $u_i$. We can write $u_i = A\dij$ where $A$ is some scalar function of $x_i$'s. If we fix one of the indices (say i) then $A\dij$ behaves as a vector. Now apply divergence theorem on $A\dij$
$$
\int \pd{A\dij}{x_i} dV = \int \dij \pd{A}{x_i} dV = \int \pd{A}{x_j} dV = \int A n_j dS
$$
In the last step, we have used the divergence theorem for a scalar field
$$
\int \pd{f}{x_i} dV = \int f n_i dS
$$
for some scalar function $f$.
\end{document}


%!TEX root = ../notes.tex
\section{April 14, 2022}
\recall Last time:
\begin{itemize}
    \item we defined fractional ideals,
    \item define the inverse of a nonzero integral ideal (and noted at the end of the same definition holds for fractional ideals)\footnote{An integral domain has all of its nonzero fractional ideals invertible iff it is a Dedekind domain.}
    \item we briefly stated the definition of a Dedekind domain.
\end{itemize}
\subsection{Dedekind Domains}
We introduced last time\dots
\begin{theorem*}[p.109 \cite{stewart2015algebraic}]
    The ring of integers $\riO_K$:
    \begin{enumerate}[(a)]
        \item is an integral domain;
        \item is Noetherian, that is to mean one of the following:
              \begin{enumerate}[(i)]
                  \item every ascending chain of ideals terminates, or
                  \item every ideal is finitely generated;
              \end{enumerate}
        \item if $\alpha\in\mathsf{Frac}(\riO_K)=K$ satisfies a nonzero monic polynomial equation with coefficients in $\riO_K$, then $\alpha\in\riO_K$ ($\riO_K$ is integrally closed in its field of fractions);
        \item every nonzero prime ideal of $\riO_K$ is maximal.
    \end{enumerate}
\end{theorem*}
\begin{proof}
    ~\begin{enumerate}[(a)]
        \item \emph{We know this.}
        \item
              We know that if $[K : Q] = n$, then $\riO_K$ is a free $\ZZ$-module of rank $n$\footnote{That is, a free Abelian group of rank $n$; or also to say possesses an integral basis of order $n$}.

              If $\frk{a}$ is an ideal of $\riO_K$, then $(\frk{a}, +)$ is a free Abelian group of rank $\leq n$\footnote{\emph{Theorem 1.16} of \cite{stewart2015algebraic} proves this fact about submodules of free modules.}. As a group, $\frk{a}$ is finitely generated, so $\frk{a}$ (with some glossing over) is finitely generated as an ideal.
        \item \emph{Was noted in a previous lecture.}
        \item
              Let $\frk{p}$ be a nonzero prime ideal of $\riO_K$. Let $0\neq \alpha\in\frk{p}$. Then $N:= N_{K/\QQ}(\alpha) = \alpha_1\alpha_2\cdots \alpha_n$\footnote{We know this lives in $\QQ$ since it's a term of the polynomial.} where $\alpha_1 := \alpha$ and $\alpha_i$ are the conjugates of $\alpha = \alpha_1$.

              Note that $\alpha_2\alpha_3\cdots \alpha_n\in K$ since the whole product $\alpha_1\alpha_2 \cdots \alpha_n\in\QQ\subseteq K$ and $\alpha_1\in K$. In fact, $\alpha_2\alpha_3\cdots \alpha_n\in\riO_K$. Hence $N:= N_{K/\QQ}(\alpha)\in\frk{p}$. Thus $N\cdot \riO_K\subseteq \frk{p}$. This means that, taking quotients\footnote{If $I\subseteq J\subseteq R$, then $R/J$ is a quotient of $R/I$.},
              \[\riO_K/\frk{p}\text{ is a quotient of }\riO_K/N\riO_K\]
              But $\riO_K/N\riO_K$ is a finitely generated Abelian group where every element has finite order, so $\riO_K/N\riO_K$ is finite.

              Hence $\riO_K/\frk{p}$ is finite. So $\riO_K/\frk{p}$ is also an integral domain (by ring theory). Any finite integral domain is a field, so $\riO_K/\frk{p}$ is a field. So $\frk{p}$ has to be maximal (again by ring theory).
    \end{enumerate}
    Which proves part (a) through (d).
\end{proof}
\begin{proposition}[p.112 \cite{stewart2015algebraic}]
    Every nonzero ideal $\frk{a}\subseteq\riO_K$ is a product of prime ideals.
\end{proposition}
\begin{proof}\footnote{This is very analogous to the proof of the existence of prime factorization in $\ZZ$. Noetherian-ness of $\riO_K$ takes the place of well-ordereding. $\frk{a}$ being maximal ideal that isn't the product of prime ideals is akin to selecting $a$ to be the least element not a product of primes. $a$ itself isn't prime so is a product, and so on\dots}
    If not, let $\frk{a}$ be maximal subject to the condition of not being a product of prime ideals.
    \begin{remark*}
        Recall Zorn's Lemma: in a partially ordered set where every chain has an upper bound, there is at least one maximal element. We apply Zorn's Lemma to ideals to find such a maximal ideal.
    \end{remark*}
    Then $\frk{a}$ is not prime, but applying Zorn to the poset of ideals containing $\frk{a}$ to conclude that $\frk{a}\subseteq \frk{p}$ for some maximal (hence prime) ideal $\frk{p}$.

    We have that $\riO_K\subsetneq \frk{p}^{-1}\subseteq \frk{a}^{-1}$, since $\frk{p}$ is a proper ideal of $\riO_K$, and $\frk{a}\subseteq\frk{p}$.

    It follows that\footnote{Inverses let us preserve containment of $\subsetneq$, because if we hit both sides with $\frk{a}^{-1}$ we get nice things.}
    \[\frk{a}\subsetneq \frk{a}\frk{p}^{-1}\subseteq \frk{a}\frk{a}^{-1} = \riO_K\]
    By the maximality of $\frk{a}$, we have that
    \[\frk{a}\frk{p}^{-1} = \frk{p}_2\frk{p}_3\cdots \frk{p}_r\]
    where $\frk{a}\frk{p}^{-1}$ is a product of prime ideals $\frk{p}_2, \frk{p}_3, \dots, \frk{p}_r$, so
    \[\frk{a} = \frk{p}\frk{p}_2\frk{p}_3\cdots \frk{p}_r\]
    which is a contradiction, since $\frk{a}$ is the product of prime ideals.
\end{proof}

\begin{lemma}[p.113 \cite{stewart2015algebraic}]
    For ideals $\frk{a}, \frk{b}$ of $\riO_K$, $\frk{a}\mid\frk{b} \iff \frk{b}\subseteq \frk{a}$.
    \begin{ques*}
        What does $\frk{a}\mid \frk{b}$ mean? It means there exists an ideal $\frk{c}$ such that $\frk{b} = \frk{c}\cdot \frk{a}$.
    \end{ques*}
\end{lemma}
\begin{proof}
    Since $\frk{c}\frk{a}\subseteq \frk{a}$, we have that $\frk{a}\mid \frk{b}$ implies that $\frk{b}\subseteq \frk{a}$.

    Now we prove the other direction. Suppose $\frk{b}\subseteq\frk{a}$, then
    \[\frk{b} = \frk{a}(\frk{a}^{-1}\frk{b}),\]
    where $\frk{a}^{-1}\frk{b}$ is integral. Letting $\frk{a}^{-1}\frk{b} = \frk{c}$ shows that $\frk{a}\mid\frk{b}$.
\end{proof}

\begin{theorem}
    Every nonzero ideal of $\riO_K$ has a unique factorization as a product of prime ideals.
\end{theorem}
\begin{proof}
    The lemma above tells us that $\frk{p}$ is prime iff $\frk{p}\mid \frk{a}\frk{b} \Rightarrow \frk{p}\mid\frk{a}$ or $\frk{p}\mid\frk{b}$. Then proceed as follows as we had done so in integers.

    Suppose
    \begin{align*}
        \frk{a} & = \frk{p}_1\frk{p}_2\cdots \frk{p}_r \\
                & = \frk{q}_1\frk{q}_2\cdots \frk{q}_s
    \end{align*}
    for some prime ideals $\frk{p}_1, \frk{p}_2, \cdots,  \frk{p}_r, \frk{q}_1, \frk{q}_2, \cdots, \frk{q}_s$. Then $\frk{p}_1$ divides $\frk{q}_j$ for some $\frk{j}$. Since $\frk{q}_j$ is maximal, $\frk{p}_1 = \frk{q}_j$. We multiply by $\frk{p}_1^{-1}$ repeat the process, concludes the proof.
\end{proof}


\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{color}
\usepackage[breaklinks,colorlinks=true]{hyperref}

\definecolor{Blue}{RGB}{0,122,255}
\hypersetup{colorlinks,breaklinks,urlcolor=Blue,linkcolor=Blue,citecolor=Blue,urlcolor=Blue}

\def\Pr{\mathop{\mathbb{P}}}
\newcommand\Ex{\mathop{\mathbb{E}}}
\newcommand\br[1]{\left(#1\right)}
\newcommand\bbr[1]{\left[#1\right]}
\newcommand\cbr[1]{\left\{#1\right\}}
\newcommand\pd[2]{\frac{\partial #1}{\partial #2}}

\begin{document}

\title{Price and greeks of American binary option}
\date{}

\maketitle

Consider an asset with spot price $S = \{S_t; 0 \leq t \leq T\}$ following geometric Brownian motion of volatility $\sigma$.

An American binary call option with strike $K$ and maturity $T$ pays off
\begin{align}
    \text{Payoff}
        = 1_{\max\{S_t; 0 \leq t \leq T\} \geq K} ,
\end{align}
where
$1_{\max\{S_t; 0 \leq t \leq T\} \geq K}$ is an indicator function.

\section*{Price}

Let $W = \{W_t; 0 \leq t \leq T\}$ be Brownian motion driving $S$.
We define the cumulative maximum of $W$ by $M_t = \max\{W_u; 0 \leq u \leq t\}$ and
consider $\hat M_t = M_t - \frac12 \sigma t$.
According to Corollary 7.2.2 of Ref.~\cite{shreve}, if $S_0 < K$,
\begin{align}
    \Pr[\hat M_t \geq m]
        = 1 - N\br{\frac{m}{\sqrt{t}} + \frac12 \sigma \sqrt{t}}
            + e^{-\sigma m} N\br{-\frac{m}{\sqrt{t}} + \frac12 \sigma \sqrt{t}} ,
\end{align}
where
$N$ is the cumulative distribution function of the normal distribution.
A condition to get the payoff of unity, $\max\{S_t; 0 \leq t \leq T\} \geq K$, is equivalent to $\hat M_T \geq - \sigma^{-1} \log(S_0 / K)$.
Therefore, the price of the American binary call option is given by
$1$ if $S_0 \geq K$ and otherwise
\begin{align}
    \text{Price}
        & = \Ex[1_{\max\{S_t; 0 \leq t \leq T\} \geq K}] \notag \\
        & = \Pr\bbr{\hat M_T \geq - \frac{1}{\sigma}\log\br{\frac{S_0}{K}}} \notag \\
        & = 1 - N\br{- \frac{\log(S_0 / K)}{\sigma \sqrt{T}} + \frac12 \sigma \sqrt{T}}
            + N\br{\frac{\log(S_0 / K)}{\sigma \sqrt{T}} + \frac12 \sigma \sqrt{T}}
            \notag \\
        & = N(d_2) + \frac{S_0}{K} N(d_1) ,
\end{align}
where
\begin{align}
    d_1
        = \frac{\log (S_0 / K)}{\sigma \sqrt{T}} + \frac12 \sigma \sqrt{T} ,
    \quad
    d_2
        = \frac{\log (S_0 / K)}{\sigma \sqrt{T}} - \frac12 \sigma \sqrt{T} .
\end{align}

\section*{Delta}

Delta is given by
$0$ if $S_0 \geq K$ and otherwise
\begin{align}
    \text{Delta}
        = \frac{N^\prime(d_2)}{S_0 \sigma \sqrt{T}}
            + \frac{N(d_1)}{K}
            + \frac{N^\prime(d_1)}{K \sigma \sqrt{T}} ,
\end{align}
where
we used a derivative $\partial d_1 / \partial S_0 = \partial d_2 / \partial S_0 = 1 / (S_0 \sigma \sqrt{T})$.

\section*{Gamma}

Gamma is given by
$0$ if $S_0 \geq K$ and otherwise
\begin{align}
    \text{Gamma}
        & = - \frac{N^\prime(d_2)}{S_0^2 \sigma \sqrt{T}}
            + \frac{N^{\prime\prime}(d_2)}{S_0^2 \sigma^2 T}
            + \frac{N^\prime(d_1)}{S_0 K \sigma \sqrt{T}}
            + \frac{N^{\prime\prime}(d_1)}{S_0 K \sigma^2 T} \notag \\
        & = - \frac{N^\prime(d_2)}{S_0^2 \sigma \sqrt{T}}
            - \frac{d_2 N^\prime(d_2)}{S_0^2 \sigma^2 T}
            + \frac{N^\prime(d_1)}{S_0 K \sigma \sqrt{T}}
            - \frac{N^\prime(d_1)}{S_0 K \sigma^2 T} ,
    \label{eq:gamma}
\end{align}
where we used a relation $N^{\prime\prime}(x) = - x N^\prime(x)$ to show the second equality.

\begin{thebibliography}{1}
\bibitem{shreve} Shreve, S.E., 2004. Stochastic calculus for finance II: Continuous-time models (Vol. 11). New York: springer.
\end{thebibliography}

\end{document}


\documentclass{article}

\usepackage[margin=3cm]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}

\title{\Large\bfseries CS 598 MP: Software Verification, Program Synthesis, and Interpretable AI \\
Fall 2021 \\
Homework 1}
\author{Chiao Hsieh, chsieh16@illinois.edu}

\begin{document}
\maketitle

\section*{Problem 1}
Modified Dafny code with verified invariant is included in the tarball.

\subsubsection*{product1.dfy}
Outer Loop Invariant: \verb|m1 <= m && res == m1 * n| \\
Inner Loop Invariant: \verb|n1 <= n && res == m1 * n + n1|

\subsubsection*{product2.dfy}
Outer Loop Invariant: \verb|m1 >= 0 && res == (m - m1) * n| \\
Inner Loop Invariant: \verb|n1 >= 0 && res == (m - m1) * n + (n - n1)|

\subsubsection*{Half.dfy}
Loop Invariant: \verb|r == i/2 && i%2 == 0|

\subsubsection*{DividesIt.dfy}
Loop Invariant: \verb|x1>=0 && y1>=0 && x1%d==0 && y1%d==0|
\medskip

\includegraphics[width=\textwidth]{hw1-dafny-output.png}

\pagebreak

\section*{Problem 2}

\begin{verbatim}
int pm(int x, int y)
@requires x >= 0 & y >= 0;
@ensures res = x * y
{
    a := x;
    b := y;
    res := 0;
    while (a > 0) {
        if ((a mod 2) = 1) then res := res + b;
        a := a div 2;
        @assert a >= 0;
        b := b * 2;
    }
    return res;
}
\end{verbatim}

\paragraph{Loop Invariant} \verb|a>=0 & a*b + res == x*y|

\subsection*{Basic Blocks/Basic Paths}
\subsubsection*{BB1:}
\begin{verbatim}
@requires x >= 0 & y >= 0;
a := x;
b := y;
res := 0;
@invariant a>=0 & a*b + res = x*y;
\end{verbatim}
\textbf{VC1:}
\verb|(x>=0 & y>=0 & a=x & b=y & res=0) ==> (a>=0 & a*b+res=x*y)| for all x, y, a, b, and res.

\subsubsection*{BB2:}
\begin{verbatim}
@invariant a>=0 & a*b + res = x*y;
@assume a > 0;  // while entry condition
@assume ((a mod 2) = 1);  // then-branch
res := res + b;
a := a div 2;
@assert a >= 0;
\end{verbatim}
\textbf{VC2:}\\
\verb|(a0>=0 & a0*b+res0=x*y & a0>0 & ((a0 mod 2)=1) & res1=res0+b & a1=(a0 div 2)) ==> a1>=0| for all x, y, a0, a1, b, res0, res1.

\subsubsection*{BB3:}
\begin{verbatim}
@invariant a>=0 & a*b + res = x*y;
@assume a > 0;  // while entry condition
@assume !((a mod 2) = 1);  // else-branch
a := a div 2;
@assert a >= 0;
\end{verbatim}
\textbf{VC3:}\\
\verb|(a0>=0 & a0*b+res=x*y & a0>0 & !((a0 mod 2)=1) & a1=(a0 div 2)) ==> a1>=0| for all x, y, a0, a1, b, res.

\subsubsection*{BB4:}
\begin{verbatim}
@invariant a>=0 & a*b + res = x*y;
@assume a > 0;  // while entry condition
@assume ((a mod 2) = 1);  // then-branch
res := res + b;
a := a div 2;
b := b * 2;
@invariant a>=0 & a*b + res = x*y
\end{verbatim}
\textbf{VC4:}
\begin{verbatim}
(a0>=0 & a0*b0+res0=x*y & a0>0 & ((a0 mod 2)=1)
       & res1=res0+b & a1=(a0 div 2) & b1=b0*2) ==> a1*b1+res1=x*y
\end{verbatim}
for all x, y, a0, a1, b0, b1, res0, res1.

\subsubsection*{BB5:}
\begin{verbatim}
@invariant a>=0 & a*b + res = x*y;
@assume a > 0;  // while entry condition
@assume !((a mod 2) = 1);  // else-branch
a := a div 2;
b := b * 2;
@invariant a>=0 & a*b + res = x*y
\end{verbatim}
\textbf{VC5:}
\begin{verbatim}
(a0>=0 & a0*b0+res=x*y & a0>0 & !((a0 mod 2)=1)
       & a1=(a0 div 2)) & b1=b0*2) ==> a1*b1+res=x*y
\end{verbatim}
for all x, y, a0, a1, b0, b1, res.

\subsubsection*{BB6:}
\begin{verbatim}
@invariant a>=0 & a*b + res = x*y
@assume !(a > 0);  // while exit condition
return res;
@ensures res = x * y;
\end{verbatim}
\textbf{VC6:}
\verb|(a>=0 & a*b+res=x*y & !(a>0)) ==> res=x*y| for all x, y, a, b, res.

\subsection*{SMT Formula}
To check if the verification conditions are valid, each VC is negated and check for UNSAT.
For simplicity, the six negated VCs are combined with a disjunction as below.
If any of negated VCs is satisfiable, the program is not proven correct using the invariant.
Z3 returns UNSAT for the combined SMT formula; hence the program is correct.

\pagebreak

\scriptsize
\begin{verbatim}
; Variable declarations
(declare-fun x () Int)
(declare-fun y () Int)
(declare-fun a () Int)
(declare-fun a0 () Int)
(declare-fun a1 () Int)
(declare-fun b () Int)
(declare-fun b0 () Int)
(declare-fun b1 () Int)
(declare-fun res () Int)
(declare-fun res0 () Int)
(declare-fun res1 () Int)

; Constraints
(assert (or
    ; VC1
    (and (>= x 0) (>= y 0) (= a x) (= b y) (= res 0)
         (not (and (>= a 0) (= (+ (* a b) res) (* x y)))))
    ; VC2
    (and (>= a0 0) (= (+ (* a0 b) res0) (* x y)) (> a0 0) (= (mod a0 2) 1) (= res1 (+ res0 b)) (= a1 (div a0 2))
         (not (>= a1 0)))
    ; VC3
    (and (>= a0 0) (= (+ (* a0 b) res0) (* x y)) (> a0 0) (not (= (mod a0 2) 1)) (= a1 (div a0 2))
         (not (>= a1 0)))
    ; VC4
    (and (>= a0 0) (= (+ (* a0 b0) res0) (* x y)) (> a0 0) (= (mod a0 2) 1) (= res1 (+ res0 b0)) (= a1 (div a0 2)) (= b1 (* b0 2))
         (not (= (+ (* a1 b1) res1) (* x y))))
    ; VC5
    (and (>= a0 0) (= (+ (* a0 b0) res) (* x y)) (> a0 0) (not (= (mod a0 2) 1)) (= a1 (div a0 2)) (= b1 (* b0 2))
         (not (= (+ (* a1 b1) res) (* x y))))
    ; VC6
    (and (>= a 0) (= (+ (* a b) res) (* x y)) (not (> a 0))
         (not (= res (* x y))))
))
(check-sat)
\end{verbatim}

\end{document}


[1.5 hours late]
\section{Second Quantization notation}
We use the notation
\begin{align}
    \ket{\varphi} = \ket{n_1, n_2, \ldots}
\end{align}
where
\begin{align}
    \hat{N} &=
    \left( n_1 + n_2 + \cdots \right)
    \ket{n_1, n_2, \ldots}
\end{align}
is the total number operator and the Hamiltonian is
\begin{align}
    \het{H} \ket{\varphi} &=
    \left(
    n_1 E_{n_1} + n_2 E_{n_2} + \cdots
    \right)
    \ket{n_1, n_2, \ldots}
\end{align}

\section{Bosonic Ideal Gas}
Second quantization notation.
We had a sum over all multi-particle states over all multi-particle states.
Now we just have
\begin{align}
    Z_G(T, V, \mu) &=
    \sum_{n_1, n_2, \cdots = 0}^{\infty}
    \bra{n_1,n_2,\ldots} e^{-\beta(H - \mu N)} \ket{n_1,n_2,\ldots}\\
    &=
    \sum_{n_1=0}^{\infty} e^{-\beta(E_1 - \mu) n_1}
    \sum_{n_2=0}^{\infty} e^{-\beta(E_2 - \mu) n_2}
    \cdots\\
    &=
    \frac{1}{1 - e^{-\beta(E_1 - \mu)}}
    \frac{1}{1 - e^{-\beta(E_2 - \mu)}}
    \cdots
\end{align}
So then
\begin{align}
    \Omega(T, V, \mu) &=
    -k_B T \ln Z_G\\
    &=
    -k_BT \sum_k \ln\left( 1 + e^{-\beta (E_k - \mu)} \right)\\
    &\approx
    k_B TV \int \frac{d^3k}{(2\pi)^3}
    \ln\left( 1 - e^{-\beta(E_k - \mu)} \right)
\end{align}
where each
\begin{align}
    E_k &= \frac{\hbar^2 k^2}{2M}
\end{align}

It's just the same thing as the modes of a crystal vibrations.
They're the same as an EM field,
because I can find the normal modes of th EM field.
This has nothing to do with Harmonic oscillators except it does.
Each single particle state mode is like a harmonic oscillator.
The state is indexed by the particle number,
and the energy levels are equally spaced just like the harmonic oscillator.
That's the special property.

\section{Fermion ideal gas}
For fermions,
just change the limit of the sum from $\infy$ to $1$
and you get
\begin{align}
    \Omega(T, V, \mu) &=
    -k_B T V g \int \frac{d^3k}{(2\pi)^3}\,
    \ln\left(
    1 + e^{\beta(E_k - \mu)}
    \right)
\end{align}
where $g$ is the number of internal states,
like the spin.

The little difference in sign changes things profoundly.

Just using the general formalism of the grand canonical ensemble,
I should be able to find the boson canonical ensemble,
etc.

For example,
if I have $\Omega$,
I can find the average $N$.
Let's compute the average number of particles over the volume so we get a
density.
\begin{align}
    \frac{N}{V} &=
    \frac{1}{V}
    \left. \frac{\partial \Omega}{\partial\mu}\right|_{T,V}\\
    &=
    - k_B T g
    \int \frac{d^3k}{(2\pi)^2}
    \frac{ \beta e^{-\beta \epsilon_k}}{%
        1 \mp e^{-\beta \epsilon_k}
    }
\end{align}
where $\epsilon_k=E_k - \mu$ which appears so frequently I may as well have a
name for it,
where the upper sign is for fermions and the lower sign is for bosons.
And then
\begin{align}
    \frac{N}{V} &=
    g \int \frac{d^3k}{(2\pi)^2}
    \frac{1}{e^{\beta\epsilon_k}\mp 1}
\end{align}
and the only difference is the sign.
The integrand is interpreted as the average occupation number.
Then I take an average over many states.
For a particular single energy state
what is the average expectation?
Well that is just the occupation number
\begin{align}
    n(E) &=
    \frac{1}{e^{\beta\epsilon_k}\mp 1}
\end{align}
which is the occupation number of the density per unit of $k$.

Another thing I like to calculate is the energy density.
How do I find that?
I can think of this $\Omega$ here,
take a derivative in relation to $T$ to find the entropy,
then use the Legendre transform to find the entropy.
The little trick about this is the following.
This gives me $N$ as a function of the temperature nd the chemical potential
but it's hard to invert the relation to find what $\mu$ is needed to give
a particular $N$.
Although it's easy to say Legendre transform,
it's hard to do in particle.

It doesn't matter,
you can manipulate the integrals back and forth,
I won't do this in front of you or do tell you to do it in the homework.
Which one do you want?
Of course it's in the homework.

The answer is something you'd expect.
It's as um over single particle states.
We're looking for the total energy.
That's the occupation number for one particular state.
If I multiply it by the energy of the single particular state I get the energy.
\begin{align}
    \frac{E}{N} &=
    g \int \frac{d^3k}{(2\pi)^3}
    \frac{E_k}{e^{\beta\left( E_k - \mu \right)} \mp 1}
\end{align}
where the  $g \int \frac{d^3k}{(2\pi)^3}$ means sum over single particle states,
the $\frac{1}{e^{\beta\left( E_k - \mu \right)} \mp 1}$ is the occupation number
for the $k$ and $E_k$ is the energy of a single particle.

In the midterm,
If I ask a question in the midterm,
I will not give you this equation,
because it's so intuitive and obvious.

I'll give you the $N/V$ because the sign is not obvious,
but this $E/N$ formula is obvious from that.
It's difficult to compute but it's a simple answer in the end.