\documentclass[12pt, titlepage]{article}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=red,
    urlcolor=blue
}
\usepackage[round]{natbib}

\input{../../Comments}
\input{../../Common}
%\newcommand{\li}[1]{\texttt{#1}}
\begin{document}

\title{A Fourier Series Library: System Verification and Validation Plan for FSL}
\author{Bo Cao}
\date{\today}

\maketitle

\pagenumbering{roman}

\section{Revision History}

\begin{tabularx}{\textwidth}{p{3cm}p{2cm}X}
\toprule {\bf Date} & {\bf Version} & {\bf Notes}\\
\midrule
Oct. 28, 2019  & 0.99 & First draft.\\
Dec. 5, 2019 & 1.0 & Final version.\\
\bottomrule
\end{tabularx}

\newpage

\tableofcontents

\newpage

\section{Symbols, Abbreviations and Acronyms}

Some symbols, abbreviations and acronyms are defined in the Software Requirements Specification(SRS)
document\footnote{This document is available at
\url{https://github.com/caobo1994/FourierSeries/blob/master/docs/SRS/SRS.pdf}.}. For
simplicity and maintainability, they are not redefined here. Readers shall refer
to the CA documents when a certain item is not defined here.

\vspace{1cm}

\renewcommand{\arraystretch}{1.2}
\begin{tabular}{l l}
  \toprule
  \textbf{symbol} & \textbf{description}\\
  \midrule
  T & Test\\
  \bottomrule
\end{tabular}\\

\newpage

\pagenumbering{arabic}

\section{General Information} This document provides an overview of the
Verification and Validation (VnV) plan for the Fourier Series Library (FSL). It
lays out the purpose, methods, and test cases for the VnV procedure.

\subsection{Summary}

The library to be tested is called the Fourier Series Library (FSL). This
library performs a set of computations, transformations, and/or input/output at
the request of the library user.

\subsection{Objectives}

The intended objective of the VnV procedure is to verify that this library has
generally met the requirements described in the CA document. These requirements
include the functional requirements (FRs) and the non-functional requirements
(NFRs).

Note that if a small part of the NFRs has not been met, the library is still
acceptable when the not-met NFRs' impact has been analyzed and deemed
non-essential.

\subsection{Relevant Documentation}

As we said before, this document relies on the CA document. This document is
also the base of the Unit Test Plan document.

\section{Plan}
This section lists the plan of the VnV of the FSL library.
\begin{itemize}
	\item \autoref{sbsc:VnVTeam} introduces the Validation and Verification Team of this library, including the team members and their duties.
	\item \autoref{sbsc:SRSVnVPlan} outlines the plan for the verification of the SRS.
	\item \autoref{sbsc:DesignVnVPlan} outlines the plan for the verification of the design of this libary.
	\item \autoref{sbsc:ImplementationVnVPlan} outlines the plan for the verification of the library's implementation.
	\item \autoref{sbsc:SoftwareVnVPlan} outlines the validation plan of the library based on the pseudo-oracle provided by MATLAB.
\end{itemize}
\wss{There should usually be text between section headings.  In this case, a
  ``roadmap'' of the subsections in this section would be appropriate.}
\an{Contents added here}

\subsection{Verification and Validation Team}\label{sbsc:VnVTeam}

The major member of the team is the author himself. Other contributors might
assist in the VnV procedure, but their contributions are not
guaranteed.
In detail, the other contributors include the following people and their github accounts.
\begin{itemize}
	\item Dr.~Spencer Smith \href{https://github.com/smiths}{smiths} and Deema Alomair \href{https://github.com/deemaalomair1}{deemaalmair1} review the whole library, including all documents and codes.
	\item Ao Dong \href{https://github.com/Ao99}{Ao99} reviews the SRS.
	\item Peter Michalski \href{https://github.com/peter-michalski}{peter-michalski} reviews the VnV plans.
	\item Sasha Soraine \href{https://github.com/sorainsm}{sorainsm} reviews the design.
\end{itemize}

\wss{You should specifically list the class mates that are assigned
  to review your documents.  You should also list the course instructor.}\an{Done.}

\subsection{SRS Verification Plan}
\label{sbsc:SRSVnVPlan}

The verification of the SRS document mainly consists of the checking of all the mathematical expressions of the system. Especially, we will use some simple mathematical functions and their related results to check the theories related to operations.

Some functions are reversions of other functions. For example, \li{Function Value} is the reversion of \li{Transform}, \li{Addition} is the reversion of \li{Subtraction}, \li{Division} is the reversion of \li{Multiplication}. For each pair of function \li{A} and \li{B}, we will see if functions \li{A(B())} and \li{B(A())}'s output is close to its input with some examples.

We will also learn from the feedback from
reviewers, and the author's experience in developing and verifying this
library. \wss{A task directed verification plan could be much more effective
  than this ad hoc approach.}\an{Some ways added before the original content.}

\subsection{Design Verification Plan}
\label{sbsc:DesignVnVPlan}

The design of this library will be verified by checking the library against all the requirements. The functional requirements shall be checked first, followed by the performance-related parts of the non-functional requirements. \wss{This is not
  a very detailed plan.  Did you consider other options?  Some of your
  colleagues, like Peter, have a detailed plan for design verification.}\an{Amended.}

\subsection{Implementation Verification Plan}
\label{sbsc:ImplementationVnVPlan}

The verification of the implementation of this library is mainly done by unit
testing. The detail of unit testing can be found in the Unit Test Plan
document. Mainly, the unit test will be done by first testing the basic
functions in this library, and then testing the advanced functions. \textbf{Please note
that the test result of any function in this library is acceptable, if and only
if the reliant functions of this function is tested to be right.}

\subsection{Software Validation Plan}\label{sbsc:SoftwareVnVPlan}

The transformation part of this library will be validated by comparing its
result with the MATLAB pseudo-oracle.

The MATLAB pseudo-oracle is computed by the implemented Fourier Transformation function within the MATLAB math libraries. We will choose several groups of $f(t), \omega, n$, compute the Fourier Transformation of $f(t)$ with frequency $\omega$, and compare the leading terms with $\mathit{CFS}(f(t), n, \omega)$  \wss{Where does the Matlab pseudo-oracle
  come from?  This is a good idea, but you should take it a step further and
  explain the source of the pseudo-oracle.}\an{Elaborated here.}

\section{System Test Description}

\subsection{Tests for Functional Requirements} All tests in this section will be
done by unit testing, the detail of which will be covered in the Unit Test VnV
Plan document.

Since these tests involve comparing floating point numbers, and there are
intrinsic errors regarding floating point computations, we have to set a
tolerance, so that two floating numbers with difference smaller than this
tolerance are considered equal. We use $\epsilon$ to represent this tolerance,
and choose its value as $10^{-6}$ for all tests. This value is chosen because it
is large enough to include all computation-related error, but small enough to
detect any error in the result of the library. This value can be changed if we
have good reasons to support this change.  \wss{Yes, using a symbolic constant
  for this is a good idea. I suggest that you put this constant in a table in
  the Appendix to this report, so that it is easy to maintain.  I see that you
  are varying $\epsilon$ throughout this document.  You should say this here,
  and not follow my advice to add a table of constants at the end, since the
  value is not constant.}

\subsubsection{Module 1: Basic comparison function}

The tests here are selected to cover the tolerated comparison function and its
base, subtraction operation and amplitude function. The tolerated comparison
function will be used in later tests to compare the resulted CFS of the tested
function with its (pseudo-)oracle counterpart, so we need to test this function
first to ensure that the following test results are reliable.

\textbf{NOTE: Do not proceed with other modules unless you have succeed in this
module. For each round of test, the result of other modules is trustworthy if
and only if the test results of this module are all successes.}

\begin{enumerate}

	\item{Test of subtraction: \\}

	Type: Automatic

	Initial State: The subtract function of the loaded FSL library.

	Input: $\mathit{CFSf}=[n=2, \omega=1.0, A=\{1.0, 0.0, 0.0\}, B=\{0.0, 1.0\}]$ and
	$\mathit{CFSg}=[n=2, \omega=1.0, A=\{0.0, 2.0, 1.0\}, B=\{1.0, 0.0\}]$

	Output: Evaluated result of $\mathit{CFSf}-\mathit{CFSg}$, which should
        be a CFS object
        $[n=2, \omega=1.0, A=\{1.0, -2.0, -1.0\}, B=\{-1.0, 1.0\}]$

	Test Case Derivation: Feed input, get output, and compare value-to-value automatically via Unit Test. \wss{Why do this manually?
          This is a good test for automation.  A unit testing framework can take
        care of the details.  I see that many of the following tests are
        manual.  Please consider making all of your tests automatic.}\an{I misunderstood the meaning of 'Test Case Derivation'. I thought it means how I find a set of input/outputs. Now, I found out that it means how we compare our output with the standard output.}

	How test will be performed: Unit Test framework will feed function with the aforementioned input,
        and compare the function output to the aforementioned standard output by
        comparing its $n$, $\omega$, $A_i$'s and $B_i$'s variable-by-variable. Called 'compute and compare later'.

	\item{Test of amplitude function: \\}

	Type: Automatic

	Initial State: None.

	Input: $\mathit{CFSf}=[n=2, \omega=1.0, A=\{1.0, 2.0, 2.0\}, B=\{2.0,
        2.0\}]$ and $\epsilon=10^{-6}$.

	Output: Evaluated result of
        $|\mathit{Amp}(\mathit{CFSf})-3.0|\leq\epsilon$, which should be
        \li{True}.

	Test Case Derivation: Feed input, get output, and compare value-to-value automatically via Unit Test.

	How test will be performed: Compute and compare.

	\item{Test of tolerated equality function \li{TolEq} (\li{True} result): \\}

	Type: Automatic

	Initial State: Verified amplitude function.

	Input: $\mathit{CFSf}=[n=2, \omega=1.0, A=\{1.0, 0.0, 0.0\}, B=\{0.0, 1.0\}]$,
	$\mathit{CFSg}=[n=2, \omega=1.0, A=\{0.0, 2.0, 1.0\}, B=\{1.0, 0.0\}]$, and error $\epsilon=10.0$.

	Output: Return value of this function, which should be \li{True} \wss{What is being
          compared?  This is not clear.}\an{I mean the return value of this function}

	Test Case Derivation: Feed input, get output, and compare value-to-value automatically via Unit Test.

	How test will be performed: Compute and compare.

	\item{Test of tolerated comparison function \li{TolEq} (\li{False} result):\\}

          Same as \textit{Test of tolerated comparison (\li{True} result)}, but
          with $\epsilon=1.0$ and Output as \li{False}.
\end{enumerate}

\subsubsection{Module 2: Fourier transformation and approximation}
This module tests the functions that compute Fourier transformation and
approximated values of functions.

\begin{enumerate}
	\item{Test of coefficient (even function):\\}

	Type: Automatic

	Initial State: Verified tolerated equality function \li{TolEq}.

	Input: $f(t)=t^2$, $\omega=1$, $n=2$, $\epsilon=10^{-2}$,
        $\mathit{CFSstd}=[n=2,\omega=1, A=\{\pi^2/3, -4.0, 1.0\}, B=\{0.0,
        0.0\}]$

	Output: Evaluated result of
        $\mathit{TolEq}(\mathit{CFSf}, \mathit{CFSstd}, \epsilon)$, which should
        be \li{True}. \wss{Is this TolEq function defined somewhere?}\an{In SRS}

	Test Case Derivation: Feed input, get output, and compare with \li{TolEq} and $\epsilon$ automatically via Unit Test.

	How test will be performed: Compute and compare, but instead of compare one-by-one, use \li{TolEq} function with the aforementioned tolerance $\epsilon$. (Called 'Compute and compare with tolerance' later.)

	\item{Test of coefficient (odd function):\\}

	Type: Automatic

	Initial State: Verified tolerated equality function.

	Input: $f(t)=t$, $\omega=1$, $n=2$, $\epsilon=10^{-2}$,
        $\mathit{CFSstd}=[n=2,\omega=1, A=\{0.0, 0.0, 0.0\}, B=\{2.0, -1.0\}]$

	Output: $\mathit{TolEq}(\mathit{CFSf}, \mathit{CFSstd}, \epsilon)$,
        which should be \li{True}.

	Test Case Derivation: Feed input, get output, and compare by \li{TolEq} and $\epsilon$ automatically via Unit Test.

	How test will be performed: Compute and compare with tolerance.

	\item{Test of approximated function value: \\}

	Type: Automatic

	Initial State: None.

	Input: $\mathit{CFSf}=[n=2,\omega=1, A=\{1.0, 2.0, 0.0\}, B=\{-1.0,
        1.0\}]$, $t=\pi/4$, $\epsilon=10^{-6}$.

	Output: Evaluated result of
        $|\mathit{App}(\mathit{CFSf}, t)-(2+\sqrt{2}/2)|\leq\epsilon$, which
        should be \li{True}.

	Test Case Derivation: Feed input, get output, and compare by \li{TolEq} and $\epsilon$ automatically via Unit Test.

	How test will be performed: Compute and compare with tolerance.

\end{enumerate}

\subsubsection{Module 3: Operations and functions}

\begin{enumerate}
	\item{Test of addition: \\}

	Type: Automatic

	Initial State: Verified tolerated equality function.

	Input: $\mathit{CFSf}=[n=2,\omega=1, A=\{0.0, 2.0, 0.0\}, B=\{-2.0,
        0.0\}]$,
        $\mathit{CFSg}=[n=2,\omega=1, A=\{1.0, 0.0, 2.0\}, B=\{0.0, 1.0\}]$,
        $\mathit{CFSstd}=[n=2,\omega=1, A=\{1.0, 2.0, 1.0\}, B=\{-2.0, 1.0\}]$,
        $\epsilon=10^{-6}$

	Output: Evaluated result of
        $\mathit{TolEq}(\mathit{CFSf}+\mathit{CFSg}, \mathit{CFSstd},
        \epsilon)$, which should be \li{True}.

	Test Case Derivation: Manual Computation.

	How test will be performed: Compute and compare.

	\item{Test of multiplication:\\}

	Type: Automatic

	Initial State: Verified tolerated equality function.

	Input: $\mathit{CFSf}=[n=2, \omega=1, A=\{1.0, 0.0, 1.0\}, B=\{1.0, 0.0\}]$,
	$\mathit{CFSg}=[n=2, \omega=1, A=\{1.0, 1.0, 0.0\}, B=\{1.0, 0.0\}]$,
	$\mathit{CFSstd}=[n=2, \omega=1, A=\{2.0, 2.0, 0.0\}, B=\{2.0, 1.0\}]$,
	$\epsilon=10^{-6}$

	Output: Evaluated result of
        $\mathit{TolEq}(\mathit{CFSf}*\mathit{CFSg}, \mathit{CFSstd},
        \epsilon)$, which should be \li{True}.

	Test Case Derivation: Manual Computation.

	How test will be performed: Compute and compare.

	\item{Test of division: \\}

          Same as \textit{Test of multiplication}, but swap $\mathit{CFSf}$ and
          $\mathit{CFSstd}$, while change $*$ to $/$.

	\item{Test of function of CFS: \\}

	Type: Automatic

	Initial State: Verified tolerated equality, addition and multiplication function.

	Input: $\mathit{CFSf}=[n=2, \omega=1, A=\{1.0, 0.0, 1.0\}, B=\{1.0,
        0.0\}]$, $g(t)=e^t$, and $\epsilon=10^{-6}$.

	Output: Evaluated result of
        $\mathit{TolEq}(g(\mathit{CFSf}), 1+\mathit{CFSf}+0.5\mathit{CFSf}^2,
        \epsilon)$, which should be \li{True}.

	Test Case Derivation: Manual Computation.

	How test will be performed: Compute and compare.

\end{enumerate}

\subsubsection{Test of conversion}

\begin{enumerate}
	\item{Test of conversion from other data format:\\}

	Type: Automatic

	Initial State: Verified tolerated equality function

	Input: $n=2$, $\omega=1$, $A={1.0, 0.0, 2.0}$, $B={2.0, 0.0}$.

	Output: constructed CFS

	Test Case Derivation: None

	How the test will be performed: convert and compare the result with a
        standard CFS using tolerated equality and $\epsilon=10^{-6}$.

	\item{Test of conversion to other data format:\\}

          Same as \textit{Test of conversion from other data format}, while
          exchanging input and output, and compare each coefficients with
          tolerance as $\epsilon$.

\end{enumerate}
\subsection{Test for input constraints}
We design input test for detecting mismatch $n$ and $\omega$ for functions that
accept two CFS's as inputs. For each test in the following list, we derive tests
for input constraints based on it.

\begin{itemize}
	\item Test of addition
	\item Test of subtraction
	\item Test of multiplication
	\item Test of division
	\item Test of tolerated equality
\end{itemize}

For each test in this list, we derive two tests. One is to change the $\omega$
in the second CFS to the half of its original value, and the other is to change
the $n$ in the second CFS to $1$, and remove $A_2$ and $B_2$ of the second CFS
accordingly. Error message indicating a pair of mismatched CFS's shall appear.

Additionally, we do input constraint check on the tests of conversion from other
data formats. We make $n$ in the original test from 2 to 3, and error message
indicating mismatched $n$, number of $A_i(i\neq0)$'s, and number of $B_i$'s.

\subsection{Tests for Nonfunctional Requirements}
The tests in this section will also be done by unit testing.

\subsubsection{Speed evaluation}
We test the speed of IM2, IM3, IM4, IM5, IM6, IM7, IM8 and IM9.

For each test, generate random CFS's with same $\omega$ and various $n$, as well as $A_i$'s and $B_i$'s from the same random number generator. \wss{be
  more specific on what is involved in generating the random CFS's.  What is the
  range of values that are allowed?}\an{The range of the values (fully decided by the random number generator) is the same within each test case, but may vary among test cases in the future, so I choose not to mention the detail of the range here, but within the test case.} clock
the execution time with the generated CFS's as input, and check whether the
relationship between $n$ and the execution time follows the requirements in the
NFR.

We will demonstrate how the test is performed by showing a template of tests, and each test's values of template parameters (shown in the following font \li{Parameter}).
\begin{enumerate}

	\item{Test the speed of \li{Operation}\\}

	Type: Automatic

	Initial State: \li{Operation}

	Input/Condition: Various pair of CFS's, with the same $\omega$,
        $n=100:100:1000$ respectively, and $A_i$'s and $B_i$'s generated from a
        random number generator. In this test, this generator is chosen as the
        uniform random number generator on $[-1.0, 1.0]$.

	Output/Result: A plot of average execution time versus $n$, together with the related \li{Speed Rule} regression coefficient $r$ (if the value of \li{Speed Rule} is unknown, we will report the $r$, $a$, and $b$ of the log-log regression $\log(y)=a\log(x)+b$ instead) \wss{I think the output should be the plot of the time
          versus $n$.}

	How test will be performed: For each $n$, generate 10 pairs of CFS's,
        clock their execution time to take average value as the execution time
        for CFS's of size $n$, plot as said before, find and show the $r$ value of a \li{Speed Rule} fitting between
        $n$ and the execution time. Usually, this test is considered a success when $|r|>0.9$, but it can also be considered a success if the tester has found a good explanation of this coefficient.

\end{enumerate}
Here is a list of the values of parameters in each test.

\begin{table}[h]
	\centering
	\begin{tabular}{|c|c|c|}
		\hline
		IM\#&\li{Operation}&\li{Speed Rule}\\
		\hline
		IM2&Approximate Function Value&Linear\\
		IM3&Addition&Linear\\
		IM4&Subtraction&Linear\\
		IM5&Multiplication&Squared\\
		IM6&Division&Unknown\\
		IM7&Function&Unknown\\
		IM8&Amplitude&Linear\\
		IM9&Tolerated Equality&Linear\\
		\hline
	\end{tabular}
	\caption{Table of parameter values for each test.}
\end{table}

\wss{You should explain all of the tests, but you can use a table to summarize
  just the deltas between the base test and the individual tests.}\an{Done accordingly.}

\wss{What about other nonfunctional tests?  Usability could be a valuable thing
  to assess.  Portability? (I think this would be a fairly easy one to assess.)
  Installability?}
\an{The usability test is deemed unnecessary, due to the fact that the interface of this library is pretty simple, and given my experience of using several libraries, I think that it is quite easy to use if the user have basic knowledge of this language.}
\an{Initially when I think about my library at this stage, I have not decided about the language, test tools, and other things. I only knows that I will distribute the source code. In the case of source code distribution, the common practice among the open-source software area is that the users shall fully taken care of the portability and installability part, thus I did not plan to test them here.}

\an{Furthermore, I anticipate that I will be writing codes strictly following basic standards with popular supporting libraries (like boost), and the portability of these standards and libraries have been tested by lots and lots of people on different kinds of platforms, so the portability of my library is guaranteed.}

\an{I will also organize my library in a popular way, and when used by the users, the library will not contain any codes to be compiled when being installed, just some source codes, and the users will compile my source code together with theirs. Thus, the install procedure only involves that the user copy/link my library files to their intended location, which is pretty easy and straightforward on the platforms that I know of, so the installability is guaranteed.}

\an{However, after I have considered the actual unit test part, I think I can do  a little bit to the two test just to provide proof to my arguments. The contents I added is shown as follows.}

\subsubsection{Test of portability and installability}
The portability and installability test will be done by doing the unit tests on several platforms, with different compilers and different versions of language standards.

The platforms include mac OS X (10.11~10.15), Windows 10 (1909 as a representative, since Windows has a good reputation of compatibility between versions), and Linux distributions including Ubuntu 18.04, CentOS 7.7-1908, Fedora 30, and Archlinux 2019-12-01 version.

At this stage, I have anticipated that I will be using C++ to implement this library. The standards I choose to test for compatibility are C++03, C++11, C++14, C++17, and C++20 (if it becomes official in the lifespan of this library).

I will also be checking the compatibility with the following C++ compilers: gcc (version 5.0\~{}8.0), clang (version 5.0, 6.0), msvc (the versions distributed with vs2017 and vs2019), and icc (16.0\~{}19.0)

\subsection{Traceability Between Test Cases and Instance Modules}
We show each instance module's covering tests. \wss{You don't have modules.  I
  think you mean requirements?}\an{Actually, I mean instance modules. Each set of tests covers the related requirements to this instance module, and how the requirements apply to this instance module.}

\begin{itemize}
\item IM1: \textit{Test of transformation (even function)} and \textit{Test of
    transformation (odd function)}.
\item IM2: \textit{Test of approximated function value}
\item IM3: \textit{Test of addition}
\item IM4: \textit{Test of subtraction}
\item IM5: \textit{Test of multiplication}
\item IM6: \textit{Test of division}
\item IM7: \textit{Test of function of CFS}
\item IM8: \textit{Test of amplitude}
\item IM9: \textit{Test of tolerated equality}
\item IM10: \textit{Test of conversion from other data format}
\item IM11: \textit{Test of conversion to other data format}
\end{itemize}

\wss{We discussed that your unit verification and validation plan will be
  identical to the system plan.  I agree there is overlap, but I expect that you
  will have unique tests for the unit case.  For instance, if you introduce a
  data structure for the CFSs, then you want to be able to check each of the
  methods for the CFSs.}\an{Indeed. The contents you mentioned will be elaborated in UnitVnV.}

\bibliographystyle{plainnat}

\bibliography{SRS}

\end{document}


\documentclass{beamer}

\usepackage{graphicx}
\usepackage{textpos}
\usepackage{listings}
\usepackage{lstautogobble}

\usetheme{Madrid}
\useoutertheme{miniframes} % Alternatively: miniframes, infolines, split

% Setup the university's color pallette
\definecolor{UIUCorange}{RGB}{19, 41, 75} % UBC Blue (primary)
\definecolor{UIUCblue}{RGB}{232, 74, 39} % UBC Grey (secondary)

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{python}{
  backgroundcolor=\color{backcolour},
  commentstyle=\color{codegreen},
  keywordstyle=\color{magenta},
  numberstyle=\tiny\color{codegray},
  stringstyle=\color{codepurple},
  basicstyle=\ttfamily\footnotesize,
  breakatwhitespace=false,
  belowskip=-0.5em,
  breaklines=true,
  captionpos=b,
  keepspaces=true,
  numbers=left,
  numbersep=5pt,
  showspaces=false,
  showstringspaces=false,
  showtabs=false,
  tabsize=2
}

\lstset{style=python}

\AtBeginSection[]{
    \begin{frame}
        \vfill
        \centering
        \begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
            \usebeamerfont{title}\insertsectionhead\par%
        \end{beamercolorbox}
        \vfill
    \end{frame}
}

\setbeamercolor{palette primary}{bg=UIUCorange,fg=white}
\setbeamercolor{palette secondary}{bg=UIUCblue,fg=white}
\setbeamercolor{palette tertiary}{bg=UIUCblue,fg=white}
\setbeamercolor{palette quaternary}{bg=UIUCblue,fg=white}
\setbeamercolor{structure}{fg=UIUCorange} % itemize, enumerate, etc
\setbeamercolor{section in toc}{fg=UIUCblue} % TOC sections

\setbeamercolor{subsection in head/foot}{bg=UIUCorange,fg=UIUCblue}
\setbeamercolor{subsection in head/foot}{bg=UIUCorange,fg=UIUCblue}

\usepackage[utf8]{inputenc}
\usepackage{graphicx}

%Information to be included in the title page:
\title{\textbf{Topic 5: Conditionals}}
\author{\textbf{David H Smith IV}}
\institute[\textbf{UIUC}]{\textbf{University of Illinois Urbana-Champaign}}
\date{\textbf{Mon, July 05 2021}}

\setbeamertemplate{title page}[default][colsep=-4bp,rounded=true]
\addtobeamertemplate{title page}{\vspace{3\baselineskip}}{}
\addtobeamertemplate{title page}{
  \begin{textblock*}{\paperwidth}(-1.0em, -1.2em)
    \includegraphics[width=\paperwidth, height=\paperheight]{imgs/uiuc.png}
  \end{textblock*}
}{}

\begin{document}

\frame{\titlepage}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Truth Table to Expressions}
	\vfill
	The As and Bs in the truth tables correspond to \textit{the result of boolean expressions}.
	\vfill
	\begin{minipage}{0.4\textwidth}
		\begin{lstlisting}[language=Python,autogobble]
	# Get some variables
	x = int(input())
	y = int(input())

	# Construct the expr
  # and assign to A or B
	A = (x == 3)
	B = (y > 5)
		\end{lstlisting}
	\end{minipage}
	\begin{minipage}{0.59\textwidth}
		\begin{table}[]
			\begin{tabular}{|cc|c|c|c|}
				{\color[HTML]{CD9934} \textbf{A}} & {\color[HTML]{3531FF} \textbf{B}} & \textbf{A OR B} & \textbf{A AND B} & \textbf{NOT A} \\ \hline
				{\color[HTML]{CD9934} T}          & {\color[HTML]{3531FF} T}          & T               & T                & F              \\
				{\color[HTML]{CD9934} T}          & {\color[HTML]{3531FF} F}          & T               & F                & T              \\
				{\color[HTML]{CD9934} F}          & {\color[HTML]{3531FF} T}          & T               & F                & F              \\
				{\color[HTML]{CD9934} F}          & {\color[HTML]{3531FF} F}          & F               & F                & T
			\end{tabular}
		\end{table}
	\end{minipage}
	\vfill
	\begin{itemize}
		\item You can have \textbf{as many operands (e.g., A, B, C, $\cdots$) as you like}.
		\item The truth tables get BIG as you have to consider more permutations.
	\end{itemize}
\end{frame}

\section{\lstinline|is| vs \lstinline|==|}

%
% Slide 1
%
\begin{frame}[fragile]
	\frametitle{Muddiest Points: \lstinline|is| vs \lstinline|==|}
  \begin{itemize}
    \item \lstinline|x is y| translates to \lstinline|id(x) == id(y)|
    \begin{itemize}
      \item \lstinline|==| is for comparing literal values
      \item \lstinline|is| is for comparing to see \textbf{two variables are referencing the same object}.
    \end{itemize}
    \item And there's a caveat\ldots
    \begin{itemize}
      \item Python pre-instantiate the first few numbers. This isn't true for large numbers.
    \end{itemize}
  \end{itemize}
\end{frame}

\section{Poll Questions: Conditional Syntax Check}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  Which of the following will correctly check if a number (int or float) is between 1 and 10 inclusive.
	\begin{minipage}{0.69\textwidth}
    1)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    1 <= x <= 10
		\end{lstlisting}
    \vspace{1cm}
    2)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    1 =< x =< 10
		\end{lstlisting}
    \vspace{1cm}
    3)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    x >= 1 and x <= 10
		\end{lstlisting}
	\end{minipage}
	\begin{minipage}{0.29\textwidth}
    \begin{enumerate}[A]
      \item 1
      \item 2
      \item 3
      \item 1 and 2
      \item Another combo...
    \end{enumerate}
	\end{minipage}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  Which of the following evaluates to \lstinline|True| if a set contains an even number of elements?\\ \hfill

	\begin{minipage}{0.69\textwidth}
    1)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    0 == len(set1) % 2
		\end{lstlisting}
    \vspace{1cm}
    2)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    len(set1) % 2 == 0
		\end{lstlisting}
    \vspace{1cm}
    3)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    not (len(set1) % 2)
		\end{lstlisting}
	\end{minipage}
	\begin{minipage}{0.29\textwidth}
    \begin{enumerate}[A]
      \item 1
      \item 2
      \item 3
      \item 1 and 2
      \item All of the above
    \end{enumerate}
	\end{minipage}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  Which of the following evaluates to \lstinline|True| if x is greater than 10?
	\begin{minipage}{0.69\textwidth}
    1)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    x not <= 10
		\end{lstlisting}
    \vspace{1cm}
    2)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    not x <= 10
		\end{lstlisting}
    \vspace{1cm}
    3)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    x > 10
		\end{lstlisting}
	\end{minipage}
	\begin{minipage}{0.29\textwidth}
    \begin{enumerate}[A]
      \item 1
      \item 2
      \item 3
      \item 2 and 3
      \item 1 and 3
    \end{enumerate}
	\end{minipage}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  Which of the following will correctly check to make sure a list \lstinline|x| does not contain a variable \lstinline|y|.

	\begin{minipage}{0.69\textwidth}
    1)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    y not in x
		\end{lstlisting}
    \vspace{.5cm}
    2)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    not (x in y)
		\end{lstlisting}
    \vspace{.5cm}
    3)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    x not in y
		\end{lstlisting}
	\end{minipage}
	\begin{minipage}{0.29\textwidth}
    \begin{enumerate}[A]
      \item 1
      \item 2
      \item 3
      \item 1 and 2
      \item All of the above
    \end{enumerate}
	\end{minipage}
  \vfill
  \pause
  With \lstinline|in|, position of operands matters. With \lstinline|is| and \lstinline|==|, it does not.
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  Which of the following will check if a value \lstinline|y| is in a dictionary \lstinline|x|?
	\begin{minipage}{0.69\textwidth}
    1)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    y in x
		\end{lstlisting}
    \vspace{1cm}
    2)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    y == x
		\end{lstlisting}
    \vspace{1cm}
    3)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    y is x
		\end{lstlisting}
	\end{minipage}
	\begin{minipage}{0.29\textwidth}
    \begin{enumerate}[A]
      \item 1
      \item 2
      \item 3
      \item All of the above
      \item None of the above
    \end{enumerate}
	\end{minipage}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  Does this segment of code evaluate to True or False in the end?
  \begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
  y = list("hello")
  x = y
  y.append("!")
  print(y is x)
  \end{lstlisting}
  \vfill
  \begin{enumerate}[A]
    \item True
    \item False
    \item SyntaxError
    \item TypeError
  \end{enumerate}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  Does this segment of code evaluate to True or False in the end?
  \begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
  y = 5
  x = y
  x = x + 1
  print(y is x)
  \end{lstlisting}
  \vfill
  \begin{enumerate}[A]
    \item True
    \item False
    \item SyntaxError
    \item TypeError
  \end{enumerate}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  What is the result of the following code?
  \begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
  x = 5
  y = 5
  x += 1
  y += 1
  print(x is y)
  \end{lstlisting}
  \vfill
  \begin{enumerate}[A]
    \item True
    \item False
    \item SyntaxError
    \item TypeError
  \end{enumerate}
  \pause
  What is I replace 5 with 1000?
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  What is the result of the following code?
  \begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
  x = None
  y = None
  print(y is x)
  \end{lstlisting}
  \vfill
  \begin{enumerate}[A]
    \item True
    \item False
    \item SyntaxError
    \item TypeError
  \end{enumerate}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Constructing Conditionals}
  What is the result of the following code?
  \begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
  x = {"baz" : 2, "bar": 3}
  y = {"foo": 1}
  z = y
  y.update(x)
  print(y is z)
  \end{lstlisting}
  \vfill
  \begin{enumerate}[A]
    \item True
    \item False
    \item SyntaxError
    \item TypeError
  \end{enumerate}
