\appendix
\section{Appendix MPC-L} \label{AppendixA}
As introduced in Section \ref{subsection:failed_tests}, during the single static obstacle avoidance testing phase, we have encountered some issues regarding the validation of the sixth requirement on the speed range specified in Section \ref{System_Requirements}. In particular, after verifying that the MPC we were developing was unable to perform well at low speeds (under 40 $km/h$), we have decided to split the main problem into two sub-problems consisting of two different speed ranges which would be managed by two different MPCs.
This choice has allowed us to continue the validation relative to MPC-H, which is the one managing high speeds (from 40 to 100 $km/h$), avoiding going back to modify the parameters of the controller to find an optimal solution (if it exists) working in the whole range of speeds.

This Appendix, instead, is dedicated to the development of the MPC-L, which manages the speeds ranging from 10 to 40 $km/h$. After validating the MPC-H, we have come back to its parameters definition and then we have set up a testing procedure where we have applied several different combinations acting on prediction horizon, sample time, and output variables weights of the cost function, aimed to find an appropriate solution.
The test setup and outcomes can be found in the Documentation folder of the repository\footnote{The ``MPC-L-Test\_Report001",\space``MPC-L-Test\_Report002",\space``MPC-L-Test\_Report0005", and ``MPC-L-Test\_Specification\_Report" files generated by Simulink Test are included in the Documentation/Test Reports/MPC-L\_Test\_Reports/ file path.}.\\
Thanks to this iterations, we have found a suitable set of parameters working at 20 $km/h$, that is reported in the following table:
\begin{table}[H]
\centering
\begin{tabular}{|l|l|}
\hline
Prediction Horizon & 10               \\ \hline
Sample Time        & 0.02             \\ \hline
WOV                & {[}30 30 8 30{]} \\ \hline
\end{tabular}
\caption{Best configuration found for MPC-L}
\label{tab:MPC_L_Config}
\end{table}
With the configuration reported in Table \ref{tab:MPC_L_Config}, we have run the test for the static obstacle avoidance in the scenarios already used in Section \ref{chap:static_obstacle_avoidance_tests}, setting a constant speed of 20 $km/h$. The results of this test, as usual, are reported in the Documentation folder\footnote{The ``MPC-L\_Static\_Obstacle\_Avoidance-Test\_Report" and ``MPC-L\_Static\_Obstacle\_Avoidance-Test\_Specification\_Report" files generated by Simulink Test are included in the Documentation/Test Reports/MPC-L\_Test\_Reports/ file path.}.
Even if this configuration seems to work pretty well on most of the scenarios, we have still found that in some situations the controller loses stability and starts oscillating, as shown in Figure \ref{fig:mpc_l_test}.

\begin{figure}[H]
    \centering
    \includegraphics[width=\textwidth,keepaspectratio]{Figures/mpc_l_test_169.png}
    \caption{Output Trajectory of the Vehicle with MPC-L controller in 135° scenario}
    \label{fig:mpc_l_test}
    \end{figure}

In order to get the best out of this controller, further tuning is required but we have decided to stop here because this goes beyond the didactic purpose of this particular project.


\par
\section{Driver programs }
\label{section:Utilities:drivers}
\par
%=======================================================================
\begin{enumerate}
%-----------------------------------------------------------------------
\item
\begin{verbatim}
test_sort msglvl msgFile target sortType n range mod seed
\end{verbatim}
This driver program tests the sort methods.
Use the script file {\tt do\_test\_sort} for testing.
\par
\begin{itemize}
\item
The {\tt msglvl} parameter determines the amount of output.
Use {\tt msglvl = 1} for just timing output.
\item
The {\tt msgFile} parameter determines the message file --- if {\tt
msgFile} is {\tt stdout}, then the message file is {\it stdout},
otherwise a file is opened with {\it append} status to receive any
output data.
\item
The {\tt target} parameter denotes the type of vector(s) to be
sorted.
\begin{itemize}
\item {\tt IV} --- {\tt int} vector sort
\item {\tt IV2} --- {(\tt int, int)} vector sort
\item {\tt IVDV} --- {(\tt int, double)} vector sort
\item {\tt IV2DV} --- {(\tt int, int, double)} vector sort
\item {\tt IVZV} --- {(\tt int, complex)} vector sort
\item {\tt IV2ZV} --- {(\tt int, int, complex)} vector sort
\item {\tt DV} --- {\tt double} vector sort
\item {\tt DV2} --- {(\tt double, double)} vector sort
\item {\tt DVIV} --- {(\tt double, int)} vector sort
\end{itemize}
\item
The {\tt sortType} parameter denotes the type of sort.
\begin{itemize}
\item {\tt IU} --- ascending insert sort
\item {\tt ID} --- descending insert sort
\item {\tt QU} --- ascending quick sort
\item {\tt QD} --- descending quick sort
\end{itemize}
\item
The {\tt n} parameter is the length of the vector(s).
\item
Integer entries are of the form {\tt k} mod {\tt mod},
where {\tt k} in {\tt [0,range]}.
\item
The {\tt seed} parameter is a random number seed.
\end{itemize}
%-----------------------------------------------------------------------
\item
\begin{verbatim}
test_sortUpAndCompress msglvl msgFile target n range mod seed
\end{verbatim}
This driver program tests the ``sort in ascending order and
compress'' methods.
Use the script file {\tt do\_test\_sortUpAndCompress} for testing.
\par
\begin{itemize}
\item
The {\tt msglvl} parameter determines the amount of output.
Use {\tt msglvl = 1} for just timing output.
\item
The {\tt msgFile} parameter determines the message file --- if {\tt
msgFile} is {\tt stdout}, then the message file is {\it stdout},
otherwise a file is opened with {\it append} status to receive any
output data.
\item
The {\tt target} parameter denotes the type of vector(s) to be
sorted.
\begin{itemize}
\item {\tt IV} --- {\tt int} vector sort
\item {\tt IV2} --- {(\tt int, int)} vector sort
\item {\tt IVDV} --- {(\tt int, double)} vector sort
\item {\tt IV2DV} --- {(\tt int, int, double)} vector sort
\item {\tt IVZV} --- {(\tt int, complex)} vector sort
\item {\tt IV2ZV} --- {(\tt int, int, complex)} vector sort
\end{itemize}
\item
The {\tt n} parameter is the length of the vector(s).
\item
Integer entries are of the form {\tt k} mod {\tt mod},
where {\tt k} in {\tt [0,range]}.
\item
The {\tt seed} parameter is a random number seed.
\end{itemize}
%-----------------------------------------------------------------------
\end{enumerate}


% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

      \subsection{concat.m}

\begin{par}
\textbf{Summary:} Compute a control signal $u$ from a state distribution $x\sim\mathcal N(x|m,s)$. Here, the predicted control distribution and its derivatives are computed by concatenating a controller "con" with a saturation function "sat", such as gSat.m.
\end{par} \vspace{1em}

\begin{verbatim}function [M, S, C, dMdm, dSdm, dCdm, dMds, dSds, dCds, dMdp, dSdp, dCdp] ...
         = conCat(con, sat, policy, m, s)\end{verbatim}

\begin{verbatim}Example call: conCat(@congp, @gSat, policy, m, s)\end{verbatim}
    \begin{par}
\textbf{Input arguments:}
\end{par} \vspace{1em}
\begin{verbatim}con       function handle (controller)
sat       function handle (squashing function)
policy    policy structure
  .maxU   maximum amplitude of control signal (after squashing)
m         mean of input distribution                             [D x 1]
s         covariance of input distribution                       [D x D]\end{verbatim}
\begin{par}
\textbf{Output arguments:}
\end{par} \vspace{1em}
\begin{verbatim}M         control mean                                           [E   x   1]
S         control covariance                                     [E   x   E]
C         inv(s)*cov(x,u)                                        [D   x   E]
dMdm      deriv. of expected control wrt input mean              [E   x   D]
dSdm      deriv. of control covariance wrt input mean            [E*E x   D]
dCdm      deriv. of C wrt input mean                             [D*E x   D]
dMds      deriv. of expected control wrt input covariance        [E   x D*D]
dSds      deriv. of control covariance wrt input covariance      [E*E x D*D]
dCds      deriv. of C wrt input covariance                       [D*E x D*D]
dMdp      deriv. of expected control wrt policy parameters       [E   x   P]
dSdp      deriv. of control covariance wrt policy parameters     [E*E x   P]
dCdp      deriv. of C wrt policy parameters                      [D*E x   P]\end{verbatim}
\begin{verbatim}where P is the total number of policy parameters\end{verbatim}
\begin{par}
Copyright (C) 2008-2013 by Marc Deisenroth, Andrew McHutchon, Joe Hall, and Carl Edward Rasmussen.
\end{par} \vspace{1em}
\begin{par}
Last modified: 2012-07-03
\end{par} \vspace{1em}

\subsection*{High-Level Steps}

\begin{enumerate}
\setlength{\itemsep}{-1ex}
   \item Compute unsquashed control signal
   \item Compute squashed control signal
\end{enumerate}

\begin{lstlisting}
function [M, S, C, dMdm, dSdm, dCdm, dMds, dSds, dCds,  dMdp, dSdp, dCdp] ...
  = conCat(con, sat, policy, m, s)
\end{lstlisting}

\subsection*{Code}

\begin{lstlisting}
maxU=policy.maxU; % amplitude limit of control signal
E=length(maxU);   % dimension of control signal
D=length(m);      % dimension of input

% pre-compute some indices
F=D+E; j=D+1:F; i=1:D;
% initialize M and S
M = zeros(F,1); M(i) = m; S = zeros(F); S(i,i) = s;

if nargout < 4   % without derivatives
  [M(j), S(j,j), Q] = con(policy, m, s);  % compute unsquashed control signal v
  q = S(i,i)*Q; S(i,j) = q; S(j,i) = q';  % compute joint covariance S=cov(x,v)
  [M, S, R] = sat(M, S, j, maxU);         % compute squashed control signal u
  C = [eye(D) Q]*R;                       % inv(s)*cov(x,u)
