\subsection{The Jacobi identity}


\documentclass{article}
\usepackage[margin=1in]{geometry}

\title{Computing distances between genome assemblies}

\author{Aakash Sur
  \and
  William Stafford Noble}

\begin{document}

\maketitle

\section{The problem}

The genome scaffolding problem involves taking a collection of
non-overlapping segments of a given genome (referred to as
``contigs''), partitioning them into groups (one group per chromosome,
called a ``scaffold''), and ordering each group of contigs in the
correct order.  The partioning and ordering of contigs is referred to
as an ``assembly'' and is carried out on the basis of some additional
data that indicates proximity of pairs of contigs in the genome.  In
some cases, the assembly may also contain information about the
distance between adjacent contigs, but we ignore this possibility here
and focus only on the case where we find a partition and ordering.

In this work, we are interested in computing a score that quantifies
the distance between two assemblies.  This can be useful, for example,
in measuring the quality of an assembly by computing its distance to a
reference genome assembly.

\subsection{Edit distance formulation}

We propose to compute the distance between assemblies as an edit
distance, where we aim to find the minimum number of edits that can
convert one assembly into another.  Formally, we define a set of
contigs $C$ using integer indices.  An assembly of $s(C)$ is a
partition and ordering of the integers in $C$.  If the assembly
contains $m$ scaffolds, then $s(C)$ can be represented as a vector
$s_1, ..., s_{n+m-1}$, where each element $s_i$ is either an integer
from $C$ or a special character (``$|$'') denoting the boundary between
two scaffolds in the partition.  The distance between two assemblies,
$s_1(C)$ and $s_2(C)$, of a given set $C$ of contigs is defined as the
minimum number of edits needed to convert $s_1(C)$ into $s_2(C)$.

Prior to computing this distance, we first must ensure that $s_1(C)$
and $s_2(C)$ are the same length.  This can be accomplished by adding
empty scaffolds to the shorter of the two assemblies, i.e., padding
the vector representation with additional ``$|$'' characters.

We then designate one of the assemblies the source and the other the
target.  Our goal is to convert the source into the target.
To do so, the following edit operations are allowed:
\begin{enumerate}
\item Swap two elements in the source assembly.  This can be a swap of
  two contigs or one contig and a boundary.
\item Reverse the entries in one scaffold in the source assembly.
\item Swap the order of two scaffolds in the source assembly.
\end{enumerate}
The latter two operations have zero cost because some syntactically
distinct assemblies are actually functionally equivalent to one
another.  For example, the order in which the scaffolds appear in the
assembly is irrelevant, so the assemblies {\tt 1 2 $|$ 3 4} and {\tt 3
  4 $|$ 1 2} are equivalent.  Furthermore, the order of contigs within
a scaffold can be reversed, so the assemblies {\tt 1 2 $|$ 3 4} and
{\tt 2 1 $|$ 4 3} are also equivalent to one another.  Practically
speaking, given a series of edits to convert $s_1(C)$ into $s_2(C)$,
the assembly distance is a count of the number of swaps in that
series.

Note that there is one additional feature of this problem, which is
that each contig can be written in forward or reverse order.  We can
indicate the orientation of the contig by adding a sign to the
corresponding integer.  If we include this feature, then we need to
include two additional edit operations:
\begin{enumerate}
\item Flip the sign of one contig.  This has a cost of 1.
\item Flip the signs of all contigs in a scaffold.  This is a
  zero-cost operation.
\end{enumerate}

Given this formulation, our goal is to find an efficient algorithm
that finds the minimum-cost edit distance between two given
assemblies.

\subsection{Graph-based formulation}

\end{document}


% !TEX root = ./Basilisk-sunSafePoint-20180427.tex

\section{Test Description and Success Criteria}
The mathematics in this module are straight forward and can be tested in a series of input and output evaluation tests.

\subsection{Check 1}
Here a check is performed where the sun vector measurement $\bm s$ has a non-zero length and is not aligned with $\hat{\bm s}_{c}$.

\subsection{Check 2}
The sun direction vector $\bm s$ is given a norm value that is less than {\tt minUnitMag}.  In this case the attitude tracking $\bm\sigma_{B/R}$ should be set to zero.  Further, the body rate errors are now evaluated relative to a fixed $\bm\omega_{R/N}$ vector.

\subsection{Check 3}
The sun direction vector $\bm s$ aligned with $\hat{\bm s}_{c}$.  In this case the attitude tracking $\bm\sigma_{B/R}$ should be set to zero.  Further, the body rate errors are simply the inertial body angular rates.

\subsection{Check 4}
The sun direction vector $\bm s \approx -\hat{\bm s}_{c}$.  In this case the attitude tracking $\bm\sigma_{B/R}$ should be set to $\hat{\bm e}_{180}$.  Further, the body rate errors are simply the inertial body angular rates.

\subsection{Check 4}
The sun direction vector $\bm s \approx -\hat{\bm s}_{c}$, but $\hat{\bm s}_{c} = \hat{\bm b}_{1}$.  In this case the attitude tracking $\bm\sigma_{B/R}$ should be set to $\hat{\bm e}_{180}$ that is evaluated with the cross product with $\hat{\bm b}_{2}$.  Further, the body rate errors are simply the inertial body angular rates.

\section{Test Parameters}
The unit test verify that the module output guidance message vectors match expected values.
\begin{table}[htbp]
	\caption{Error tolerance for each test.}
	\label{tab:errortol}
	\centering \fontsize{10}{10}\selectfont
	\begin{tabular}{ c | c } % Column formatting,
		\hline\hline
		\textbf{Output Value Tested}  & \textbf{Tolerated Error}  \\
		\hline
		$\bm\sigma_{B/R}$        & \input{AutoTex/toleranceValue}	   \\
		$\bm\omega_{B/R}$        & \input{AutoTex/toleranceValue}\\
		$\bm\omega_{R/N}$        & \input{AutoTex/toleranceValue} \\
		$\dot{\bm\omega}_{R/N}$        & \input{AutoTex/toleranceValue}  \\
		\hline\hline
	\end{tabular}
\end{table}

The nominal module test input values are $\hat{\bm s}_{c} = (0,0,1)$, $\bm s = (1,0,0)$ and $\leftexp{B}{\bm\omega}_{B/N} = (0.01, 0.50, -0.20)$ rad/sec.  The nominal body-fixed search rate is set to $\leftexp{B}{\bm\omega}_{R/N} = (0.0, 0.0, 0.1)$ rad/sec.  This rate is only used if no sun direction vector is available.  The small angle is set to $\epsilon$ = 0.01 degrees.

\section{Test Results}

All of the tests passed:
\begin{table}[H]
	\caption{Test results}
	\label{tab:results}
	\centering \fontsize{10}{10}\selectfont
	\begin{tabular}{c | c  } % Column formatting,
		\hline\hline
		\textbf{Check} 						  		&\textbf{Pass/Fail} \\
		\hline
	   1	   			& \input{AutoTex/passFail1} \\
	   2	   			& \input{AutoTex/passFail2} \\
	   3	   			& \input{AutoTex/passFail3} \\
	   4	   			& \input{AutoTex/passFail4} \\
	   5	   			& \input{AutoTex/passFail5} \\
	   \hline\hline
	\end{tabular}
\end{table}


\subsection{Sample splitting for treatment effects}


\documentclass[a4paper,12pt]{article}

\usepackage[1925275]{MCMthesis}\problem{D}
\usepackage{palatino}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{minted}
\usepackage{float}
\usepackage{appendix}
\usepackage{threeparttable}
\usepackage{supertabular}
\usepackage{url}
\usepackage{amsmath}
\usepackage{textcomp,booktabs}
\usepackage[usenames,dvipsnames]{color}
\usepackage{colortbl}
\definecolor{mygray}{gray}{.9}
\definecolor{mypink}{rgb}{.99,.91,.95}
\definecolor{mycyan}{cmyk}{.3,0,0,0}

\setlength{\belowcaptionskip}{4pt}
\setlength{\abovecaptionskip}{4pt}

\usepackage{titlesec}
\usepackage{titletoc}
\setcounter{tocdepth}{2}

\titlecontents{section}[12mm]{\fontsize{12pt}{32pt}\selectfont \bf}{\contentslabel{2.5em}}{}{\titlerule*{.}\contentspage}
\titlecontents{subsection}[18mm]{\fontsize{12pt}{22pt}\selectfont \fs}{\contentslabel{3.3em}}{}{\titlerule*{.}\contentspage}

\usepackage[font=small,]{caption}
\title{GUSH Model for Emergency Evacuation Planning}  %Title

\begin{document}

%----------Summary----------
\begin{abstract}\footnotesize
The evacuation problem of public places is of great concern around the world. Facing the threat of terror attacks, the Louvre needs to design an evacuation plan that's effective and efficient.

Now there are mainly two ways to make the evacuation planning: \textbf{network flow models}, assuming everyone is under control; and \textbf{probability models}, focusing on individual behavior. In this paper, we combine these two approaches and present a novel \textbf{GUSH (Global gUidance - perSonal beHavior) model}. Global guidance means that the managers give real-time and dynamic guidance for everyone, which is an optimal plan for all the people as a whole. It is realized by an \textbf{App} serving as a guide during the evacuation. Meanwhile, this model also considers personal psychology and behavior that affect the ideal plan given by the managers.

Firstly, we adopt the \textbf{dynamic maximal flow model} as the basic model to build the GUSH model. The dynamic maximal flow model can find out a plan consuming the shortest time for the whole people. We draw the network graph of the Louvre and use the \textbf{Edmond-Karp algorithm} to calculate the model. The optimal routes for everyone are shown and the shortest evacuation time is 11.6 minutes.

Secondly, we introduce the \textbf{selfishness factor} into the basic model to describe the effect of the selfish people. It is based on the judgement that people who are selfish tend to take the shortest way and deviate from the way allocated to them. In addition, to design the best route for the disabled people, we introduce the \textbf{disabled people factor}. We assume the disabled exclude the passages with high popularity density and \textbf{take the shortest way} to the elevators specially prepared for them. What's more, we introduce an \textbf{emergency personnel factor} to design the route for the emergency personnel entering the museum. They take the shortest way to the bottlenecks to manage the crowd. By applying this adjusted GUSH model to the Louvre, we find the \textbf{bottlenecks} that should be paid attention to if the owner wants to shorten the evacuation time.

Thirdly, we create an example to justify our model. Assuming a terror attack happens in the museum at a random place on a random day, we use our model to formulate the most effective evacuation plan and calculate the total time. From this example, it's clear that our model is able to address various types of potential threats. We also conduct \textbf{sensitivity analysis} on the flow speed and the capacity of bottlenecks. It proves that the evacuation time takes on the shape of \textbf{ "U" } with the increasing of the flow speed. Meanwhile, the speed at which the evacuation time gets shorter slows down with the expansion of the bottlenecks. According to these results, we propose suggestions to the museum owners.

Finally, we discuss the strengths and weaknesses of the proposed models. It's believed that our model is adaptable. It can be adopted to help design the evacuation plan for other large, crowded structures.

\end{abstract}

\maketitle
\thispagestyle{empty}

\newpage
\setcounter{tocdepth}{3}
\tableofcontents
\thispagestyle{empty}
\newpage

\setlength\parskip{0.8\baselineskip}
\setcounter{page}{1}
\pagestyle{fancy}

\section{Introduction}
\subsection{Background}

The emergency evacuation is one of the most important issues a popular destination must pay attention to, especially in these days when terror attacks happen from time to time. In Paris, the Louvre welcomes millions of visitors every year, home and abroad. Nothing can compromise the critical role of a reasonable evacuation plan in case anything urgent takes place in the museum.

\subsection{Problem Statement and Analysis}

To formulate an evacuation plan, it's straightforward that the \textbf{goal} is to determine an evacuation routing that allows all the occupants leave the building as quickly and securely as possible.

Interested in this problem, several methods have been adopted to address it, among which the \textbf{network models} are the most popular. For example, someone transforms the problem into a \textbf{minimal cost flow problem} on a slighted modified graph \citep{TAKEOYAMADA1996A}, while some others solve this problem using the dynamic network model with the procedure of \textbf{Edmond-Karp algorithm} \citep{edmonds1972theoretical}.

The shortcomings of the network model is that it doesn't consider the behavior of individuals. To solve this problem, somebody builds a \textbf{probabilistic model} and develops a \textbf{divide-and-conquer approach} \citep{Wang2008Modeling}. However, this way is focused on each person and loses a "global view". These two models are complementary \citep{Chalmet1982Network}, and there's a need to combine these two approaches. Based on it, we establish a \textbf{GUSH (Global gUidance - perSonal beHavior) model}.

\subsection{Our work}
To further present our solutions, we arrange our paper as follows.
\begin{itemize}
\item \textbf{In section 2}, we give out the reliable assumptions to simplify the model.
\item \textbf{In section 3}, we introduce the methodology. We first construct a dynamic maximal flow model. Based on it we build a GUSH model, taking human behavior factors into consideration. We also adjust the GUSH model by including other factors such as the disabled people and the emergency personnel.
\item \textbf{In section 4}, we apply our model to determine an optimal evacuation plan for the Louvre. We consider several factors to make our model more adaptable to the real situation. A specific example is given to show how our model works facing a specific urgency.
\item \textbf{In section 5}, we carry out sensitivity analysis of the flow speed and the capacity of bottlenecks.
\item \textbf{At last}, we discuss the strengths and weaknesses of our model in detail and make conclusions. We give suggestions to the emergency management department of the Louvre.
\end{itemize}