\end{frame}

\section{Poll Questions: Correct Functions}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Conditionals in Functions}
  Which of the following functions will ask the user for a sentence and return that sentence only if it is of even length?
	\vfill
	\begin{minipage}{0.32\textwidth}
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def get_even_sentence():
      x = input("Enter a string with an even number of letters: ")
      if x % 2 == 0:
        return x
		\end{lstlisting}
	\end{minipage}
	\begin{minipage}{0.32\textwidth}
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def get_even_sentence():
      x = input("Enter a string with an even number of letters: ")
      if len(x) % 2 == 0:
        return x
		\end{lstlisting}
	\end{minipage}
	\begin{minipage}{0.32\textwidth}
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def get_even_sentence():
      x = input("Enter a string with an even number of letters: ")
      if len(x) % 2 is 0:
        return x
		\end{lstlisting}
	\end{minipage}
	\vfill
	\begin{enumerate}[A]
    \item 1
    \item 2
    \item 3
    \item 2 and 3
    \item All of the above
	\end{enumerate}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Conditionals in Functions}
  Which fuction(s) return true if both elem1 and elem2 are in some\_list?
	\begin{minipage}{0.69\textwidth}
    1)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def are_in_list(elem1, elem2, some_list):
      return elem1 and elem2 in some_list
		\end{lstlisting}
    \vspace{1cm}
    2)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def are_in_list(elem1, elem2, some_list):
      return (elem1 in some_list) and (elem2 in some_list)
		\end{lstlisting}
    \vspace{1cm}
    3)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def are_in_list(elem1, elem2, some_list):
      return (elem1 in some_list) or (elem2 in some_list)
		\end{lstlisting}
	\end{minipage}
	\begin{minipage}{0.29\textwidth}
    \begin{enumerate}[A]
      \item 1
      \item 2
      \item 3
      \item 2 and 3
      \item All of the above
    \end{enumerate}
	\end{minipage}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Conditionals in Functions}
  Which function will return the kth word in a list of words given any list of strings only if that kth word contains an even number of letters?
	\vfill
	\begin{minipage}{0.7\textwidth}
    1)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def get_kth_word_if_even_len(k, words):
      if len(words) > k:
        if len(words[k]) % 2 == 0:
          return words[k]
		\end{lstlisting}
    2)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def get_kth_word_if_even_len(k, words):
      if len(words[k]) % 2 == 0 and len(words) > k:
          return words[k]
		\end{lstlisting}
    3)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def get_kth_word_if_even_len(k, words):
      if len(words) > k and len(words[k]) % 2 == 0:
          return words[k]
		\end{lstlisting}
	\end{minipage}
  \begin{minipage}{0.29\textwidth}
    \begin{enumerate}[A]
      \item 1
      \item 2
      \item 3
      \item 1 and 2
      \item Another option
    \end{enumerate}
	\end{minipage}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
	\frametitle{Poll Question: Conditionals in Functions}
  Which of the functions will correctly execute the task?
	\begin{minipage}{0.7\textwidth}
    1)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def is_one_through_five(x):
      return 1 <= x <=5
		\end{lstlisting}
    2)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def is_one_through_five(x):
      return x in [1, 2, 3, 4, 5]
		\end{lstlisting}
    3)
		\begin{lstlisting}[language=Python, autogobble,basicstyle=\tiny,numbers=none]
    def is_one_through_five(x):
      return x == (1 or 2 or 3 or 4 or 5)
		\end{lstlisting}
	\end{minipage}
  \begin{minipage}{0.29\textwidth}
    \begin{enumerate}[A]
      \item 1
      \item 2
      \item 3
      \item 1 and 2
      \item All of the above
    \end{enumerate}
	\end{minipage}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
  \frametitle{Poll Question: Nesting}
  What does the code on the right print?
  \vfill
  \begin{minipage}{0.49\textwidth}
    \begin{enumerate}[A]
      \item 2
      \item 5
      \item 8
      \item SyntaxError
    \end{enumerate}
  \end{minipage}
  \begin{minipage}{0.49\textwidth}
    \begin{lstlisting}[language=Python, autogobble]
    x = 2
    if x < 8:
      if x > 5:
        print(8)
      else:
        print(5)
    else:
      print(2)
    \end{lstlisting}
  \end{minipage}