else             % with derivatives
  Mdm = zeros(F,D); Sdm = zeros(F*F,D); Mdm(1:D,1:D) = eye(D);
  Mds = zeros(F,D*D); Sds = kron(Mdm,Mdm);

  X = reshape(1:F*F,[F F]); XT = X';                  % vectorized indices
  I=0*X;I(j,j)=1; jj=X(I==1)'; I=0*X;I(i,j)=1;ij=X(I==1)'; ji=XT(I==1)';

  % 1. Unsquashed controller --------------------------------------------------
  [M(j), S(j,j), Q, Mdm(j,:), Sdm(jj,:), dQdm, Mds(j,:), ...
    Sds(jj,:), dQds, Mdp, Sdp, dQdp] = con(policy, m, s);
  q = S(i,i)*Q; S(i,j) = q; S(j,i) = q';  % compute joint covariance S=cov(x,v)

  % update the derivatives
  SS = kron(eye(E),S(i,i)); QQ = kron(Q',eye(D));
  Sdm(ij,:) = SS*dQdm;      Sdm(ji,:) = Sdm(ij,:);
  Sds(ij,:) = SS*dQds + QQ; Sds(ji,:) = Sds(ij,:);

  % 2. Apply Saturation -------------------------------------------------------
  [M, S, R, MdM, SdM, RdM, MdS, SdS, RdS] = sat(M, S, j, maxU);

  % apply chain-rule to compute derivatives after concatenation
  dMdm = MdM*Mdm + MdS*Sdm; dMds = MdM*Mds + MdS*Sds;
  dSdm = SdM*Mdm + SdS*Sdm; dSds = SdM*Mds + SdS*Sds;
  dRdm = RdM*Mdm + RdS*Sdm; dRds = RdM*Mds + RdS*Sds;

  dMdp = MdM(:,j)*Mdp + MdS(:,jj)*Sdp;
  dSdp = SdM(:,j)*Mdp + SdS(:,jj)*Sdp;
  dRdp = RdM(:,j)*Mdp + RdS(:,jj)*Sdp;

  C = [eye(D) Q]*R; % inv(s)*cov(x,u)
  % update the derivatives
  RR = kron(R(j,:)',eye(D)); QQ = kron(eye(E),[eye(D) Q]);
  dCdm = QQ*dRdm + RR*dQdm;
  dCds = QQ*dRds + RR*dQds;
  dCdp = QQ*dRdp + RR*dQdp;
end
\end{lstlisting}


% Copyright 2019 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\section{Through Library}
\label{section-through-library}

\begin{tikzlibrary}{through}
    This library defines keys for creating shapes that go through given points.
\end{tikzlibrary}

\begin{key}{/tikz/circle through=\meta{coordinate}}
    When this key is given as an option to a node, the following happens:
    %
    \begin{enumerate}
        \item The |inner sep| and the |outer sep| are set to zero.
        \item The shape is set to |circle|.
        \item The |minimum size| is set such that the circle around the center
            of the node (which is specified using |at|), goes through
            \meta{coordinate}.
    \end{enumerate}
    %
\begin{codeexample}[preamble={\usetikzlibrary{through}}]
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (3,2);
  \node (a) at (2,1.5) {$a$};
  \node [draw] at (1,1) [circle through={(a)}] {$c$};
\end{tikzpicture}
\end{codeexample}
    %
\end{key}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "pgfmanual-pdftex-version"
%%% End:


% !TEX root = main.tex
% !TEX spellcheck = en-US
\section{Preliminaries}
\label{sec:preliminaries}
\subsection{Notations} Let $\ppt$ denote probabilistic polynomial-time and $\secpar \in \NN$ be the
security parameter. All adversaries $\adv$  are stateful.
Since every algorithm $\adv$ takes as input
the public parameters we skip them when describing $\adv$'s input.

For an algorithm $\adv$, let
$\image (\adv)$ be the image of $\adv$ (the set of valid outputs of $\adv$), let
$\RND{\adv}$ denote the set of random tapes of correct length for $\adv$
(assuming the given value of $\secpar$), and let $r \sample \RND{\adv}$ denote
the random choice of the randomiser $r$ from $\RND{\adv}$. We denote by $\negl$
($\poly$) an arbitrary negligible (resp.~polynomial) function.

Probability ensembles $X = \smallset{X_\secpar}_\secpar$ and $Y =
\smallset{Y_\secpar}_\secpar$, for distributions $X_\secpar, Y_\secpar$, have
\emph{statistical distance} $\SD$ equal $\epsilon(\secpar)$ if $\sum_{a \in
  \supp{X_\secpar \cup Y_\secpar}} \abs{\prob{X_\secpar = a} - \prob{Y_\secpar =
    a}} = \epsilon(\secpar)$. We write $X \approx_\secpar Y$ if $\SD(X_\secpar,
Y_\secpar) \leq \negl$. For values $a(\secpar)$ and $b(\secpar)$ we write
$a(\secpar) \approx_\secpar b(\secpar)$ if $\abs{a(\secpar) - b(\secpar)} \leq
\negl$.

For a probability space $(\samplespace, \eventspace, \probfunction)$ and event
$\event{E} \in \eventspace$ we denote by $\nevent{E}$ an event that is
complementary to $\event{E}$,
i.e.~$\nevent{E} = \samplespace \setminus \event{E}$.

Denote by $\RELGEN = \smallset{\REL}$ a family of relations. We assume that if
$\REL$ comes with any auxiliary input, the later is benign. Directly from the
description of $\REL$ one learns security parameter $\secpar$ and description of the
group $\GRP$, if the relation is a relation of group elements (as it usually is
in case of zkSNARKs).

\ourpar{Bilinear groups.} We use the  standard bracket notation for groups $\GRP_{\gi}$. i.e., we
write $\bmap{a}{\gi}$ to denote $a g_{\gi}$ where $g_{\gi}$ is a fixed generator
of $\GRP_{\gi}$.
A bilinear group generator $\pgen (\secparam)$ returns public parameters $ \pp =
(p, \GRP_1, \GRP_2, \GRP_T, \pair, \gone{1}, \gtwo{1})$, where $\GRP_1$,
$\GRP_2$, and $\GRP_T$ are additive cyclic groups of prime order $p = 2^{\Omega
  (\secpar)}$, $\gone{1}, \gtwo{1}$ are generators of $\GRP_1$, $\GRP_2$, resp.,
and $\pair: \GRP_1 \times \GRP_2 \to \GRP_T$ is a non-degenerate
$\ppt$-computable bilinear pairing $\pair (\gone{a}, \gtwo{b}) := \gone{a} \bullet
\gtwo{b}= \gtar{a b}$. We assume the bilinear pairing to be Type-3,
i.e., that there is no efficient isomorphism from $\GRP_1$ to $\GRP_2$ or from
$\GRP_2$ to $\GRP_1$.
%We freely use the bracket notation with matrices, e.g., if $\vec{A} \vec{B} = \vec{C}$ then
%$\vec{A} \grpgi{\vec{B}} = \grpgi{\vec{C}}$ and $\gone{\vec{A}}\bullet\gtwo{\vec{B}} = \gtar{\vec{C}}$.

\begin{lemma}[Difference lemma,~{\cite[Lemma 1]{EPRINT:Shoup04}}]
	\label{lem:difference_lemma}
	Let $\event{A}, \event{B}, \event{F}$ be events defined in some probability
	space, and suppose that $\event{A} \land \nevent{F} \iff \event{B}
		\land \nevent{F}$.  Then
	$
		\abs{\prob{\event{A}} - \prob{\event{B}}} \leq \prob{\event{F}}\,.
	$
\end{lemma}
\subsection{Algebraic Group Model}
The algebraic group model (AGM) introduced in \cite{C:FucKilLos18} lies between
the standard model and generic group model. In the AGM it is assumed
that an adversary $\adv$ can output a group element $\gnone{y} \in \GRP$ if
$\gnone{y}$ has been computed by applying known group operations to group elements
given to $\adv$ as input.  More precisely, the AGM requires that
whenever $\adv(\gnone{\vec{x}})$ outputs a group element $\gnone{y}$ then it
also outputs $\vec{c}$ such that $\gnone{y} = \vec{c}^\top \cdot
\gnone{\vec{x}}$. Both $\plonk$ and $\sonic$ have been shown secure using the
AGM. An adversary that works in the AGM is called \emph{algebraic}.

\subsection{Polynomial commitment}
\label{sec:poly_com}
In the polynomial commitment scheme $\PCOM = (\kgen, \com, \open, \verify)$ the
committer $\committer$ can convince the receiver $\receiver$ that some
polynomial $\p{f}$ which $\committer$ committed to evaluates to $s$ at some
point $z$ chosen by $\receiver$. $\PCOM$'s subroutines are defined as follows
\begin{description}
\item[$\kgen(1^\secpar, \maxdeg)$:] The key generation algorithm
  $\kgen(1^\secpar, \maxdeg)$ takes in a security parameter $1^\secpar$ and a
  parameter $\maxdeg$ which determines the maximal degree of the committed
  polynomial. It outputs a structured reference string $\srs$ (including a
  commitment key).
\item[$\com(\srs, \p{f})$:] The commitment algorithm $\com(\srs, \p{f})$ takes
  in $\srs$ and a polynomial $\p{f}$ with maximum degree $\maxdeg$, and outputs
  a commitment $c$.
\item[$\open(\srs, z, s, \p{f})$:] The opening algorithm
  $\open(\srs, z, s \p{f})$ takes as input $\srs$, an evaluation point $z$, a
  value $s$ and the polynomial $\p{f}$. It outputs an opening $o$.
\item[$\verify(\srs, c, z, s, o)$:] The verification algorithm takes in $\srs$,
  a commitment $c$, an evaluation point $z$, a value $s$ and an opening $o$. It
  outputs 1 if $o$ is a valid opening for $(c, z, s)$ and 0 otherwise.
\end{description}

$\plonk$ and $\sonic$ use variants of the KZG polynomial commitment scheme
\cite{AC:KatZavGol10}. We denote the first by $\PCOMp$ and the latter by
$\PCOMs$. Due to page limit, we omit their presentation here and refer to
\cref{fig:pcomp} and \cref{fig:pcoms} in the \cref{sec:pcom}.  In this paper we
use evaluation binding, commitment of knowledge, and, newly introduced, unique
opening and hiding properties. Formal definitions of these could be find in
\cref{sec:pcom}, here we briefly introduce them.
\begin{compactdesc}
  \item[Evaluation binding] intuitively, this property assures that no adversary
    could provide two valid openings for two different evaluations of the same
    commitment in the same point.
  \item[Commitment of knowledge] when a commitment scheme is ``of
    knowledge'' then if an adversary produces a (valid) commitment $c$, which it
    can open, then it also knows the underlying polynomial $\p{f}$ which commits
    to that value.  \cite{CCS:MBKM19} shows, using AGM, that $\PCOMs$ is a
    commitment of knowledge.  The same reasoning could be used to show that
    property for $\PCOMp$.
  \item[Unique opening] this property assures that there is
    only one valid opening for the committed polynomial and given evaluation
    point. This property is crucial in showing forking simulation-extractability
    of $\plonk$ and $\sonic$. We show that the $\plonk$'s and $\sonic$'s
    polynomial commitment schemes satisfy this requirement in
    \cref{lem:pcomp_op} and \cref{lem:pcoms_unique_op} respectively.
  \item[Hiding] assures that no adversary is able to tell anything about the
    polynomial given only its commitment and bounded number of evaluations.
\end{compactdesc}

\subsection{Zero-Knowledge Proof Systems}
Let $\RELGEN(\secparam) = \smallset{\REL}$ be a family of
$\npol$ relations. Denote by $\LANG_\REL$ the language determined by $\REL$.
Let $\prover$ be a \emph{prover} and $\verifier$ be the \emph{verifier}, both $\ppt$ algorithms. We allow our proof system to have
a setup, i.e.~there is a $\kgen$ algorithm that takes as input the relation
description $\REL$ and outputs a common reference string $\srs$. We assume that
the $\srs$ defines the relation and for universal prove systems, such as Plonk
and Sonic, we treat both the reference string and the relation as universal.

We denote by $\ip{\prover(\srs, \inp, \wit)}{\verifier(\srs,\inp)}$ a
\emph{transcript} (also called \emph{proof}) $\zkproof$ of a conversation
between $\prover$ with input $(\srs, \inp, \wit)$ and $\verifier$ with input
$(\srs, \inp)$. We write
$\ip{\prover (\srs, \inp, \wit)}{\verifier(\srs, \inp)} = 1$ if in the end of
the transcript the verifier $\verifier$ returns $1$ and say that $\verifier$
accepts it.  For non-interactive proof systems we abuse notation and write
$\verifier(\srs, \inp, \zkproof) = 1$ to denote a fact that $\zkproof$ is
accepted by the verifier.

A proof system $\proofsystem = (\kgen, \prover, \verifier, \simulator)$ for
$\RELGEN$ is required to have three properties: completeness, soundness and zero
knowledge, which are defined as follows:
% \begin{description}

\ourpar{Completeness.}
%\item[Completeness]
  An interactive proof system $\proofsystem$ is
  \emph{complete} if an honest prover always convinces an honest verifier, that
  is for all $\REL \in \RELGEN(\secparam)$ and $(\inp, \wit) \in \REL$
	\[
		\condprob{\ip{\prover (\srs, \inp, \wit)}{\verifier (\srs,
        \inp)} = 1}{\srs \gets \kgen(\REL)} = 1\,.
	\]
    % \item[Soundness]
\ourpar{Soundness.}
    We say that $\proofsystem$ for $\RELGEN$ is \emph{sound} if no
  $\ppt$ prover $\adv$ can convince an honest verifier $\verifier$ to accept a
  proof for a false statement $\inp \not\in\LANG$. More precisely, for
  all $\REL \in \RELGEN(\secparam)$
	\[
    \condprob{\ip{\adv(\srs, \inp)}{\verifier(\srs, \inp)} = 1 \land \inp
      \not\in \LANG_\REL}{\srs \gets \kgen(\REL), \inp \gets \adv(\srs)} \leq
    \negl\,;
	\]
%\end{description}
Sometimes a stronger notion of soundness is required---except requiring that the
verifier rejects proofs of statements outside the language, we request from the
prover to know a witness corresponding to the proven statement. This property is
called \emph{knowledge soundness}.%\markulf{Commented out the formal definition as we don't use it.}

\ourpar{Zero knowledge.}  We call a proof system $\proofsystem$
\emph{zero-knowledge} if for any $\REL \in \RELGEN(\secparam)$, and adversary
$\adv$ there exists a $\ppt$ simulator $\simulator$ such that for any
$(\inp, \wit) \in \REL$
\begin{multline*}
	  \left\{\ip{\prover(\srs, \inp, \wit)}{\adv(\srs, \inp, \wit)}
      \,\left|\, \srs \gets \kgen(\REL)\COMMENT{, (\inp, \wit) \gets \adv(\REL,
          \srs)}\vphantom{\simulator^\adv}\right.\right\} \approx_\secpar
		%\\
		\left\{\simulator^{\adv}(\srs, \inp)\,\left|\, \srs \gets
        \kgen(\REL)\COMMENT{, (\inp, \wit) \gets \adv(\REL,
          \srs)}\vphantom{\simulator^\adv}\right.\right\}\,.
\end{multline*}
	%
We call zero knowledge \emph{perfect} if the distributions are equal and
\emph{computational} if they are indistinguishable for any $\ppt$ distinguisher.

% \end{description}
Alternatively, zero-knowledge can be defined by allowing the simulator to use
the trapdoor $\td$ that is generated along the $\srs$. In this paper we distinguish
simulators that requires a trapdoor to simulate and those that do not. We call
the former \emph{SRS-simulators}. We say that a protocol is zero knowledge in
the standard model if its simulator does not require the trapdoor.

% Occasionally, a weaker version of zero knowledge is sufficient. So called
% \emph{honest verifier zero knowledge} (HVZK) assumes that the verifier's
% challenges are picked at random from some predefined set. Although weaker, this
% definition suffices in many applications. Especially, an interactive
% zero-knowledge proof that is HVZK and \emph{public-coin} (i.e.~the verifier
% outputs as challenges its random coins) can be made non-interactive and
% zero-knowledge in the random oracle model by using the Fiat--Shamir
% transformation.

In security reductions in this paper it is sometimes needed to produce
simulated NIZK proofs without knowning the trapdoor, just by
programming the random oracle. We call protocols which allow for such kind of
simulation \emph{trapdoor-less zero-knowledge} (TLZK). More precisely,

\begin{definition}[Trapdoor-less zero-knowledge proof system]
  Let $\ps = (\kgen, \prover, \verifier, \simulator)$ be a NIZK proof
  system and $\ro$ a random oracle. Let $\simulator$ be ana pair of
  algorithms: $\simulator_\ro$ that takes random oracle queries and
  answers them, $\simulator_\prover$ that takes as input an SRS $\srs$
  and instance $\inp$ and outputs a proof $\zkproof_\simulator$.  We
  call $\ps$ \emph{trapdoor-less zero-knowledge} if for any adversary
  $\adv$, $\eps_0 \approx \eps_1$, where
  \begin{align}
    \eps_b = \Pr\left[
    \begin{aligned}
      \adv^{\oracleo_b}(\srs) = 0
    \end{aligned}
    \, \left| \,
    \begin{aligned}
      \srs \sample \kgen(\secpar)
    \end{aligned}
    \right.\right]
  \end{align}
  where $\oracleo_b$ takes two types of adversary's queries:
  \begin{description}
  \item[random oracle calls:] on $\adv$'s query $x$, $\oracleo_b$
    responds with $\ro(x)$ if $b = 0$, and with $y \gets
    \simulator_\ro(\srs, x)$, if $b = 1$.
  \item[proof calls:] on $\adv$'s query $\inp, \wit$ responds
  with a real proof $\zkproof_\prover \gets
  \prover(\srs, \inp, \wit)$ if $b = 0q$ or a simulated proof $\zkproof_\simulator \gets \simulator (\srs,
  \inp)$ if $b = 1$.
  \end{description}
\end{definition}

% In our simulation soundness proof (but not simulation extractability
% \hamid{you mean forking simulation extractability?}) we need an
% additional property of the zero-knowledge proof system which we call
% $k$-programmable ZK.
\begin{definition}[$k$-programmable ZK]
  \label{def:kzk}
  Let $\ps$ be a $(2\mu + 1)$-message ZK proof system and let $\ps_\fs$ be its
  Fiat--Shamir variant. We say that $\ps_\fs$ is $k$-programmable ZK if there
  exists a simulator $\simulator_\fs$ that
  \begin{compactenum}
  \item produces proofs indistinguishable from proofs output by an honest
    prover;
  \item $\simulator_\fs$ programs the random oracle \emph{only} for
    challenges from round $k$ to $\mu + 1$.
  \end{compactenum}
\end{definition}
We note that $\plonk$ is $2$-programmable ZK, $\sonic$ is $1$-programmable ZK,
and $\marlin$ is $1$-programmable ZK. This follows directly from the proofs of
their standard model zero-knowledge property in
\cref{lem:plonk_hvzk,lem:sonic_hvzk, lem:marlin_hvzk}.

\oursubsub{Idealised verifier and verification equations} Let
$(\kgen, \prover, \verifier)$ be a proof system.
% or a polynomial commitment
% scheme\hamid{might be unclear as we are defining polynomial commitments as
%   $(\kgen, \com, \open, \verify)$.}.
Observe that the $\kgen$ algorithm provides an SRS which can be interpreted as a
set of group representation of polynomials evaluated at trapdoor
elements. E.g.~for a trapdoor $\chi$ the SRS contains
$\gone{\p{p_1}(\chi), \ldots, \p{p_k}(\chi)}$, for some polynomials
$\p{p_1}(X), \ldots, \p{p_k}(X) \in \FF_p[X]$. On the other hand, the verifier
$\verifier$ accepts if a (possibly set of) verification equation
$\vereq_{\inp, \zkproof}$ (note that the verification equation changes relate to
the instance $\inp$ and proof $\zkproof$), which can also be interpreted as a
polynomial in $\FF_p[X]$ whose coefficients depend on messages sent by the
prover, zeroes at $\chi$. Following \cite{EPRINT:GabWilCio19} we call verifiers
who checks that $\vereq_{\inp, \zkproof}(\chi) = 0$ \emph{real verifiers} as
opposed to \emph{ideal verifiers} who accepts only when
$\vereq_{\inp, \zkproof}(X) = 0$. That is, while a real verifier accepts when a
polynomial \emph{evaluates} to zero, an ideal verifier accepts only when the
polynomial \emph{is} zero.

Although ideal verifiers are impractical, they are very useful in our
proofs. More precisely, we show that
\begin{compactenum}
\item the idealised verifier accepts an incorrect proof (what ``incorrect''
  means depends on the situation) with at most negligible probability (and many
  cases---never);
\item when the real verifier accepts, but not the idealised one, then we show
  how to use a malicious $\prover$ to break the underlying security assumption
  (in our case---a variant of $\dlog$.)
\end{compactenum}

Analogously, idealised verifier can also be defined for polynomial commitment scheme.

\oursubsub{Sigma protocols}
A sigma protocol $\sigmaprot = (\prover, \verifier, \simulator)$ for a relation
$\REL \in \RELGEN(\secparam)$ is a special case of an interactive proof where a
transcript consists of three messages $(a, b, z)$, where $b$ is a challenge
provided by the verifier. Sigma protocols are honest verifier zero-knowledge in
the standard model and specially-sound. That is, there exists an extractor
$\ext$ which given two accepting transcripts $(a, b, z)$, $(a, b', z')$ for a
statement $\inp$ can recreate the corresponding witness if $b \neq b'$.
More formally:
% \begin{description}

\ourpar{Special soundness.}
% \hamid{The last (short) sentence looks a little unclear.}
A sigma protocol $\sigmaprot$ is \emph{specially-sound}
  if for any adversary $\adv$ the probability
\[
\Pr\left[
\begin{aligned}
& \verifier(\REL, \inp, (a, b, z)) = %\\
\verifier(\REL, \inp, (a, b', z')) = 1 \\
& \land b \neq b' \land \REL(\inp, \wit) = 0 \\
\end{aligned}
\,\left|\,
\begin{aligned}
& (\inp, (a, b, z), (a, b', z')) \gets \adv(\REL), \\ %\\
& \wit \gets \ext(\REL, \inp, (a, b, z), (a, b', z'))\\
\end{aligned}
\right.\right]
\]
is upper-bounded by some negligible function $\negl$.
%\end{description}

Another property that sigma protocols may have is a unique response
property \cite{C:Fischlin05} which states that no $\ppt$ adversary can
produce two accepting transcripts that differ only on the last
element. More precisely,
%\begin{description}
\ourpar{Unique response property.} Let
$\sigmaprot = (\prover, \verifier, \simulator)$ be a sigma-protocol for
$\REL \in \RELGEN(\secparam)$ with proofs of the form
$(a, b, z)$. We say that $\sigmaprot$ has the unique response property if for
all $\ppt$ algorithms $\adv$, it holds that,:
\[ \condprob{\verifier (\REL, \inp, (a, b, z)) = \verifier (\REL, \inp, (a, b,
	z')) = 1 \land z \neq z'}{(\inp, a, b, z, z') \gets \adv(\REL)} \leq \negl\,.  \]
%\end{description}
If this property holds even against unbounded adversaries, it is called
\emph{strict}, cf.~\cite{INDOCRYPT:FKMV12}. Later on we call protocols that
follows this notion \emph{ur-protocols}. For the sake of completeness we note
that many sigma protocols, like e.g.~Schnorr's protocol \cite{C:Schnorr89},
fulfil this property.

\subsection{From interactive to non-interactive---the Fiat--Shamir transform}
Consider a $(2\mu + 1)$-message, public-coin, honest verifier zero-knowledge (HVZK)
interactive proof system
$\proofsystem = (\kgen, \prover, \verifier, \simulator)$ for
$\REL \in \RELGEN(\secparam)$.  Let $\zkproof$ be a proof performed by the
prover $\prover$ and verifier $\verifier$ compound of messages
$(a_1, b_1, \ldots, a_{\mu}, b_{\mu}, a_{\mu + 1})$, where $a_i$ comes from
$\prover$ and $b_i$ comes from $\verifier$.  Denote by $\ro$ a random oracle.
Let $\proofsystem_\fs = (\kgen_\fs, \prover_\fs, \verifier_\fs, \simulator_\fs)$
be a proof system such that
\begin{compactitem}
  \item $\kgen_\fs$ behaves as $\kgen$.
  \item $\prover_\fs$ behaves as $\prover$ except after sending message
    $a_i$, $i \in \range{1}{\mu}$, the prover does not wait for
    the message from the verifier but computes it locally setting $b_i
    = \ro(\zkproof[0..i])$, where $\zkproof[0..j] = (\inp, a_1, b_1, \ldots,
    a_{j - 1}, b_{j - 1}, a_j)$. (Importantly, $\zkproof[0..\mu + 1] =
    (\inp, \zkproof)$).
  \item $\verifier_\fs$ behaves as $\verifier$ but does not provide
    challenges to the prover's proof. Instead it computes the
    challenges locally as $\prover_\fs$ does. Then it verifies the
    resulting transcript $\zkproof$ as the verifier $\verifier$ would.
  \item $\simulator_\fs$ behaves as $\simulator$, except when
    $\simulator$ picks challenge $b_i$ before computing message $\zkproof[0, i]$, $\simulator_\fs$ programs the
    random oracle to output $b_i$ on $\zkproof[0, i]$.
  \end{compactitem}

\noindent
The Fiat--Shamir heuristic states that $\proofsystem_\fs$ is a zero-knowledge
non-interactive proof system for $\REL \in \RELGEN(\secparam)$.

\subsection{Non-malleability definitions for NIZKs}
\label{sec:simext_def}
Real life applications often require a NIZK proof system to be
non-malleable. That is, no adversary seeing a proof $\zkproof$ for a statement
$\inp$ should be able to provide a new proof $\zkproof'$ related to $\zkproof$.
\emph{Simulation extractability} formalizes a strong version of non-malleability
by requiring that no adversary can produce a valid proof without knowing the
corresponding witness. This must hold even if the adversary is allowed to see
polynomially many simulated proofs for any statements it wishes.

%\chaya{remove reference to forking soundness. quantify for $\ext_\se$}
\begin{definition}[Forking simulation-extractable NIZK, \cite{INDOCRYPT:FKMV12}]
	\label{def:simext}
  Let $\ps_\fs = (\kgen_\fs, \prover_\fs, \verifier_\fs, \simulator_\fs)$ be a non-interactive proof system.
%  HVZK proof system\hamid{$\ps_\fs$ is the Fiat-Shamir variant of the underlying proof system. So maybe we mean the underlying proof system is HVZK?}.
We say that $\ps_\fs$ is \emph{forking
    simulation-extractable} with \emph{extraction error} $\nu$ if for any $\ppt$
  adversary $\adv$ that is given oracle access to a random oracle $\ro$ and
  simulator $\simulator_\fs$, and produces an accepting transcript of $\ps$ with
  probability $\accProb$, where
	\[
		\accProb = \Pr \left[
		\begin{aligned}
			& \verifier_\fs(\srs, \inp_{\advse}, \zkproof_{\advse}) = 1,\\
			& (\inp_{\advse}, \zkproof_{\advse}) \not\in Q
		\end{aligned}
		\, \left| \,
		\begin{aligned}
			& \srs \gets \kgen_\fs(\REL), r \sample \RND{\advse}, \\
			& (\inp_{\advse}, \zkproof_{\advse}) \gets \advse^{\simulator_\fs,
			\ro} (\srs; r)
		\end{aligned}
		\right.\right]\,,
	\]
	there exists an extractor $\extse$ such that
	\[
		\extProb = \Pr \left[
		\begin{aligned}
			& \verifier_\fs(\srs, \inp_{\advse}, \zkproof_{\advse}) = 1,\\
			& (\inp_{\advse}, \zkproof_{\advse}) \not\in Q,\\
			& \REL(\inp_{\advse}, \wit_{\advse}) = 1
		\end{aligned}
		\, \left| \,
		\begin{aligned}
			& \srs \gets \kgen_\fs(\REL), r \sample \RND{\advse},\\
			& (\inp_{\advse}, \zkproof_{\advse}) \gets \advse^{\simulator_\fs,
			\ro} (\srs; r) \\
			& \wit_{\advse} \gets \ext_\se (\srs, \advse, r, \inp_{\advse}, \zkproof_{\advse},
			Q, Q_\ro)
		\end{aligned}
		\right.\right]
	\]
	is at at least
	\[
		\extProb \geq \frac{1}{\poly} (\accProb - \nu)^d - \eps(\secpar)\,,
	\]
	for some polynomial $\poly$, constant $d$ and negligible $\eps(\secpar)$ whenever
  $\accProb \geq \nu$. List $Q$ contains all $(\inp, \zkproof)$ pairs where
  $\inp$ is an instance provided to the simulator by the adversary and
  $\zkproof$ is the simulator's answer. List $Q_\ro$ contains all $\advse$'s
  queries to $\ro$ and $\ro$'s answers.
\end{definition}

% Consider a sigma protocol $\sigmaprot = (\prover, \verifier, \simulator)$ that
% is special-sound and has a unique response property. Let $\sigmaprot_\fs =
% (\prover_\fs, \verifier_\fs, \simulator_\fs)$ be a NIZK obtained by applying the
% Fiat--Shamir transform to $\sigmaprot$. Faust et al.~\cite{INDOCRYPT:FKMV12}
% show that every such $\sigmaprot_\fs$ is forking simulation-extractable. This result is
% presented in \cref{sec:forking_lemma} along with the instrumental forking lemma,
% cf.~\cite{CCS:BelNev06}.

\iffalse
\noindent \textbf{Simulation sound NIZKs.}
Another notion for non-malleable NIZKs is \emph{simulation soundness}. It allows the adversary to see simulated proof, however, in contrast to simulation
extractability it does not require an extractor to provide a witness for the
proven statement. Instead, it is only necessary, that an adversary who sees
simulated proofs cannot make the verifier accept a proof of an incorrect
statement. More precisely,
\chaya{this definition will go}
\begin{definition}[Simulation soundness]
  	\label{def:simsnd}
    Let $\ps = (\kgen, \prover, \verifier, \simulator)$ be a NIZK proof and
    $\ps_\fs = (\kgen_\fs, \prover_\fs, \verifier_\fs, \simulator_\fs)$ be $\ps$
    transformed by the Fiat--Shamir transform. We say that $\ps_\fs$ is
    \emph{simulation-sound}
    for any $\ppt$ adversary $\adv$ that is given oracle access to a random
    oracle $\ro$ and simulator $\simulator_\fs$, probability
    \[
      \ssndProb =
      \Pr\left[
        \begin{aligned}
          & \verifier_\fs(\srs, \inp_{\adv}, \zkproof_{\adv}) = 1,\\
          & (\inp_{\advse}, \zkproof_{\advse}) \not\in Q,\\
          & \neg \exists \wit_{\adv}: \REL(\inp_{\adv}, \wit_{\adv}) = 1
        \end{aligned}
        \, \left| \,
          \vphantom{\begin{aligned}
          & \verifier_\fs(\srs, \inp_{\adv}, \zkproof_{\adv}) = 1,\\
          & (\inp_{\advse}, \zkproof_{\advse}) \not\in Q,\\
          & \neg \exists \wit_{\adv}: \REL(\inp_{\adv}, \wit_{\adv}) = 1
        \end{aligned}}
      \begin{aligned}
        & \srs \gets \kgen(\REL), r \sample \RND{\advse},\\
        & (\inp_{\advse}, \zkproof_{\advse}) \gets \advse^{\simulator_\fs,
          \ro} (\srs; r)
      \end{aligned}
		\right.  \right]
    \]
    is at most negligible.  List $Q$ contains all $(\inp, \zkproof)$ pairs where
  $\inp$ is an instance provided to the simulator by the adversary and
  $\zkproof$ is the simulator's answer.
\end{definition}

  \label{rem:simext_to_simsnd}
  We note that the probability $\ssndProb$ \cref{def:simsnd} can be expressed in
  terms of simulation-extractability. More precisely, the
  condition $\neg \exists \wit: \REL(\inp_\adv, \wit_\adv) = 1$ can be substituted with
  $\REL(\inp_\adv, \wit_\adv) = 0$, where $\wit_\adv$, returned by a possibly unbounded
  extractor, is either a witness to $\inp_\adv$ (if there exists any) or $\bot$ (if
  there is none). More precisely,
\[
      \ssndProb =
      \Pr\left[
        \begin{aligned}
          & \verifier_\fs(\srs, \inp_{\adv}, \zkproof_{\adv}) = 1,\\
          & (\inp_{\advse}, \zkproof_{\advse}) \not\in Q,\\
          & \REL(\inp_{\adv}, \wit_{\adv}) = 0
        \end{aligned}
        \, \left| \,
      \begin{aligned}
        & \srs \gets \kgen(\REL), r \sample \RND{\advse},\\
        & (\inp_{\advse}, \zkproof_{\advse}) \gets \advse^{\simulator_\fs,
          \ro} (\srs; r)\\
        & \wit_{\adv} \gets \ext(\srs, \advse, r, \inp_{\advse}, \zkproof_{\advse},
			Q, Q_\ro,)
      \end{aligned}
		\right.  \right].
\]
The only necessary input to the unbounded extractor $\ext$ is the instance
$\inp_\adv$ (the rest is given for the consistency with the simulation extractability
definition).
%
With the probabilities in \cref{def:simext} holding regardless of whether the extractor
is unbounded or not, we obtain the following equality
$ \ssndProb = \accProb - \extProb$.

% In \cref{cor:simext_to_ssnd} we show that (under some mild conditions) this is enough
% to conjecture that probability $\ssndProb$ is not only at most negligible, but
% also, in some parameters, exponentially smaller than $(1 - \extProb)$
% (probability of extraction failure in \cref{def:simext}).

\fi


\documentclass[acmsmall,nonacm, screen]{acmart}
\acmConference[]{}{}{}

\usepackage{xspace}
\usepackage{enumitem}
\setlist[itemize]{leftmargin=*}

\newcommand{\lang}{Sized CC$_\omega$\xspace}
\newcommand{\CICE}{CIC$_\mathrm{E}$\xspace}
\newcommand{\our}{my\xspace}
\newcommand{\Our}{My\xspace}
\newcommand{\we}{I\xspace}
\newcommand{\We}{I\xspace}

% Each submission (referred to as “abstract” below) should include the student author’s name and e-mail address;
% institutional affiliation; research advisor’s name; ACM student member number; category (undergraduate or graduate)
\title{Towards a Syntactic Model of Sized Dependent Types}
\author{Jonathan Chan}
\email{jcxz@cs.ubc.ca} % why doesn't this show up?
\affiliation{
  \institution{University of British Columbia}
  \city{Vancouver}
  \country{Canada},
  \href{mailto:jcxz@cs.ubc.ca}{jcxz@cs.ubc.ca} \\
  Graduate student (MSc.) advised by William J. Bowman
}

\begin{document}
\maketitle

\section{Termination Checking for Dependent Type Theories}

The types-as-propositions paradigm associates certain type theories with formal logical systems,
and consequently types in those theories with propositions in those logics.
Furthermore, well-typed programs are associated with proofs of the corresponding proposition.
Many dependent type theories, for instance, correspond to higher-order logics,
and having an automated type checker means having the ability to automatically verify proofs.

One must be careful, however, not to allow nonterminating programs,
because they correspond to logical inconsistencies, i.e. proofs of falsehood.
Additionally, in dependent type checkers where programs may be evaluated during type checking,
failure to rule out nonterminating programs leads to nonterminating type checking.
Contemporary proof assistants based on dependent type theories, such as Coq, Agda, Lean, Idris,
and many more, typically restrict recursive functions to \emph{structurally-recursive} ones,
where the argument of recursive calls must be \emph{syntactically} smaller,
peeling away layers of constructors until a base case is reached.
Type checkers in these proof assistants use \emph{guard predicates}~\citep{guard-predicate} to ensure the restriction.

However, the guard predicate is often \emph{too} restrictive to accept a variety of recursive functions
for which termination is otherwise evident to the discerning programmer.
In particular, functions recurring on subarguments that have first been passed to other functions
known not to add any more layers of constructors must surely terminate,
but since the recursive argument is not \emph{syntactically} the subargument,
the guard predicate does not hold.

Some type checkers will inline function definitions for the purpose of termination checking,
but this reliance on other function definitions makes code non-modular,
and inlining very large definitions could severely negatively impact type checking performance.
Furthermore, the syntactic nature of the guard predicate makes it sensitive to minor syntactic changes,
and a subtle refactoring of a function inlined in later functions could affect whether
those functions even pass termination checking at all!
In short, a syntactic guard predicate goes against good programming practices.

\section{Type-Based Termination Checking}

An alternative to syntactic termination checking is to instead use \emph{type-based} termination checking,
where if a recursive function type checks without involving any other termination conditions,
then it is guaranteed to terminate.
One such method uses \emph{sized types}~\citep{hughes}, where inductive types carry additional size information.
Intuitively, the size is a measure of how many layers a member of that type contains,
and constructors must have a greater size than its subarguments.
The types of functions then carry information about whether it affects the size of its argument,
meaning that no inlining is required --- only the type is needed, not the whole definition.

Sized types have been implemented in Agda and can be enabled with the \texttt{-\hspace{0em}-sized-types} pragma.%
\footnote{Unfortunately, the implementation is inconsistent due to the presence of an \emph{infinite size},
which is defined to be the size strictly greater than all other sizes, including itself.}
It encludes sophisticated features like first-class sizes and bounded size quantification.
There is also a large body of theoretical work on sized types in various type systems,
but none of them quite satisfy all of the desirable features.

\begin{itemize}
  \item \citet{cic-hat}, \citet{cic-hat-minus-nat}, \citet{cic-hat-minus}, and \citet{cc-hat-omega}
    introduce and prove consistent a lineage of Calculi of (Co)Inductive Constructions (CIC) with sized types,
    but only prenex size quantification is possible: one cannot, for instance,
    pass around a higher-order function quantifying over a size.
  \item \citet{abel-diss}, \citet{flationary}, and \citet{f-omega-cop}
    introduce not only higher-rank size quantification but also bounded size quantification,
    the latter of which eliminates the need for complex monotonicity checks or syntactic approximations thereof.
    However, these type systems extend System F$_{\omega}$ rather than a dependent type theory.
  \item \citet{nbe-sized} prove normalization of a higher-rank sized dependent type theory with naturals,
    but without bounded size quantification.
\end{itemize}

\textbf{In ongoing work, \we seek to prove the logical consistency of \lang,
a higher-rank sized dependent type theory with bounded size quantification.}
Rather than using very involved set-theoretic methods like in Sacchini's dissertation~\citep{cic-hat-minus}
or the normalization by evaluation technique in~\citet{nbe-sized}
which requires a typed definitional equality judgement in the type theory,
\we instead define a \emph{syntactic model}~\citep{syntactic-models} into Extensional CIC (\CICE)~\citep{CCE}.
That is, \we need to define a compiler from \lang to \CICE, then prove that it is \emph{type-preserving}:
given some well-typed term in \lang, if both the term and its type are translated to \CICE,
then the translated term should also be well typed against the translated type.
Because \CICE is known to be consistent, and an inconsistency in \lang
implies the existence of an inconsistency in \CICE via the type-preserving compilation,
inconsistency of \lang would be a contradiction.

\section{Syntactic Model of \texorpdfstring{\lang}{Sized CCω}}

\lang is a Generalized Calclulus of Constructions with definitions (CC$\omega$)~\citep{universes} ---
that is, a Calculus of Constructions with untyped equality, a cumulative universe hierarchy, and \texttt{let} expressions ---
extended with bounded and unbounded size quantification, abstraction, and application,
as well as size expressions consisting of size variables, a base size, and a size successor operation.
\We further add naturals and W types only, but these should scale directly to inductive types in general.

In \lang, the natural type and W types are parametrized by some size, and their constructors quantify
over a bounded size representing the strictly smaller size of recursive subarguments.
In \CICE, \we define a \texttt{Size} inductive type representing the sizes in \lang,
and an indexed inductive type \texttt{\_$\leqslant$\_} on \texttt{Size}
representing the ordering relation used in bounded quantification and abstraction.
The natural type and W types then compile to corresponding inductive types literally parametrized by \texttt{Size},
and whose constructors take proofs of strict inequality of two \texttt{Size}s.

The majority of the remaining translation is straightforward,
especially for universes, functions, \texttt{let} expressions, and \texttt{case} expressions.
Bounded size quantification and abstraction correspond to quantification and abstraction
over a \texttt{Size} and an inequality, and correspondingly for unbounded ones.
But what about fixpoints?

The typing rule for fixpoints in \lang has as premise the well-typedness of its body
in an environment where the fixpoint itself is in scope, but quantifying over a smaller size.
The key insight is that fixpoints now correspond to \emph{well-founded induction} over sizes,
rather than structural induction.
To show that well-founded induction indeed holds for \texttt{Size},
\we first show that all \texttt{Size}s satisfy an \emph{accessibility predicate}~\citep{wfind};
well-founded induction then follows by a structurally-inductive proof over the predicate.
Fixpoints in \lang then translate immediately to applications of well-founded induction.

Now that a translation from \lang to \CICE is established, \we show that it is type preserving.
Because \lang uses an untyped equality judgement, \we can use standard techniques for showing type preservation~\citep{compiling}.
An important proof detail is that equality reflection (and therefore extensionality) is required
to show an $\eta$-equivalence rule for \texttt{case} expressions
and to show that proofs of accessibility are equal,
which are properties used to prove that the translations of an applied fixpoint and its reduction in \lang
are definitionally equal in \CICE.

\section{Status and Future Work}

The work is not yet done;
there remain unresolved problems with the model,
and additional features to add that one would expect
from a practically-useable sized dependent type theory.

\subsection{Universe Levels and \texttt{Size}}

To be able to assign sizes to \emph{general inductive types} such as W types,
which conceptually can have transfinitely many recursive subarguments,
\texttt{Size} itself must be able to express the same transfinitivity.
Therefore, its inductive definition in \CICE mirrors that of \emph{Brouwer ordinals}~\citep{ordinals},
although the domain of the function in the size corresponding to the limit ordinal is an arbitrary type $A$
rather than merely the usual natural numbers.
\texttt{Size} itself must then live in a universe higher than that of $A$,
according to the usual well-formedness restrictions on inductive types.

Recall that the natural type and W types in \lang are parametrized by \texttt{Size}.
Given a W type with type parameters $A : \texttt{Type}_\ell$ and $B : A \rightarrow \texttt{Type}_\ell$,
the type used in limit sizes for the W type would also be $A$.
Meanwhile, the naturals aren't transfinite, so we simply have $A \coloneq \bot : \texttt{Type}_0$, the uninhabited type.
Unfortunately, since \texttt{Size} itself would then live in
\texttt{Type}$_{\ell+1}$ and \texttt{Type}$_1$, respectively,
so must the W type and the natural type,
rather than in \texttt{Type}$_{\ell}$ and \texttt{Type}$_0$ as one would expect.
Intuitively, \texttt{Size} itself must be ``large enough'' (in the type universe sense)
to include all sizes of naturals and elements of W types,
which makes it ``too large'' to live in the same universe as what it should include.

One unsatisfactory solution would be to accept the natural type and W types living in larger universes
than they normally would in an unsized dependent type theory.
Another solution would be to parametrize \texttt{Size} itself by the limit size's type $A$,
which would allow it to live in the same universe as $A$.
However, the translation of sizes and size quantifications and abstractions would have
an underdetermined parameter, and sizes used for one inductive could not be used for another.

\subsection{The Infinite Size}

In nearly all past work on sized types, including the Agda implementation,
there is a notion of an infinite size $\infty$ that is strictly larger than all sizes,
including itself: the relation $\infty < \infty$ holds.
\lang does not have the infinite size, because this property would make sizes no longer well-founded,
undermining all efforts to interpret fixpoints as applications of well-founded induction.
In fact, this is why sized types are inconsistent in Agda:
dependent types make it possible to internalize the order on sizes as an inductive type within Agda itself,
from which well-foundedness can be proven, yielding falsehood when combined with $\infty < \infty$.
Finding a suitable replacement for uses of $\infty$ that capture its convenience while retaining consistency
remains an open problem.
One possibility is to use an existentially size-quantified inductive type in place of the $\infty$-sized inductive%
%\footnote{Dually, the $\infty$-sized \emph{coinductive} type would be \emph{universally} size-quantified.},
but it appears this might require a nonconstructive axiom that does not compute.

\subsection{Coinductive Types}

Aside from termination checking, sized types are also used for
\emph{productivity checking} of \emph{corecursive} definitions,
making reasoning about corecursive constructions much easier.
If \lang is indeed consistent, \we expect that extending the language and the proofs
to include sized coinductive types would be relatively straightforward.

\bibliography{SRC}
\bibliographystyle{ACM-Reference-Format}
\end{document}


\section{The \remove algorithm}
\Label{sec:remove}

The \cxx Standard Library also
contains a function \remove\cite[28.6.8]{cxx-17-draft} performing
the same operation as \removecopy as an in-place algorithm.
Its signature is very similar to that of \removecopy,
except that there is no need for an output array.

\begin{lstlisting}[style=acsl-block]

  size_type remove(value_type* a, size_type n, value_type v);
\end{lstlisting}

Figure~\ref{fig:remove} shows how \remove is supposed
to remove all occurrences of the given value~4 from a range.

\begin{figure}[hbt]
\centering
\includegraphics[width=0.85\textwidth]{Figures/remove.pdf}
\caption{\Label{fig:remove}Effects of \remove}
\end{figure}

\FloatBarrier

\subsection{Formal specification of \remove}

The following listing shows a formal specification of the function \specref{remove}.
Our specification is very similar to the one of \specref{removecopyiii}
except that we using a version of \logicref{Remove} that takes only one pointer argument.

\input{Listings/remove.h.tex}

\clearpage

\subsection{Implementation of \remove}

In the following listing we show our implementation of \implref{remove} together with
the additional loop annotations.
Again, the annotations are very similar to those of the
implementation of \implref{removecopyiii}.

\input{Listings/remove.c.tex}

Also note the use of the predicate \logicref{At} in the loop invariant \inl{unchanged}
and the assertion \inl{update}.

\clearpage


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{physics}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}

\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}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

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

\setlength\parindent{0pt}

%
% Create Problem Sections
%
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\bea}{\begin{flalign*}}
\newcommand{\eea}{\end{flalign*}}

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

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

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Assignment\ \#5}
\newcommand{\hmwkDueDate}{Due on 20th November, 2018}
\newcommand{\hmwkClass}{Advanced Quantum Mechanics}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{}
\newcommand{\hmwkAuthorName}{\textbf{Aditya Vijaykumar}}

%
% Title Page
%

\title{
    %\vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{\hmwkDueDate\ }\\
%    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\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
(\textbf{Acknowledgements} - I would like to thank Chandramouli Chowdhury, Sarthak Duary and Junaid Majeed for discussions.)
\\

\begin{homeworkProblem}[1]
	\textbf{Part (a)}\\
	We first note that,
	\begin{align*}
	\lambda e^{-t/\tau} \mel{n}{x^2}{m} &= \lambda e^{-t/\tau}  \mel{n}{\dfrac{(a_+ + a_-)^2}{2m\omega}}{m} \\
	&=\lambda e^{-t/\tau}  \mel{n}{\dfrac{a_+^2 + a_-^2 + a_+ a_- + a_- a_+}{2m\omega}}{m}\\
	&= \lambda e^{-t/\tau} \dfrac{1}{2 m \omega} \qty[\sqrt{(m+1)(m+2)} \delta_{n,m+2} + \sqrt{m(m-1)} \delta_{n, m-2} + (2m-1) \delta_{n,m}]
	\end{align*}
	As is evident from above, a state $ \ket{m} $ can transition into  $ \ket{m}, \ket{m+2}, \ket{m-2} $ and no other states under a potential with spatial dependence that goes as $ x^2 $. In general, the $ k $-th order coefficient $ c^k_n(t) $ will have $ k $ terms of the form $ \mel{.}{x^2}{.} $. If we start out with ground state $ \ket{0} $, the final state will have contributions from the following states order by order
	\begin{align*}
	\order{\lambda} &\rightarrow \ket{0}, \ket{2} \\
	\order{\lambda^2} &\rightarrow \ket{0}, \ket{2}, \ket{4} \\
	\order{\lambda^3} &\rightarrow \ket{0}, \ket{2}, \ket{4}, \ket{6} \\
	\therefore \order{\lambda^k} &\rightarrow \ket{0}, \ket{2}, \ket{4}, \ldots \ket{2k}
	\end{align*}
	Hence, we see that the $ \ket{n} $ as mentioned in the question should be such that $ n $ is even, and the leading order contribution to the probability will $ \sim (\lambda^{n/2})^2 \sim \lambda^n $.\\

	\textbf{Part (b)}\\
	As described above, upto $ \order{\lambda^2} $ in probability (ie upto $ \order{\lambda} $ in the coefficients), $ \ket{2} $ is the only excited state that can be reached. From $ (5.7.17) $ of Sakurai, we have the relations, (with $ \ket{i,t_0;t} = \sum c_n(t) \ket{n} $)
	\begin{equation*}
	c_n^0 (t) = \delta_{ni} \qq{,} c_n^1 (t) = -i \int_{t_0}^{t} e^{i \omega_{ni} t'} V_{ni}(t') dt'
	\end{equation*}
	Let's calculate $ c_n^1 (t) $,
	\begin{align*}
	c_n^1 (t) &=  -i \lambda \int_{0}^{t} e^{i n \omega t'} \mel{n}{ x^2}{0} e^{-t'/\tau} dt' \\
	&= \dfrac{-i \lambda}{2 m \omega} (\sqrt{2} \delta_{n,2} + \delta_{n,0}) \int_{0}^{t} e^{i n \omega t'}  e^{-t'/\tau} dt'\\
	c_n^1 (t) &= \dfrac{-i \lambda}{2 m \omega} (\sqrt{2} \delta_{n,2} + \delta_{n,0} )\dfrac{e^{i n \omega t}  e^{-t/\tau} - 1}{i n \omega - 1/\tau} \\
	\implies c_2^1 (t) &= \dfrac{-i \lambda }{\sqrt{2} m \omega}  \dfrac{e^{2 i \omega t}  e^{-t/\tau} - 1}{2 i \omega - 1/\tau} \implies  \abs{c_2^1 (t)}^2 = \dfrac{\lambda^2 }{{2} m^2 \omega^2}  \dfrac{ e^{-2t/\tau} + 1 - 2 e^{-t / \tau } \cos 2 \omega t}{4 \omega^2 + 1/\tau^2}
	\end{align*}
	$ \abs{c_2^1}^2 $ is the required probability.
\end{homeworkProblem}

\begin{homeworkProblem}[2]

	We don't need to apply any perturbation theory in this problem, and it can be solved exactly. The Hamiltonian is $ H = \lambda S_1 \cdot S_2 = \lambda( S^2 - S_1^2 - S_2^2 ) $. We consider the action of the Hamiltonian on the singlet state $ \ket{0 0} = \dfrac{\ket{+ -} - \ket{- +}}{\sqrt{2}}$ and $ \ket{1 0 }  = \dfrac{\ket{+ -} + \ket{- +}}{\sqrt{2}} $. We know $ H \ket{00} = -3\lambda /4 \ket{00}  $ and $ S^2 \ket{10} = \lambda/4 \ket{10} $. Initially the system is in $ \ket{+-} = \dfrac{\ket{00} + \ket{10}}{\sqrt{2}} $. Then we know, by the usual rules of time-evolution,
	\begin{align*}
	\ket{\psi_f(t)} = e^{i H t} \ket{+-} &= \dfrac{e^{i\lambda t/4}}{\sqrt{2}} \ket{10} + \dfrac{e^{-i3\lambda t/4}}{\sqrt{2}} \ket{00}\\
	&= \qty(\dfrac{e^{i\lambda t/4}  +{e^{-i3\lambda t/4}}}{2}) \ket{+-} + \qty(\dfrac{e^{i\lambda t/4}  - {e^{-i3\lambda t/4}}}{2}) \ket{-+}\\
	\implies \abs{\ip{+-}{{\psi_f(t)}}}^2 &= \abs{\qty(\dfrac{e^{i\lambda t/4}  +{e^{-i3\lambda t/4}}}{2})}^2  = \dfrac{1 + \cos \lambda t}{2} =  P(\ket{+-})\\
	\implies \abs{\ip{-+}{{\psi_f(t)}}}^2 &= \abs{\qty(\dfrac{e^{i\lambda t/4}  - {e^{-i3\lambda t/4}}}{2})}^2  = \dfrac{1 - \cos \lambda t}{2} = P(\ket{-+})\\
	\implies \abs{\ip{++}{{\psi_f(t)}}}^2 &= 0 =  P(\ket{++})\\
	\implies \abs{\ip{--}{{\psi_f(t)}}}^2 &= 0 =  P(\ket{--})
	\end{align*}
	where $ P(\ket{}) $ denotes probability of initial state to be in state $ \ket{} $.
\end{homeworkProblem}

\begin{homeworkProblem}[3]
	\textbf{Part (a)}\\
	From $ (5.7.17) $ of Sakurai, we have the relations, (with $ \ket{i,t_0;t} = \sum c_n(t) \ket{n} $)
	\begin{equation*}
	c_n^0 (t) = \delta_{ni} \qq{,} c_n^1 (t) = -i \int_{t_0}^{t} e^{i \omega_{ni} t'} V_{ni}(t') dt'
	\end{equation*}
	For our problem, we have $ V = \lambda \delta (x - vt) $. We insert $ 1 = \int dx \ket{x} \bra{x} $ such that $ V_{ni}(t) = \int V(t) u_i^* (x) u_n (x) dx $. We have initial state $ u_i (x) $ and final state $ u_f(x) $. Hence, we can write the above coefficients as,
	\begin{align*}
	c_f^1 (t) &= -i \lambda \int_{-\infty}^{\infty} dx \int_{0}^{t} dt' e^{i (E_i - E_f) t'} \delta(x - vt') u_i^* (x) u_f (x)  \\
	 &= -i \lambda \int_{-\infty}^{\infty} dx  e^{i (E_i - E_f) x/v}  u_i^* (x) u_f (x)
	\end{align*}
	Hence the probability is just $ \abs{c_f^1}^2 $

	\textbf{Part (b)}\\
	We now write,
	\begin{equation*}
	\delta(x-vt) = \dfrac{1}{2 \pi v} \int_{- \infty}^{\infty} d\omega  e^{i\omega (x/v - t)}
	\end{equation*}
	\begin{align*}
	\therefore c_f^1 (t) &= -i \lambda \int_{-\infty}^{\infty} dx \int_{0}^{t} dt' e^{i (E_i - E_f) t'} \dfrac{1}{2 \pi v} \int_{- \infty}^{\infty} d\omega  e^{i\omega (x/v - t')} u_i^* (x) u_f (x)  \\
	&= \dfrac{-i \lambda}{2 \pi v} \int_{-\infty}^{\infty} dx \int_{0}^{t} dt' e^{i (E_{if} - \omega) t'}  \int_{- \infty}^{\infty} d\omega  e^{i\omega x/v} u_i^* (x) u_f (x)  \\
	&=  \dfrac{-i \lambda}{2 \pi v} \int_{-\infty}^{\infty} dx \int_{- \infty}^{\infty} d\omega \delta(E_{fi} - \omega)  e^{i\omega x/v } u_i^* (x) u_f (x)4
	\end{align*}
	Integrating the above will give us the same expression as that is Part (a). We notice that there is this $ \delta (E_{fi} - \omega) $ term, which basically ensures energy conservation.
\end{homeworkProblem}

\begin{homeworkProblem}[4]
	The ground state wavefunction for a hydrogen-like atom is given by,
	\begin{equation*}
	\ket{0_Z} = \dfrac{1}{\sqrt{\pi}} \qty(\dfrac{Z}{a_0})^{3/2} e^{-Zr/a_0}
	\end{equation*}
	We need to find $ \abs{\ip{0_2}{0_1}}^2 $,
	\begin{align*}
	\ip{0_2}{0_1} &= \dfrac{1}{\pi} \qty(\dfrac{2}{a_0^2})^{3/2} \int_{0}^{2\pi} d \phi \int_{0}^{\pi} -d(\cos\theta)  \int_{0}^{\infty} dr r^2 e^{-3r/a_0} \\
	&= \dfrac{1}{\pi} \qty(\dfrac{2}{a_0^2})^{3/2} (4 \pi) \qty(\dfrac{2 a_0^3}{27})\\
	\ip{0_2}{0_1} &= \sqrt{8} \dfrac{8}{27}\\
	\implies \abs{\ip{0_2}{0_1}}^2 &\approx 0.7
	\end{align*}
	So, the probability is close to $ 0.7 $.
\end{homeworkProblem}

\begin{homeworkProblem}[5]
	\textbf{Part (a)}\\
	We first note for $ \ket{\psi_I(t)} = \sum_{n} {c_n(t) \ket{\alpha_n}} $
	\begin{align*}
	i \pdv{\ket{\psi_I}}{t} &= i \pdv{(e^{iH_0t} \ket{\psi_S})}{t} \\
	&= i \qty[e^{iH_0t}\pdv{\ket{\psi_S}}{t}  + iH_0 e^{iH_0t} \ket{\psi_S}]\\
	&= -e^{iH_0t} (H_0 + V) \ket{\psi_S} - H_0 e^{iH_0t} \ket{\psi_S}\\
	&=e^{iH_0t}  V \ket{\psi_S}\\
	\end{align*}

	\begin{align*}
	i \pdv{\ket{\psi_I}}{t} &= V_I \ket{\psi_I}\\
	i \pdv{\ip{\alpha_n}{\psi_I}}{t} &=  \mel{\alpha_n}{V_I}{\psi_I}\\
	\dot{c_n} &= -i  \mel{\alpha_n}{V_I}{\psi_I}\\
	\dot{c_n} &= -i  \mel{\alpha_n}{V}{\alpha_m} e^{i{(E_n - E_m)t}} c_m
	\end{align*}
	So for the given problem, we have
	\begin{align*}
	\ket{\psi_I(t)} &=  {c_1(t) \ket{1} + c_2(t) e^{iEt} \ket{2}}	\\
	\dot{c_1} = -i V_{11} c_1 - i V_{12} e^{-iEt} c_2 = - i \gamma e^{i (\omega-E) t} c_2  &\qq{and} \dot{c_2} = -i V_{21}  e^{iEt}  c_1 - i V_{22}c_2 = -i \gamma e^{i(E-\omega)t} c_1
	\end{align*}
	To solve the above equations, we make the substitution $  c_1 = b_1 e^{i\Delta t} $ and $c_2 = b_2 e^{-i \Delta t}  $, where $ 2 \Delta = \omega - E$. We then have the equations in terms of $ b $'s,
	\begin{equation*}
	i \dot{b_1} = \Delta b_1 + \gamma b_2 \qq{and} i \dot{b_2} =
	\gamma b_1 - \Delta b_2
	\end{equation*}
	These are coupled equations, and we can solve these by making the substitution $ b_1 = A e^{i \Omega t} $ and $  b_2 = B e^{i \Omega t} $. We then have,
	\begin{align*}
	- A \Omega = \Delta A + \gamma B &\qq{and} - B \Omega = \gamma A - \Delta B \\
	\qq{For non-trivial solutions,} -\dfrac{\gamma}{\Delta + \Omega} &= \dfrac{\Delta - \Omega}{\gamma} \implies \Omega = \pm \sqrt{\gamma^2 + \Delta^2} = \pm \Omega_0\\
	\implies c_1 = A_1 e^{i(\Delta + \Omega_0)t} + A_2 e^{i(\Delta - \Omega_0)t} &\qq{and}  c_2 = B_1 e^{i(-\Delta + \Omega_0)t} + B_2 e^{i(-\Delta - \Omega_0)t}
	\end{align*}
	We are told that at $ t=0 $, the system is in state $ \ket{1} \implies c_1(0) = 1, c_2(0) = 0 \implies A_1 = 1 - A_2, B_1 = - B_2$. We also know that $ \dot{c}_2(0) = - i \gamma c_1 (0) $ and $ \dot{c}_1(0) = - i \gamma c_2 (0)  $ which means,
	\begin{align*}
	-i (1-A_1) \Omega_0 +i A_1 \Omega_0 +i \Delta =0 &\implies A_1 = \frac{\Omega_0 -\Delta }{2 \Omega_0 } \qq{and}  A_2 = -\frac{\Omega_0 -\Delta }{2 \Omega_0 }\\
	2 i B_1 \Omega_0 =-i \gamma &\implies B_1 = -\frac{\gamma }{2 \Omega_0 } \qq{and} B_2 = 1 + \frac{\gamma }{2 \Omega_0 } \\
	 \implies c_1 =  \frac{\Omega_0 -\Delta }{2 \Omega_0 } e^{i(\Delta + \Omega_0)t} -\frac{\Omega_0 -\Delta }{2 \Omega_0 } e^{i(\Delta - \Omega_0)t} &\qq{and}  c_2 = -\frac{\gamma }{2 \Omega_0 }  e^{i(-\Delta + \Omega_0)t} + \qty(1 + \frac{\gamma }{2 \Omega_0 }) e^{i(-\Delta - \Omega_0)t}
	\end{align*}
	where $ \Delta = \dfrac{\omega - E}{2} $ and $ \Omega_0 = \sqrt{\gamma^2 + \Delta^2} $\\. We calculate $ \abs{c_2(t)}^2 $ using Mathematica, and we get,
	\begin{equation*}
	 \abs{c_2(t)}^2 = \frac{\gamma ^2 \sin ^2(t \Omega_0 )}{\Omega_0 ^2} \qq{and}	\abs{c_1(t)}^2 = 1 - \frac{\gamma ^2 \sin ^2(t \Omega_0 )}{\Omega_0 ^2}
	 \end{equation*}
	\textbf{Part (b)}\\
	To prove to all orders in perturbation, we consider $ \omega = E \implies \Omega_0 = \gamma \implies \abs{c_2(t)}^2 = {\sin ^2(t \gamma)} $. From the Dyson series, we have,
	\begin{equation*}
	c_2^n (t) =  \bra{2} (-i)^n \int_{0}^{t} dt' \ldots \int_{0}^{t^{(n-1)}} dt^n V_I (t') \ldots V_I(t^{(n)}) \ket{1}
	\end{equation*}
	Inserting a complete set of state before each $ V_I $
	\begin{equation*}
	c_2^n (t) =  \bra{2} (-i)^n \int_{0}^{t} dt' \ldots \int_{0}^{t^{(n-1)}}  dt^n V_I (t') (\ket{1} \bra{1} + \ket{2} \bra{2}) \ldots  (\ket{1} \bra{1} + \ket{2} \bra{2}) V_I(t^{(n)}) \ket{1}
	\end{equation*}
	There is a constraint that the initial state should be $ \ket{1} $ and the final state should be $  \ket{2} $. Since, $  \ket{1} \rightarrow \ket{2} $ and $  \ket{2} \rightarrow \ket{1} $ at each application of $ V_I $, terms with even $ n $ will vanish. For terms with odd $ n $, let's first consider $ n=3 $
	\begin{align*}
	c_2^3 (t) &=   (-i)^3 \int_{0}^{t} dt' \int_{0}^{t'} dt'' \int_{0}^{t''} dt'''  \mel{2}{V_I(t')}{1} \mel{1}{V_I(t'')}{2} \mel{2}{V_I(t''')}{1} \\
	&=   (-i)^3 \int_{0}^{t} dt' \int_{0}^{t'} dt'' \int_{0}^{t''} dt'''  \mel{2}{V_I(t')}{1} \mel{1}{V_I(t'')}{2} \mel{2}{V_I(t''')}{1}\\
	&=   (-i\gamma)^3 \int_{0}^{t} dt' \int_{0}^{t'} dt'' \int_{0}^{t''} dt'''  e^{iEt'} \mel{2}{V(t')}{1} e^{iEt''} \mel{1}{V(t'')}{2} e^{iEt''} \mel{2}{V(t''')}{1} \\
	&=   (-i \gamma)^3 \int_{0}^{t} dt' \int_{0}^{t'} dt'' \int_{0}^{t''} dt'''  e^{iEt'} e^{-iEt'}  e^{iEt''}  e^{-iEt''}  e^{iEt''} e^{-iEt''} \\
	&=   (-i \gamma)^3 \dfrac{t^3}{3!}
	\end{align*}
	We see that because $ \omega = E $, all the matrix elements become independent of $ t $, and we get a very simple answer for $ c_2^n = (-i \gamma)^n \dfrac{t^n}{n!}  $. Hence,
	\begin{equation*}
	c_2 (t) = \sum_{\qq{odd n}}(-i \gamma)^n \dfrac{t^n}{n!} = -i \sin t \gamma  \implies  \abs{c_2(t)}^2  = \sin^2 t \gamma
	\end{equation*}
	Hence the formula is verified.
\end{homeworkProblem}

\end{document}


\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{amsthm}
\usepackage{amsfonts,amsmath, amssymb,latexsym,mathrsfs}
\usepackage[margin=1.15in]{geometry}
\usepackage{enumitem}
\setlength{\parindent}{0pt}
\usepackage{tikz-cd}
\usepackage{fancyhdr}

\theoremstyle{definition}
\newtheorem{thm}{Theorem}[section]

\newtheorem{prop}{Proposition}[section]

\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\theoremstyle{remark}
\newtheorem*{remark}{Remark}

\theoremstyle{definition}
\newtheorem{example}{Example}[section]

\theoremstyle{definition}
\newtheorem{lem}{Lemma}[section]

\theoremstyle{definition}
\newtheorem{cor}{Corollary}[section]

\date{}
\title{Final Exam Summary(After Exam 2)}

\begin{document}
\maketitle

\section{Power Series}
\begin{definition}
	A power series about $x = a$ is a sum of constants times powers of $(x - a)$:
	$C_0 + C_1(x - a) + C_2(x - a)^2 + \ldots + C_n(x - a)^n + \ldots =	\sum_{n
	=0}^{\infty}	C_n(x - a)^n$.
\end{definition}

If we fix a specific value of $x$, we can just consider plugging x with the value we have, and convergence here makes sense.

\begin{definition}
For a fixed value of $x$, if this sequence of partial sums converges to a limit $L$, that is, if
$\lim_{n \to \infty}S_n(x) = L$, then we say that the power series converges to $L$ for this value of $x$.
\end{definition}

Based on the discussion we will see that, The interval of convergence for a power series is usually centered at a point $x=a$, and extends the same length to both side, thus we denote this length as radius of convergence.\\

Moreover, each power series falls into one of the three following cases, characterized by its \textcolor{red}{radius of convergence}, $R$.
\begin{itemize}
\item The series converges only for $x = a$; the radius of convergence is defined to be $R = 0$.
\item The series converges for all values of $x$; the radius of convergence is defined to be
$R = \infty$.
\item There is a positive number $R$, called the radius of convergence, such that the series
converges for $|x - a| < R$ and diverges for $|x - a| > R$.
\end{itemize}
The interval of convergence is the interval between $a - R$ and $a + R$, including any
endpoint where the series converges.
\\

Then there is a question arises, how to find this radius of convergence then?\\

This question can be determined by considering using \textcolor{red}{ratio test} on the series, assuming $x\neq a$.
The details are included in Chapter 9.5 in the book.

\section{Taylor Polynomial and Taylor Series}
\subsection{Taylor Polynomial}
If we try to approximate the function locally using a polynomial, there is one thing we want to acquire, i.e. we want the polynomial $P(x)$ with the property that $P^{(n)}(a)=f^{(n)}(a)$ if we approximate the function at the point $x=a$. Considering merely the situation about $x=0$, recall what we did in the class, we will have the following.

\textcolor{red}{Taylor Polynomial of Degree $n$ Approximating $f(x)$ for $x$ near $0$} is \[f(x) \approx P_n(x)
	= f(0) + f'(0)x + \frac{f''(0)}{2!}x^2 + \frac{f'''(0)}{3!}x^3 + \frac{f^{(4)}(0)}{4!} x^4 + \ldots + \frac{f^{(n)}(0)}{n!} x^n\]
	We call $P_n(x)$ the Taylor polynomial of degree $n$ centered at $x = 0$, or the Taylor poly
	nomial about $x = 0$.\\