\section{Assumptions}
\begin{itemize}
\item By technology, the emergency personnel of the Louvre can locate everyone instantly. Using a certain model, it can provide the optimal route for everyone dynamically.
\item The Louvre can provide the evacuation guide function in its official App. It serves as a
navigation, instructing the best way when emergency happens. Most people install the app and follow the instruction of the app, while some people who are selfish don't follow it, but tend to choose the shortest way out.
\item We assume that the capacity of the components of a building (rooms, stairs, passages, etc.) is proportional to their space area, which can be estimated from the map provided on the official website of Louvre (\url{https://www.louvre.fr/en/plan}). To make it simpler, we assume each stair has the same capacity.
\item We don't consider elevators since we assume the emergency (such as fire or bombing) will make it unsafe to take the elevator, but We assume there are elevators specially for the disabled when emergency happens.
\item Since the entrances/exits are blocked because of the outflow of people, the emergency personnel all enter through the extra entrances on the ground floor. They are commanded by the app and move to the most crowded places to help control the crowd. Because we don't know the location of the extra entrances, we assume the extra entrances distribute uniformly in the Louvre. To simplify the model, we assume the emergency personnel are only responsible for crowd control.
\end{itemize}

\section{Glossary \& Symbols}
\subsection{Glossary}
\paragraph{Being selfish} If everyone follows the App, the overall time is shortest, but some people may take a detour and be the last to evacuate. Ideally, everyone follows the instruction. However, considering the selfishness of human nature, people tend to make decisions in their own interests. We think a man who is “selfish” tends to take the shortest route, rather than the guided route.
\paragraph{Selfishness factor}  Some people may not follow the guide but take the shortest way to the nearest exit out of selfishness. Consequently, they deviate from the appointed route and disturb the global optimal model result, making the total evacuation time longer. The degree to which those selfish people affect the overall optimal model is defined as the "selfishness factor".
\paragraph{Disabled people factor} The disabled have special needs that make their optimal routing different from normal people. We define the degree to which those disabled people affect the GUSH model as the "disabled people factor".
\paragraph{Emergency personnel factor} The emergency personnel enter the building. They head to the most crowded passages to help control the crowd. We define the degree to which the emergency personnel affect the GUSH model as the "emergency personnel factor".
\subsection{Symbols}

\begin{table}[h]
  \caption{Symbols}
  \label{tab1}
  \centering
  \begin{tabular}{cc}
  \toprule
   \textbf{Symbol} & \textbf{Definition}\\
  \midrule
 $v_s$ & the source node \\
 $v_e$ & the sink node \\
 $v_i$ & the node $i$\\
 $v_iv_j$ & the edge connecting $v_i$ and $v_j$\\
 $\bm{E}$ & the set of the edges\\
 $C_{ij}$ & the capacity of the edge $v_iv_j$\\
 $f_{ij}$ & the flow of the edge $v_iv_j$\\
 $C^t_{ij}$ & the capacity of the edge $v_iv_j$ in the time period $t$\\
 $f^t_{ij}$ & the flow of the edge $v_iv_j$ in the time period $t$\\
 x & each person in the building\\
 $\bm{M}$ & the set of all the persons in the building\\
 $\bm{S}$ & the set of all the selfish persons in the building\\
 $\bm{D}$ & the set of all the disabled persons in the building\\
 $t$ & the time period of the dynamic optimal flow model \\
 $n$& the total number of the time periods\\
 $p^t_x$ & the possibility of the person x being selfish in the time period t\\
  \bottomrule
  \end{tabular}
\end{table}

\section{Model for Evacuation Planning}
In this section we develop three models: the dynamic maximal flow model, the GUSH model and the adjusted GUSH model. The last two are both established based on the first basic.
\subsection{Global Guidance: Dynamic Maximal Flow Model}
The maximal flow model is effective to figure out the overall quickest evacuation routing in a building \citep{lim2012capacitated}. Since the emergency personnel have the instant location of people, they can use this model and adjust the guide frequently, depending on the constant change of the distribution of people.

To use this model, firstly, we need to draw the network graph . As is shown in Figure \ref{fig4-1}, we see each component as a node and each passage as an edge. We add a source node and connect it to the node of each room. The capacity of these edges is the number of people in this room. We also add a sink node and connect it to the exits. The capacity of these edges is infinite. The capacity of other edges is the capacity of passages.

\begin{figure} [H]
\centering
\includegraphics{networkflow.jpg}
\caption{Network Graph}
\label{fig4-1}
\end{figure}

This maximal flow model should be dynamic. For each of the period $t$, the capacity of edges changes because some people already flow out. We consider the following.
\begin{eqnarray}
\label{equ1}
 & \textrm{maximize} &               \ \    \sum \limits_{(v_i,v_j)\in \bm{E}} f^t_{ij},\quad t=1, 2, \ldots,n \nonumber \\
 & \textrm{subject}\ \textrm{to} &    \ \   0\leq f^t_{ij}\leq C^t_{ij}\\
 &   &  \ \
\sum_{(v_i,v_k) \in  \bm{E}}f^t_{ik} - \sum_{(v_j,v_i)\in  \bm{E}}f^t_{ji}=
\left\{\begin{matrix}
\sum\limits_{(v_i,v_j) \in  \bm{E}}f^t_{ij} & i=s\\
0 & i \neq s,e\\
-\sum\limits_{(v_i,v_j) \in  \bm{E}}f^t_{ij} & i=e
\end{matrix}\right. \nonumber
\end{eqnarray}
where $v_i$ denotes the node $i$,  $f^t_{ij}$ and $C^t_{ij}$ respectively represents the flow and the capacity of the edge $v_iv_j$ in the time period $t$.

\subsection{Personal Behavior: GUSH Model}
Personal behavior is a significant factor when making the evacuation plan. Faced with urgent situations, people probably become panic, fear, and as a result, out of control \citep{zhang2005personal}. Here in our basic model, since people can see the nearest exit in the App,  they may also be uncontrollable out of selfishness. Although the basic model is the most timesaving plan for all, some people may take a detour and be the last to evacuate. For these people, chances are that they may choose the shortest way in their own interests. To take this into consideration, we add a selfishness factor to the basic model:

\begin{equation}
\label{equ2}
C^t_{ij}=C^{t-1}_{ij}-s^{t-1}_{ij},\ \ t = 2,3,\ldots, n
\end{equation}
  where $C^1_{ij}$ denotes the initial capacity of the edge $v_iv_j$.

It means in each time period $t$, the capacity of the edge $v_iv_j$ should be the capacity of the last period deducting the selfishness factor. This is because those selfish people occupy the passages which are not allocated to them, making this passage more crowded and prevent some others from passing through this way.

We use the \textbf{Dijkstra Algorithm} to formulate the shortest route. For each person x, defining $\bm{B}_x$ as the set of edges of the shortest route the selfish person x takes, $\bm{A}_x$ as the set of edges of the guided route the selfish person x should take initially, we have

\begin{equation}
\label{equ3}
a^{t}_{xij}=\left\{\begin{matrix}
1 &v_iv_j\in \bm{B}^t_x \\
-1 & v_iv_j\in \bm{A}^t_x\\
0 & else
\end{matrix}\right.
\end{equation}
\begin{equation}
\label{equ4}
s^{t}_{ij}=\sum_{x=1}^{\left | \bm{S}  \right |} a^{t}_{xij}
\end{equation}
where $a^t_{xij}$ is corresponding to the personal selfishness factor for person x of the edge $v_iv_j$ in the time period $t$.

In conclusion, \textbf{the GUSH model is presented as follows.}
\begin{eqnarray}
\label{equ5}
 & \textrm{maximize} &               \ \    \sum \limits_{(v_i,v_j)\in \bm{E}} f^t_{ij},\quad t=1, 2, \ldots,n \nonumber \\
 & \textrm{subject}\ \textrm{to} &    \ \   \sum_{(v_i,v_k) \in  \bm{E}}f^t_{ik} - \sum_{(v_j,v_i)\in  \bm{E}}f^t_{ji}=
\left\{\begin{matrix}
\sum\limits_{(v_i,v_j) \in  \bm{E}}f^t_{ij} & i=s\\
0 & i \neq s,e\\
-\sum\limits_{(v_i,v_j) \in  \bm{E}}f^t_{ij} & i=e
\end{matrix}\right.\\
 &   &  \ \   0\leq f^t_{ij}\leq C^t_{ij} \nonumber \\
 &  & \ \ C^t_{ij}=C^{t-1}_{ij}-s^{t-1}_{ij} \nonumber
\end{eqnarray}
where $v_i$ denotes the node $i$,  $f^t_{ij}$ and $C^t_{ij}$ respectively represents the flow and the capacity of the edge $v_iv_j$ in the time period $t$. $s^{t}_{ij}$ is defined in (\ref{equ3}) and (\ref{equ4}).

For each person, there is a probability of being selfish. We use the symbol $P^{t}_x$ to represent the probability of the person x being selfish at the time period $t$. We assume if $P^{t}_x>0.5$, the person x takes the shortest way. In a real sense, $P^{t}_x$ is dynamic, because at each period, people should make a decision: to "be selfish" or to follow the guide, especially when finding the shortest route is blocked.

The Figure \ref{fig4-2} is an example. Here for a person, he has two periods to make decisions. In $t_1$, the probability of being selfish is bigger than 0.5, which means he decides to choose the shortest way(blue). In $t_2$, because the shortest road is blocked, he faces two choices. One is following the App (green), with the possibility smaller than 0.5; the other is continuing to take the shortest way, taking another shortest way(yellow), with the possibility bigger than 0.5.

\begin{figure} [H]
\centering
\includegraphics[width=15cm]{123.jpg}
\caption{Two Cases of the Route Taken by the "Selfish" Person}
\label{fig4-2}
\end{figure}

$P^{t}_x$ can be forecasted since we can observe the behavior of the person in last periods. Below we illustrate how to forecast $P^{t}_x$ by utilizing the \textbf{exponential smoothing method}.
\begin{equation}
\label{equ6}
For\ x\in  \bm{M}, \ \
P^{t+1}_x=\eta \gamma ^t_x+(1-\eta )P^t_x
\end{equation}
where $\bm{M}$ is the set of all the persons in the building, $\eta$ represents the smoothing coefficient, and $\gamma ^t_x$ follows:
\begin{equation}
\label{equ7}
\gamma^t_x=\left\{\begin{matrix}
1 & x\ doesn't\ follow\ the\ guide\\
0 & x\ follow\ the\ guide
\end{matrix}\right.
\end{equation}

Rearranging (\ref{equ6}) produces
\begin{equation}
\label{equ8}
    P^{t+1}_x=\eta \gamma ^t_x +(1-\eta)*\eta \gamma^{t-1}_x + \ldots + (1-\eta)^i \eta \gamma^{t-i}_x+ \ldots + (1-\eta)^t P^1_x
\end{equation}

Here we assume $\eta=0.8$, so we can get
\begin{equation}
\label{equ9}
P^{t+1}_x=0.8\gamma ^t_x+0.16\gamma ^{t-1}_x+0.032\gamma ^{t-2}_x + \ldots
\end{equation}

It implies that the "older" the observation value is, the smaller effect it has on the forecast of the possibility.

\subsection{Disabled People \& Emergency Personnel: Adjusted GUSH Model}
To take the disabled people and the emergency Personnel into consideration, we add a disabled people factor and emergency personnel factor into our GUSH model:
\begin{equation}
\label{equ10}
    C^t_{ij}=C^{t-1}_{ij}-s^{t-1}_{ij}-d^{t-1}_{ij}-e^{t-1}_{ij},\quad t=2,3,\ldots,n
\end{equation}

Similar to the selfishness factor, we have
\begin{equation}
\label{equ11}
a^{t+1}_{xij}=
\left\{
  \begin{array}{ll}
    1 & v_i v_j\in \bm{F}^{t+1}_x\\
    -1 & v_i v_j\in \bm{C}^{t+1}_x\\
    0 & else
  \end{array}
\right.
\end{equation}
\begin{equation}
\label{equ12}
d^{t+1}_{ij}=\sum_{x=1}^{\left | \bm{D}  \right |} a^{t+1}_{xij}
\end{equation}
where $\bm{F}^{t+1}_x$ is set of the edges the disabled person/emergency personnel person x take at the time period $t+1$, $\bm{C}^{t+1}_x$ is the set of the edges of the guided route the disabled person/emergency personnel person x should take initially, $d^1_{ij}=0$.

For the emergency personnel, they should take the shortest way to the bottlenecks. For the disabled, they should take the shortest way to the elevators specially prepared for them. We use the Dijkstra Algorithm to formulate the shortest route. However, the disabled people can't take the passage that's too crowded out of safety. We use $g^t_{ij}$ to indicate the population density of the edge $ij$ in the time period $t$.
\begin{equation}
\label{equ13}
    g^t_{ij}=f^t_{ij}/c^t_{ij}
\end{equation}

We assume the disabled can only take the passages whose population density are no more than 0.5. Below we show the set of the passages acceptable for them.
\begin{equation}
\label{equ14}
    \bm{G}^t=\{v_iv_j|g^t_{ij}>0.5\}
\end{equation}
\begin{equation}
\label{equ16}
    \bm{D}^{t+1}_x=\{v_iv_j|v_iv_j\notin \bm{G}^t\}
\end{equation}

In conclusion, \textbf{the adjusted GUSH model is presented as follows.}
\begin{eqnarray}
\label{equ18}
 & \textrm{maximize} &               \ \
 \sum \limits_{(v_i,v_j)\in \bm{E}} f^t_{ij},\quad t=1, 2, \ldots,n
 \nonumber
 \\
 & \textrm{subject}\ \textrm{to} &    \ \
\sum_{(v_i,v_k) \in  \bm{E}}f^t_{ik} - \sum_{(v_j,v_i)\in  \bm{E}}f^t_{ji}=
\left\{\begin{matrix}
\sum\limits_{(v_i,v_j) \in  \bm{E}}f^t_{ij} & i=s\\
0 & i \neq s,e\\
-\sum\limits_{(v_i,v_j) \in  \bm{E}}f^t_{ij} & i=e
\end{matrix}\right.
\\
 &   &  \ \
 0\leq f^t_{ij}\leq C^t_{ij} \nonumber
 \\
 &  & \ \
 C^t_{ij}=C^{t-1}_{ij}-s^{t-1}_{ij}-d^{t-1}_{ij}-e^{t-1}_{ij} \nonumber
\end{eqnarray}
where $v_i$ denotes the node $i$,  $f^t_{ij}$ and $C^t_{ij}$ respectively represent the flow and the capacity of the edge $v_iv_j$ in the time period $t$, $s^{t}_{ij}$ is defined in (\ref{equ3}) and (\ref{equ4}), $d^{t-1}_{ij}$ and $e^{t-1}_{ij}$ are defined in (\ref{equ12}) and (\ref{equ13}).

\section{Model Applying to the Louvre}
\subsection{Basic Network Model in the Ideal Situation}
\paragraph{Drawing the network graph} According to the tourist map, we draw the network graph of each floor of the museum. The graph of Floor 0 and -1 are shown as follows.

\begin{figure} [H]
\centering
\includegraphics[width=15cm]{floor_0_comp.jpg}
\caption{Network Graph of the Floor 0}
\label{fig5-1}
\end{figure}

\begin{figure} [H]
\centering
\includegraphics[width=15cm]{floor_u1_comp.jpg}
\caption{Network Graph of the Floor -1}
\label{fig5-2}
\end{figure}

In Figure \ref{fig5-1} and Figure \ref{fig5-2}, the nodes are stylized as to suggest different building components, among which squares represent rooms, with the label of each room inside, circles represent stairs and lines represent passages, whose degree of thickness indicates the capacity. On each floor there are three kinds of stairs: the stairs only for walking up (which is represented by $S_u$), only for walking down ($S_d$) and for both up and down ($S$).

By determining the scale, we get the space area of rooms, passages and stairs. We use these data to estimate the capacity, assuming that the capacity is proportional to the space area.
\paragraph{Calculating the network model} We adopt the
the procedure of Edmond-Karp algorithm to run this dynamic maximal flow model. In this ideal situation, where everyone follows the App, it takes 11.6 minutes for all the occupants to go out. Figure \ref{fig5-3} shows the population density of one period during the whole evacuation periods.

\begin{figure} [H]
\centering
\includegraphics[width=15cm]{1234.jpg}
\caption{Population Density Graph of the Maximal Flow Model (the darker the colour, the denser the population)}
\label{fig5-3}
\end{figure}
According to the computer run of the model, there are altogether 38 bottle necks. Most are the stairs and passages directly connected to the exit. Some passageways between rooms that are slim are also bottle necks, such as Room 408 to Room 347, Room 183 to Room 181.

\subsection{GUSH Model Considering Specific Problems}
We calculate the GUSH model. Based on the results, the evacuation time is 15.2 minutes and the number of bottlenecks is 45. Figure \ref{fig5-4} shows the population density of one period during the whole evacuation periods.
\begin{figure} [H]
\centering
\includegraphics[width=15cm]{ttest.jpg}
\caption{Population Density Graph of the Adjusted GUSH Model}
\label{fig5-4}
\end{figure}

As is shown in Figure \ref{fig5-4}, there are more bottlenecks than those in the ideal situation. For the route of the emergency personnel, we take three groups as an example. They enter the extra entrances and head for the bottlenecks via the shortest routes.
\subsection{An Example of Applying Our Model}
We create an example of terror attack in the Louvre to justify our model. Assuming that on December 29th, 2019, a terror attack happens in the Room 338 on the ground floor. The managers use the GUSH model to give guidance for everyone. Figure \ref{fig5-5} shows the changed network flow graph according to the reality.

\begin{figure} [H]
\centering
\includegraphics[width=15cm]{floor_0_new_new.jpg}
\caption{Changed Network Flow Graph in the Case of Terror Attack}
\label{fig5-5}
\end{figure}

From Figure \ref{fig5-5}, we can see that the edges connecting the room where terror attack happens are removed. Calculating the model, we get the evacuation time, 18.3 minutes and the bottleneck, 48. Figure \ref{fig5-6} shows the population density of one period during the whole evacuation periods.
\begin{figure} [H]
\centering
\includegraphics[width=15cm]{app3.jpg}
\caption{Population Density Graph in the Case of Terror Attack}
\label{fig5-6}
\end{figure}
As is shown in Figure \ref{fig5-6}, the evacuation plan changes. The route of the emergency personnel also changes. This implies that our model is adaptable enough to react quickly to different emergencies.

\section{Sensitivity Analysis}
In this section, we change the value of the two parameters, the length of each time period and the capacity of the bottlenecks, in our adjusted GUSH model and test their influence on the evacuation time.
\subsection{Faster is Slower}
In our model, time is divided into time periods which are very short and of equal length so that we can recalculate results in every time period to provide real-time evacuation plans. The time period length is determined in consideration of the crowd flow rate. For example, if people run fast, we should shorten the time period length to update paths more frequently, and vice versa. Thus, the change of the time period length may well affects the outcome.

When applying our model in the above case, the time period length is set as 5 seconds under the assumption that people move at the speed of 1m/s. When people move faster or slower a bit, the time period length have many different values. We test these values in our model and get the results as follows.
\begin{table}[ht]
  \caption{Evacuation Time Change with the Time Period Length}
  \label{tab3}
  \centering
  \begin{threeparttable}
    \setlength{\extrarowheight}{2mm}
    \begin{tabular}{|c|ccccccccccc|}
    \hline
    \rowcolor[gray]{0.9}
    TPL\tnote{1}&3    & 3.3  & 3.6  & 3.9  & 4.2  & 4.5  & 4.8  & 5.1  & 5.4 & 5.7  & 6.0 \\
    \rowcolor{mycyan}
    ET \tnote{2}&20.9 & 19.8 & 18.6 & 17.6 & 16.8 & 16.2 & 15.6 & 15.3 & 16.3& 18.6 & 2.7\\
    \hline
    \end{tabular}
        \begin{tablenotes}
        \footnotesize
        \item[1] Time Period Length
        \item[2] Evacuation Time
      \end{tablenotes}
          \end{threeparttable}
\end{table}

\begin{figure} [H]
\centering
\includegraphics[width=10cm]{time_period.jpg}
\caption{Evacuation Time Change with the Time Period Length}
\label{fig8}
\end{figure}

As is shown in Figure \ref{fig8}, with the time period length increasing from 3s to 6s at the step of 0.2s, the evacuation time takes on an "U" shape, i.e., it reduces first and then increases. As mentioned above, the time period length reflects the crowed flow rate. The smaller length value indicates the larger flow rate. Thus, Figure \ref{fig8} can be also interpreted as a relationship between the crowed flow rate and the evacuation time, which is still an "U" shape, i.e., the slow or fast enough crowed flow rate leads to a long evacuation time.

From the analysis above, we find an interesting phenomenon: \textbf{faster is slower}. That is to say, if everyone seeks to reach a high moving speed, instead of being faster, the crowd flow rate for all slow down, eventually causing block.

\subsection{Optimal Expansion Percentage of Bottlenecks}

According to the application of our model in the above case, 45 bottlenecks are examined out of nearly 300 passages. Hence, we can recommend the managers to expand the capacity of some bottlenecks to reduce the possibility of block. However, the specific expansion percentage can be difficult to determine, because more expansion will inevitably lead to higher costs.

To figure out the expansion problem, we test the edge capacity parameter in our model to simulate the process of expansion, while observing the change of the evacuation time. For all the bottleneck edges, we increase part of their capacity values and get the results as follows.

\begin{table}[ht]
  \caption{Evacuation Time Change with the Expansion Percentage of Bottlenecks}
  \label{tab2}
  \centering
  \begin{threeparttable}
    \setlength{\extrarowheight}{2mm}
    \begin{tabular}{|c|ccccccccccc|}
    \hline
    \rowcolor[gray]{0.9}
    EPB\tnote{1} &0       & 0.1   & 0.2  & 0.3  & 0.4  & 0.5  & 0.6  & 0.7  & 0.8 &0.9    &1\\
    \rowcolor{mycyan}
    ET\tnote{2} &15.2    &14.6   & 12.9 & 11.2 & 8 & 7.8 & 7 & 6.9 & 6.8 & 6.7 & 6.7\\
    \hline
    \end{tabular}
        \begin{tablenotes}
        \footnotesize
        \item[1] Expansion Percentage of Bottlenecks
        \item[2] Evacuation Time
      \end{tablenotes}
          \end{threeparttable}
\end{table}

\begin{figure} [H]
\centering
\includegraphics[width=10cm]{expansion.jpg}
\caption{Evacuation Time Change with the Expansion Percentage of Bottlenecks}
\label{fig9}
\end{figure}
As is shown in Figure \ref{fig9}, we adjust the values of expansion percentage of bottlenecks in the interval of [0,1], with 0 representing no expansion at all and 1 representing doubling the original capacity. The evacuation time changes accordingly. With the expansion of the bottlenecks, the speed at which the evacuation time gets shorter tends to slow down.

Observing the trend, we can draw a conclusion: \textbf{the optimal expansion percentage of bottlenecks is around 60\%}. Because when the percentage exceeds this threshold, the declining rate of evacuation time approaches zero. In other words, in this period, expanding bottlenecks is worthless, for it will not bring about any change in evacuation time basically.

\section{Strengths and Weaknesses}
\subsection{Strengths}
\paragraph{Viewing from different angels} We develop our model from two angles. One is in the manager's position, the other is from the view of the evacuees. Thus our model is creative and considerable.
\paragraph{Considering different groups} We take different groups into consideration, including selfish people, disabled people and emergency personnel, making our model
comprehensive and and reflect the reality well.
\subsection{Weaknesses}
\paragraph{Demanding certain technology} In our model, the plan is dynamic and real-time, depending on the location of people. So we require that the managers of the museum can locate everyone and provide guide function in the official App.
\paragraph{Lacking accurate information} Because of several factors not considered and the lack of data, our model are not enough to indicate the accurate situation which has a risk of error.
\section{Conclusions}
In this paper, we develop a GUSH model to help the managers of the Louvre make an evacuation plan, which contains:
\begin{itemize}
\item An optimal route for each employee, including the special route for the disabled people.
\item An optimal route for the emergency personnel entering the museum and the way of using the extra entrances.
\item A global population distribution graph, showing the bottlenecks, which are critical for the managers to do the crowd control.
\end{itemize}

Based on our analysis, we propose several recommendations for the emergency management of the Louvre:
\begin{itemize}
\item The museum can add the evacuation guide function in their official App. The App is extremely efficient in planning the optimal route consuming the shortest time in a global view.
\item To improve the evacuation efficiency, the museum can do some reconstruction. According to our sensitivity analysis, the best strategy is to increase 60\% of the capacity of the bottlenecks, which can shorten the evacuation time to a high degree.
\end{itemize}

By adopting our GUSH model and making the most of technology, the museum emergency management can react quickly to any emergency. The GUSH model is also adaptable. It can be adopted to help design the evacuation plan for other large, crowded structures.
\addcontentsline{toc}{section}{Reference}
\bibliographystyle{apalike}
\bibliography{icmmcm}

\end{document}


\documentclass{memoir}
\usepackage{notestemplate}

%\logo{./resources/pdf/logo.pdf}
%\institute{Rice University}
%\faculty{Faculty of Whatever Sciences}
%\department{Department of Mathematics}
%\title{Class Notes}
%\subtitle{Based on MATH xxx}
%\author{\textit{Author}\\Gabriel \textsc{Gress}}
%\supervisor{Linus \textsc{Torvalds}}
%\context{Well, I was bored...}
%\date{\today}

\begin{document}

% \maketitle

% Notes taken on 02/08/21

\section{Quotient Modules and Isomorphism Theorems}
\label{sec:quotient_modules_and_isomorphism_theorems}

\begin{prop}[Modules of homomorphisms]
	Let \(R\) be a ring, and take \(R\)-modules \(\prescript{}{R}M\) and \(\prescript{}{R}N\).
	\begin{enumerate}
		\item If \(\varphi,\psi \in \textrm{Hom}_R(M,N)\), then define
			\begin{align*}
				(\varphi+\psi)(m) := \varphi(m) + \psi(m) \quad \forall m \in M\\
				(r \varphi) (m) := r \varphi(m) \quad \forall r \in R, m \in M
			\end{align*}
		This gives \( \textrm{Hom}_R(M,N)\) the structure of an \(R\)-module, which we denote by \(\prescript{}{R}{\textrm{Hom}_R(M,N)}\).
		\item We denote \( \textrm{Hom}_R(M,M)\) by \( \textrm{End}_R(M)\). We get that \( \textrm{End}_R(M)\) is a ring with addition defined as above, and multiplication as defined in the exercise. We call this the \textbf{endomorphism ring of \(M\)}, and elements are \textbf{endomorphisms}.
	\end{enumerate}
\end{prop}
There is a structure that combines being an \(R\)-module and a ring, which we call \(R\)-algebras.

\begin{defn}[\(R\)-algebra]
	Let \(R\) be a commutative ring with \(1_R\). A \textbf{(unital) \(R\)-algebra} is a unital ring \(A\) equipped with a unital ring homomorphism \(f:R\to A\) such that the subring \(f(R)\leq A\) is contained in the center \(Z(A)\).
\end{defn}
It is easy to see that \(A\) has a natural \(R\)-module structure given by \(ra \mapsto f(r)a\). This is not the only module structure, but it is the most natural.\\

\begin{exmp}[Endomorphism]
If \(R\) is commutative, then \(\prescript{}{R}{\textrm{End}}_R(M)\) is an \(R\)-algebra via the action of function composition \(r\varphi \mapsto r(\varphi (m))\).\\

	The unital ring homomorphism from \(R\to \textrm{End}_R(M)\) is given by \(r\mapsto r\cdot \textrm{Id}\), where \(\textrm{Id}\) is the identity endomorphism. When \(R\) has an identity, this gives \(\textrm{End}_R(M)\) an \(R\)-algebra structure, as the image is clearly in the center of \(\textrm{End}_R(M)\).
\end{exmp}
Notice that it isn't necessarily injective, as \(rm=0\) is possible. If \(R\) is a field, however, it will be injective in which case the image is the \textbf{subring of scalar transformations}.

\begin{defn}[\(R\)-algebra homomorphism]
	If \(A,B\) are two \(R\)-algebras, an \textbf{\(R\)-algebra homomorphism} is a ring homomorphism \(\varphi :A\to B\) such that, for all \(r \in R\) and \(a \in A\):
	\begin{align*}
		\varphi (r\cdot a) = r\cdot \varphi (a).
	\end{align*}
\end{defn}
It follows that if \(A\) is an \(R\)-algebra, then it satisfies \(r\cdot (ab) = (r\cdot a)b = a(r\cdot b)\) for all \(r \in R\) and \(a,b \in A\) because \(f(r)\) is in the center. If these conditions hold for a ring, then it defines an \(R\)-algebra-- hence it can be considered an alternate definition.

\subsection{Quotient Modules}
\begin{prop}
	Take \(R\) as a ring, and \(\prescript{}{R}M\) an \(R\)-module with \(R\)-submodule \(\prescript{}{R}N\).
	\begin{enumerate}
		\item The quotient group \(M / N\) can be made into an \(R\)-module \(\prescript{}{R}(M / N)\) via
			\begin{align*}
				R\times M / N \to M / N\\
				(r,m+N) \mapsto rm + N \quad \forall r \in R, \; m+N \in M / N
			\end{align*}
		\item The canonical projection map of groups
			\begin{align*}
				\pi:M\to M / N\\
				m\mapsto m+N \quad \forall m \in M
			\end{align*}
			is a surjective \(R\)-module map, with \( \textrm{Ker}\pi = N\).
	\end{enumerate}
\end{prop}

\begin{thm}[Module Isomorphism Theorems]
	Let \(R\) be a ring, and \(\prescript{}{R}M, \prescript{}{R}N\) to be \(R\)-modules.
	\begin{enumerate}[(i).]
		\item If \(\varphi \in \textrm{Hom}_R(M,N)\), then \( \prescript{}{R}{\textrm{Ker}}\varphi\) is a \(R\)-submodule of \(M\), and \(M / \textrm{Ker}\varphi \stackrel{R}{\cong} \varphi(M)\) as \(R\)-modules (by \(R\)-module isomorphism).
		\item If \(\prescript{}{R}A,\prescript{}{R}B\) are \(R\)-submodules of \(M\), then \((A+B) / B \stackrel{R}{\cong} A / (A\cap B)\) as \(R\)-modules.
		\item If \(\prescript{}{R}A,\prescript{}{R}B\) are \(R\)-submodules of \(M\) and \(A\subset B\), then
			\begin{align*}
			(M / A) / (B / A) \stackrel{R}{\cong} M / B
			\end{align*}
			as \(R\)-modules.
		\item Suppose \(\prescript{}{R}N\) is an \(R\)-submodule of \(\prescript{}{R}M\). Then there exists a bijection:
			\begin{align*}
				\left\{ \text{submodules } \prescript{}{R}A \text{ of \(\prescript{}{R}M\) containing \(\prescript{}{R}N\)} \right\} \iff \left\{ \text{submodules \(\prescript{}{R}(A / N)\) of \(\prescript{}{R}(M/N)\)} \right\} .
			\end{align*}
	\end{enumerate}
\end{thm}

\subsection{Direct Products}
\label{sub:direct_products}

Let \(R\) be a ring with \(1_R\).
\begin{prop}
	Let \(\prescript{}{R}M\) be an \(R\)-module, with \(\prescript{}{R}N_1,\ldots,\prescript{}{R}N_t\) as \(R\)-submodules. Then
	\begin{enumerate}[(i).]
		\item The sum of \(\left\{ N_i \right\}_{i=1}\) is
			\begin{align*}
				N_1+\ldots+N_t = \left\{n_1+\ldots+n_t \mid n_i \in N_i, \; i=1,\ldots,t \right\}
			\end{align*}
			and forms an \(R\)-module.
		\item The direct product of \(\left\{ N_i \right\} \) is
			\begin{align*}
				N_1\times \ldots\times N_t = \left\{(n_1,\ldots,n_t) \mid n_i \in N_i, \; i=1,\ldots,t \right\}
			\end{align*}
			and forms an \(R\)-module.
	\end{enumerate}
\end{prop}
One can also define the direct product of \(R\)-modules (i.e. not just submodules).

\begin{prop}
	Let \(\prescript{}{R}N_1,\ldots,\prescript{}{R}N_t\) be \(R\)-submodules of an \(R\)-module \(\prescript{}{R}M\). Then the following are equivalent:
	\begin{enumerate}[(i).]
		\item
			\begin{align*}
				\varphi:N_1\times \ldots\times N_t \to N_1+\ldots+N_t\\
				(n_1,\ldots,n_t) \mapsto n_1+\ldots+n_t
			\end{align*}
			is an \(R\)-module isomorphism
		\item \(N_j \cap (N_1+\ldots+N_{j-1}+N_{j+1} + \ldots N_t) = 0\) for all \(j=1,\ldots,t\)
		\item Every \(x \in N_1+\ldots+N_t\) can be written as \(n_1+\ldots+n_t\) uniquely for some \(n_i \in N_i\) for all \(i=1,\ldots,t\)
	\end{enumerate}
\end{prop}
If the proposition holds, then
\begin{align*}
	N_1\times \ldots\times N_t \stackrel{R}{\cong} N_1+\ldots+N_t
\end{align*}
and we refer to the structure as the direct sum of \(R\)-modules.
\end{document}

Abstract Algebra - Introductory/Algebra II/Notes/source/Lecture7 - QuotModules_IsoThms_Prod.tex


\section{Converting
Node Ages to Durations}
\label{sct_duration}

Sometimes you have information about the \textit{age} of a node rather than the
length of its branch. Consider the following phylogeny of major chordate groups:

\begin{center}
 \includegraphics{duration_1_svg.pdf}
\end{center}

Suppose we have the following information about the age of certain events (not
that it matters, I found it in Wikipedia and the Palaeos website
(\url{www.palaeos.com}):

\smallskip
\begin{tabular}{lr}
\textbf{event} & \textbf{age} (million years ago)\\
\hline
split of vertebrates into gnathostomes and conodonts & 530 \\
extinction of conodonts & 200 \\
split of chordates into vertebrates and urochordates & 540 \\
\end{tabular}
\smallskip

\noindent{}We can use the "branch length" field of Newick to specify ages, like
this:

\begin{samepage}
\verbatiminput{duration_2_nw.cmd}
\verbatiminput{duration_2_nw.out}
\end{samepage}

\noindent{}The "branch length" of \texttt{Vertebrata} becomes \texttt{530},
because the vertebrate lineage split into conodonts and gnathostomes at that
date\footnote{Of course there are other branches in the vertebrate lineage, but
they are not shown in this tree}. Note that the \texttt{Gnathostomata} leaf has
no age: this means that there are still living gnathostomes (such as you and
I\footnote{Well, at least \textit{I} am one}); the same goes for urochordates.
In other words, a leaf with no age has an implicit age of zero. This also
ensures that the leaves of the extant taxa are aligned.  The \texttt{Conodonta},
on the other hand, has an age although it is a leaf: this is because the
conodonts went extinct, around \texttt{200} Mya.

Now, if we were to display this tree without further ado, it would be nonsense.
We have to convert the ages into durations, and this is the function of
\duration{}:

\verbatiminput{duration_3_svg.cmd}
\begin{center}
 \includegraphics{duration_3_svg.pdf}
\end{center}

\noindent{}We can improve the graph by supplying option \texttt{-t} to
\display{}: this aligns the origin of the scale bar with the leaves and counts
backwards. To top it off, we'll specify the units as million years ago:

\verbatiminput{duration_4_svg.cmd}
\begin{center}
 \includegraphics{duration_4_svg.pdf}
\end{center}

Since you're curious, here is what the \texttt{age.nw} tree looks like if we
"forget" to run it through \duration:

\verbatiminput{duration_5_svg.cmd}
\begin{center}
 \includegraphics{duration_5_svg.pdf}
\end{center}

\noindent{}Now it looks as though only the conodonts are still alive, while the
gnathostomes and urochordates each had brief flashes of existence 200 and 730
million years ago, respectively. Don't show this to a palaeontologist.


\documentclass{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{latexsym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{xfrac}
\usepackage{bm}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage[thinc]{esdiff}

\newcommand\tab[1][1cm]{\hspace*{#1}}

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

%\pagestyle{fancy}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

\newcommand{\hmwkTitle}{Final Exam\ \#Set-09}
\newcommand{\hmwkDueDate}{GROUP NAME - WaiT A SecanD}
\newcommand{\hmwkClass}{MAT120 }
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{\item ANIKA PRIODORSHINEE MRITTIKA  [ Sec-07, ID-19101298 ]\\[5mm]
ANIKA TAHSIN MIAMI  [ Sec-02,  ID-19101518 ]\\[5mm]
SYED ZUHAIR HOSSAIN  [ Sec-07, ID-19101573 ]\\[5mm]
AKASH GHOSH  [ Sec-11, ID-19101425 ]\\[5mm]
ADIBA ANBAR AHONA  [ Sec-12, ID-19101257 ]\\[10mm]
}
\newcommand{\hmwkAuthorName}{\textbf{BRAC University}}

%
% Title Page
%

\title{
    \vspace{2in}
    \textmd{\texttt{\textbf{\hmwkClass:\ \hmwkTitle}}}\\
    \normalsize\vspace{0.2in}{\texttt{\textbf{\normalsize \hmwkDueDate}}}\\
    \vspace{0.1in}\large{\texttt{\hmwkClassInstructor\ \hmwkClassTime}}
    \vspace{2in}
}
\author{\texttt{\hmwkAuthorName}}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

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

                %Solution Number 01%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}
    \[      \textbf{\underline{Answer to the Question Number One}}
    \]
    \textbf{[Part a]}\\
    \vspace{5mm}\\
    \tab $\int^1_0 \int^x_0 4y \sqrt{x^2 - y^2}$dy dx
\\

Let , \\
$ x^2 - y^2 = u$\\
$\Rightarrow (0-2y)$ dy = du\\
$\Rightarrow-2y$ dy = du \\
$\Rightarrow4y$ dy = $-2$ du\\
\\
\\ If , $y=0$ ; $u =x^2$\\
\\ If , $y=x$ ; $u=0$\\
\\
\\
\\
\\$\int^1_0 \int^0_{x^2}(-2\sqrt{u})$ du dx\\
\\$= -2 \int^1_0 \left[\frac{(u)^{(\frac{1}{2}+1)}}{\frac{3}{2}} \right]^0_{x^2} $ dx\\
\\$= -2 \int^1_0 \left[\frac{(u)^{\frac{3}{2}}}{\frac{3}{2}} \right]^0_{x^2} $ dx\\
\\$= -2 \int^1_0 \left[\frac{(x^2 - y^2)^{\left(\frac{3}{2}\right)}}{\frac{3}{2}} \right]^x_{0} $ dx\\
\\$=-\frac{-2*2}{3} \int^1_0\big[[x^2 - x^2]^{\left(\frac{3}{2}\right)} - (x^2-0)^{\frac{3}{2}} \big] $ dx\\
\\$=-\frac{4}{3} \int^1_0 -(x^2)^{\frac{3}{2}} $\\
\\$=\frac{4}{3} \int^1_0x^3  $dx\\
\\$= \frac{4}{3}\left[\frac{x^4}{4}\right]^1_0 $\\
\\$= \frac{4}{3} * \frac{1}{4}$ $ \bigg[(1^4)- 0\bigg]$\\
\\$=\frac{1}{3}$\\
\vspace{3mm}\\
\tab\tab\tab\texttt{[ANSWER]}

\newpage
\textbf{[Part b]}\\
    \vspace{5mm}\\
\tab $\int^2_1 \int^2_z \int^{\sqrt{3}y}_0 \frac{y}{2x^2 +2y^2} $ dx dy dz
\\

Let ,\\
$u = \frac{x}{y} $ ; $ x= uy$\\
$\Rightarrow dx = du $\\
\\
\\
If , x$ = \sqrt{3} y $ ; u = $\sqrt{3}$\\
\\ If , x$ =0 $   ; u = $0$\\
\\
\\ $\int^2_1 \int^2_z \int^{\sqrt{3}}_0 \frac{y * y du}{2 u^2 y^2 +2y^2}$ dy dz\\
\\ $ = \int^2_1 \int^2_z \int^{\sqrt{3}}_0 \frac{ y^2 du}{2 y^2(u^2 +1)}$ dy dz\\
\\ $ =\frac{1}{2} \int^2_1 \int^2_z \int^{\sqrt{3}}_0 \frac{  du}{(u^2 +1)}$ dy dz\\
\\ $ =\frac{1}{2} \int^2_1 \int^2_z \left[tan^{-1} (u)\right]^{\sqrt{3}}_0$ dy dz\\
\\ $ =\frac{1}{2} \int^2_1 \int^2_z \left[tan^{-1} (\frac{x}{y})\right]^{\sqrt{3}y}_0$ dy dz\\
\\ $ =\frac{1}{2} \int^2_1 \int^2_z \left[tan^{-1} (\sqrt{3}) - tan^{-1}( 0)\right]$ dy dz\\
\\ $ =\frac{1}{2} \int^2_1 \int^2_z \left(\frac{\pi}{3}\right)$ dy dz\\
\\ $ =\left(\frac{1}{2}\right) \left(\frac{\pi}{3}\right) \int^2_1 \int^2_z $ dy dz\\
\\ $ =\left(\frac{\pi}{6}\right) \int^2_1 \left[y\right]^2_z $  dz\\
\\ $ =\left(\frac{\pi}{6}\right) \int^2_1 \left[2-z\right] $  dz\\
\\ $ =\left(\frac{\pi}{6}\right) \left[\left[2z\right]^2_1 - \left[\frac{z^2}{2}\right]^2_1\right] $  \\
\\ $ =\left(\frac{\pi}{6}\right) \left[\left(4-2\right) - \left(\frac{4}{2} - \frac{1}{2}\right)\right] $  \\
\\$= \frac{\pi}{6}(2-\frac{3}{2})$\\
\\$= \frac{\pi}{6} \left(\frac{4-3}{2}\right)$\\
\\$= \frac{\pi}{6}* \frac{1}{2}$\\
\\$= \frac{\pi}{12}$  \\
\vspace{3mm}\\
\tab\tab\tab\texttt{[ANSWER]}
\end{homeworkProblem}
\pagebreak

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

                %Solution Number 02%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}
    \[      \textbf{\underline{Answer to the Question Number Two}}
    \]
    \section{Solve the following 1st order DE:}
\textbf{[Part a]}\\
 \tab $\frac{2}{3}x\frac{dy}{dx}-{\frac{2}{3}y = \frac{2}{3}x} ; \ y(1)=2 $\\
 \vspace{5mm}\\
\begin{equation*}
\begin{aligned}
Given \ equation, \\
   &  \frac{2}{3}x\diff{y}{x}-{\frac{2}{3}y = \frac{2}{3}x}\\
   & \frac{2}{3}[x\diff{y}{x}-y] = \frac{2}{3}x\\
   & x\diff{y}{x}-y = x\\
   & \diff{y}{x}-\frac{1}{x}y = 1\\
   \\
   Solution:  \\
   & y \frac{1}{x} = \int 1* \frac{1}{x} dx + c\\
   & \frac{y}{x} = \ln x + c\\
   & y = x (\ln x + c ).....[1]\\
   &Again\ ,\ y(1)=2 \ then, \\
  & 2 = 1 * (\ln 1 + c)\\
   &2 = \ln 1 + c\\
   & \therefore c = 2\\
   & Putting\ the\ value\ of\ c\ into\ [1]\\
   & y = x(\ln x+2)\\
   \vspace{3mm}\\
\tab\tab\tab\texttt{[ANSWER]}
 \end{aligned}
 \qquad\Bigg\vert\qquad
 \begin{aligned}
  & Comparing\ with\ general\\\
  & equation\ of\ 1st\ order\ DE : \\
  & y' + P(x) y = Q(x)\\
 & Here,\ P(x) = \frac{1}{x}\ ; \ Q(x) = 1\\
 & general\ solution:\\
 & y I(x) = \int I(x) Q(x) dx + c\\ \\
  & Here,\ I(x)= e^{\int P(x)dx}\\
  & = e^{\int{-\frac{1}{x}dx}}\\
  &=  e^{-\ln x}\\
  &= e^\ln{\frac{1}{x}}\\
  &= \frac{1}{x}\\
 \end{aligned}
 \end{equation*}
 \newpage
\textbf{[Part b]}\\
\tab $(32y-8cosy) \frac{dy}{dx} - 24x^2 = 0 \ ; \ y(0)=0 $\\
\vspace{5mm}\\
\begin{equation*}
\begin{aligned}
given\ equation,\\
& (32y-8\cos y) \diff{y}{x} = 24x^2\\
& 8 (4y-\cos y) \diff{y}{x} = 24 x^2\\
& (4y-\cos y) \diff{y}{x} = 3x^2\\
& (4y-\cos y) dy = 3 x^2 dx\\
& \int (4y-\cos y) dy = \int 3x^2 dx\\
& \int 4ydy - \int \cos y dy = 3 \int x^2 dx\\
& 4 \frac{y^2}{2} - \sin y = 3 \frac{x^3}{3} + c\\
& 2 y^2 - \sin y = x^3+c..........[1]\\\\
given\ condition,\
& y(0)=0\\
& 2*0-\sin 0 = 0 + c\\
& \therefore c =0;\\
putting\ value\ of\ c\ in\ to\ [1],\\
& 2 y^2 - \sin y = x^3+ 0\\
& 2 y^2 - \sin y = x^3\\
\vspace{3mm}\\
\tab\tab\tab\texttt{[ANSWER]}
\end{aligned}
\end{equation*}
\end{homeworkProblem}
\pagebreak

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

                %Solution Number 03%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}
    \[      \textbf{\underline{Answer to the Question Number Three}}
    \]
    \textbf{[Part a]}
    \\
    \[
    \begin{split}
    Given,
    \\
    &(2 e^{2y} - 2y cos(xy)) dx + (4xe^{2y} - 2x cos(xy) + 4y ) dy =0
    \\
    &here,
    \\
    &M(x,y) = (2 e^{2y} - 2y cos (xy))
    \\
    &N(x,y) = (4xe^{2y} - 2 x cos (xy) + 4y)
    \\
    \\
    &\frac{\partial M}{\partial y} = \frac{\partial }{\partial y} (2 e^{2y} - 2y cos(xy))
    \\
    &\Rightarrow \frac{\partial M}{\partial y} = \frac{\partial }{\partial y} (2 e^{2y}) \frac{\partial}{\partial y} (2 y cos(xy))
    \\
    &\Rightarrow \frac{\partial M}{\partial y} = 4 e^{2y} - 2 (cosxy - xy(sinxy)
    \\
    \\
    & \frac{\partial N}{\partial x} = \frac{\partial }{\partial x} (4 x e^{2y} - 2 x cos(xy) + 4y)
    \\
     & \frac{\partial N}{\partial x} = \frac{\partial}{\partial x} (4 x e^{2y}) - \frac{\partial }{\partial x} (2x cos (xy) + 4y)
     \\
      & \frac{\partial N}{\partial x} = 4 e^{2y} - 2( cos (xy) - xy sin (xy))
      \\ \\ \\
      &\text{As, $\frac{\partial M}{\partial y} = \frac{\partial N}{\partial x}$ ,we have an exact equation}\\
   & We\: know,\\
    & \psi (x,y) = C\\
& Again,\\
&\psi (x,y) = \int N(x,y)dy \\
& = \int (4xe6(2y)-2xcos(xy)+4y)dy\\
& = \int 4ydy - \int 2cos(xy)dy+ \int 4xe^(2y)dy\\
& = 2y^2 - 2sin(xy)+2xe6(2y)+c_1\\
&\psi (x,y) = c_2\\
& 2y^2 - 2sin(xy)+2xe^(2y)+c_1 = c_2\\
&\therefore 2y^2 - 2sin(xy)+2xe^(2y) = C
\\ \\ \\ \\
    &\texttt{[ANSWER]}
    \end{split}
    \]
\textbf{[Part b]}
       \begin{align*}
           & (8x^2 + 12y^2 -80)dy = -4xydx\\
& \Rightarrow (8x^2 + 12y^2 -80)dy + 4xydx=0\\
& \Rightarrow (8x^2 + 12y^2 -80)\frac{dy}{dx} + 4xy = 0;\:\:\:[divided\:by\:dx] \\
& \Rightarrow (8x^2 + 12y^2 -80)y' + 4xy = 0\\
&\Rightarrow 4xy^4 + y^3(8x^2+12y^2-80)y' = 0 ;\:\:\:[multiplied\: by\: y^3]\\
&\Rightarrow 4xy^4dx + y^3(8x^2+12y^2-80)dy = 0;\:\:\:[multiplied\: by\: dx]
       \end{align*}
       \begin{align*}
           & Here,\\
           & M(x,y) = 4xy^4\\
           & N(x,y) = y^3(8x^2+12y^2-80)\\
           & \frac{\partial }{\partial y}(M) = \frac{\partial }{\partial y}4xy^4 = 16xy^3\\
& \frac{\partial}{\partial x}(N) = \frac{\partial }{\partial x} y^3 (8x^2 + 12y^2 - 80)\\
& \Rightarrow \frac{\partial }{\partial x}(N) =
y^3 \frac{\partial }{\partial x}(8x^2 + 12y^2-80)\\
& \Rightarrow\frac{\partial }{\partial x}(N) = y^3 16x = 16xy^3
       \end{align*}
      \begin{align*}
          As,\: \frac{\partial M }{\partial y} = \frac{\partial N}{\partial x},\: we\:get\:an\:exact\:equation.
      \end{align*}
      \begin{align*}
          & we\: know,\; \psi (x,y)= c\\
& so,\\
& \psi (x,y) = \int N(x,y)dy\\
& \;\:\:\:\:\:\:\:\:\:= \int y^3 (8x^2 +12y^2 -80)dy\\
& \;\:\:\:\:\:\:\:\:\: = \int 4(-20+3y^2 + 2x^2)y^3 dy\\
& \;\:\:\:\:\:\:\:\:\: = 4 \int (-20+3y^2+2x^2)y^3 dy\\
& Here,\: Let,\: u = (-20+3y^2 + 2x^2 ) and\: v'= y^3
      \end{align*}
      \pagebreak
      \begin{align*}
          \text{Applying integration by parts}\\
         & 4 \int (-20+3y^2 + 2x^2)y^3 dy\\
& = 4(\frac{1}{4}y^4 (-20+3y^2 + 2x^2 )- \int \frac{3y^5}{2}dy)\\
& = 4(\frac{1}{4}y^4 (-20+3y^2 +2x^2 - \frac{y^6}{4})\\
& = 2y^6 + 2x^2y^4-20y^4
      \end{align*}
      \begin{align*}
      & \therefore \psi (x,y) = \int N (x,y)dy = 2y^6 + 2x^2y^4-20y^4 +c_1\\
      & \psi (x,y) = c_2\\
      & 2y^6 + 2x^2y^4-20y^4 + c_1 = c_2\\
      &\therefore 2y^6 + 2x^2y^4-20y^4 = C\\
      \\ \\ \\ \\ \\ \\ \\ \\
    \texttt{[ANSWER]}
      \end{align*}
\end{homeworkProblem}
\pagebreak

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

                %Solution Number 04%

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

\begin{homeworkProblem}
    \[      \textbf{\underline{Answer to the Question Number Four}}
    \]
    \textbf{[Part a]}
    \\
     \tab$y''+y'+\frac{17}{4}y=0;y(0)=-1,y'(0)=2$\\
    \vspace{5mm}\\
Let,
\begin{align*}
    &y=e^{rt}\:\:\:where\:\:\:r=root\:\:\:of\:\:\:the\:\:\:auxiliary\:\:\:equation\\
    &\therefore y''=r^2 e^{rt},y'=r e^{rt}\\
    &\therefore r^2 e^{rt}+r e^{rt}+\frac{17}{4}e^{rt}=0\\
    &\Rightarrow r^2+r+\frac{17}{4}=0 &[divided\:\:\:by\:\:\:e^{rt}]\\
    &\therefore r=\frac{-1\pm \sqrt{1-17}}{2}=-\frac{1}{2}\pm2i
\end{align*}

The two solutions of the differential equation,
\begin{align*}
    &y_1(t)=e^{(-\frac{1}{2}+2i)t}=e^{-\frac{t}{2}}[\cos (2t)+i\:\sin (2t)]\\
    &y_2(t)=e^{(-\frac{1}{2}-2i)t}=e^{-\frac{t}{2}}[\cos (2t)-i\:\sin (2t)]\\
    &Let,\\
    &u(t)=e^{-\frac{t}{2}}\cos (2t)\\
    &v(t)=e^{-\frac{t}{2}}\sin (2t)
\end{align*}
\begin{align*}
    \therefore y_c(t)&=c_1u(t)+c_2v(t)\\
    &=e^{-\frac{t}{2}}(c_1\cos (2t)+c_2\sin (2t))\\
\end{align*}

For $y(0)=-1,$
\begin{align*}
    -1&=(c_1\cos 0+c_2\sin 0)\\
    \therefore c_1&=-1
\end{align*}

For $y'(0)=2,$
\begin{align*}
    y'(t)&=\frac{d}{dt} (e^{-\frac{t}{2}})(c_1\cos (2t)+c_2\sin (2t))+\frac{d}{dt}(c_1\cos (2t)+c_2\sin (2t))e^{-\frac{t}{2}}\\
    &=-\frac{1}{2} e^{-\frac{t}{2}}(c_1\cos (2t)+c_2\sin (2t))+(-2c_1\sin (2t)+2c_2\cos (2t))e^{-\frac{t}{2}}\\
    \Rightarrow 2&=-\frac{1}{2}c_1+2c_2\\
    \Rightarrow 2c_2&=\frac{1}{2}(-1)+2\\
    \therefore c_2&=\frac{3}{4}
\end{align*}
$$\therefore y_c=e^{-\frac{t}{2}}(-\cos (2t)+\frac{3}{4}\sin (2t))$$\\
\vspace{3mm}\\
\tab\tab\tab \texttt{[ANSWER]}
\newpage
\textbf{[Part b]}
\\
\tab$\frac{1}{2}\frac{d^2y}{dy^2}-5\frac{dy}{dx}+\frac{25}{2}y=0;y(0)=1,y'(0)=1$\\
\vspace{5mm}\\
Let,
\begin{align*}
    &y=e^{rt}\:\:\:where\:\:\:r=root\:\:\:of\:\:\:the\:\:\:auxiliary\:\:\:equation\\
    &\therefore y''=r^2 e^{rt},y'=r e^{rt}\\
    &\frac{1}{2}\frac{d^2y}{dy^2}-5\frac{dy}{dx}+\frac{25}{2}y=\frac{1}{2} y''-5y'+\frac{25}{2}y=0\\
    &\Rightarrow \frac{1}{2}r^2 e^{rt}-5r e^{rt}+\frac{25}{2}e^{rt}=0\\
    &\Rightarrow \frac{1}{2}r^2-5r\frac{25}{2}=0 &[divided\:\:\:by\:\:\:e^{rt}]\\
    &\Rightarrow r^2-10r+25=0\\
    &\Rightarrow(r-5)^2=0
\end{align*}\\
The roots $r_1=r_2=5$ are real and equal.\\
We know, if a differential equation is linear and have constant coefficient, then for root $\lambda_1=\lambda_2$, the general solution, $y_c=c_1 e^{\lambda_1x}+c_2 xe^{\lambda_1x}$
$$y_c=c_1e^{5t}+c_2 te^{5t}$$\\
For $y(0)=1,$\\
   $$1=c_1$$\\
For $y'(0)=1,$
\begin{align*}
y’&=5c_1 e^{5t}+c_2 e^{5t}+5c_2 te^{5t}\\
\Rightarrow 1&=5c_1+c_2\\
\Rightarrow c_2&=1-5\\
&=-4\\
\end{align*}
$$\therefore y_c=e^{5t}-4te^{5t}$$\\
\vspace{3mm}\\
\tab\tab\tab \texttt{[ANSWER]}
\end{homeworkProblem}
\pagebreak

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

                %Solution Number 05%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}
    \[ \textbf{\underline {Answer to the Question Number Five}}
    \]
    \textbf{ Solve the following Second Order Differential Equation}
    \\
    \textbf{[Part a]}
    \\
    \[
    \begin{split}
    Given,
    \\
    &{2y}'' - {4y}' + 2y = 2e^{x}
    \\
    \Rightarrow &{y}'' - {2y}' + y = e^x \ \ \ \ \ \ \ \ [\text{dividing both side by 2}]
    \\ \\
    let,
    \\
    &y = e^{mx}
    \\
    &y' = m e^{mx}
    \\
    &{y}'' = m^2 e^{mx}
    \\
    \text{For complimentary function:}
    \\
    &\therefore m^2 e^{mx} - 2me^{mx} + e^{mx} = 0
    \\
    \Rightarrow & m^2 - 2m + 1 = 0\\
    \Rightarrow & m^2 - m -m + 1 = 0\\
    \Rightarrow & m(m-1) - 1(m-1) = 0\\
    \Rightarrow & (m-1)(m-1) = 0\\
    \therefore  \ & m_1 = m_2 = 1\\
    \\
    \therefore \ & y_c = c_1 e^x + c_2 x e^x
    \end{split}
    \]
    \pagebreak
    \[
    \begin{split}
        \textbf{For particular solution:}\\
        y_p &= x^2 (A e^x) \ \ \ \ \ \ \ \ \ \ \ [to \ make \ it \ distinct \ from \ y_c]
        \\
        {y_p}' &= (A e^x x^2) \frac{d}{dx}
        \\
        &= A e^x x^2 + 2 A e^x x
        \\[5mm]
        & {y_p}'' = (A e^x x^2) \frac{d^2}{dx^2}
        \\
        &= (A e^x x^2)\frac{d}{dx} + (2 A e^x x) \frac{d}{dx}
        \\
        &= A 2 e^x +  A e^x x^2 + A 2 e^x x + A 2 e^x x
        \\
        &= A(2e^x + e^xx^2 + 4 e^x x)
        \\\\
        &\therefore {y}'' - 2{y}' + y = e^x
        \\
        &\Rightarrow A 2 e^x + A e^x x^2 + A 4 e^x x - 2 A e^x x + A e^x x^2 = e^x
        \\
        &\therefore 2 A e^x = e^x
        \\
        &\Rightarrow 2 A = 1
        \\
        &\therefore A = \frac{1}{2}
        \\
        &\therefore y_P = \frac{1}{2} \times e^x x^2
        \\\\
        \therefore y_G(x) &= y_C(x) + y_P(x)
        \\
        &= c_1 e^x + c_2 x e^x + \frac{e^x x^2}{2}
        \\
        \\
        \\
        & & \texttt{[ANSWER]}
    \end{split}
    \]
\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    \textbf{[Part b]}
    \\
    \vspace{5mm}
    \[
    \begin{split}
        Given,
        \\
        & 5 \frac{d^2y}{dx^2} + 20y = 15 sin 2x
        \\
        \Rightarrow & 5{y}'' + 20 y = 15 sin 2x
        \\
        \Rightarrow & {y}'' + 4y = 3 sin 2x \ \ \ \ \ \ \ \ \ [dividing \  both \ side \ by \ 5]
        \\
        \\
        let,
        \\
        & y = e^{mx}
        \\
        \Rightarrow & y' = m  e^{mx}
        \\
        \Rightarrow & y'' = m^2  e^{mx}
        \\ \\ \\
        \textbf{For complimentary function:}
        \\
        m^2  e^{mx} + 4  e^{mx} = 0
        \\
        \Rightarrow & m^2 + 4 = 0
        \\
        \Rightarrow & m^2 = -4
        \\
        \therefore & m = \pm \sqrt{-4}
        \\
        & = \pm i \sqrt{4}
        \\
        & = 0 \pm  i\sqrt{4}
        \\ \\
        y_c &= e^{0 \cdot x} (c_1 cos \sqrt{4}x + c_2 sin \sqrt{4}x)
        \\
        y_c &= c_1 cos \sqrt{4}x + c_2 sin \sqrt{4}x
        \\
        &= c_1 cos 2x + c_2 sin 2x
        \\ \\ \\
        \textbf{For particular solution:}
        \\
        y_p &= e ^{0 \cdot x} (A x cos 2 x + B x sin 2x)
        \\
        &= A x cos 2x + B x sin 2x
        \\
        \Rightarrow {y_p}' &= A cos 2x - 2 A sin 2 x + B sin 2x + 2Bx cos 2x
        \\
        \Rightarrow {y_p}'' &= - 2A sin 2x - 2A sin 2x - 4Ax cos 2x + 2B cos 2x + 2B cos 2x - 4B sin 2 x
        \\
        & = -4A sin 2x - 4 A x cos 2x + 4B cos 2x - 4B x sin 2x
        \\\\
        \therefore y'' + 4y &= -4A sin 2x - 4Ax cos 2x + 4B cos 2x - 4B x sin 2x + 4 cos 2x + 4B x sin 2x
        \\[5mm]
        \Rightarrow 3 sin 2x &=  -4A sin2x + 4 B cos 2x . \ . \ . \ . \  . \ . \ . \ . \ . \ . \ . \ . \ . \ (i)
    \end{split}
    \]
    \pagebreak

    \[
    \begin{split}
        \text{equate coefficient of sin(2x) on both sides of equation (i):}
        \\
        -4A = 3
        \\
        A = - \frac{3}{4}
        \\ \\
        \text{equate coefficient of cos(2x) on both sides of equation (i):}
        \\
        4B = 0
        \\
        \therefore B = 0
        \\
        \\
        \therefore y_p &= A cos 2 x + 0 \times sin 2x
        \\
        & = - \frac{3}{4} x cos 2 x
        \\ \\
        \therefore y_G(x) &= y_c (x) + y_p (x)
        \\
        &= c_1 cos 2x + c_2 sin 2x - \frac{3}{4} x cos 2 x
        \\ \\ \\ \\
        \texttt{[ANSWER]}
        \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\
        \texttt{[THANK YOU]}
    \end{split}
    \]
\end{homeworkProblem}

%                       END
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

\end{document}


% !TEX root = ../../../proposal.tex
\subsection{The OpenSSL ``extra clear'' oracle}

%\subsubsection{A key recovery attack on SSLv2 handshakes}

\label{sec:clear-key-vuln}

Prior to the fix, OpenSSL servers improperly allowed the \texttt{ClientMasterKey} message to contain
\texttt{clear\_key\_data} bytes for \emph{non-export} ciphers.  When such bytes are present,
the server substitutes them for bytes from the
encrypted key. For example, consider the case that the client chooses a 128-bit cipher and sends a 16-byte
encrypted key $k\pos{1}, k\pos{2}, \ldots, k\pos{16}$ but, contrary to the protocol specification, includes 4
null bytes of \texttt{clear\_key\_data}. Vulnerable OpenSSL versions will
construct the following \texttt{master\_key}:

\small $[00\ 00\ 00\ 00\ k\pos{1}\ k\pos{2}\ k\pos{3}\ k\pos{4}\ \dots\ k\pos{9}\ k\pos{10}\ k\pos{11}\ k\pos{12}]$\normalsize

This enables a straightforward key recovery attack against such versions.
An attacker that has intercepted an \ssltwo connection takes the RSA
ciphertext of the encrypted key and replays it in non-export handshakes to
the server with varying lengths of \texttt{clear\_key\_data}. For a 16-byte
encrypted key, the attacker starts with 15 bytes of clear key, causing the server to use the \texttt{master\_key}:

\small$[00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ k\pos{1}]$\normalsize

The attacker can brute force the first byte of the encrypted key by
finding the matching \texttt{ServerVerify} message among 256
possibilities. Knowing $k\pos{1}$, the attacker makes another
connection with the same RSA ciphertext but 14 bytes of clear key,
resulting in the \texttt{master\_key}:

\small $[00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ 00\ k\pos{1}\ k\pos{2}]$\normalsize

% Note: The number below is 15, since you the original intercepted connection
% servers as the case with 0 bytes of clear_key_data.
The attacker can now easily brute force $k\pos{2}$. With only 15 probe
connections and an expected $15 \cdot 128 = 1,920$
trial encryptions, the attacker learns the entire \texttt{master\_key} for the
recorded session.

%\subsubsection{An improved oracle for DROWN}

As this oracle is obtained by improperly sending unexpected clear-key bytes,
we call it the Extra Clear oracle.

This session key-recovery attack can be directly converted to a Bleichenbacher oracle. Given a candidate ciphertext and symmetric key length $\ell_k$, the attacker sends the ciphertext with $\ell_k$ known bytes of \texttt{clear\_key\_data}. The oracle decision is simple:
\begin{itemize}
\item If the ciphertext is valid, the \texttt{ServerVerify} message will reflect a \texttt{master\_key} consisting of those $\ell_k$ known bytes.
\item If the ciphertext is invalid, the \texttt{master\_key} will be replaced with $\ell_k$ random bytes (by following the countermeasure against the Bleichenbacher attack), resulting in a different \texttt{ServerVerify} message.
\end{itemize}

This oracle decision requires one connection to the server and one \texttt{ServerVerify} computation. After the attacker has found a valid ciphertext corresponding to a $\ell_k$-byte encrypted key, they recover the $\ell_k$ plaintext bytes by repeating the key recovery attack from above.  Thus our oracle $\OracleSSLclear(c)$ requires one connection to determine whether $c$ is valid.  After $\ell_k$ connections, the attacker additionally learns the $\ell_k$ least significant bytes of $m$.  We model this as a single oracle call, but the number of server connections will vary depending on the response.


\input{../../_common/preamble}

\title{Introduction to prediction}

\begin{document}

\maketitle

\begin{frame}{Contents}
    \tableofcontents[hideallsubsections]
\end{frame}

\section{Prediction and loss functions}

\begin{frame}{Guessing values}
    \begin{itemize}
        \item $Y$ = `time it takes you to get to work in the morning'
        \item You have some realisations $y_{1}, y_{2}, \ldots$ collected over
              time
        \item You want to predict the value of $Y$ tomorrow
    \end{itemize}
    \vfill\pause
    \begin{center}
        {\Large%
         How do you do this?} \\[1em]
        {If you prefer, what's the \alert{optimal point forecast} for $Y$?}
    \end{center}
\end{frame}

\begin{frame}{Loss functions}
    Before you can answer, you need a \alert{loss function} that\ldots
    \begin{itemize}
        \item Measures how big an error you're making with your guess $g$
        \item Can be minimised to obtain the `best' $g$
    \end{itemize}
    \vfill\pause
    \begin{center}
        \renewcommand*{\arraystretch}{1.5}
        \begin{tabular}{ll}
            \toprule
            \textbf{Mean squared error}  & $\operatorname{MSE}(g) = \E{ (Y - g)^{2}}$ \\
            \textbf{Mean absolute error} & $\operatorname{MAE}(g) = \E{ |Y - g|}$ \\
            \bottomrule
        \end{tabular}
    \end{center}
\end{frame}

\begin{frame}{Towards prediction\ldots}
    Usually we have at least another variable $X$ that we believe to be related
    to $Y$\ldots
    \vfill\pause
    \begin{block}{Idea}
        Using some function $f$ of $X$, we should be able to predict $Y$
        `\alert{better}' (i.e.\ reduce the mean error) than by ignoring it
        \vfill
        \[
            g
            \;
            \rightarrow
            \;
            f(X)
            \quad
            \text{and thus}
            \quad
            \operatorname{MSE}(f\,) = \E{(Y - f(X))^{2}}
        \]
    \end{block}
\end{frame}

\begin{frame}[t]{What should $f$ be?}
    \only<1>{%
        Consider the decomposition
        \[
            Y\,|\,X = f^{\,\star}(X) + \epsilon
        \]
        \begin{itemize}
            \item $f^{\,\star}$ is the optimal prediction (conditional on knowing $X$)
            \item $\epsilon$ is a random variable (since $f^{\,\star}$ is not)
            \item $\E{\epsilon} = 0$ without loss of generality
        \end{itemize}}
    \only<2>{%
        For the MSE, it can be shown that
        \[
            f^{\,\star}(x) = \E{ Y\,|\,X = x }
        \]
        \vfill
        $f^{\,\star}$ is what we'd like to know when we want to predict $Y$
        given $X$
        \begin{flushright}
            \ldots but can we?
        \end{flushright}}
\end{frame}

\section{Bias\hyp{}variance trade\hyp{}off}

\begin{frame}[t]{Bias\hyp{}variance trade\hyp{}off}
    \only<1>{%
        Suppose that\ldots
        \begin{itemize}
            \item The `true' regression function is $f^{\,\star}$
            \item We have to make do with some suboptimal $f$
        \end{itemize}
        \vfill
        Let's start by expanding\ldots
        \begin{align*}
            (Y - f \,)^{2}
            &= ( Y - f^{\,\star} + f^{\,\star} - f \,)^{2} \\
            &= [ ( Y - f^{\,\star} ) + ( f^{\,\star} - f \,) ]^{2} \\
            &= ( Y - f^{\,\star} )^{2}
               + 2 ( Y - f^{\,\star} ) ( f^{\,\star} - f \,)
               + ( f^{\,\star} - f \,)^{2}
        \end{align*}}
    \only<2>{%
        Now take the expectation\ldots
        \[
            \E{( Y - f^{\,\star} )^{2}
               + 2 ( Y - f^{\,\star} ) ( f^{\,\star} - f \,)
               + ( f^{\,\star} - f \,)^{2}}
        \]
        \vfill
        Since $Y - f^{\,\star} = \epsilon$ and $\E{\epsilon} = 0$\ldots
        \begin{itemize}
            \item $\E{( Y - f^{\,\star} )^{2}} = \V{\epsilon}$
            \item $\E{Y - f^{\,\star}} = \E{\epsilon} = 0$
            \item $\E{( f^{\,\star} - f \,)^{2}} = ( f^{\,\star} - f \,)^{2}$ (non\hyp{}random)
        \end{itemize}}
    \only<3>{%
        \[
            \operatorname{MSE}(f\,) = \alert{\V{\epsilon}} + ( f^{\,\star} - f \,)^{2}
        \]
        \vfill
        \begin{block}{Variance $\V{\epsilon}$}
            \begin{itemize}
                \item Doesn't depend on $f$, just on `how hard' it is to predict
                      $Y\,|\,X = x$
                \item It's the unpredictable, irreducible fluctuation around
                      even the best prediction (randomness rules our lives!)
            \end{itemize}
        \end{block}}
    \only<4>{%
        \[
            \operatorname{MSE}(f\,) = \V{\epsilon} + \alert{( f^{\,\star} - f \,)^{2}}
        \]
        \vfill
        \begin{block}{Bias $( f^{\,\star} - f \,)^{2}$}
            \begin{itemize}
                \item It's the `extra error' we get from not knowing $f^{\,\star}$
                \item It's also the amount by which we are systematically off
            \end{itemize}
        \end{block}}
    \only<5>{%
        Since $f$ is itself estimated from a sample (it's actually $\hat{f}\,$),
        we have\ldots
        \begin{itemize}
            \item The \alert{irreducible variance} due to the stochastic process
            \item The \alert{bias} in approximating $f^{\,\star}$ using $f$
            \item The additional \alert{estimation variance} of $\hat{f}$
        \end{itemize}
        \vfill
        \begin{block}{Consistent methods}
            \begin{itemize}
                \item Bias and estimation variance $\to 0$ as the sample size
                      increases
                \item Different consistent methods may converge at different
                      rates
            \end{itemize}
        \end{block}}
    \only<6>{%
        \begin{center}
            \vfill
            \includegraphics[width=\textwidth]{figures/underfitting_overfitting} \\[\bigskipamount]
            {\scriptsize%
             From Andrew Ng's \textit{Machine Learning} course}
            \vfill
        \end{center}}
\end{frame}

\section{Generalisability}

\begin{frame}{Bias\hyp{}variance trade\hyp{}off and generalisability}
    \begin{center}
        \includegraphics[height=0.8\textheight]{figures/generalisability} \\
        {\scriptsize%
         From \textit{The Elements of Statistical Learning}}
    \end{center}
\end{frame}

\begin{frame}{Cross\hyp{}validation}
    \begin{block}{General idea}
        \begin{itemize}
            \item Fit several models on subsets of the data
            \item Measure performance of each
            \item Compute the mean performance
        \end{itemize}
    \end{block}
\end{frame}

\begin{frame}{$k$-fold cross\hyp{}validation}
    \begin{itemize}
        \item Split the data into $k$ groups (a.k.a.\ `folds')
        \item Repeat for each fold:
              \begin{itemize}
                  \item Fit the model using all but the selected fold
                  \item Measure performance on the selected fold
              \end{itemize}
        \item Compute the mean performance across folds
    \end{itemize}
\end{frame}

\begin{frame}{Regularisation}
        \begin{itemize}
        \item Penalise `large' coefficients by shrinking them
        \item Helps avoid overfitting
        \item Requires \alert{tuning} of an additional parameter $\alpha$
              representing the `weight' of the penalty (relative to the
              prediction error)
    \end{itemize}
    \vfill
    \begin{center}
        \renewcommand*{\arraystretch}{1.5}
        \begin{tabular}{lll}
            \toprule
            $L_{1}$ & LASSO & $\sum_{j} | \beta_{j} |$ \\
            $L_{2}$ & Tikhonov or ridge & $\sum_{j} \beta_{j}^{2}$ \\
            \bottomrule
        \end{tabular}
    \end{center}
\end{frame}

\end{document}


% !TEX root =  paper.tex
\begin{figure*}[t]
	\begin{center}
		\begin{minipage}{0.48\linewidth}
			\centering
			\includegraphics[width=0.9\linewidth]{./figures/encoding_diagram_opt.pdf}
		\end{minipage}
		\begin{minipage}{0.48\linewidth}
			\centering
			\includegraphics[width=0.9\linewidth]{./figures/window_values.pdf}
		\end{minipage}
	\end{center}
	\caption{Compresso works by dividing up the segmentation data into small blocks. On the left we show the intersection of three segments in a $4\times4\times1$ window. We extract a boundary map from this segmentation to transform the window into an integral value between $0$ and $2^{16} - 1$. This window has an encoded value of 50,978 $(2^1 + 2^5 + 2^8 + 2^9 + 2^{10} + 2^{14} + 2^{15})$. The location $i$ requires some additional bookkeeping. On the right are the $100$ most common $8 \times 8 \times 1$ windows accounting for $\sim82\%$ of the volume on a representative dataset.}
	\label{fig:compression}
\end{figure*}

\section{Compression of Label Volumes}

An often overlooked aspect of these segmentation datasets is how to efficiently store the label volumes.
These label volumes are often 32- or 64-bit to account for the massive number of neurons that interweave through a cubic millimeter.
Uncompressed, a cubic millimeter of segmentation data is nearly 20 petabytes.
Thus, compression techniques are needed for fast transmission and cost-efficient storage.

\subsection{Related Works}

General-purpose compression schemes~\cite{collet2016smaller,deutsch1996zlib,google2016brotli,lehmann2016liblzf,oberhumer2005lzo,pavlov2007lzma,seward1998bzip2,vandevenne2016zopfli,welch1984technique,ziv1978compression} are not optimized for this data.
These methods do not exploit the typical characteristics of label volumes such as large invariant regions without natural relationship between label values.
These properties render 2D image compression schemes inadequate since they rely on frequency reduction (using e.g., wavelet or discrete cosine transform) and value prediction of pixels based on local context (differential pulse-code modulation)~\cite{roelofs1999png,skodras2001jpeg}.
Color space optimization strategies in video codecs~\cite{aimar2005x264} also have no effect on label volumes, even though the spatial properties of a segmentation stack (\textit{z}-axis) are similar to the temporal properties of video data (time-axis).
A compression scheme designed specifically for label volumes is part of the visualization software Neuroglancer~\cite{google2016compressed}.
This method exploits segmentation homogeneity by creating small blocks with $N$ labels and reducing local entropy to $\log_2{N}$ per pixel.
Lookup tables then decode the values $[0,N)$ to the original 64-bit labels.

\subsection{Method}

We propose Compresso, which is specifically designed for compression of EM label volumes~\cite{matejek2017compresso}.
Compresso works by decoupling the two important components across the image stack: per-segment shape and per-pixel label.
To encode the segment shapes, we consider the boundary pixels between two segments.
Removing the per-pixel labels, we produce a boundary map for each slice where a pixel $(x, y, z)$ is 1 if either pixel at $(x + 1, y, z)$ or $(x, y + 1, z)$ belongs to a different segment (Fig.~\ref{fig:compression}, left).
The boundary map is divided into non-overlapping congruent 3D windows. If there are $n$ pixels per window, each window $w$ is assigned an integer $V_w \in [0, 2^n)$ where $V_w$ is defined as:

\begin{equation}
V_w = \sum_{i = 0}^{n - 1} \mathbb{I}(i) 2^i,
\end{equation}

\noindent
and $\mathbb{I}(i)$ is 1 if pixel $i$ is on a boundary and 0 otherwise.
Figure~\ref{fig:compression}, left, shows an example segmentation with a window size of $4 \times 4 \times 1$.

A priori, each window could take any of $2^n$ distinct values, and therefore require $n$ bits to encode without further manipulation.
However, boundaries in segmentation images are not random, and many of these values never appear.
Indeed, we find that a small subset of high-frequency $V_w$ values accounts for most windows, allowing for significant compression.
Figure~\ref{fig:compression}, right, shows the 100 most common windows for a representative connectomics dataset.
These 100 frequently occurring windows account for approximately 82\% of the over 1.2 million $V_w$ values in this dataset.
Nearly all of these windows correspond to simple lines traversing through the window.
For contrast, we also provide 5 randomly generated windows that never occur in the dataset.

We define $N$ as the number of distinct $V_w$ representing all of the windows in an image stack.
We construct an invertible function $f(V_w) \to [0, N)$ to transform the window values into a smaller set of integers.
For all real-world segmentations $N \ll 2^n$; however, we assume no constraint on $N$ in order to guarantee lossless compression.
With this function, each $V_w$ requires $\log_2{N}$ bits of information to encode.
This is fewer than the initial number of bits so long as $N \leq 2^{n - 1}$.
Therefore, when compressing the label volumes, we can store $f(V_w)$ for every window as well as a lookup function for the $N$ unique $f(V_w)$ values to the original integral value.

So far we have focused exclusively on transforming the boundary map of an image segmentation.
However, the per-pixel labels themselves are equally important.
The boundary map divides each image slice into different segments.
By design, all pixels in the same segment have the same label so we store only one label per segment for each slice.
We use a connected-component labeling algorithm to identify each component and store one label per segment \cite{he2009fast}.

Thus far, we have assumed the boundaries provide enough information to reconstruct the entire segmentation.
Pixels not on a segment boundary are easily relabeled.
However, more care is needed for pixels on the segment boundaries.
Consider figure~\ref{fig:compression}, left, which depicts a difficult boundary to decode.
If a boundary pixel has a non-boundary neighbor to the left or above, then that pixel merely takes on the value of that neighbor.
However, pixel $i$ requires more care since its relevant neighbors are both boundary pixels.
We simply just store the label values for indeterminate pixels like $i$.

To decompress the data, we first reconstruct the boundary map from the windows that we extracted.
From there, we can run the same deterministic connected-components algorithm per slice.
We can traverse through the saved labels to fill in all non-boundary labels.
To determine the per-pixel labels for every boundary pixel, we iterate over the entire dataset in raster order.
Any boundary pixel $(x, y, z)$ with a non-boundary neighbor at $(x - 1, y, z)$ or $(x, y - 1, z)$ shares the same per-pixel label.
If both relevant neighbors are boundaries (i.e., like pixel $i$ in Fig.~\ref{fig:compression}) we extract the value we previously stored.

\subsection{Results}

Our compression scheme outperforms all existing methods.
We follow our scheme with LZMA which uses sophisticated probabilistic bit prediction strategies and together they achieve ratios of $920\times$ on average.
This outperforms existing strategies by over 80\%.
The fundamental principles guiding Compresso are valid for a diverse set of segmentation datasets and we improve on existing methods for MRI and image segmentation datasets.
We compressed an 18 terabyte label volume of 100 microns cubed to 26.2 gigabytes, a ratio of $\sim687\times$.


\section{Related Work}\label{sec:related}

The notion of type refinements was introduced by Freeman and
Pfenning~\cite{FreemanPfenning91}, with refinements limited to
restrictions on the structure of algebraic datatypes, for which
inference is decidable.
%
Our present notion of refinement types has its roots in the
\emph{indexed types} of Xi and Pfenning~\cite{pfenningxi98}, wherein
data types' ranges are restricted by \emph{indices}, analogous to our
refinement predicates, drawn from a decidable domain; in the example
case explored by Xi and Pfenning, types were indexed by terms from
Presburger arithmetic.
%
Since then, several approaches to developing richer refinement type
systems and accompanying methods for type checking have been
developed.
%
Knowles and Flanagan~\cite{Knowles10} allow refinement predicates to
be arbitrary terms of the language being typechecked and present a
technique for deciding some typing obligations statically and
deferring others to runtime.
%; Gronksi \etal~\cite{Gronski06} present animplementation of such a system.
%
Findler and Felleisen's~\cite{Findler02} higher-order contracts, which
extend Eiffel's~\cite{MeyerBook} first-order contracts --- ordinary
program predicates acting as dynamic pre- and post-conditions --- to
the setting of higher-order programs, eschew any form of static
checking, and can be seen as a dynamically-checked refinement type
system.
%
Bengtson \etal~\cite{GordonTOPLAS2011} present a refinement type
system in which type refinements are drawn from a decidable logic,
making static type checking tractable.
%
Greenberg \etal~\cite{Greenberg11} gives a rigorous treatment of the
metatheoretic properties of such a refinement type system.

Refinement types have been applied to the verification of a variety of
program properties~\cite{pfenningxi98,Dunfield,GordonTOPLAS2011,FournetCCS11}.
%
In the most closely related work to our own, Kawaguchi \etal~\cite{LiquidPLDI09}
introduce \emph{recursive} and \emph{polymorphic} refinements for data
structure properties.
%
The present work unifies and generalizes these two somewhat ad-hoc notions
into a single, strictly and significantly more expressive mechanism of
abstract refinements.

%  Higher-order logics: Coq/HTT/F*/Agda which have explicit predicates, quantification
A number of higher-order logics and corresponding verification tools
have been developed for reasoning about programs.
%
Example of systems of this type include NuPRL \cite{Constable86},
%F$_{<:}$ \cite{Cardelli91},
Coq \cite{coq-book}, F$^\star$ \cite{SwamyCFSBY11} and Agda \cite{norell07}
which support the development and verification of higher-order,
pure functional programs.
%
While these systems are highly expressive, their expressiveness comes at the
cost of making logical validity checking undecidable.
%
To help automate validity checking, both built-in and user-provided
tactics are used to attempt to discharge proof obligations; however,
the user is ultimately responsible for manually proving any
obligations which the tactics are unable to discharge.


\section{Reasoning About Lambdas}\label{sec:lambdas}

Soundness and precision of \corelan relies
on the $\beta$-equivalence and extensionality axioms that are undecidable.
%
Next, we present a decidable but incomplete way
to approximate $\beta$-equivalence
by strengthening the VCs with equalities~\S~\ref{subsec:equivalences},
and extensionality by introducing a combinator for safely asserting
extensional equality~\S~\ref{subsec:extensionality}.
%
In the rest of this section,
for clarity we omit $\smtappname{}{}$ when it is clear from the context.

\subsection{Equivalence}\label{subsec:equivalences}

As soundness relies on axioms of $\beta$-equivalence
we can safely \emph{instantiate} the axioms of
$\alpha$- and $\beta$-equivalence on any set of
terms of our choosing and still preserve soundness.
%
That is, instead of checking the validity
of a VC
${p \Rightarrow q}$,
we check the validity of a \emph{strengthened VC},
${a \Rightarrow p \Rightarrow q}$,
where $a$ is a (finite) conjunction
of \emph{equivalence instances}
derived from $p$ and $q$,
as discussed below.

% Since it is unclear how to reify this axiomatization
% while preserving decidability, we choose (once again)
% to syntactically instantiate the axioms of $\alpha$-,
% $\beta$- and normal form equivalence on the relevant
% candidates.

\mypara{Representation Invariant}
%
The lambda binders,
for each SMT sort, are drawn from a
pool of names $x_i$ where the index
$i=1,2,\ldots$.
%
When representing
$\lambda$ terms we enforce
a \emph{normalization invariant}
that for each lambda term
$\slam{x_i}{e}$, the index $i$
% $x_i$
is greater than any lambda
argument appearing in $e$.

\mypara{$\alpha$-instances}
For each syntactic term
${\slam{x_i}{e}}$, and $\lambda$-binder
$x_j$ such that $i < j$ appearing in the VC,
we generate an \emph{$\alpha$-equivalence instance predicate}
(or \emph{$\alpha$-instance}):
$$\slam{x_i}{e} = \slam{x_j}{e \subst{x_i}{x_j}}$$

% , x_i < x_j \leq \maxlamarg$$
%\leq \maxlamarg$
% that follow the ordering
% $i < j \Leftrightarrow x_i < x_j$.
%
% The number of distinct valid lambda
% arguments is determined by the
% maximum number of $\lambda$s
% syntactically in program's refinements.
% In the implementation, we bound
% this number by $\maxlamarg = 7$.
% %
% In practice we only encountered
% 4 nested lambdas when verifying
% monadic left identity of the
% reader monad.

The conjunction of $\alpha$-instances
can be more precise than De Bruijn
representation, as they let the SMT
solver deduce more equalities via
congruence.
%
For example, consider the VC needed
to prove the applicative laws for @Reader@:
%
\begin{align*}
d  = \slam{x_1}{(\sapp{x}{x_1})}
   \Rightarrow \slam{x_2}{(\sapp{(\slam{x_1}{(\sapp{x}{x_1})})}{x_2})}
              = \slam{x_1}{(\sapp{d}{x_1})}
\end{align*}
%
The $\alpha$ instance
%
${\slam{x_1}{(\sapp{d}{x_1})} = \slam{x_2}{(\sapp{d}{x_2})}}$
%
derived from the VC's hypothesis,
combined with congruence immediately
yields the VC's consequence.

\mypara{$\beta$-instances}
%
For each syntactic term $\smapp{(\slam{x}{e})}{e_x}$,
with $e_x$ not containing any $\lambda$-abstractions,
appearing in the VC,
we generate an \emph{$\beta$-equivalence instance predicate}
(or \emph{$\beta$-instance}):
$$
\smapp{(\slam{x_i}{e})}{e_x} = \SUBST{e}{x_i}{e_x},
  \mbox{ s.t. } e_x \mbox{ is $\lambda$-free}
$$
%
We require the $\lambda$-free restriction as
a simple way to enforce that the reduced
term ${\SUBST{e}{x_i}{e'}}$ enjoys the
representation invariant.
%
%%\NV{This restriction is not implemented, but neither has a normalization function}
%%\RJ{Then why are we discussing it?}

For example, consider the following VC
needed to prove that the bind operator for
lists satisfies the monadic associativity law.
%
$$(\sapp{f}{x} \ebind g) = \smapp{(\slam{y}{(\sapp{f}{y} \ebind g)})}{x}$$
%
The right-hand side of the above VC generates
a $\beta$-instance that corresponds directly
to the equality, allowing the SMT solver to
prove the (strengthened) VC.

%% immediately yields
%% $\beta$-equivalence is required in our benchmarks to for example prove
%% monadic associativity for lists.
%% %
%% An intermediate step in the proof is to verify that
%%
%% Assuming that @h x = f x >>= g@ the above
%% translates to the logical query
%% $$
%% \sapp{h}{x} = \sapp{(\slam{x_1}{(\sapp{h}{x_1})})}{x}
%% $$
%%
%% The right hand side of the query will fire a
%% $\beta$-equivalence instantiation
%% and the assumption
%% $
%% \sapp{(\slam{x_1}{(\sapp{h}{x_1})})}{x} = \sapp{h}{x}
%% $
%% will be added in the environment, allowing SMT to prove the equivalence.

\mypara{Normalization}
%
The combination of $\alpha$- and $\beta$-instances
is often required to discharge proof obligations.
%
For example, when proving that the bind operator
for the @Reader@ monad is associative, we need
to prove the VC:
%
$$\slam{x_2}{(\slam{x_1}{w})} =
  \slam{x_3}{(\smapp{(\slam{x_2}{(\slam{x_1}{w})})}{w})}$$
%
The SMT solver proves the VC via the equalities
corresponding to an $\alpha$ and then $\beta$-instance:
%
\begin{align*}
\slam{x_2}{(\slam{x_1}{w})}
  \ =_{\alpha}\ & \slam{x_3}{(\slam{x_1}{w})} \\
  \ =_{\beta}\ & \slam{x_3}{(\smapp{(\slam{x_2}{(\slam{x_1}{w})})}{w})}
\end{align*}

%%% of monadic
%%% associativity for the reader monad requires to prove a $\lambda$ equality
%%% simplified to
%%% %
%%% \begin{code}
  %%% w:a -> {(\x y -> w) = (\x -> (\z y -> w) w)}
%%% \end{code}
%%% %
%%% The proof for the above code is @trivial@ as
%%% in the logic, the $\lambda$ arguments are renamed to
%%% @(\x2 x1 -> w) = (\x3 -> (\x2 x1 -> w) w)@.
%%% Due to $\alpha$- equivalence the
%%% right hand side is equal to
%%% @\x3 x1 -> w@.
%%% Due to $\beta$-equivalence we get
%%% @((\x2 x1 -> w) w) = \x1 -> w@,
%%% by which and due to congruence axiom
%%% we get the desired equality,
%%% \begin{code}
  %%% \x y -> w               -- lhs
  %%% \x2 x1 -> w             -- representation
  %%% \x3 x1 -> w             -- alpha
  %%% \x3 ->((\x2 x1 -> w) w) -- beta
  %%% \x -> ((\z y -> w) w)   -- rhs
%%% \end{code}

\subsection{Extensionality} \label{subsec:extensionality}

Often, we need to prove that two
functions are equal, given the
definitions of reflected binders.
%
For example, consider
%
\begin{code}
  reflect id
  id x = x
\end{code}
%
\toolname accepts the proof that
@id x = x@ for all @x@:
%
\begin{code}
  id_x_eq_x :: x:a -> {id x = x}
  id_x_eq_x = \x -> #id# x =. x ** QED
\end{code}
%
as ``calling'' @id@ unfolds its definition,
completing the proof.
%
However, consider this $\eta$-expanded variant of
the above proposition:
%
\begin{code}
  type Id_eq_id = {(\x -> id x) = (\y -> y)}
\end{code}
%
\toolname \emph{rejects} the proof:
%
\begin{code}
  fails :: Id_eq_id
  fails =  (\x -> #id# x) =. (\y -> y) ** QED
\end{code}
%
The invocation of @id@ unfolds the
definition, but the resulting equality
refinement @{id x = x}@ is \emph{trapped}
under the $\lambda$-abstraction.
%
That is, the equality is absent from the
typing environment at the \emph{top} level,
where the left-hand side term is compared to @\y -> y@.
%
% NV LHS reads like LiquidHaskell
Note that the above equality requires
the definition of @id@ and hence is
outside the scope of purely the
$\alpha$- and $\beta$-instances.

\newcommand\eqfun{\ensuremath{\texttt{=}\forall}}

\mypara{An Exensionality Operator}
%
To allow function equality via
extensionality, we provide the
user with a (family of)
%
\emph{function comparison operator(s)}
that transform an \emph{explanation} @p@
which is a proof that @f x = g x@ for every
argument @x@, into a proof that @f = g@.
%
\begin{mcode}
  =* :: f:(a -> b) -> g:(a -> b)
     -> exp:(x:a -> {f x = g x})
     -> {f = g}
\end{mcode}
%
Of course, @=*@ cannot be implemented;
its type is \emph{assumed}. We can use
@=*@ to prove @Id_eq_id@ by providing
a suitable explanation:
%
\begin{mcode}
  pf_id_id :: Id_eq_id
  pf_id_id = (\y -> y) =* (\x -> id x) $\because$ expl ** QED
   where
     expl  = (\x -> #id# x =. x ** QED)
\end{mcode}
%
%   =* (\x -> id x) $\because$ exp
%   where
%    exp   :: x:a -> {(\x -> id x) x = (\x -> x) x}
%    exp x = #id# x =. x ** QED
%
The explanation is
% the proof passed as
the second argument to $\because$ which has
the following type that syntactically fires $\beta$-instances:
\begin{code}
  x:a -> {(\x -> id x) x = ((\x -> x) x}
\end{code}