\end{frame}

%
% Slide 2
%
\section{Code Blocks}
\begin{frame}[fragile]
  \frametitle{Code Blocks}

  \begin{itemize}
    \item Fancy term for defining a unit of execution.
  \end{itemize}
  \begin{lstlisting}[language=Python, autogobble]
  model = input('Enter car model: ')
  year = int(input('Enter year of car manufacture: '))

  antique = False
  domestic = False

  if year < 1970:
    antique = True

  if model in ['Ford', 'Chevrolet', 'Dodge']:
    domestic = True

  if antique:
    if domestic:
      print('My own model-T still runs like a charm...')
  \end{lstlisting}
\end{frame}

%
% Slide 2
%
\section{Conditional Expressions}
\begin{frame}[fragile]
  \frametitle{Conditional Expressions vs if-else}

  \begin{itemize}
    \item Follows this template: \lstinline|x if <cond> else y|
    \item Useful for item assignment where a condition must be met in order to avoid errors
    \item More concise
  \end{itemize}
  \vfill
  \begin{minipage}{0.49\textwidth}
    \begin{lstlisting}[language=Python, autogobble]
    x = input()
    if len(x) > 9:
      y = x[9]
    else:
      y = None
    \end{lstlisting}
  \end{minipage}
  \begin{minipage}{0.49\textwidth}
    \begin{lstlisting}[language=Python, autogobble]
    x = input()
    y = x[9] if len(x) > 9 else None
    \end{lstlisting}
  \end{minipage}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
  \frametitle{Poll Questions: Conditional Expressions}
  What is the value of \lstinline|x| after this code runs and the user attempts to enter the value 10?
  \begin{lstlisting}[language=Python, autogobble]
  x = "Odd" if int(input("Enter a number")) % 2 != 0 else "Even"
  \end{lstlisting}
  \vfill
  \begin{enumerate}[A]
    \item SyntaxError
    \item "Odd"
    \item "Even"
    \item This code contains another error
  \end{enumerate}