More generally, \textcolor{red}{Taylor Polynomial of Degree $n$ Approximating $f(x)$ for $x$ near $a$} is \[f(x) \approx P_n(x)
= f(a) + f'(a)(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \frac{f'''(a)}{3!}(x-a)^3  + \ldots + \frac{f^{(n)}(a)}{n!} (x-a)^n\]
We call $P_n(x)$ the Taylor polynomial of degree $n$ centered at $x = a$, or the Taylor poly
nomial about $x =a$.\\

Notice that Taylor Polynomial of Degree $n$ Approximating $f(x)$ for $x$ near $a$ will have the property that $P_n^{(m)}(a)=f^{(m)}(a)$ for $0 \leq m \leq n$.

\subsection{Taylor Series}

Notice that in the Taylor polynomial, if we let $n$ here goes to infinity, we will get a series $P(x)$ with $P^{(m)}(a)=f^{(m)}(a)$ for $0 \leq m < \infty$ and thus we will expect that the series gives a good approximation about $f(x)$ around $a$, and actually when it converges, it is exactly the value you will get in $f(x)$, and this is called the Taylor Series.

\textcolor{red}{Taylor Series for $f(x)$ about $x=0$} is \[f(x) = f(0) + f'(0)x + \frac{f''(0)}{2!}x^2 + \frac{f'''(0)}{3!}x^3 + \frac{f^{(4)}(0)}{4!} x^4 + \ldots + \frac{f^{(n)}(0)}{n!} x^n+ \ldots \]
We call $P_n(x)$ the Taylor polynomial of degree $n$ centered at $x = 0$, or the Taylor poly
nomial about $x = 0$.\\

More generally, \textcolor{red}{Taylor Series for $f(x)$ about $x=a$} is \[f(x) = f(a) + f'(a)(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \frac{f'''(a)}{3!}(x-a)^3  + \ldots + \frac{f^{(n)}(a)}{n!} (x-a)^n+ \ldots \]
We call $P_n(x)$ the Taylor polynomial of degree $n$ centered at $x = a$, or the Taylor poly
nomial about $x =a$.\\

Moreover, there are \textcolor{red}{several important cases} that we consider, each of them is an Taylor expansion of a function about $x=0$:
\begin{itemize}
\item \[e^{x}= 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \frac{x^5}{5!} + \frac{x^6}{6!} + \frac{x^7}{7!} + \frac{x^8}{8!} + \cdots\text{ converges for all } x\]
\item \[\sin(x)=\sum\limits_{n=0}^\infty \dfrac{x^{2n+1}}{(2n+1)!}\cdot(-1)^n = x-\dfrac{x^3}{3!}+\dfrac{x^5}{5!}-\dfrac{x^7}{7!}+\dots\text{ converges for all } x\]
\item \[\cos(x)=\sum\limits_{n=0}^\infty \dfrac{x^{2n}}{(2n)!}\cdot(-1)^n = 1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}+\dots \text{ converges for all } x\]
\item \[(1 + x)^p = \sum_{k=0}^{\infty} \binom{p}{k} x^k= \sum_{k=0}^{\infty} \frac{p!}{k!(p-k)!} x^k=\]\[1 + px + \frac{p(p - 1)}{2!}x^2 + \frac{p(p - 1)(p - 2)}{3!}x^3 + \cdots \text{ converges for } -1 < x < 1.\]
\item \[\ln(1+x) =\sum_{n = 0}^{\infty}\frac{(-1)^nx^{n+1}}{n+1}= x-\frac{x^2}{2}+\frac{x^3}{3}-\frac{x^4}{4}+\cdots,\]