\end{frame}

%
% Slide 2
%
\begin{frame}[fragile]
  \frametitle{Poll Questions: Conditional Expressions}
  What is the the resulting value of \lstinline|x|?
  \begin{lstlisting}[language=Python, autogobble]
  y = 1.0
  x = "It's a float!" if type(y) == float
  \end{lstlisting}
  \vfill
  \begin{enumerate}[A]
    \item SyntaxError
    \item "It's a float!"
    \item None
    \item This code contains another error
  \end{enumerate}
\end{frame}

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Beamer Presentation
% LaTeX Template
% Version 1.0 (10/11/12)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
% Modified by Jeremie Gillet in November 2015 to make an OIST Mini Course template
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------
%	PACKAGES AND THEMES
%----------------------------------------------------------------------------------------

\documentclass{beamer}

\mode<presentation> {

\usetheme{Madrid}

\definecolor{OISTcolor}{rgb}{0.65,0.16,0.16}
\usecolortheme[named=OISTcolor]{structure}

%\setbeamertemplate{footline} % To remove the footer line in all slides uncomment this line
%\setbeamertemplate{footline}[page number] % To replace the footer line in all slides with a simple slide count uncomment this line

%\setbeamertemplate{navigation symbols}{} % To remove the navigation symbols from the bottom of all slides uncomment this line
}

\usepackage{graphicx} % Allows including images
\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables
\usepackage{textpos} % Use for positioning the Mini Course logo

%----------------------------------------------------------------------------------------
%	TITLE PAGE
%----------------------------------------------------------------------------------------

\title[Mini Course]{Mini Course: Mini Course: Matrix Eigendecomposition} % The short title appears at the bottom of every slide, the full title is only on the title page
\subtitle{Video Lecture 1: What is an Eigendecomposition?}

\author{Jeremie Gillet} % Your name
\institute[OIST] % Your institution as it will appear on the bottom of every slide, may be shorthand to save space
{
Okinawa Institute of Science and Technology \\ % Your institution for the title page
\textit{jeremie.gillet@oist.jp} % Your email address
}
\date{June 28, 2021} % Date, can be changed to a custom date

\begin{document}

\setbeamertemplate{background}{\includegraphics[width=\paperwidth]{SPbackground.png}} % Adding the background logo

\begin{frame}
\vspace*{1.4cm}
\titlepage % Print the title page as the first slide
\end{frame}

\setbeamertemplate{background}{} % No background logo after title frame

\begin{frame}
\frametitle{Overview} % Table of contents slide, comment this block out to remove it
\tableofcontents % Throughout your presentation, if you choose to use \section{} and \subsection{} commands, these will automatically be printed on this slide as an overview of your presentation
\end{frame}

%----------------------------------------------------------------------------------------
%	PRESENTATION SLIDES
%----------------------------------------------------------------------------------------

%------------------------------------------------
\section{Eigenvalues} % Sections can be created in order to organize your presentation into discrete blocks, all sections and subsections are automatically printed in the table of contents as an overview of the talk
%------------------------------------------------

\begin{frame}
\frametitle{Eigenvalues}

Given a complex, square matrix $A \in \mathbb{C}^n_n$, find, if it exists, the invertible matrix $S$ such that
$$
S^{-1} A S = \textrm{diag} \left( \lambda_1, \ldots, \lambda_n \right),
$$
with $ \lambda_1, \ldots, \lambda_n $ complex numbers called \textit{eigenvalues}.

\vfill

\end{frame}

%------------------------------------------------

\section{Eigenvectors}

\begin{frame}
\frametitle{Eigenvectors}

If $S = (C_1, \ldots, C_n)$ such that $S^{-1} A S = \textrm{diag} \left( \lambda_1, \ldots, \lambda_n \right)$, then
$$
A C_k = \lambda_k C_k,
$$
and $C_k$ is called an \textit{eigenvector} of $A$ associated with the eigenvalue $\lambda_k$.

\vfill

\end{frame}

%------------------------------------------------

\section{Characteristic Polynomials}

\begin{frame}
\frametitle{Characteristic Polynomials}

The complex number $\lambda$ is an eigenvalue of $A \in \mathbb{C}^n_n$ if and only if
$$
\textrm{det} \left( A - \lambda \mathbb{I} \right) = 0.
$$

\vfill

\end{frame}

%------------------------------------------------

\section{Useful Properties }

\begin{frame}
\frametitle{Trace and Determinant of a Diagonalizable Matrix}

The \textit{trace} $\textrm{Tr}(A)$ of a square matrix $A$ is the sum of its diagonal values. If the matrix $A$ is diagonalizable, we always have
$$
\textrm{Tr}(A) = \textrm{Tr} \left(  \textrm{diag} \left( \lambda_1, \ldots, \lambda_n \right) \right) = \sum_i \lambda_i.
$$

We also have
$$
\textrm{det}(A) = \prod_i \lambda_i.
$$

\vfill

\end{frame}

%----------------------------------------------------------------------------------------

\end{document}


\documentclass[10pt,landscape]{article}
\usepackage[landscape]{geometry}
\input{math_header}

% Format inherited from <MA1101R Cheatsheet 17/18 Sem 1 Finals>
% Original document is by Tysng
% Original link: https://github.com/tysng/ma1521-cheatsheet
% PDE Removed given it is not examinable for 1920S1

% Turn off header and footer
\pagestyle{empty}

% Redefine section commands to use less space
\makeatletter
\renewcommand{\section}{\@startsection{section}{1}{0mm}%
                                {-1ex plus -.5ex minus -.2ex}%
                                {0.5ex plus .2ex}%x
                                {\normalfont\large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
                                {-1explus -.5ex minus -.2ex}%
                                {0.5ex plus .2ex}%
                                {\normalfont\normalsize\bfseries}}
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
                                {-1ex plus -.5ex minus -.2ex}%
                                {1ex plus .2ex}%
                                {\normalfont\small\bfseries}}
\makeatother

% Define BibTeX command
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}

% print only section numbers
\setcounter{secnumdepth}{1}

\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt plus 0.5ex}

%My Environments
\newtheorem{example}[section]{Example}

% -----------------------------------------------------------------------

\begin{document}
\raggedright
\footnotesize
\begin{multicols}{3}

% multicol parameters
% These lengths are set only within the two main columns
%\setlength{\columnseprule}{0.25pt}
\setlength{\premulticols}{1pt}
\setlength{\postmulticols}{1pt}
\setlength{\multicolsep}{1pt}
\setlength{\columnsep}{2pt}

\begin{flushleft}
\large{
    \underline{MA1521 Cheat Sheet} \\
    \texttt{by Howard Liu based on versions of Tysng} \\
    AY2019/20 Semester 1}
\end{flushleft}

% ------------------------------ACTUAL CONTENT-----------------------------------

\section{MF26 Magic}

\subsection{Trigo}
\begin{gather*}
   \sin (A \pm B) = \sin A \cos B \pm \cos A \sin B \\
   \cos (A \pm B) = \cos A \cos B \mp \sin A \sin B \\
   \tan (A \pm B) = \frac{\tan A \pm \tan B}{1 \mp \tan A \tan B} \\
   \sin 2A = 2 \sin A \cos A \\
   \cos 2A = \cos ^ 2 A - \sin ^ 2 A = 2\cos^2A - 1 = 1 - 2\sin^2A \\
   \tan 2A = \frac{2 \tan A}{1- \tan^2 A} \\
   \sin P + \sin Q = 2 \sin \frac{1}{2} (P + Q) \cos \frac{1}{2} (P - Q) \\
   \sin P - \sin Q = 2 \cos \frac{1}{2} (P + Q) \sin \frac{1}{2} (P - Q) \\
   \cos P + \cos Q = 2 \cos \frac{1}{2} (P + Q) \cos \frac{1}{2} (P - Q) \\
   \cos P - \cos Q = -2 \sin \frac{1}{2} (P + Q) \sin \frac{1}{2} (P - Q) \\
   \frac{\sin A}{a} = \frac{\sin B}{b} = \frac{\sin C}{c} \\
   a^2 =  b^2 + c^2 - 2bc \cos A
\end{gather*}

\subsection{Derivatives}
\begin{gather*}
   \frac{d}{dx} \sin ^{-1} x = \frac{1}{\sqrt{1-x^2}} \\
   \frac{d}{dx} \cos ^{-1} x = -\frac{1}{\sqrt{1-x^2}} \\
   \frac{d}{dx} \tan ^{-1} x = \frac{1}{1+x^2} \\
   \frac{d}{dx} \csc x = - \csc x \cot x \\
   \frac{d}{dx} \sec x = \sec x \tan x \\
   \frac{d}{dx} \tan x = \sec^2 x \\
   \frac{d}{dx} \cot x = -\csc^2 x
\end{gather*}

\subsection{Integrals}
Take note of the absolute sign, and always remember to $+c$
\begin{gather*}
   \int \frac{1}{x^2 + a^2} dx = \frac{1}{a} \tan ^{-1} (\frac{x}{a}) + c \\
   \int \frac{1}{\sqrt{a^2 - x^2}} dx = \sin ^{-1} (\frac{x}{a}) + c \\
   \int \frac{1}{x} dx = \ln \abs{x} + c \\
   \int \frac{x}{\sqrt{a^2 - x^2}} dx = -\sqrt{a^2 - x^2} + c \\
   \int x^n e^x dx = x^n e^x - n x^{n-1} e^x + n (n-1) x^{n-2}e^x - \dots \pm n! e^x + c
\end{gather*}

\section{Basics}
\subsection{Extreme Values}
Points where $f$ can have an extreme value:
\begin{itemize}
   \item Interior point where $f'(x) = 0$
   \item Interior points where $f'(x)$ doesn't exist
   \item End points of the domain of $f$
\end{itemize}

\subsection{L'Hospital's Rule}
The $\frac{0}{0}$ form: (1) $f$ and $g$ are differentiable in a neighborhood of $x_0$,
(2) $f(x_0) = g(x_0) = 0$, (3) $g'(x) \neq 0$ except possibly at $x_0$
\begin{gather*}
   \lim_{x\to x_0} \frac{f(x)}{g(x)} = \lim_{x\to x_0} \frac{f'(x)}{g'(x)}