\end{itemize}

Moreover, we can definitely find Taylor Series based on the existing series using \textcolor{red}{four methods}:
\begin{itemize}
	\item Substitude

Example: Taylor Series about $x=0$ for $f(x)=e^{-x^2}$

	\item Differentiate

Example: Taylor Series about $x=0$ for $f(x)=\frac{1}{(1-x)^2}$

	\item Integrate

Example: Taylor Series about $x=0$ for $f(x)=\arctan x$ (Hint: What is $\frac{d}{dx}(\arctan x)$?)
	\item Multiply

	Example: Taylor Series about $x=0$ for $f(x)=x^2 \sin x$\\
	Example: Taylor Series about $x=0$ for $f(x)=\sin x \cos x$\\
	Example: Taylor Series about $x=0$ for $f(x)=e^{\sin x}$\\

\end{itemize}

\section{Parametric Equations and Polar Coordinate}
\subsection{Parametric Equations}
To represent the motion of a particle in the $xy$-plane we use two equations, $x=f(t)$ and $y=g(t)$, then at the time $t$ the particle is at the location $(f(t),g(t)$. In this case, we call the equations for $x$ and $y$ the parametric equations, with parametrization $t$.

Remember that, in parametric equation, for the same line, the parametrization is not unique, and the different parametrization encodes two information:\\
1. Speed of the particle.\\
2. Direction of the motion.\\

\subsubsection{Special Parametric Equations}

\begin{itemize}
\item \textcolor{red}{Parametric Equations for a Straight Line}

An object moving along a line through the point $(x_0, y_0)$, with $dx/dt = a$ and $dy/dt = b$,
has parametric equations
$x = x_0 + at, y = y_0 + bt$.
The slope of the line is $m = b/a$.
\item\textcolor{red}{Parametric Equations for a circle with radius $k$}

An object moving along a circle of radius $k$ counterclockwise has parametric equations
$x = k\cos(t), y = k\sin(t)$.
\end{itemize}

\subsubsection{Slope and concavity of the curve}
As we discussed in class, we can think of this as a result due to chain rule if we have that $y=F(x)$ as well.

But to summarize, we have the \textcolor{red}{slope} of the parametrized curve to be
\[\frac{dy}{dx}=\frac{dy/dt}{dx/dt}\]
and the \textcolor{red}{concavity} of the parametrized curve to be
\[\frac{d^2y}{dx^2}=\frac{(dy/dx)/dt}{dx/dt}\]

\subsubsection{Speed and distance}

The \textcolor{red}{instantaneous speed} of a moving object is defined to be
$$v = \sqrt{(dx/dt)^2 + (dy/dt)^2} =\sqrt{(v_x)^2 + (v_y)^2}$$.
The quantity $v_x = dx/dt$ is the instantaneous velocity in the $x$-direction; $v_y = dy/dt$ is the
instantaneous velocity in the $y$-direction.
And we call that $(v_x,v_y)$ to be the velocity vector.

Moreover, the \textcolor{red}{distance} traveled from time $a$ to $b$ is $$\int^b_a v(t) dt = \int_a^b \sqrt{(dx/dt)^2 + (dy/dt)^2} dt$$

\subsection{Polar Coordinate}

Polar coordinates is the coordinates determined by specifying the distance of the point to origin and the angle measured counterclockwise from positive $x$-axis to the line joining the line connecting the point and the origin.

\subsubsection{Relation between Cartesian and Polar}

\textcolor{red}{Cartesian to Polar}: $$(x,y) \to (r= \sqrt{x^2 + y^2}, \theta) \text{ (Here we have that } \tan \theta = \frac{y}{x} \text{)}$$
Note that $\theta$ does not have to be $\arctan(\frac{y}{x})$!

Polar to Cartesian: $$(r,\theta) \to (x=r \cos \theta, y=r \sin \theta)$$

\subsubsection{Slope, Arc length and Area in Polar Coordinates}

By the relation $x=r \cos \theta, y=r \sin \theta$, given a curve $r=f(\theta)$, we have that $x=f(\theta) \cos \theta, y=f(\theta) \sin \theta$, and thus are parametrized equations of parameter $\theta$. Therefore we have that the \textcolor{red}{slope} of to be
\[\frac{dy}{dx}=\frac{dy/d\theta}{dx/d\theta}\]

The \textcolor{red}{arc length} from angle $a$ to $b$ is $$\int_a^b \sqrt{(dx/d\theta)^2 + (dy/d\theta)^2} d\theta=\int_a^b \sqrt{r^2 + (dr/d\theta)^2} d\theta$$

Moreover, due to the fact that the \textcolor{red}{area of the sector} is $1/2 r^2 \theta$, we have that for a curve $r = f(\theta)$, with \textcolor{red}{$f(\theta)$ continuously of the same sign}, the area of the region enclosed is $$\frac{1}{2}\int^{b}_{a}f(\theta)^2 d\theta$$

\end{document}


\documentclass[paper=a4, fontsize=11pt]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsmath,amsfonts,amsthm}