\end{gather*}
E.g. $\lim_{x\to 0} \frac{3x - \sin x }{x} = \frac{3-\cos x }{1} \rvert_{x = 0} = 2$

The $\frac{\infty}{\infty}$ form: when $x \to a$, $f(x), g(x) \to \infty$,
and both differentiable,
\begin{gather*}
   \lim_{x\to a} \frac{f(x)}{g(x)} = \lim_{x\to a} \frac{f'(x)}{g'(x)}
\end{gather*}

Else, change to these two forms. (e.g $\lim_{x\to 0^+} x \cot x = \lim_{x\to 0^+} \frac{x}{\tan x}
= \lim_{x\to 0^+} \frac{1}{\sec^2 x} = 1$ )

\subsection{Fundamental Theorem of Calculus}
\begin{gather*}
   \frac{d}{d\Box} \int_{c}^{\Box} f(t) dt = f(\Box)
\end{gather*}

\section{Series}
\subsection{Geometric Series}
Sum: $S_n = a \frac{1-r^n}{1-r}$, $r\neq 1$

Ratio test: $\lim_{n\to\infty} = \abs{\frac{a_{n+1}}{a_n}} = \rho$;
\begin{enumerate}
   \item $\rho < 1$: converge;
   \item $\rho > 1$: diverge;
   \item $\rho = 1$, no conclusion;
\end{enumerate}
For convergent series: $S_n \to \frac{a}{1-r}$

\subsection{Power Series}
$\sum_{n = 0}^{\infty} c_n(x-a)^n = c_0 + c_1(x-a) + c_2(x-a)^2 + \ldots + c_n(x-a)^n + \ldots$, where $a$ is the center of the power series

Convergence: $n\to\infty, S_n \to k$
\begin{enumerate}
   \item $\sum c_n(x-a)^n$ converges at $x=a$ and diverges elsewhere
   \item $h \in \mathbb{Z}$ that the series only converges in $(a-h, a + h)$
   \item converges for every $x$
\end{enumerate}

\subsection{Finding Radius of Convergence}
Apply ratio test and find
\begin{gather*}
   M = \lim_{n\to\infty} \abs{\frac{u_{n+1}}{u_n}}
   M < 1
\end{gather*}
and transform it to the form of $\abs{x-a} < b$; $a$ is the center, $b$ is the RoC

Or, if the series converges for all $x$, the RoC is $\infty$; if it only converges at $a$, the RoC is 0;

Some magic:
\begin{gather*}
   \frac{1}{1-\Box} = \sum_{n = 0 }^{\infty} \Box^n, \abs{\Box} < 1
\end{gather*}

\subsection{Taylor Series}
of $f$ at $a$:
\begin{gather*}
   \sum_{k=0}^{\infty} \frac{f^{(k)}(a)}{k!} (x-a)^k = f(a) + f'(a)(x-a) + \ldots \\
   + \frac{f^{(n)}(a)}{n!} (x-a)^n +\ldots \\
   e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} \\
   \sin x = \sum_{n=0}^{\infty} \frac{(-1)^n x ^{2n+1}}{(2n+1)!} \\
   \cos x = \sum_{n=0}^{\infty} \frac{(-1)^n x ^{2n}}{(2n)!} \\
   \ln (1+x )= \sum_{n=1}^{\infty} \frac{(-1)^{n-1}x^n}{n} \\
   \tan^{-1} x = \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n+1}}{2n+1}
\end{gather*}

\subsection{Finding a specific high order derivative}
\begin{enumerate}
   \item given $\int f dx$
   \item evaluate f in polynomial form and integrate the polynomial form
   \item Compare the coefficient with the item that contains $f^{(100)}(0)$ in the Taylor expansion
\end{enumerate}

\subsection{Rules of Series}
\begin{gather*}
   \int \sum_{n=0}^{\infty} \Box dx = \sum_{n=0}^{\infty} \int \Box dx \\
   \frac{d}{dx} \sum_{n=0}^{\infty} \Box = \sum_{n=0}^{\infty} \frac{d}{dx} \Box \\
   x^k e^x = x^k \sum_{n=0}^{\infty} \frac{x^n}{n!} = \sum_{n=0}^{\infty} \frac{x^{n+k}}{n!} \text{ (Note: $x^k$ is a constant in the series)}
\end{gather*}

\section{Vectors}
Angle between two vectors: $\cos \theta = \frac{x_1 x_2 + y_1 y_2 + z_1 z_2}{\norm{\vec{v_1}} \norm{\vec{v_2}}}$ \\

Perpendicular vectors: $\vec{v_1} \cdot \vec{v_2} = 0$

\section{Partial Differentiation}
\begin{gather*}
f_{xy} (a,b) = f_{yx} (a,b) \\
\frac{dz}{dt} = \frac{\partial f}{\partial x} \frac{dx}{dt} + \frac{\partial f}{\partial y} \frac{dy}{dt} \\
\end{gather*}

\subsection{Directional Derivative}
For \textbf{unit vector} $u = u_1 \vec{i} + u_2 \vec{j}$, we have:

$$D_{\vec{u}}f(a,b) = f_x(a, b) \cdot u_1 + f_y(a,b) \cdot u_2$$

Gradient Vector:

$$\nabla f = f_x \vec{i} + f_y \vec{j}$$

Relation between $D_{\vec{u}}f(a,b)$ and $\nabla f$:

$$D_{\vec{u}}f(a,b) = \nabla f(a,b) \cdot \vec{u} = \norm{\nabla f(a,b)} \cos \theta$$

Some characteristics:
\begin{itemize}
	\item $f$ increases most rapidly in $\nabla f(a,b)$ and decreases most rapidly in $ -\nabla f(a,b)$.
	\item Max value of $D_{\vec{u}}f(a,b) = \norm{\nabla f(a,b)}$ when $\vec{u}$ and $\nabla f$ in the same direction, since $\cos \theta = 0$
	\item Increment in $f$ (approx.): $\Delta f \approx [D_{\vec{u}} f(\vec{p})] (\Delta t)$, where $p$ is the point to measure the increment and $u$ is the unit vector of direction.
\end{itemize}

\subsection{Finding $D_{\vec{u}}f$}
\begin{enumerate}
   \item Find the direction $\vec{p}$
   \item Find the unit vector $\vec{u} = \frac{\vec{p}}{\norm{\vec{p}}}$
   \item Find $\nabla f$, then find $D_{\vec{u}} f = \nabla f \cdot \vec{u}$
\end{enumerate}

\subsection{Critical Points}
A point of $f$ that satisfies either is a critical point:
\begin{enumerate}
   \item $f_x (a,b) = 0$ and $f_y(a,b) = 0$
   \item $f_x (a,b)$ or $f_y(a,b)$ doesn't exist
\end{enumerate}

Perform Second Derivative Test: let $f_x(a,b) = 0$ and $f_y(a,b) = 0$
$$ D = f_{xx}(a,b) f_{yy} (a,b) - f_{xy} (a,b)^2 $$

\begin{itemize}
   \item $D > 0, f_{xx} >0$, f has a local minimum at (a,b)
   \item $D > 0, f_{xx} <0$, f has a local maximum at (a,b)
   \item $D < 0$, f has a saddle point at (a,b)
   \item $D = 0$, no conclusion
\end{itemize}

\section{Double Integrals}
For a region $R$ s.t. $a \leq x \leq b$ and $c \leq y \leq d$, volume is given by:
\begin{gather*}
\int\!\int_R\! f(x, y)\, \mathrm{d}A = \int_c^d\!\int_a^b\! f(x, y)\, \mathrm{d}x \mathrm{d}y = \int_a^b\!\int_c^d\! f(x, y)\, \mathrm{d}y \mathrm{d}x
\end{gather*}
if $f(x, y) = g(x)h(y)$,
then $$\int\!\int_R f(x,y) \, \mathrm{d}A = (\int_a^b\!g(x)\, \mathrm{d}x) (\int_c^d\!h(y)\, \mathrm{d}y)$$

\subsection{Rectangular Regions}
Express horizontal/vertical bounds as a function $g(x)$ or $h(y)$ \\
Type A(top and bottom are curves)
$$
\int_a^b\!
\left [
\int_{g_1(x)}^{g_2(x)}\!f(x, y)\, \mathrm{d}y
\right ] \mathrm{d}x $$
Type B(left and right are curves) $$\int_c^d\!
\left [
\int_{h_1(y)}^{h_2(y)}\!f(x, y)\, \mathrm{d}x
\right ] \mathrm{d}y$$

\subsection{Polar Coordinates}
$R$: $a \leq r \leq b$, $\alpha \leq \theta \leq \beta$
$$
\int\!\int_R\! f(x, y)\, \mathrm{d}A =
\int_\alpha^\beta\!\int_a^b\!f(r\cos\theta, r\sin\theta)r\, \mathrm{d}r\mathrm{d}\theta
$$

\subsection{Surface Area}
$$S = \int\!\int_R\! \sqrt{(\frac{\partial z}{\partial x})^2 + (\frac{\partial z}{\partial y})^2 + 1 }\, \mathrm{d}A$$

\section{Ordinary Differential Equation}
\subsection{Separable Equations}
\begin{gather*}
   M(x) - N(y) y' = 0 \implies \int M(x) dx = \int N(y) dy + c
\end{gather*}

\subsection{Reduction to Separable Form}
Let $v = y / x \implies y = xv \rightarrow y' = v + xv'$, transform equations of $y' = g(\frac{y}{x})$
to $v + xv' = g(v) $ such that
\begin{gather*}
   \frac{dv}{g(v) - v} = \frac{dx}{x}
\end{gather*}
Similarly, $y' = f(ax + by + c)$ can be solved by $u = ax + by + c$

\subsection{Linear First Order ODE}
To solve $y' + Py = Q$: find integration factor
$$R = e^{\int P dx}$$
Then, answer $$y = \frac{1}{R} \int RQ dx$$

\subsection{Reduction to Linear Form}
A Bernoulli equation: $y' + P(x)y = Q(x) y^n$, where $n \in \mathbb{R}$; \\
(When $n = -1$, try Reduction to Separable Form)
To solve it, let $v = y^{1-n}$; \\
Find and express $dv / dx$ in $dy / dx$; find $dy/dx$ and sub that in original equation; transform into
$$v' + (1 - n)Pv = Q(1-n)$$
and solve the linear ODE.

\subsection{Homogeneous Linear Second Order DE}
For $y'' + a y' + by = 0$, the characteristic equation is $\lambda^2 + a \lambda + b = 0$

Find $\Delta = a ^2 -4b$:

\begin{enumerate}
   \item $\Delta > 0$, $y = c_1e^{\lambda_1x} + c_2e^{\lambda_2x}$
   \item $\Delta = 0$, $y = (c_1 + c_2 x) e^{-\frac{ax}{2}} $
   \item $\Delta < 0$, it has two complex roots;$ \lambda_1 = \alpha + \beta i, \lambda_2 = \alpha -\beta i$; $y = c_1 e^{\alpha x} \cos \beta x + c_2 e^{\alpha x} \sin \beta x$
\end{enumerate}
where,
\begin{gather*}
   \lambda_1 = \frac{1}{2} (-a+\sqrt{a^2-4b}) \\
   \lambda_2 = \frac{1}{2} (-a-\sqrt{a^2-4b})
\end{gather*}

\section{Modelling}
\subsection{Population Growth}
Malthus's Model: not an accurate representation
\begin{gather*}
   \frac{dN}{dt} = kN, k = B - D \\
   N(t) = N_0 e^{kt}
\end{gather*}

\subsection{Logistic Model}
Let $D = sN$, where $s$ is a constant and $B$ is birth rate per capita:
$$ \frac{dN}{dt} = BN - DN = BN - sN^2 $$

The curve approaches carrying capacity $N = B/S$; point of inflection is at $N = B/2s$

$$ N = \frac{N_{\infty}}{1 + (\frac{N_{\infty}}{N_0} - 1) e^{-Bt}}, N_{\infty} = \frac{B}{s} $$

\subsection{Harvesting}
Let $E$ is fish caught per year, similar to the above model:
$$\frac{dN}{dt} = BN - sN^2 - E$$

Desirable result: $E < \frac{B^2}{4s}$, approaches the second root $\beta_2 = \frac{B + \sqrt{B^2 - 4Es}}{2s}$, when $\frac{dN}{dt} = 0$

\subsection{Strategies}
\begin{itemize}
   \item When given $dx/dt$, find $x$ that $dx/dt = 0$, draw out the axis, determine the sign of $dx/dt$ within
      each region, and find the flow (+ to the right, - to the left)
   \item To find E, draw the graph without E and find the line of symmetry; use the product of the roots to find E;
\end{itemize}

\end{multicols}
\end{document}


\documentclass[11pt]{article}
\usepackage[cm]{fullpage}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[section]{placeins}
\usepackage{float}
\usepackage{amsmath}
\usepackage{multicol}

\setlength{\columnsep}{1cm}

\title{S1336 - Project 2}
\author{Erik Weilow}