\usepackage{pstricks}
\usepackage{auto-pst-pdf}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{hhline}

\usepackage{lipsum}

\usepackage{graphicx}
\usepackage{float}
  \floatplacement{figure}{H}
  \floatplacement{table}{H}

\usepackage{sectsty}
\allsectionsfont{\centering \normalfont\scshape}

\usepackage{fancyhdr} % Custom headers and footers
\pagestyle{fancyplain} % Makes all pages in the document conform to the custom headers and footers
\fancyhead{} % No page header - if you want one, create it in the same way as the footers below
\fancyfoot[L]{} % Empty left footer
\fancyfoot[C]{} % Empty center footer
\fancyfoot[R]{\thepage} % Page numbering for right footer
\renewcommand{\headrulewidth}{0pt} % Remove header underlines
\renewcommand{\footrulewidth}{0pt} % Remove footer underlines
\setlength{\headheight}{13.6pt} % Customize the height of the header

\usepackage[labelformat=empty]{caption}
\usepackage{color}
\usepackage{listings}
\lstset{ %
language=bash,                % choose the language of the code
basicstyle=\footnotesize,       % the size of the fonts that are used for the code
numbers=left,                   % where to put the line-numbers
numberstyle=\footnotesize,      % the size of the fonts that are used for the line-numbers
stepnumber=1,                   % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt,                  % how far the line-numbers are from the code
backgroundcolor=\color{white},  % choose the background color. You must add \usepackage{color}
showspaces=false,               % show spaces adding particular underscores
showstringspaces=false,         % underline spaces within strings
showtabs=false,                 % show tabs within strings adding particular underscores
frame=single,           % adds a frame around the code
tabsize=2,          % sets default tabsize to 2 spaces
captionpos=b,           % sets the caption-position to bottom
breaklines=true,        % sets automatic line breaking
breakatwhitespace=false,    % sets if automatic breaks should only happen at whitespace
escapeinside={\%*}{*)}          % if you want to add a comment within your code
}
\usepackage{hyperref}