\newcommand{\doublefigure}[2]{
\begin{figure}[H]
  \centering
  \begin{minipage}{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{#1}
  \end{minipage}
  \begin{minipage}{0.45\textwidth}
    \centering
    \includegraphics[width=\textwidth]{#2}
  \end{minipage}
\end{figure}
}
\newcommand{\singlefigure}[1]{
\begin{figure}[H]
  \centering
  \begin{minipage}{0.4\textwidth}
    \centering
    \includegraphics[width=\textwidth]{#1}
  \end{minipage}
\end{figure}
}

\begin{document}
\maketitle
\newpage

\section*{2.1}

\subsection*{Effects of rounding errors}
\doublefigure{./plots/2_1/r06.png}{./plots/2_1/r091.png}

It can be concluded that when $r < r_\infty$, rounding doesn't have much of an effect on the system.

When $r > r_\infty$, rounding does however have an effect on the system.

\section*{2.2}

If settling for $n=200$, we can use the following formula to calculate $\lambda$:
$$
\lambda = \frac{1}{n} \sum_{i=0}^{i=n-1}{\text{log}\left| \frac{\Delta x_{i+1}}{\Delta x_i}\right|}
$$

This can be done numerically by solving the system, for many values of $r$.

\subsection*{The Lyapunov exponent for a population model}
\singlefigure{./plots/2_2/study.png}
We see that for $0.76 < r < r_\infty$, when the system isn't chaotic, the sign of $\lambda$ is positive.
Effects of rounding doesn't affect $\lambda$ unless $r > r_\infty$.

\subsection*{The dependence on initial value}
\begin{figure}[H]
  \centering
  \begin{minipage}{0.8\textwidth}
    \centering
    \includegraphics[width=\textwidth]{./plots/2_2/dependence.png}
  \end{minipage}
\end{figure}
In this plot, we see that selecting different $x_0$ has an effect on the calculation of $\lambda$.
For $r < 0.76$, it's clear that the system is non-chaotic since $\lambda$ is strictly equal to 0.
For approximately $0.76 < r < 0.87$, $\lambda$ is either positive or negative depending on the initial value.
It then takes on many values, incredibly dependent on $x_0$.

\section*{2.3}

\subsection*{Lorenz attractor}
To figure out which parts of space get attracted in to the basin of the Lorenz attractor, trajectories for different starting conditions randomly sampled on the interval
$$
x(0) \in (-1000, 1000), \quad
y(0) \in (-1000, 1000), \quad
z(0) \in (-1000, 1000) \\
$$
are computed.

The time averaged "radius" is calculated for each trajectory:
$$
r = \frac{1}{n} \sum_{i=0}^n{\sqrt{x{(i \Delta t)}^2 + y{(i \Delta t)}^2 + z{(i \Delta t)}^2}}
$$

25 CPU hours later, for a time step of $\Delta t = 0.00008$ and a time boundary of $0 < t < 150$, the following histogram can be plotted:
\singlefigure{./plots/2_3/histo.png}

It shows that for all (roughly 2500) computed trajectories, they all average to within a distance 60 from $x = 0, y = 0, z = 0$.
We can thus conclude that it's very unlikely that a solution doesn't get attracted into the basin.

It's also interesting to note that the distribution is starting to look like a normal distribution. This could be investigated further in the future and left as an excercise for the reader.
\section*{2.4}

\subsection*{Sensitivity to initial values}
\doublefigure{./plots/2_4/solution.png}{./plots/2_4/difference.png}

The right plot shows the "distance" between the solutions at each time $t$.
It can be seen that even for a small difference in initial value ($0.01$), the solutions differ much after some time.

\newpage

\section*{2.5}
\singlefigure{./plots/2_5/peaks.png}
We can have a look at the, seemingly symmetrical, plot of $z_m$ vs $z_{m+1}$.
This plot is generated for a time duration of $0<T<5000$ with a time step of $\Delta t = 0.0001$, so with a total of $50$ million time steps.

We can clearly see that if we divide the $z_{m+1}$ versus $z_{m}$ curve into two regions, one to the left of $z_m \approx 38.5$ and one to the right,
the magnitude of the slope of the curve is always greater than unity.
It is also interesting to note that the map symmetrically maps $z_m$ onto $z_{m+1}$ around $z_m \approx 38.5$ (both $z_m = 35$ and $z_m = 42.5$ map to approximately $z_{m+1} = 36$).
In reality, this plot lets us predict the next $z_{m+1}$ for any given $z_{m}$, but not generally $z_M$ where $M >> m$.

Now to answer why a slope magnitude greater than 1 indicates chaos.
Qualitatively,
I'm thinking that if we calculate the Lyapunov exponent for the plot (where we set $z_{m+1} = f(z_m)$) we'll have something like
$$
\lambda = \lim_{n\rightarrow \infty} \frac{1}{n} \sum_{i=0}^{i=n-1} { \text{log} |f'(z_m)| }
$$
But we've seen in the plot that $|f'(z_m)| \geq 1$, so
$$\text{log} |f'(z_m)| \geq 0 \text{ } \forall \text{ } z_m$$
This means that $\lambda > 0$ for the $z_m$ vs $z_{m+1}$ plot and indicates chaos.
\end{document}


\documentclass[twocolumn]{revtex4}
%\documentclass[onecolumn,12pt]{revtex4}
%\usepackage{amsfonts,amssymb,amsmath,mathbbol}              % for math symbols.
%\usepackage{epstopdf}
%\usepackage{mathbbol}              % for math symbols.
\usepackage{graphics,graphicx,epsfig,ulem}
\usepackage{amsmath}
\newcommand{\squeezeup}{\vspace{-2.5mm}}

\begin{document}

\textheight=24.75cm

\title{Determining the half-life of Ba-137m, and applying theoretical Poisson plus Gaussian distributions to radioactive decay}

\author{Jacky Cao, Lab Group A, Thursday, Lab Partner: - \\ Date of experiment: 04/02/2016, Date of report: 12/02/2016}

\begin{abstract}

The half-life of Ba-137m and the Poisson and Gaussian probabilities for Am-241 can be calculated by collecting the activity and time period obtained from radioactive decay. Using a Geiger-M\"{u}ller tube and software such as \textit{CASSY Labs} and Excel it is possible to do so. The values obtained for half-life are $t\textsubscript{1/2-CSY}=2.73\pm0.03$ mins and $t\textsubscript{1/2-EXL}=2.92\pm0.07$ mins, which are consistent with literature. The experimental probability does not fit the theoretical probability distributions due to incomplete data set.

\end{abstract}

\maketitle

\section{Introduction}
\vspace{-2ex}

In nature, radioactivity deals with the instability of atomic nuclei and the subsequent emission of electromagnetic radiation and particles. The half-life, $t\textsubscript{1/2}$, of an unstable particle is the time required for the number of remaining nuclei to decrease to one half of the original number $N\textsubscript{0}$. The decay of the nuclei can be described by the decay constant, $\lambda $, which can be explained as the probability per unit time that any individual nucleus will decay \cite{decay}.

Both the half-life and the decay constant can be related together by,
\begin{equation} \tag{1}
t\textsubscript{1/2} = \frac{\ln2}{\lambda}\\
\end{equation}

The initial amount of nuclei in a sample, $N\textsubscript{0}$, and the number of nuclei left after a period of time, $N(t)$, can be related together using the decay constant,
\begin{equation} \tag{2}
N(t)=N\textsubscript{0}e\textsuperscript{-$\lambda t$}
\end{equation}

In observing the number of atoms which have decayed in a time period we can thus calculate the half-life of a specific nucleus through data analysis. The nature of this decay can be subsequently described as random and spontaneous, conditions which can fit certain probability distributions such as the Poisson distribution and Gaussian distribution.

For the Poisson distribution to apply certain conditions must be met first: the counts are of rare events, all events are independent, and the average rate does not change over the period of interest \cite{decay}. These conditions are met by the random nuclear radioactivity so the probability that $N$ pulses will be counted is a function of the expected number of pulses, in this case the mean, $\overline{N}$,
\begin{equation} \tag{3}
P(N)=\frac{\overline{N}^N}{N!} \exp(-\overline{N})
\end{equation}

For cases where the mean becomes large (e.g. greater than 20), then the Poisson distribution can be approximated to the Gaussian distribution, expressed as,
\begin{equation} \tag{4}
P(N)=\frac{1}{\sqrt{2\pi\sigma ^2}} \exp\Big[-\frac{(N-\overline{N})^2}{2\sigma ^2}\Big]
\end{equation}

where the standard deviation, $\sigma=\sqrt{\overline{N}}$.
\\
Through experimentation we can attempt to verify a value of half-life with given literature values, and we can aim to fit experimental probability to the theoretical predictions of the Poisson and Gaussian distributions. Additionally, the uncertainty when counting randomly occurring events can also be investigated by testing.
\vspace{-3ex}
\section{Method}
\vspace{-2ex}
The experimental setup involved a Geiger-M\"{u}ller tube which was connected to a data logger. This allowed us to use a piece of software called \textit{CASSY Labs}, measurements of the activity in a given time period could be made without having to manually time the system. This was initially used to measure the background count rate - for the first half of the experiment (half-life measurement) this was done for about 300s, while for the second half (probabilities calculations) about 200s.

The metastable isotope Ba-137m is formed during the decay of Cs-137 which is contained in an isotope generator. To use the isotope we had to use elution, so a solution of acidified sodium chloride was passed through the isotope generator into a test tube. This sat directly above the GM tube, the activity per second, $A$, was counted for a total time of 700s in individual 12s time periods. The half-life of Ba-137m was then calculated using two methods.

Firstly using \textit{CASSY Labs}, an exponential graph was fitted to the data with time axis as the 'x-axis' and $A$ as the 'y-axis'. The main method of computing the half-life involved calculating the differences between the times where the activity had fallen to half of its initial value. Horizontal and vertical lines were plotted onto the graph to do this. In doing so three values of half-life were calculated and then averaged.

The second method involved importing the data into Excel and then plotting a graph with the x-axis as time and the y-axis as the natural log of the activity, then the $LINEST$ function was used to calculate a value for decay constant then subsequently the half-life.

When Am-241 was used as the next source for the probability data it was placed at a distance of 3.0cm from the GM tube. Data was then collected again using the same software, but instead of activity, the number of events per second and the frequency density was measured. Other values recorded from the software included mean counting rate $\overline{N}$ and the total number of counts $n$. These were to be used in later calculations of Poisson and Gaussian distributions.

To calculate the various probabilites Excel was used, the experimental probability was plotted against the number of counts. Then using equations (3) and (4), the Poisson and Gaussian Distributions were also calculated and plotted on the same graph.

It is worth noting that data collection was incomplete, there was not enough time to collect all the experimental results so the accuracy may be questioned.

\vspace{-3ex}
\section{Results and Discussion}
\vspace{-2ex}
When \textit{CASSY Labs} was used to calculate an average value for the half-life, the outcome was $t\textsubscript{1/2-CSY}=2.73\pm0.03$ mins. Comparing this value with the one from Excel, $t\textsubscript{1/2-EXL}=2.92\pm0.07$ mins. We see that both are similar, however the uncertainty on the Excel value is larger than from CASSY so if we were to accept an experimental value it would be the former.

Following from this, comparison with the literature value for Ba-137m \cite{true}, $t\textsubscript{1/2-ACT} = 2.552$ min shows that we would be correct in accepting the software value, firstly as it is the closest (out by around 7\% versus 14\%) and secondly because it has the smallest uncertainty.

If we look at the data for the Excel value then we see that it follows a generally linear relationship which agrees with equation (2), $\ln{(N(t)/N\textsubscript{0})}=-\lambda{t}$. Where $\lambda$ is the gradient of the trendline which in turn was used to calculate a value for half-life. As time passes on the data slightly deviates from the linear relationship, this could potentially be due to the fact that the source is becoming less intense so the amount of direct hits on the detector may be decreasing, while radiation is still being emitted in all directions.

\begin{figure}[!h]
\begin{center}
\includegraphics[width=8cm]{fig1}
\caption[]{The natural logarithm of the radioactive activity plotted as a function of time. The vertical error bars are displayed while the horizontal error bars are too small to be seen.}
\label{fig:fig1}
\end{center}
\end{figure}
\squeezeup

The data for the probabilities is plotted onto the same graph, Fig. 2.. It is difficult to distinguish between the Gaussian and Poisson points, they both share a similar distribution as seen by the graph. In terms of the experiment, it would appear that both would be good theoretical models to fit the data by. The mean value of the number of counts is large enough so that the Poisson distribution looks like the Gaussian, there is no particular difference between the two as they both agree with each other.

On the other hand the experimental probability does not entirely match the theoretical distributions. It bears some resemblance but not completely. The potential reason for this could be due to the lack of data, the experiment was not complete so we cannot make any adequate comparisons between this probability and the theory. We would not be able to discuss on any actual basis how the obtained results would improve if measuring time is increased.

\begin{figure}[!h]
\begin{center}
\includegraphics[width=8cm]{fig2}
\caption[]{The experimental (bottom set of points), Poisson (lighter coloured crosses) and Gaussian (darker coloured dots) probabilities plotted with the number of counts.}
\label{fig:fig2}
\end{center}
\end{figure}
\squeezeup
\squeezeup
\squeezeup

It is worth noting the large uncertainty on the number of counts as shown in Fig. 2., the error is about 7\% of the actual value. One possible reason for this could be due to the fact that the data is being applied to a Poisson model and the model does not entirely fit. Or it could be related to the issue above, there is not enough data to provide an adequate result.

\vspace{-2ex}
\section{Conclusions}
\vspace{-2ex}

In conclusion, through experimentation it has been possible to calculate multiple values of half-life for Ba-137m, $t\textsubscript{1/2-CSY}=2.73\pm0.03$ mins and $t\textsubscript{1/2-EXL}=2.92\pm0.07$ mins, values which are similar to the literary value. It has also been possible to construct theoretical probability distributions for random radioactive decay, however comparisons with the experimental probability is not possible as the data set is incomplete. Given more time the experiment could potentially be repeated and then the data could possibly be fitted to the theory, for now that cannot be done.

\begin{thebibliography}{5}
\bibitem{decay}
Hugh D. Young and Roger A. Freedman.
\textit{University Physics with Modern Physics, 13th Edition}.
Pearson Education Limited, Harlow, Essex, 2015.

\bibitem{true}
W. M. Haynes.
\textit{CRC Handbook of Chemistry and Physics}.
CRC Press, Florida, USA, 2011.
\end{thebibliography}

\clearpage

\vspace{-3ex}
\section*{Appendix}
\vspace{-2ex}

The uncertainty calculated for $t\textsubscript{1/2-CSY}$ is the standard error, $\alpha_\sigma$. This error only depends on the standard deviation, $\sigma$, and the number of initial half-lives measured $x$,

\begin{equation} \tag{5}
\alpha_\sigma=\sigma \frac{1}{\sqrt{x}}
\end{equation}

 it does not take into account any potential uncertainty on the recorded activity or time period. The precision of the value could have been increased if the number of measurements used to calculate the mean was increased from three to a higher value.
\\

For $t_{1/2-EXL}$ the error, $\alpha_{1/2-EXL}$, is found by using,

\begin{equation} \tag{6}
\alpha_{1/2-EXL}=t_{1/2-EXL}\sqrt{\Big(\frac{\alpha_\lambda}{\lambda}\Big)^2}
\end{equation}

where $t_{1/2-EXL}$ is the calculated value of half-life from the rearranged equation (2), the value of the decay constant ($\lambda$) was calculated using the LINEST function in Excel, subsequently the error on the decay constant ($\alpha_{\lambda}$) was found by using LINEST as well.
\\

The uncertainty on $\ln{activity}$ as shown in Fig. 1. was calculated through using the number of counts ($N$), and the time at which the number of counts correspond to ($t$),

\begin{equation} \tag{7}
\alpha_{\ln{A}}=\frac{\sqrt{N}}{12t}
\end{equation}

In measuring the distance between the Am-241 source and the Geiger-M\"{u}ller tube a 30 cm ruler was used, the error here should not matter too much as we do not require it in any of our calculations. However we should at least make a note of it. So, we shall take a value of half of the smallest unit that the ruler can measure to be the uncertainty thus the distance is ($3.0\pm0.5$) cm.

There are no uncertainties for the experimental, Poisson or Gaussian probabilities, but there is uncertainty on the the number of counts measured, $N$.

\begin{equation} \tag{8}
\alpha_{N}=\sqrt{N}
\end{equation}

This data can have the Poisson distribution applied to it due to the events being random, individual from each other, and occuring over a mean rate without changing.

%\footnotetext{I am not entirely too sure about what I did for (7), it was help from other students and the demonstrator}

\end{document}