\numberwithin{equation}{section} % Number equations within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{figure}{section} % Number figures within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)

\setlength\parindent{0pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text

%----------------------------------------------------------------------------------------
%	TITLE SECTION
%----------------------------------------------------------------------------------------

\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height

\title{
\normalfont \normalsize
\textsc{Computational Science} \\ [25pt] % Your university, school and/or department name(s)
\horrule{0.5pt} \\[0.2cm] % Thin top horizontal rule
\small Homework - Introduction to Frontiers of Computational Science\\ % The assignment title
%\horrule{2pt} \\[0.5cm] % Thick bottom horizontal rule
}

\author{\small{Ridlo W. Wibowo || 1215011069}} % Your name

\date{\small\today} % Today's date or a custom date

\begin{document}
\maketitle % Print the title

\section{Problem 1}
Solve the following equations:
\begin{equation}
\label{eq:satu}
\frac{d}{dt} x_1(t) = \dot{x}_1 =  \mu(-x_1(t) +   x_2(t)         )
\end{equation}
\begin{equation}
\label{eq:dua}
\frac{d}{dt} x_2(t) = \dot{x}_2 =  \mu( x_1(t) - 2x_2(t) + x_3(t))
\end{equation}
\begin{equation}
\label{eq:tiga}
\frac{d}{dt} x_3(t) = \dot{x}_3 =  \mu(            x_2(t) - x_3(t))
\end{equation}
where $x_i(0) = x^0_i$ ($i=1,2,3$).\\

\textbf{Answer}\\
if we sum all the equations we obtain:
\begin{equation}
\label{eq:jwb1}
\dot{x}_1 + \dot{x}_2 + \dot{x}_3 = 0
\end{equation}
then if we substract \eqref{eq:satu} with \eqref{eq:tiga}, we obtain:
\begin{equation}
\label{eq:jwb2}
\dot{x}_1 - \dot{x}_3 = -\mu(x_1 - x_3)
\end{equation}
also, we can sum \eqref{eq:satu} and \eqref{eq:dua} then substract it with two times \eqref{eq:dua}, and we will get:
\begin{equation}
\label{eq:jwb2}
\dot{x}_1 - 2\dot{x}_2 + \dot{x}_3 = -3 \mu(x_1 - 2x_3 + x_3)
\end{equation}

the solution:
\begin{equation}
\label{eq:sol1}
(x_1 + x_2 + x_3)_{(t)} = (x_1 + x_2 + x_3)_{(0)}
\end{equation}
\begin{equation}
\label{eq:sol2}
(x_1 - x_3)_{(t)} = (x_1 - x_3)_{(0)} e^{-\mu t}
\end{equation}
\begin{equation}
\label{eq:sol3}
(x_1 - 2x_2 + x_3)_{(t)} = (x_1 - 2x_2 + x_3)_{(0)} e^{-3 \mu t}
\end{equation}

if we add two times \eqref{eq:sol1} with \eqref{eq:sol3}:
\begin{equation}
(x_1 + x_3)_{(t)} = \frac{1}{3} x_1^{(0)} ( 2 + e^{-3\mu t}) + \frac{2}{3} x_2^{(0)} ( 1 - e^{-3\mu t}) + \frac{1}{3} x_3^{(0)} (2 + e^{-3\mu t})
\end{equation}
operate with \eqref{eq:sol2}:
\begin{equation}
\label{eq:fin1}
x_1^{(t)} = \frac{1}{6} x_1^{(0)} ( 2 + e^{-3\mu t} + e^{-\mu t}) + \frac{1}{3} x_2^{(0)} ( 1 - e^{-3\mu t}) + \frac{1}{6} x_3^{(0)} ( 2 + e^{-3\mu t} - e^{-\mu t})
\end{equation}
\begin{equation}
\label{eq:fin2}
x_3^{(t)} = \frac{1}{6} x_1^{(0)} ( 2 + e^{-3\mu t} - e^{-\mu t}) + \frac{1}{3} x_2^{(0)} ( 1 - e^{-3\mu t}) + \frac{1}{6} x_3^{(0)} ( 2 + e^{-3\mu t} + e^{-\mu t})
\end{equation}
if we substract \eqref{eq:sol1} with \eqref{eq:sol3}:
\begin{equation}
\label{eq:fin3}
x_2^{(t)} = \frac{1}{3} x_1^{(0)} ( 1 - e^{-3\mu t}) + \frac{1}{3} x_2^{(0)} ( 1 + 2e^{-3\mu t}) + \frac{1}{3} x_3^{(0)} ( 1 - e^{-3\mu t})
\end{equation}

so we get the solutions for this problem in equation \eqref{eq:fin1}, \eqref{eq:fin2}, and \eqref{eq:fin3}. We also can use eigenvalue problem to get the same result.

%\begin{figure}
%	\centering
%	\includegraphics[width=0.8\textwidth]{verlet2.png}
%	\caption{Comparison of the result from Verlet algorthm using different $\Delta t$.}
%\end{figure}

\newpage
\section{Problem 2}
Check if $\begin{pmatrix} 1 \\ 1 \\ 1\end{pmatrix}$, $\begin{pmatrix} 1 \\ 0 \\ -1\end{pmatrix}$, and $\begin{pmatrix} 1 \\ -2 \\ 1\end{pmatrix}$ are orthogonal to each others. Normalize and check the unitary condition.\\

\textbf{Answer}:\\
for orthogonality we can use dot product to each pair of vector:
$v_{i} \cdot v_{j} = 0$ for $i \neq j$, easily we can prove that all combination resulting zero dot product. For example:\\
$ v_1 \cdot v_2 = \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix} \cdot \begin{pmatrix} 1 \\ 0 \\ -1 \end{pmatrix} = 1\cdot 1 + 1 \cdot 0 + 1 \cdot -1 = 0 $\\

Normalize vector would be $(e_1, e_2, e_3)$:\\
$\frac{1}{\sqrt{3}} \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix}$, $\frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0 \\ -1 \end{pmatrix}$, and $\frac{1}{\sqrt{6}} \begin{pmatrix} 1 \\ -2 \\ 1 \end{pmatrix}$

Checking unitary relation\\
$Q = \begin{pmatrix} \frac{1}{\sqrt{3}} & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{6}} \\
\frac{1}{\sqrt{3}} & 0 & \frac{-2}{\sqrt{6}} \\
\frac{1}{\sqrt{3}} & \frac{-1}{\sqrt{2}} & \frac{1}{\sqrt{6}}
\end{pmatrix}$\\

if we inverse it using $Q^{-1} = \frac{1}{\det(Q)} (adj(Q))$, this matrix will become:\\

$Q^{-1} =
\begin{pmatrix}
\frac{1}{\sqrt{3}} & \frac{1}{\sqrt{3}} & \frac{1}{\sqrt{3}}\\
\frac{1}{\sqrt{2}} & 0 & \frac{-1}{\sqrt{2}} \\
\frac{1}{\sqrt{6}} & \frac{-2}{\sqrt{6}} & \frac{1}{\sqrt{6}}
\end{pmatrix}$\\

and the unitary relation is proven $Q^{-1} = Q^{T}$

\begin{postscript}
\psset{fillstyle=solid}
\psscalebox{0.75}{%
\begin{pspicture}(-5.25,-5.25)(5.25,5.25)%
  \pscircle*[linecolor=cyan]{5}
  \psgrid[subgriddiv=0,gridcolor=lightgray,gridlabels=0pt]
  \Huge\sffamily\bfseries
  \rput(-4.5,4.5){A} \rput(4.5,4.5){B}
  \rput(-4.5,-4.5){C}\rput(4.5,-4.5){D}
  \rput(0,0){auto-pst-pdf}
  \rmfamily
  \rput(0,-3.8){PSTricks}
  \rput(0,3.8){\LaTeX}
\end{pspicture}}
\end{postscript}

\scalebox{1} % Change this value to rescale the drawing.
{
\begin{pspicture}(0,-2.69)(5.38,2.69)
\psframe[linewidth=0.04,dimen=outer](5.38,2.69)(0.0,-2.69)
\psframe[linewidth=0.04,dimen=outer](4.34,1.53)(1.2,-1.61)
\psframe[linewidth=0.04,dimen=outer](2.18,1.31)(1.48,0.61)
\psframe[linewidth=0.04,dimen=outer](3.16,-0.79)(2.48,-1.47)
\end{pspicture}
}

\end{document}


\section{Data} \label{sec:data}

In this paper I've selected 11 differenct stocks, to run my analysis on. The companies are:
\textit{Apple, General Electric, Boeing, Walmart, Coca Cola, JP Morgan Chase, Chevron, Cardinal Health, Exxon Mobile, IBM, Intel}. The companies have been chosen because they represent different sectors of the economy, and all of them have been going concerns for +30 years. The data covers the period: January 1990 to June 2019. The data consists of daily the Adjusted Close price. The data is acquired using a public API provided by \textit{Quandle}.

\begin{table}[ht]
\centering
\caption{Summary statistics of all 11 stocks}
\input{tables/describe.tex}
\label{tab:rawdata}
\end{table}

Table \ref{tab:rawdata} shows summary statistics of the raw data. On average 7114 observations is present for the total time period of 30 years. Figure \ref{fig:historicaltraces} presents all 11 traces. From this figure we can quickly deduce that the timeseries does not show stationarity, and in the long run follows an upward trend. For the analysis carried out in this paper, a transformation of the data is therefore necessary.
Instead of investigating stock prices, the focus will be on daily percentage change in stock prices. The summary statistics of this is shown in figure \ref{tab:cleandata}. Where the count of this now cleansed data is 7113. Additional to finding the percentage change of daily stock prices, rows containing NaN-values have been purged. In the appendix figure \ref{fig:returns_boxplots} shows the boxplot of the individual stocks expected daily return

\begin{figure}[ht]
\centering
\includegraphics[scale=0.45]{figures/historicaltraces.png}
\caption{Historical trace plots of all 11 stocks}
\label{fig:historicaltraces}
\end{figure}

\begin{table}[ht]
\centering
\caption{Summary statistics of all 11 stocks, percentage change}
\input{tables/cleandescribe.tex}
\label{tab:cleandata}
\end{table}

\subsection{Structural Breaks in the data}

This paper assumes that the underlying data generating process of the stock market experiences structural breaks. To confirm this whether or not the data display structural breaks we continue with a visual inspection of the expected returns and covariances of the returns.

Figure \ref{fig:structuralbreaksmeans} displays the bi-annual means of 4 stocks, these being Apple, General Electric, Boeing and Walmart. The displayed stocks are chosen randomly, and it is confirmed in the data that the same pattern is present in the other stocks. The figure shows the expected daily return on each of the stocks for a given year in the sequence: $1992, 1992, 1994, \cdots, 2018$. So for each of the calculated means, we have a one year period, where no mean is calculated. This is to avoid, that a possible structural break could be between two years an disturb the picture. This figure shows, as suspected, that the returns does not seem to adhere to the CAPM assumptions, of a single a vector of expected returns $\mu$, since this would imply that for each year each stock would have the approximately same expected return, which is not what the data displays. The same is true for the covariance matrix $\Omega$ which can be seen in the appendix figure \ref{fig:structuralbreakscovariances}.

\begin{figure}[ht]
\centering
\includegraphics[scale=0.45]{figures/structural_breaks_means.png}
\caption{Bi-annual means of 4 stocks}
\label{fig:structuralbreaksmeans}
\end{figure}


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage[utf8]{luainputenc}
\usepackage{aeguill}
\usepackage{setspace}

\tikzstyle{edge} = [fill,opacity=.5,fill opacity=.5,line cap=round, line join=round, line width=50pt]
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{9 février, 2015}
\maketitle
{\bfseries hypergraph} $H$ is a set $V$ called the vertex set together with nonempty subsets of $V$ called edges.
\subsubsection*{example}
\begin{enumerate}
\item
every  graph is a hypergraph. in a graph all edges are size $2$.
\item
$H: V=\{1,2,3,4\}, E=\{\{1,2,4\},\{2,3,4\},\{3,4,5\}\}$
\item
\begin{tikzpicture}[main_node/.style={circle,draw,text=black,inner sep=1pt,outer sep=0pt]}]
\node[main_node] (1) at (-1,-1) {};
\node[main_node] (2) at (0,-1) {};
\node[main_node] (3) at (1,-1) {};
\node[main_node] (4) at (0,1) {};
\node[main_node] (5) at (1,1) {};
\begin{pgfonlayer}{background}
\draw[edge,color=yellow] (1) -- (2) -- (3);
\begin{scope}[transparency group,opacity=.5]
\draw[edge,opacity=1,color=green] (2) -- (3) -- (5);
%\fill[edge,opacity=1,color=green] (v3.center) -- (v5.center) -- (v6.center) -- (v3.center);
\end{scope}
\draw[edge,color=red,line width=40pt] (4) -- (5);
\end{pgfonlayer}
\end{tikzpicture}
\end{enumerate}
if each edge has the same size then they are called {\bfseries $k$-uniform}. degree still makes sense,as does multi vs simple

we can associate a bipartite graph to any hypergraph

the bipartite graph of $H$ has partites $V$ and $E$. it has edges from $v_i$ to $e_j$ if $v_i\in e_j$
\begin{tikzpicture}[main_node/.style={circle,draw,text=black,inner sep=1pt,outer sep=0pt]}]
\node[main_node] (5) at (-1,-1) {5};
\node[main_node] (6) at (0.5,1) {a};
\node[main_node] (4) at (0,-1) {4};
\node[main_node] (3) at (1,-1) {3};
\node[main_node] (1) at (0,1) {1};
\node[main_node] (2) at (1,1) {2};
\node[main_node] (7) at (-1.5,-1) {d};
\node[main_node] (8) at (0.5,-1) {c};
\node[main_node] (9) at (.5,0) {b};
\begin{pgfonlayer}{background}
\draw[edge,color=yellow] (5) -- (4) -- (3);
\begin{scope}[transparency group,opacity=.5]
\draw[edge,opacity=1,color=green] (2) -- (3) -- (4);
%\fill[edge,opacity=1,color=green] (v3.center) -- (v5.center) -- (v6.center) -- (v3.center);
\end{scope}
\draw[edge,color=red,line width=40pt] (1) -- (2);
\draw[edge,color=purple,line width=40pt] (5)--(5);
\end{pgfonlayer}
\end{tikzpicture}
\tikz\path [graphs/.cd, nodes={shape=circle, draw, text=black,inner sep=1pt,outer sep=0pt}]
%  graph [tree layout] { 1 -- a,a--2,2--b,b--3,3--c,b---4,4--c,5--d,c--5 }
  graph [tree layout] {1--a--2--b--3--c--5--d, b--4--c}
  [shift=(0:1)];
\subsubsection*{question}
can we construct a hypergraph out of a bipartite graph? no in general.

restriction: cannot have an isolated vertex on the edge side of hypergraph.

$\{\text{hpergraphs}\}\leftrightarrow\{\text{hypergraphs w/ no isolated right side vertices}\}$

\section*{adjacency matrices}
they still exist

a hypergraph $H=(V,E)$ is an $|V|\times|E|$ matrix $A(H)$ such that $a_{ij}=1$ if $v_i\in e_j$ or else $a_{ij}=0$

example:
\begin{tikzpicture}[main_node/.style={circle,draw,text=black,inner sep=1pt,outer sep=0pt]}]
\node[main_node] (5) at (-2,-2) {5};
\node[main_node] (6) at (1,2.3) {b};
\node[main_node] (4) at (0,-2) {4};
\node[main_node] (3) at (2,-2) {3};
\node[main_node] (3) at (2.5,-2) {e};
\node[main_node] (1) at (0,2) {1};
\node[main_node] (2) at (2,2) {2};
\node[main_node] (7) at (-1,0) {c};
\node[main_node] (8) at (1,-2) {d};
\node[main_node] (9) at (1.3,-.) {a};
\begin{pgfonlayer}{background}
\draw[edge,color=yellow] (5) -- (4) -- (3);
\begin{scope}[transparency group,opacity=.5]
\draw[edge,opacity=1,color=green] (2) -- (5) -- (4);
%\fill[edge,opacity=1,color=green] (v3.center) -- (v5.center) -- (v6.center) -- (v3.center);
\end{scope}
\draw[edge,color=red,line width=40pt] (1) -- (2);
\draw[edge,color=purple,line width=40pt] (1)--(3);
\draw[edge,color=blue,line width=40pt] (3)--(3);
\end{pgfonlayer}
\end{tikzpicture}

the transpose of $A(h)$ has another hypergraph associated to it called the dual of $H$. Denoted $H^*$. note $H^{**}=H$.

\subsection*{question:} how do hypergraph adjacency matrices compare to ``regular'' adjacency matrices?

hypergraph:
no symmetry, $A^T(H)\ne A(H)$
and $H^*\ne H$

graph:
$A^T(G)=A(G)$, $G^*=G$

it turns out that the matrices are \emph{very}  different.
\end{document}


% !Mode:: "TeX:UTF-8"
% !TEX program  = xelatex
\section{Conclusions and Discussions}\label{S:conclusions}
From this article, we introduce projectile motion and quadratic equation through a real world problem --- \emph{what angle should we throw a football for maximum range}, then we give a proper and accurate definition of quadratic equation, from which we derive quadratic formula for solving quadratic equations. Furthermore, we list some useful applications of the quadratic equation and implement them in \texttt{Python}.


\documentclass{article}
\usepackage{tocloft}
\include{common_symbols_and_format}
\renewcommand{\cfttoctitlefont}{\Large\bfseries}

\begin{document}
\logo
\rulename{Percentage Price Oscillator} %Argument is name of rule
\tblofcontents

\ruledescription{The percentage price oscillator (PPO) is a momentum indicator that measures the difference between two moving averages as a percentage of the larger moving average. The moving averages are a 26-period and 12-period exponential moving average (EMA). The Percentage Price Oscillator is shown with a signal line, a histogram and a centerline. Signals are generated with signal line crossovers, centerline crossovers, and divergences. A bullish reversal of an asset is identify when the PPO cross above zero line.
                 And a bearish reversal when the PPO cross below the zero line.
}

\howtotrade
{The strategy is to identify asset's price cycles.
Bullish Reversal - when PPO is above zero \&
Bearish Reversal - when PPO is below zero.
}

\ruleparameters %You can include however many arguments (in groups of 4) as you want!
{Short term look back Length}{12}{Short term look back length used to compute EMA.}{$\lookbacklength_{s}$}
{Long term look back Length}{26}{Long term look back length used to compute EMA.}{$\lookbacklength_{l}$}
{Signal look back Length}{9}{Look back length used to generate Signal line.}{$S_{l}$}
\stoptable %must be included or Tex engine runs infinitely

\newpage
\section{Equation}
Below are the equations which govern how this specific trading rule calculates a trading position.

\begin{equation}
    PPO = \frac{EMA(\lookbacklength_{s}) -         EMA(\lookbacklength_{l})}{EMA(\lookbacklength_{l})} \times 100
\end{equation}
\begin{equation}
    Signal = EMA(S_{l})
\end{equation}
\\ % creates some space after equation
where:

$EMA(\lookbacklength_{s})$: is the short term exponentially weighted average.

$EMA(\lookbacklength_{l})$: is the long term exponentially weighted average.

$EMA(S_{l})$: is the exponentially weighted average computed to generate signal line.

\keyterms
\furtherlinks %The footer
\end{document}