%%%%%%%%%%%%%%%%%%%%
%%%%% Preamble %%%%%
%%%%%%%%%%%%%%%%%%%%

%This is a simple template for the LaTeX 'article' class document
\documentclass[]{article}%

%These are general packages that we will use quite a bit
%Once you begin using Latex more and more, you will learn what packages suit your needs the best and you can just copy and paste them into any new documents your are creating
\usepackage{amsmath}					%Standard math package built by the American Mathematical Society
\usepackage{amsfonts}					%Standard font package
\usepackage{amssymb}					%Extended symbol collection
\usepackage{amsthm}						%To use the AMS theorem collection
\usepackage{graphicx}					%For when you want to include images or figures into your document
\usepackage{url} 						%For when you want to include a url into your document
\usepackage[hidelinks]{hyperref} 		%For hyperlinking references (NOTE: can remove the [hidelinks] to show link boxes around hyperlinks
\usepackage[usenames,dvipsnames]{color} %This allows me to change the color of my font
\usepackage{comment}					%For block comments under figures and tables
\usepackage{fancyhdr}					%Allows for a fancy header and footer on your document
\usepackage{lastpage}					%Keeps count of what page number is the last page to be used in the footer
\usepackage{titling}					%Allows for image on title page
\usepackage{hologo}						%Allows for typsetting of the bibtex logo

%Set the margins of the paper using the geometry package
\usepackage[margin = 2cm]{geometry} %This creates a 2 cm margin around the page (NOTE: this does not include the header or footer in the 2 cm cutoff.  If you wanted to you could 										say \usepackage[margin = 2cm, includefoot, includehead]{geometry} which would make it so the header and footer start 2 cm down the page and 										the contents would follow appropriately)

%The following allows for the necessary documents to build the pdf to be embedded into the final pdf file.
%This allows for ease of sharing and automatically generates a back up in a sense in case you lose your .tex file.
%This isn't critical to include but it is nice to know about.
\usepackage{embedfile} 					%Allows embedding of files into the pdf document
\embedfile{MasterGuide.tex} 			%Embed the .tex file into the pdf
\embedfile{MyBib.bib}					%Embed the .bib file into the pdf
\embedfile{./Figs/cat.jpg}				%Embed the .jpg file into the pdf

%This is the standard setup for creating new commands
%The following commands are two that have been regularly throughout this document
%If you want to rename an already defined command, you must use \renewcommand instead
\newcommand{\del}{\partial}
\newcommand{\bs}{\textbackslash}
\newcommand{\TT}[1]{\texttt{#1}}
\newcommand{\tpc}{\textperiodcentered}

\definecolor{darkgrey}{gray}{0.3}
\newcommand{\greytext}[1]{{\textcolor{darkgrey}{#1}}}

\theoremstyle{definition}
\newtheorem{dfn}{Definition}

%Create the header for the paper
\pagestyle{fancy}				%Makes header in the style of 'fancy', look up LaTeX's fancyhdr to see how you can customize
\lhead{\today}			%Left head
\rhead{MEGC \LaTeX\ Workshop}	%Right head
\cfoot{Page \thepage\ of \pageref{LastPage}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Preamble Ends, Content Begins %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Includes figure on title page but needs the titling package to work
\pretitle{
	\begin{center}
		\LARGE
		\includegraphics[width=0.5\textwidth]{./Figs/MEGC_logo.png}\\[\bigskipamount]
	}
	\posttitle{\end{center}}

\begin{document}

	%%%%%%%%%%%%%%%%%
	%%%%% Title %%%%%
	%%%%%%%%%%%%%%%%%

	%The commands below define and make the titlepage
	\title{Learning \LaTeX\ with MEGC}
	\author{\vspace{1 in} \\University of Michigan
		\\Ann Arbor, Michigan \vspace{.25 in} \\by: \\Jeff Koller \vspace{1 in}
	}
	\date{October 1\textsuperscript{rd}, 2015}
	\maketitle				%Create title
	\thispagestyle{empty} 	%Remove header and footer.
	\clearpage				%Equivalent to a page break

	%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Introduction %%%%%
	%%%%%%%%%%%%%%%%%%%%%%%%

	\section{Introduction}

	\subsection{Editors}
	There are many different \LaTeX\ editors out there.
	This website gives a good overview of the different editors, their benefits and disadvantages, and what operating systems they work on:
	\begin{center}
		\url{http://en.wikipedia.org/wiki/Comparison_of_TeX_editors}.
	\end{center}
	It is important to note that you can do all of your \LaTeX\ using online editors like ShareLaTeX, but you need an internet connection to do so.
	If you wish to work on your local machine (which is typically faster to compile than going through a cloud service) you may want to consider downloading an editor.
	When you download, you will receive a default editor called TeXworks.
	This is a bare bones editor and you could greatly benefit from an alternative.
	Some editors that MEGC members have used or have considered are the following:
	\begin{itemize}
		\item \textbf{Windows:} \url{https://www.youtube.com/watch?v=g6ez7sbaiWc}
		\begin{itemize}
			\item \href{http://www.texstudio.org/}{TeXstudio} $\leftarrow$ \emph{This is T.J.'s favorite editor}
			\item \href{http://www.xm1math.net/texmaker/}{Texmaker} $\leftarrow$ \emph{This is Jeff's favorite editor}
			\item \href{http://www.texniccenter.org/}{TeXnicCenter} $\leftarrow$ \emph{This editor is not our favorite, but is the most widely used on Windows OS}
		\end{itemize}
		\item \textbf{Mac OS:} \url{https://www.youtube.com/watch?v=5CNmIaRxS20}
		\begin{itemize}
			\item \href{http://pages.uoregon.edu/koch/texshop/}{TeXShop} $\leftarrow$ \emph{Sara's go to editor on Mac}
			\item \href{http://tacosw.com/latexian/download.php}{Latexian} $\leftarrow$ \emph{Does live previewing but somewhat out of date}
		\end{itemize}
		\item \textbf{Ubuntu (Linux):} \url{https://www.youtube.com/watch?v=g6ez7sbaiWc}
		\begin{itemize}
			\item \href{https://apps.ubuntu.com/cat/applications/texmaker/}{Texmaker}
			\item \href{https://apps.ubuntu.com/cat/applications/precise/gummi/}{Gummi} $\leftarrow$ \emph{Brandon's go to editor in Ubuntu and has live previewing}
			\item \href{https://apps.ubuntu.com/cat/applications/kile/}{Kile} $\leftarrow$ \emph{Sara's go to editor in Ubuntu}
			\item \href{https://www.gnu.org/software/auctex/}{AUCTeX} $\leftarrow$ \emph{Works with Emacs}
		\end{itemize}
	\end{itemize}

	\subsection{Syntax}
	\begin{itemize}
		\item Command Syntax
		\begin{itemize}
			\item For the most part, every command in \LaTeX\ can be described as \TT{\bs command[options]\{argument\}}.
		\end{itemize}
		%
		\item Environments
		\begin{itemize}
			\item Writing in \LaTeX\ can be thought of as writing in multiple different environments.
			You can have text environments, math environments, table environments, figure environments, and many many more.
			These environments can be nested and are typically marked by \TT{\bs begin\{\tpc\}} and \TT{\bs end\{\tpc\}} where what is inside of \TT{\{\tpc\}} denotes the environment.
			By default you are usually in the text environment when writing a document.
			%
			\item One exception to the \TT{\bs begin\{\tpc\}} and \TT{\bs end\{\tpc\}} markings is when you switch between text and math environments while keeping the math inline with the text.
			This switch is marked by \TT{\$\tpc\$}, but we will get to more of this in Section \ref{sec:math}.
		\end{itemize}
	\end{itemize}

	\subsection{Components to a \LaTeX\ Document}
	\begin{itemize}
		\item Preamble
		\begin{itemize}
			\item The preamble sets up the document by telling \LaTeX\ what document type you are working on, what the page layout should look like, what packages you plan to use, and allows you to define new commands.
			The preamble is everything before the \TT{\bs begin\{document\}} command.
		\end{itemize}
		\item Content
		\begin{itemize}
			\item The content of the \LaTeX\ document is everything between the \TT{\bs begin\{document\}} command and the \TT{\bs end\{document\}} command.
			This includes everything that you see in the finalized PDF document.
			By default the \TT{document} environment is a text environment.
			Everything you write between \TT{\bs begin\{document\}} and \TT{\bs end\{document\}} will be plain text unless an alternative environment is indicated.
		\end{itemize}
	\end{itemize}

	\subsection{Document Class}
	There are many different classes of documents you can write in \LaTeX.
	The document class can be thought of the style that you are writing in.
	The document class is defined at the top of the preamble (line 6 in this .tex file) and is generally denoted by \TT{\bs documentclass[options]\{class\}}.
	\begin{itemize}
		\item \TT{article} - for short documents such as a publication (this document)
		\item \TT{report} - for longer technical documents; like articles, but has chapters
		\item \TT{book} - for large documents, such as books
		\item \TT{letter} - for writing letters (has other special properties which have to be set)
	\end{itemize}
	A full list of document classes and class options can be found here: \url{https://en.wikibooks.org/wiki/LaTeX/Document_Structure#Document_classes}.

	\subsection{Packages}
	Packages are essentially libraries of commands that you are telling \LaTeX\ you will be using throughout the document.
	Packages may be needed for specific mathematical symbols, fonts, colors, the ability to insert figures, the ability to change document formatting, and much much more.
	An example of a package used in this document is the following:\\
	\begin{center}
		{\TT{\bs usepackage[margin = 2cm]\{geometry\}}}
	\end{center}
	The package \TT{geometry} allows for an easy way to customize the document margins.
	The option \TT{[margin = 2cm]} allows for a 2 centimeter margin all the way around the page without including the header or footer in that cutoff (ie the header and footer are within 2 centimeters of the paper's edge).
	We could change the option to \TT{[margin = 2cm, includefoot, includehead]} to make sure that the header and footer are outside of this margin cutoff as well.
	The option \TT{margin} can also be changed to \TT{top}, \TT{bottom}, \TT{left}, and \TT{right}.
	You can always look up a package name to figure out the specific options for that given package.
	Take a minute to try changing the options on the \TT{geometry} package in the preamble to see how it effects this document.
	%
	\clearpage

	%%%%%%%%%%%%%%%%%%%
	%%%%% Writing %%%%%
	%%%%%%%%%%%%%%%%%%%

	\section{General Writing with \LaTeX}
	In this section, we are mainly going to talk about general writing in \LaTeX.
	To write in \LaTeX, you can just start typing regularly like you would do in a normal text editor (e.g. Notepad in Windows; TextEdit in Mac).
	However, your document will be void of any formatting.
	Therefore, to make it easier to read, we must add in different types of formatting. \vspace{0.25cm}

	\noindent \textbf{\underline{Note:}} We suggest that you keep every sentence on its own separate line when writing.
	This way if your code fails to compile, you should get an error message saying which line caused the crash and you can easily debug the problem.

	\subsection{General Formatting}
	\begin{itemize}
		\item Basic text formatting
		\begin{itemize}
			\item For basic text formatting, we can include \textit{italics} with \TT{\bs textit\{\tpc\}}, \underline{underline} with \TT{\bs underline\{\tpc\}}, or \textbf{bold face} with \TT{\bs textit\{\tpc\}}.
			You can format text with \textit{\underline{\textbf{all three}}} by nesting the commands!
			\item The percent symbol (\%) is used to comment any lines out
		\end{itemize}
		\item Text color
		\begin{itemize}
			\item You can change the color of your text.
			For example, we can make our text \textcolor{red}{red}, \textcolor{blue}{blue}, \textcolor{yellow}{maize}, \textcolor{darkgrey}{dark grey}, etc.
			To change the colors of text though you must make sure you have the \TT{color} package included in your preamble.
			\item Information about the different colors, the packages needed, and how to create your own color can be found here: \url{https://en.wikibooks.org/wiki/LaTeX/Colors}.
		\end{itemize}
		\item Change font type
		\begin{itemize}
			\item You can easily change the font size in \LaTeX\ using commands.
			\begin{itemize}
				\item \tiny For example this text is tiny
				\item \LARGE For example this text is Large
			\end{itemize}
			We are not going to show you how to do much font changes in this presentation, as it is not the most vital.
			You can easily search online for how to do this (for a start, look here: \url{http://en.wikibooks.org/wiki/LaTeX/Fonts}.
			%		\item One font system that is already built into the packages we have above (i.e. \TT{amssymb}) is the font system for when we want to refer to the real number system.
			%		To do this, we use \TT{\$\bs mathbb\{R\}\$} to get $\mathbb{R}$.
			%		So for example we could say the following:
			%		\begin{center}
			%			$\pi \in \mathbb{R}$ and $\pi \notin \mathbb{Z}$
			%		\end{center}
			%		Note: We will talk more about what these \TT{\$\tpc\$} mean when we get to the math environment in Section \ref{sec:math}.
		\end{itemize}
		\item Starting new paragraph
		\begin{itemize}
			\item Leave a blank line between sentences $\leftarrow$ \emph{Would recommend most}
			\item Use the command \TT{\bs newline} followed by \TT{\bs indent} $\leftarrow$ \emph{Would avoid to keep .tex readable}
			\item Use the command \TT{\bs \bs} $\leftarrow$ \emph{Would avoid to keep .tex readable}
		\end{itemize}
	\end{itemize}

	\subsection{Creating List Environments}
	\LaTeX\ has different kinds of list environments, and you can even create your own (e.g. see the \TT{Resume\_Template} that we will give you at the end of the workshop).
	You can read more about the lists here: \url{http://en.wikibooks.org/wiki/LaTeX/List_Structures}.
	In general, the three standard list environments are the following:
	\begin{enumerate}
		\item \textbf{Enumerate} -- What was used for this list.
		\item \textbf{Itemize} -- Standard bulleted item list; can choose your own bullets and place them in brackets right after item.
		For example \TT{\bs item[\$\bs circ\$]} will give you this symbol $\circ$ as your bullet.
		\item \textbf{Description} -- More freedom to specify the item label.
	\end{enumerate}
	For a list, you must start with for example \TT{\bs begin\{enumerate\}} and end with \TT{\bs end\{enumerate\}} (or  \TT{\bs begin\{itemize\}}; \TT{\bs end\{itemize\}}, etc.).
	In between those two commands, you can have as many items as you would like.
	You must signify each item using the command \TT{\bs item}.

	\subsection{Labels and References}
	\label{sec:labelsreferences}
	One of the best parts of \LaTeX\ is the ease at which you can reference the different elements in your document, and \LaTeX\ will automatically number everything accordingly (if you have different preferences for numbering, you can make your own styling--but that is a little more advanced).
	Labels and references are commonly used for these elements:
	\begin{itemize}
		\item Sections in the document (e.g. a numbered subsection, a chapter, an appendix)
		\item Figure
		\item Equations
		\item Table
		\item Citation
	\end{itemize}
	Now look at the \LaTeX\ code and see what was typed just below \TT{\bs subsection\{Labels and References\}}. You should see a \TT{\bs label\{sec:labelsreferences\}}.
	This command assigned the label ``sec:labelsreference'' to this very subsection.
	Now if you want to refer to this section anywhere throughout the document, all you have to do is type the command \TT{\bs ref\{sec:labelsreferences\}} and \LaTeX\ will reference Section \ref{sec:labelsreferences}.
	There is a special reference command you can use for equations that will include parenthesis around the citation.
	The command is \TT{\bs eqref\{\tpc\}}.

	The same labeling technique can be used for equations, figures, tables, appendices, chapters etc.
	It is usually considered good practice to put a signifier in your label as to what you are actually labeling.
	For example, if you were to label an equation, such as the first equation in Section \ref{sec:equations}, you could call it ``eq:\dots''.
	This labeling convention just makes things easy to interpret when writing.
	So for the first equation in Section \ref{sec:equations}, we have labeled the equation \TT{\bs label\{eq:example\}}.
	Now we can refer to Eqn. \eqref{eq:example} by using the command \TT{\bs eqref\{eq:example\}}.

	The signifier for a table is usually \TT{tab:}, the signifier for a figure is usually \TT{fig:}, and the signifier for an equation is usually \texttt{eq:}.
	You can then create your own signifiers for everything else.
	We will discuss how to make references to citations in Section \ref{sec:bibliography}, but just as a heads up, instead of using the command \TT{\bs ref\{\tpc\}} we will use \TT{\bs cite\{\tpc\}} for bibliography citations.

	\paragraph{Practice your text skills by trying to replicate Exercise1.pdf}
	\clearpage

	%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Math Environment %%%%%
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	\section{Math environment}
	\label{sec:math}
	Another wonderful aspect of \LaTeX\ is its ability to seamlessly move from mathematical environments to text environments.
	When we are going into math environment, we are telling \LaTeX\ that we are now using math symbols.
	There are two ways to enter the math environment:
	\begin{enumerate}
		\item Inline with your other text.
		You enter in and out of the math environment using a set of dollar signs: \TT{\$\textit{math stuff}\$}.
		\item In a display style.
		For the display style you entering into a different environment (ie. equation, align, matrix, etc.) which assumes everything you are typing is a math symbol unless you specify otherwise.
		You will see more of this in Section \ref{sec:equations}.
	\end{enumerate}
	%
	Some other notes for the math environment:
	\begin{itemize}
		\item Spacing is done automatically unless forced with dedicated commands (\texttt{\bs quad}, \texttt{\bs vspace}, \texttt{\bs hspace}, etc...these are described in detail in Section \ref{sec:spacemanagement})
		\item Empty lines are not allowed so use comments (\%...) to clean things up.
		\item After entering a math environment, math fonts will be used unless the \texttt{\bs text\{\tpc\}} environment is invoked.
		\item As was stated above, to use the math environment in prose writing, you must separate whatever you are writing that is ``math'' by dollar signs (i.e. \TT{\$\textit{math stuff}\$}).
		Thus, if you want to write \emph{sigma} in line with your text, you should type \TT{\$\bs sigma\$} to get $\sigma$.
	\end{itemize}
	%
	\subsection{Basic Math Commands}
	Some basic math environment commands:
	\begin{itemize}
		\item \TT{\bs\bs} is used to end a line and start a new one
		\item The \textbf{ampersand} (\&) is usually used for alignment in the math environment.
		You will see this when we create arrays and equations with more than one line.
		\item $\_$ gives you a subscript.
		For example to get $x_2$, you type \TT{\$x\_2\$}.
		\item $ ^\wedge $ gives you a superscript.
		For example to get $x^2$, you type \TT{\$x$^\wedge$2\$}.
		\item \textbf{\TT{\{\tpc\}}} are used to include extra but necessary information for a command.
		For example, if you want to type $x_{i+1}$, you must put \TT{i+1} inside of \TT{\{\tpc\}}, otherwise the subscript only reads the \TT{i}.
		So to get $x_{i+1}$ you would type \TT{\$x\_\{i+1\}\$}.
		Without the \textbf{\TT{\{\tpc\}}} around the \TT{i+1}, it looks like $x_i+1$.
		\item \textbf{Greek symbols} are widely used in the math mode.
		Greek symbols are usually the name of the symbol with a \TT{\bs} at the beginning.
		For example, $\delta$ is typed as \TT{\$\bs delta\$}.
		For the upper-case version of the greek symbols, you usually just capitalize the first letter of the greek symbol command.
		Thus, for $\Delta$, we type \TT{\$\bs Delta\$}.
		For more on Greek symbols, look here: \url{http://en.wikibooks.org/wiki/LaTeX/Mathematics#List_of_Mathematical_Symbols}.
		\item A \textbf{fraction} command is another widely used math command.
		For a fraction, you will use the command \TT{\bs frac\{\}\{\}\$} where you must input two arguments.
		The first argument is the \emph{numerator} and the second argument is the \emph{denominator}.
		So for example, if you want $\frac{1}{2}$, you would type it as \TT{\$\bs frac\{1\}\{2\}\$}.
	\end{itemize}
	%
	\subsection{Equations}
	\label{sec:equations}
	%******************************* Equations ******************************************************
	One of the most attractive parts of \LaTeX\ is the ease and cleanliness when typing complicated equations.
	%
	Here is our basic equation presented using the align environment:
	\begin{align}
		\label{eq:example}
		\frac{\partial u}{\partial y} + C_1^2
	\end{align}
	%
	The align environment is the same as the equation environment shown below however we recommend always using align because it allows for added features:
	\begin{equation}
		\frac{\partial u}{\partial y} + C_1^2
	\end{equation}
	%
	Adding a star inside of the brackets of \TT{equation} (or any numbered environment for that matter) will take away the numbering associated with it.
	For example, if we begin our \TT{equation} environment with \TT{\bs begin\{environment*\}} we get the following:
	\begin{equation*}
		\frac{\partial u}{\partial y} + C_1^2
	\end{equation*}
	%
	Using the \TT{align} command, we can easily align parts of a multi-lined equation using \TT{\&} as the alignment object for each line (where you end a line of the equation using the standard \TT{\bs \bs}):
	\begin{align*}
		5 x^2 - 20x &= 20 \\
		5 x^2 - 20x -20 &= 0 \\
		x^2 - 4x -4 &= 0 \\
		(x-2)^2 &= 0 \\
		\Rightarrow x - 2 &= 0 \\
		x &= 2
	\end{align*}
	%
	Let's show another example of using alignment with our equations. Let $y=3$ then we can solve for $x$:
	\begin{align*}
		x &= y^3 + e^{y^2} - y + \log y \\
		& = (3)^3 + e^{3^2} - 3 + \log 3 \\
		& = 27 + e^9 - 3 + \log 3 \\
		& = 30 + e^9 - \log 3 \\
		& \approx 30 + 8103.082  - 1.099 \\
		& \approx \mathbf{8131.983}
	\end{align*}
	%
	We can also implement more complicated math symbols such as summation and integration.
	To demonstrate this, we will write out the definition to a definite integral:
	\begin{dfn}
		Let $f(x)$ be a function which is continuous on the closed interval $[a,b]$. The definite integral of $f(x)$ from $a$ to $b$ is
		\begin{align*}
			\int_a^b f(x)\,dx = \lim_{n\rightarrow \infty} \sum_{i=1}^n f(x_i) \Delta x
		\end{align*}
		where
		\begin{align*}
			\sum_{i=1}^n \Delta x_i
		\end{align*}
		is a Riemann sum of $f(x)$ on $[a,b]$.
	\end{dfn}
	\noindent It should be noted that using \TT{\bs,} right after \TT{f(x)} in the integral, gives the correct spacing between $f(x)$ and $dx$.

	You may also need to utilize the \TT{\bs displaystyle} command when your integrals or summations are inline. So for example:
	\begin{align}
		f(x) = \frac{\int_0^1g(x)\,dx}{\int_0^1h(x)\,dx}
	\end{align}
	Here is the same function but written using \TT{\bs displaystyle} before \TT{\bs int}:
	\begin{align}
		f(x) = \frac{\displaystyle\int_0^1g(x)\,dx}{\displaystyle\int_0^1h(x)\,dx}
	\end{align}
	If you ever need to write an integral, a fraction, or a summation inline, you can use \TT{\bs displaystyle} command.

	\subsection{Matrices}
	\label{sec:matrices}
	We can make a matrix by entering the \TT{matrix} environment.
	Here, we use \TT{\&} to separate items in the row of a matrix and we use \TT{\bs\bs} to create new rows.
	Here is the basic $3 \times 3$ identity matrix using the matrix environment \TT{\bs begin\{matrix\}} and \TT{\bs end\{matrix\}}:
	\begin{align*}
		\begin{matrix}
			1 & 0 & 0 \\
			0 & 1 & 0 \\
			0 & 0 & 1 \\
		\end{matrix}
	\end{align*}
	%%
	You can add brackets around it by typing \TT{\bs left[} and \TT{\bs right]} before and after you enter the \TT{matrix} environment, respectively:
	\begin{align*}
		\left[
		\begin{matrix}
			1 & 0 & 0 \\
			0 & 1 & 0 \\
			0 & 0 & 1 \\
		\end{matrix}
		\right]
	\end{align*}
	%
	You can also do the same thing as above but using the \TT{array} environment.
	This environment is a little more complicated than the matrix environment, but does give you more control when you get the hang of it.
	You can learn more about it here: \url{http://en.wikibooks.org/wiki/LaTeX/Mathematics#Matrices_and_arrays}.
	Here is an example of the same thing, but using the \TT{array} environment:
	\begin{align*}
		\begin{array}{ccc}
			1 & 0 & 0 \\
			0 & 1 & 0 \\
			0 & 0 & 1 \\
		\end{array}
	\end{align*}
	%
	We can also use the \TT{array} environment for certain types of equations:
	\begin{align}
		F(x) = \left\{
		\begin{array}{ll}
			0, & x \leq 0 \\
			\frac{\partial u}{\partial y} + C_1^2  & x > 0\\
		\end{array}
		\right.
	\end{align}
	Note here that using the command \TT{\bs left\{} puts a curly bracket to encompass the left side of the array, but when using \TT{\bs left}, you must also have a \TT{\bs right} command at some point. However, since we do not want a curly bracket on the right, we use \TT{\bs right.} (\TT{\bs right} with a period).
	%
	Using the \TT{\bs dfrac\{numerator\}\{denominator\}} command will make the fractions larger and easier to read
	\begin{align}
		\label{eq:exampledel}
		F(x) = \left\{
		\begin{array}{ll}
			0, & x \leq 0 \\
			\dfrac{\partial u}{\partial y} + C_1^2  & x > 0\\
		\end{array}
		\right.
	\end{align}

	\paragraph{Practice your math skills by attempting to replicate Exercise2.pdf}
	\clearpage

	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Figures and Tables %%%%%
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	\section{Tables and Figures}
	\LaTeX\ has the ability to include nicely formatted tables and figures.
	These can sometimes be a pain to get in the right place because they are known in \LaTeX\ as floats.
	\LaTeX\ typically places floats where it deems best for them to go, but this typically isn't where you want them placed.
	You can constrain a float to be in the location it is typed in the code using the \texttt{[h]} command directly after the begin environment command (see code for the following table and figure for an example) but there are many other ways to place floats where you want them.
	A good description on how to control floats is listed here: \url{http://tex.stackexchange.com/questions/39017/how-to-influence-the-position-of-float-environments-like-figure-and-table-in-lat}.

	\label{sec:tablesfigures}
	\subsection{Tables}
	To create tables, we use the \TT{tabular} environment nested within a \TT{table} environment.
	It is important to note that most tables will begin with \TT{\bs begin\{tabular\}\{\tpc\}} and what is inside of the \TT{\{\tpc\}} helps preallocate the table itself.
	Take a look at the following table.

	\begin{table}[h]
		\begin{center}
			\begin{tabular}{l | l | l} \hline\hline
				\textbf{Greek symbol} & \textbf{Upper-case} & \textbf{Lower-case} 	\\ \hline
				Omega 	& \TT{\bs Omega} ($\Omega$) & \TT{\bs omega} ($\omega$) 	\\
				Beta 	& \text{N/A} 				& \TT{\bs beta} ($\beta$) 		\\
				Delta 	& \TT{\bs Delta} ($\Delta$) & \TT{\bs delta} ($\delta$) 	\\
				Sigma 	& \TT{\bs Sigma} ($\Sigma$) & \TT{\bs sigma} ($\sigma$) 	\\
				Alpha 	& \text{N/A} 				& \TT{\bs alpha} ($\alpha$) 	\\ \hline
			\end{tabular}
			\caption{Some Greek symbols and their corresponding commands.}
			\label{tab:greeksymbols}
		\end{center}
	\end{table}

	This table has three columns that are all left aligned.
	If you take a look at the \LaTeX\ code that generated the table you will see that it begins with \TT{\bs begin\{tabular\}\{l | l | l\}}.
	The \TT{l}'s in this preallocation define the alignment of each column.
	Preallocation can be defined with \TT{l}'s, \TT{c}'s, or \TT{r}'s for alignment.
	The \TT{|}'s that separates each \TT{l} tell \LaTeX\ to put a vertical line between each column.
	You should also notice that each row uses ampersands (\TT{\&}) to signify which content belongs in each column and \TT{\bs\bs} are used to signify when to start a new row (just like when creating matrices as explained in Section~\ref{sec:matrices}).
	Additionally, the command \TT{\bs hline} can be used to put in horizontal lines where needed.
	A really good overview of \LaTeX\ tables can be seen here: \url{http://en.wikibooks.org/wiki/LaTeX/Tables}.
	\clearpage

	\subsection{Figures}
	In order to insert figures into your \LaTeX\ documents you must include the \TT{graphicx} package.
	To begin a figure you will enter the \TT{figure} environment.
	Once in the \TT{figure} environment you can then include a figure using the \TT{\bs includegraphics\{\tpc\}} command where the figure name (or figure path relative to your \TT{.tex} file location and filename) are in the \TT{\{\tpc\}}.
	A common method of sizing an image is to size it relative to the paper's text width.
	An example of this is below.

	\begin{figure}[h]
		\begin{center}
			\includegraphics[width=0.5\textwidth]{./Figs/cat}
			\caption{Picture of an awesome cat.}
			\label{fig:awesomecat}
		\end{center}
	\end{figure}

	If you look at the \LaTeX\ code that generated this figure you will see that the figure width was set to $\frac{1}{2}$ the documents text width.
	Additionally a caption can be added to a figure using the \TT{\bs caption\{\tpc\}} command where the caption text is between the \TT{\{\tpc\}}.
	More information on figures can be found here: \url{https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions}.

	\LaTeX\ also has the ability for you to draw your own pictures.
	We are not going to go into that for this presentation.
	But if you want to learn more about it, you can find out more here: \url{http://en.wikibooks.org/wiki/LaTeX/PGF/TikZ}

	\paragraph{Practice your figure and table skills by trying to replicate Exercise3.pdf}
	\clearpage

	%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Space Management %%%%%
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	\section{Space Management}
	\label{sec:spacemanagement}
	A great freedom (and curse) of \LaTeX\ is that you have free range to change mostly any spacing on the page.
	Sometimes you need to nudge something up, down, left, or right.
	The following section will discuss how to do this.

	\subsection{Units}
	\noindent Common units used in \LaTeX:
	\begin{itemize}
		\item pt - point (1 in = 72.27 pt)
		\item in - inch (1 in = 25.4 mm)
		\item cm - centimeter (1 cm = 10 mm)
		\item mm - millimeter
		\item em - roughly the width of an 'M' (uppercase) in the current font
		\item ex - roughly the height of an 'x' in the current font
	\end{itemize}

	\noindent Useful \LaTeX\ measurements to reference:
	\begin{itemize}
		\item \TT{\bs textwidth} - The width of the text on the page (margin to margin)
		\item \TT{\bs textheight} - The height of the text on the page (margin to margin)
	\end{itemize}

	\subsection{Creating Whitespace}
	The following are commonly used commands for creating whitespace.

	\begin{itemize}
		\item \TT{\bs noindent} - Removes indent at the beginning of a new paragraph
		\item \TT{\bs} - About a single spacebar of spacing
		\item \TT{\bs quad} - About the spacing of `M'
		\item \TT{\bs qquad} - Add the spacing of `MM'
		\item \TT{\bs vspace\{\tpc\}} and \TT{vspace*\{\tpc\}} - Add vertical space of \TT{\{\tpc\}} units(*indicates manual override)
		\item \TT{\bs hspace\{\tpc\}} and \TT{hspace*\{\tpc\}} - Add horizontal space of \TT{\{\tpc\}} units (*indicates manual override)
		\item \TT{\bs vfill} - Adds whitespace to fill the page vertically
		\item \TT{\bs hfill} - Adds whitespace to fill the page horizontally
	\end{itemize}

	\subsection{Minipages}
	Sometimes you want to section out a page into subsections of space making it easier to manipulate sets of objects or place objects relative to one another.
	This can be difficult to do traditionally in \LaTeX\ but minipages can be used to make it easier.
	Minipages is somewhat analogous to axes in MATLAB.
	The general syntax for minpages is as follows:
	\begin{center}
		\TT{\bs begin\{minipage\}[pos][height][contentpos]\{width\}}\\
	\end{center}
	Minipages are a somewhat advanced feature and we will not go into too much detail on the topic here yet they are used quite a bit in the \TT{Slides\_Template.tex} file that will be shared with you after the workshop.

	\paragraph{Practice your whitespace management by trying to replicate Exercise4.pdf}
	\clearpage

	\section{Custom commands}
	\label{sec:customcommands}
	When using commands that can be tedious to type (e.g. \TT{\bs partial}), we can create new command handles that are easier to type out.
	For this one, we created a command such that \TT{\bs del} also gives us the same symbol as \TT{\bs partial}.
	At the beginning of the document, you can see where we typed this:
	\begin{center}
		\TT{\bs newcommand\{\bs del\}\{\bs partial\}} \\
	\end{center}
	So now we can retype Eqn. \eqref{eq:exampledel} using \TT{\bs del} instead of \TT{\bs partial} and we get the same result:
	\begin{align*}
		F(x) = \left\{
		\begin{array}{ll}
			0, & x \leq 0 \\
			\dfrac{\del u}{\del y} + C_1^2  & x > 0\\
		\end{array}
		\right.
	\end{align*}
	\vspace{1cm}

	\begin{center}
		\textbf{Can you find the other custom commands that we made in this document?}
	\end{center}

	\clearpage
	\section{Bibliographies \& BibTeX}
	\label{sec:bibliography}
	As we have seen in the previous sections, \LaTeX\ is very very good at keeping track of the numbering of labels and compiling them in the proper order.
	This becomes EXTREMELY useful when it comes to creating a bibliography.
	In short, with the use of \hologo{BibTeX} a handle can be assigned to each reference.
	When you would like to cite the reference in writing all you need to do is use the command \TT{\bs cite\{\tpc\}}.
	\LaTeX\ will take care of the rest!

	\subsection{Using \hologo{BibTeX}}
	Creating bibliographies in \LaTeX\ is easy using \hologo{BibTeX}.
	\hologo{BibTeX} is awesome and a simple extension of \LaTeX\ \cite{MyRef0}.

	\begin{itemize}
		\item Information for references is stored in a separate \TT{.bib} file.
		\item For each reference the \TT{.bib} file will include an entry with your label for that reference and other relevant citation information such as author, title, journal, year, publisher, etc...
		\item These \TT{.bib} entries can usually be downloaded directly from the documents online source (eg., Google Scholar, Web of Knowledge, Elsevier, etc...) or generated with a third party literature management software such as Mendeley.
		\item Once the \TT{.bib} file is populated with reference entries and compiled, a reference can be cited in the text using \TT{\bs cite\{ReferenceLabel\}}.
		This will automatically add the reference to the bibliography and keep things in the order defined by the bibliography style being used.
		\item At the end of your document you will define the bibliography style using the command \TT{\bs bibliographystyle\{\tpc\}} and then point \LaTeX\ to your BibTex file name using the command \TT{\bs bibliography\{Filename.bib\}}
		\begin{itemize}
			\item There are many different bibliography styles and many journals will have their own style defined which you can just insert in your manuscript writing.
			Here we are using IEEE Transactions which is a standard built in style in \LaTeX.
		\end{itemize}
	\end{itemize}
	Take a look at the code that generated the citation at the beginning of this subsection and the corresponding \hologo{BibTeX} file to see how it was done.

	\subsection{Creating a \hologo{BibTeX} File and Entry Content}
	Creating a \TT{.bib} file is super easy.
	All you need to do is open a new file in \LaTeX, include the references, and save it as a \TT{.bib}.
	There is no limit to how many references you put in your \TT{.bib} file and only the ones that are cited will show up in the reference section.
	There is no need for a document class definition at the top of your \TT{.bib} file or any \TT{\bs begin\{\tpc\}} or \TT{\bs end\{\tpc\}} statements necessary.
	Like stated above, you can easily pull \hologo{BibTeX} citations from Google Scholar, but it is important to understand the content of a \hologo{BibTeX} entry.
	A sample reference entry for the \TT{.bib} file is shown below.
	\begin{verbatim}
	@article{hawking1982,
	title={The development of irregularities in a single bubble inflationary universe},
	author={Hawking, Stephen W},
	journal={Physics Letters B},
	volume={115},
	number={4},
	pages={295--297},
	year={1982},
	publisher={Elsevier}
	}
	\end{verbatim}
	More information on different types of entries can be found here: \url{https://en.wikipedia.org/wiki/BibTeX}

	\paragraph{Practice your \hologo{BibTeX} skills by trying to replicate Exercise5.pdf}

	\clearpage
	\section{Other Random Resources}
	\begin{itemize}
		\item Templates - Can pull pre-generated style and class files for a specific document type (\url{http://www.latextemplates.com/})
		\item Mathematica - Can copy inputs and outputs as \LaTeX\, great for large tables and matrices
		\item Detexify - Can draw symbols and it will output the \LaTeX\ command (\url{http://detexify.kirelabs.org/classify.html})
		\item Codecogs  - Real time typing of \LaTeX\ math equations with a helpful user interface (\url{https://www.codecogs.com/latex/eqneditor.php})
	\end{itemize}

	\clearpage
	\bibliographystyle{ieeetr}
	\bibliography{MyBib}
\end{document}


% !TeX root = ../bd-screen.tex

\chapter{Preface}

This is an introductory textbook on modal logic. I use it as the main
text when I teach Philosophy~579.2 (Modal Logic) at the University of
Calgary. It is based on material from the
\href{https://openlogicproject.org}{Open Logic Project}.

The main text assumes familiarity with some elementary set theory and
the basics of (propositional) logic. This material is part of a
prerequisite for my course, Logic~II. The textbook for that course,
\href{https://slc.openlogicproject.org}{\emph{Sets, Logic,
Computation}}, is also based on the OLP, and so is available for free.
The required material is included as appendices in this book,
however. I assign these appendices for background reading whenever I
teach the material.

\Cref{nml:::part} is originally based in part on Aldo Antonelli's
lecture notes on ``Classical Correspondence Theory for Basic Modal
Logic,'' which he contributed to the OLP before his untimely death in
2015. I heavily revised and expanded these notes, e.g., the material
on frame definability and tableaux is new.


\documentclass[a4paper,11pt]{article}
\usepackage{graphicx}
\usepackage{enumerate}
\usepackage{amsmath}

\begin{document}

\begin{flushright}

\vspace{1.1cm}

{\bf\Huge Problem Set 1}

\rule{0.25\linewidth}{0.5pt}

\vspace{0.5cm}
%Put Authors
Justin Ely
\linebreak
\newline
%Put Author's affiliations
\footnotesize{Foundations of Algorithms \\}
% Date here below
June 06, 2016 \\
612-240-0924
\end{flushright}

\noindent\rule{\linewidth}{1.0pt}

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

\section*{1)}
We wish to prove by induction that $\sum_{i=1}^n i^3 = (\frac{n(n+1)}{2})^2$.  We start this by proving a trivial case of n=1.

\begin{equation}
1 = (\frac{1(1 + 1)}{2})^2
\end{equation}

Now we prove that the solution works for n+1.

\begin{eqnarray}
\sum_{i = 1}^{k+1} i^3 &=& \sum_{i=1}^k i^3 + (k+1)^3 \\
&=&(\frac{k (k+1)}{2})^2 + (k+1)^3 \\
&=& \frac{k^2 (k+1)^2}{2^2} + \frac{2^2 (k+1)^3}{2^2} \\
&=& \frac{k^2 (k+1)^2 + 2^2 (k+1)^3}{2^2} \\
&=& k^2(k^2 + 2k + 1) + 2^2(k^2 + 2k + 1)(k+1) \\
&=& k^4 + 2k^3 + k^2 + (4k^2 + 8k + 4)(k+1) \\
&=& k^4 + 2k^3 + k^2 + 4k^3 + 12k^2 + 12k + 4 \\
&=& k^4 + 6k^3 + 13k^2 + 12k + 4 \\
&=& \frac{(k + 1)^2 (k+2)^2}{2^2} \\
&=& (\frac{(k + 1) (k + 1 + 1)}{2})^2
\end{eqnarray}

Which proves the induction hypothesis. \\

Using:
\begin{eqnarray}
(k + 1)(k + 1) &=& k^2 + 2k + 1 \\
(k + 2)(k + 2) &=& k^2 + 4k + 4 \\
(k + 1)^2 (k + 2)^2 &=& k^4 + 6k^3 + 13k^2 + 12k + 4
\end{eqnarray}

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

\section*{2a)}
\begin{verbatim}
[40, 17, 45, 82, 62, 32, 30, 44, 93, 10]
[17, 40, 45, 82, 62, 32, 30, 44, 93, 10]
[17, 40, 45, 82, 62, 32, 30, 44, 93, 10]
[17, 40, 45, 82, 62, 32, 30, 44, 93, 10]
[17, 40, 45, 62, 82, 32, 30, 44, 93, 10]
[17, 32, 40, 45, 62, 82, 30, 44, 93, 10]
[17, 30, 32, 40, 45, 62, 82, 44, 93, 10]
[17, 30, 32, 40, 44, 45, 62, 82, 93, 10]
[17, 30, 32, 40, 44, 45, 62, 82, 93, 10]
[10, 17, 30, 32, 40, 44, 45, 62, 82, 93]
\end{verbatim}

\section*{2b)}
\begin{verbatim}
Split:  [75, 56, 85, 90, 49, 26, 12, 48, 40, 47]  ->
        [75, 56, 85, 90, 49] & [26, 12, 48, 40, 47]
Split:  [75, 56, 85, 90, 49]  ->
        [75, 56] & [85, 90, 49]
Split:  [75, 56]  ->
        [75] & [56]
Merge: [75] with [56] -> [56, 75]
Split:  [85, 90, 49]  ->
        [85] & [90, 49]
Split:  [90, 49]  ->
        [90] & [49]
Merge: [90] with [49] -> [49, 90]
Merge: [85] with [49, 90] -> [49, 85, 90]
Merge: [56, 75] with [49, 85, 90] -> [49, 56, 75, 85, 90]
Split:  [26, 12, 48, 40, 47]  ->
        [26, 12] & [48, 40, 47]
Split:  [26, 12]  ->
        [26] & [12]
Merge: [26] with [12] -> [12, 26]
Split:  [48, 40, 47]  ->
        [48] & [40, 47]
Split:  [40, 47]  ->
        [40] & [47]
Merge: [40] with [47] -> [40, 47]
Merge: [48] with [40, 47] -> [40, 47, 48]
Merge: [12, 26] with [40, 47, 48] -> [12, 26, 40, 47, 48]
Merge: [49, 56, 75, 85, 90] with [12, 26, 40, 47, 48] ->
       [12, 26, 40, 47, 48, 49, 56, 75, 85, 90]
\end{verbatim}

\section*{2c)}
With $\frac{n}{k}$ sublists, each of length $k$ elements, and insertion sort running at order $\Theta (n^{2})$; then $\frac{n}{k} k^2 = nk $ to sort all lists.

\section*{2d)}
Each merge operation takes on order n, operating $log(\frac{n}{k})$ times, thus merging all the sublists takes: $\Theta(n log(\frac{n}{k}))$.

\section*{2e)}
The largest value of k will come when the modified merge sort is of the same order as the standard merge sort, which happens when:

\begin{equation}
\Theta(n log(n)) = \Theta(nk + nlog\frac{n}{k})
\end{equation}

We know that k cannot be a higher order than $log(n)$, as this would cause the modified algorithm to have a higher order
worst-case growth rate than the standard merge sort.  We can thus make the assumption that $k=log(n)$ is the valid solution,
and test.

\begin{eqnarray}
\Theta(n log(n)) &=& \Theta(nk + nlog(\frac{n}{k})) \\
&=& \Theta(nk + nlog(n) - nlog(k)) \\
&=& \Theta(nlog(n) + nlog(n)- nlog(log(n))) \\
&=& \Theta(2nlog(n) - nlog(log(n))) \\
&=& \Theta(nlog(n))
\end{eqnarray}

\section*{2f)}
In practice, a modified merge sort is chosen to execute in a faster time than a standard merge sort.  Therefore, k should be
chosen to to be the maximum size for which insertion sort is faster than merge sort.

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

\section*{3)}
My implementation is in python; as I find it very close to pseudo-code in simple cases - with the added benefit that i can run it
on sample cases.  Please let me know if this is an issue and I can modify my approach in the future.

The algorithm loops over the nodes and adjacent nodes a maximum of only 1 time each; thus running in $\Theta(n + m)$.
The out-degree is a simple count of the adjacency list, while the in-degree must be tracked and summed from all adjacency lists
as the nodes are iterated.

\begin{verbatim}
def compute_degree(adj_list):
    """Computer the in-degree and out-degree of a given node"""
    out_counts = {}
    in_counts = {}

    for node in adj_list:
        out_counts[node] = len(adj_list[node])

        for other_node in adj_list[node]:
            if not other_node in in_counts:
                in_counts[other_node] = 0
            in_counts[other_node] += 1

    return out_counts, in_counts
\end{verbatim}

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

\section*{4}
For a path to be a valid binary search tree, each left subtree must be strictly smaller than it's root, and every right subtree must
be strictly larger than it's root.  For any of the paths given, if either of these conditions are broken then the path is not a
valid binary search tree.

\section*{4.1)}
This path is valid.

\section*{4.2)}
This path is valid.

\section*{4.3)}
This path is invalid.  The node 912 appears on the left subtree of node 911, which violates the binary search conditions.

\section*{4.4)}
This path is valid.

\section*{4.5)}
This path is invalid.  The node 299 appears on the right subtree of node 347, which violates the binary search conditions.

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

\section*{5)}
Lets assume that the number of executions takes the form $2n + 1$.  Solving the simple base case of $n=0$:

\begin{equation}
2(0) + 1 = 1
\end{equation}

Which agrees with a tree of 0 nodes, for which only the initial conditional will be executed a single time.

For $n > 0$, execution will happen once on the root, pluse $2n+1$ for the left subtree and $2n+1$ for the right subtree:

\begin{eqnarray}
N_{tot} &=& 1 + (2n_l + 1) + (2n_r + 1) \\
&=& 1 + (2n_l + 2n_r + 2) \\
&=& 1 + 2(n_l + n_r + 1)
\end{eqnarray}

Using the total number of nodes in the tree as $n = n_l + n_r + 1$:

\begin{equation}
N_{tot} = 1 + 2n
\end{equation}

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

\end{document}


\documentclass[11pt]{article}

\usepackage{alltt,fullpage,graphics,color,epsfig,amsmath, amssymb}
\usepackage{hyperref}
\usepackage{boxedminipage}
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{amsmath}
\usepackage{commath}
\usepackage{graphicx}
\graphicspath{ {.} }
\newcommand{\floor}[1]{\lfloor #1 \rfloor}
\newcommand{\ceil}[1]{\lceil #1 \rceil}

\title{CS 512 Assignment 1}
\author{Daniel Campos}
\date{March 5th,2021}
\begin{document}

\maketitle
\section{Problem 1}
\subsection{List two differences between Frequent Pattern Growth algorithm and Apriori
algorithm
}
Apriori requires K+1 scans of the database while FPGrowth requires 2. The apriori algorithm is a breath first search while FPGrowth is divide and conquer.  Apriori requires a large amount of memory and FPGrowth does not.
\subsection{Prove all nonempty subsets of a frequent itemset must also be frequent and prove the support of any nonempty subset s' of itemset s must be at least as large as the support of s.}
\subsubsection{Answer Prove all nonempty subsets of a frequent item list must be frequent}
\begin{enumerate}
    \item Let $S = {i_0, i_1,..., i_n}$ be a set of items.
    \item Let $R = {r_0, r_1, ...,r_m}$ be a set of records where each record $r_j$ is a set of items where $\forall k \in r_j$ $r_{jk} \in S$.
    \item Let $F = {i_0, i_1, ...,i_k}$ where each $\forall k \in F$ $F_k \in S$
    \item A frequent item set contains items where their occurrence is $>= minsup$ where minsup represents a minimum support threshold where only items that occur at or more than this threshold are in $F$.
    \item Let $ss$ represent possible non empty subsets of $F$
    \item Since every possible $ss \in F$ all items in $ss$ occur $>= minsup$ and therefore all items $\in ss$ must all be frequent as well.
    \item As a result, all non empty subsets of a frequent itemset must be frequent.
\end{enumerate}
\subsubsection{Prove any nonempty subset s must be at least as large as the support of s}
\begin{enumerate}
    \item Let $S = {i_0, i_1,..., i_n}$ be a set of items.
    \item Let $R = {r_0, r_1, ...,r_m}$ be a set of records where each record $r_j$ is a set of items where $\forall k \in r_j$ $r_{jk} \in S$.
    \item Given all non-empty subsets of $S$ where $s' = {i_1, i_k, ...}$ where $s' \in S$.
    \item Since the support of a itemset is driven by how often its items occur in $R$ the support of $S$ is that of its least common item.
    \item Since all items $i_k \in ss$ are also in $S$ the support for $i_k \in s'$ > = support($S$).
    \item Since $\forall i_k \in s'> support(S)$ then we know $support(s') \ge support(s)$
    \item Thus all non-empty subsets $s'$ must be at least as large as the support of $S$
\end{enumerate}
\subsection{What problem might lift and $\chi^2$ have? Explain why Jaccard function is null-invariant}
Lift and $X^2$
\subsubsection{What problems do $Lift$ and $\chi^2$ have}
Neither deal way with datasets that have large amounts of null transaction for the variables being compared. In other words if we are studying the correlation between variable A and B and both A and B do not have a balanced occurrence(in other words $\neg A > A$ and $\neg B > B$ both $\chi^2$ and $Lift$ will not be good measures.
\subsubsection{Why is Jaccard function null-invariant}
The Jaccard function is null invariant because it is only looking at when variables occur and does not use information from where the variables do not occur. To build on our example from part a: Jaccard function looks at $A$ and $B$ and ignores $\neg A$ and $\neg B$. This makes Jaccard null-invariant.
\subsection{Under what circumstances will PrefixSpan also have poor performance}
Since the major cost in prefixspan is Constructing projected dbs and Suffixes are largely repeating, if the target records include a large quantity of unique items then storing the physical DB in memory can be prohibitive and require projections. In short when the transaction dataset is large and there are a large amount of prefixes(say items on amazon).
\section{Problem 2: Apriori vs Frequent Pattern Growth}
\subsection{Present the intermediate results of the first three scans and the final derived frequent itemsets.}
\subsubsection{First Scan}
See results in table \ref{tab:1st}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
        Itemset & Support \\ \hline
        A & 4 \\ \hline
        B & 3 \\ \hline
        C & 5 \\ \hline
        F & 4 \\ \hline
        M & 3 \\ \hline
        P & 3 \\ \hline
    \end{tabular}
    \caption{Apriori first scan}
    \label{tab:1st}
\end{table}
\subsubsection{Second Scan}
See results in table \ref{tab:2nd}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
        Itemset & Support \\ \hline
        A,C & 4 \\ \hline
        A,M & 3 \\ \hline
        A,P & 3 \\ \hline
        C, F & 3 \\ \hline
        C, M & 3 \\ \hline
        C, P & 3 \\ \hline
    \end{tabular}
    \caption{Apriori second scan}
    \label{tab:2nd}
\end{table}
\subsubsection{Third Scan}
See results in table \ref{tab:3rd}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
        Itemset & Support \\ \hline
        A, C, M & 3  \\ \hline
        A, C, P & 3  \\ \hline
    \end{tabular}
    \caption{Apriori third scan}
    \label{tab:3rd}
\end{table}
\subsubsection{Final derived frequent itemsets}
See results in table \ref{tab:final}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
        Itemset & Support \\ \hline
        A & 4 \\ \hline
        B & 3 \\ \hline
        C & 5 \\ \hline
        F & 4 \\ \hline
        M & 3 \\ \hline
        P & 3 \\ \hline
        A,C & 4 \\ \hline
        A,M & 3 \\ \hline
        A,P & 3 \\ \hline
        C, F & 3 \\ \hline
        C, M & 3 \\ \hline
        C, P & 3 \\ \hline
        A, C, M & 3  \\ \hline
        A, C, P & 3  \\ \hline
    \end{tabular}
    \caption{Apriori Derived frequent itemsets}
    \label{tab:final}
\end{table}
\subsection{Frequent Pattern}
First off we go ahead and sort our items by frequency giving us the ordering: C(5), A(4), F(4), B(3), M(3), P(3).
Using the updated frequency sorted ordering the updated transactional database is found in table \ref{tab:sorted}.
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
        TID & ITEMS \\ \hline
        1 & {C, A, B, P} \\ \hline
        2 & {C, A, B, M} \\ \hline
        3 & {F, B} \\ \hline
        4 & {C, A, F, M, P} \\ \hline
        5 & {C, A, F, M, P} \\ \hline
        6 & {C, F} \\ \hline
    \end{tabular}
    \caption{FPGrowth updated and sorted transaction database}
    \label{tab:sorted}
\end{table}
Using this updated transaction database we create the pattern tree found in figure \ref{fig:fptree}.
\begin{figure}[]
\centering1
\includegraphics[width=8cm]{Assignments/Assignment1/FPtree.png}
\caption{Frequent Pattern Tree}
\label{fig:fptree}
\end{figure}
\subsection{Association rules}
Top 3 association rules and their confidence. \\
$M \rightarrow A = 1.0$ \\
$A \rightarrow C = 1.0$ \\
$P \rightarrow C = 1.0$ \\
\section{Problem 3: Frequent Pattern Mining Implementation}
\subsection{Data statistics}
\begin{table}[]
    \centering
    \resizebox{\textwidth}{!}{%
    \begin{tabular}{|c|c|} \hline
       Product Types  & 169  \\ \hline
       Transactions & 9835 \\ \hline
       Average Products per transactions & 4.41 \\ \hline
       Top 5 most popular products  & Whole milk(2513), other vegetables(1903), rolls/buns(1809), soda(1715), yogurt(1372) \\ \hline
       Items with single purchase & baby food, sound storage medium  \\ \hline
    \end{tabular}}
    \caption{Grocery dataset statistics}
    \label{tab:stats}
\end{table}
\subsection{Results }
Using the minimum support values of 0.05 and confidence of 0.25 the top 10 frequent item sets:
\begin{enumerate}
    \item whole milk: 0.26
    \item other vegetables:0.19
    \item rolls/buns:0.184
    \item soda:0.174
    \item yogurt:0.140
    \item bottled water: 0.11
    \item root vegetables: 0.109
    \item tropical fruit: 0.11
    \item shopping bags: 0.10
    \item sausage:0.09
\end{enumerate}
Using the same thresholds the inferred rules are:
\begin{enumerate}
    \item (whole milk) $\rightarrow$ (other vegetables) : $0.29$
    \item (rolls/buns) $\rightarrow$ (whole milk) : $0.29$
    \item (other vegetables) $\rightarrow$ (whole milk) : $0.29$
    \item (yogurt) $\rightarrow$ (whole milk) : $0.40$
\end{enumerate}
\subsection{Contingency Table: Yogurt and Whole milk}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|c|c| } \hline
       Item & Yogurt & $\neg$ Yogurt & Total  \\ \hline
       Whole Milk & 551 & 1962 & 2513 \\ \hline
       $\neg$ Whole Milk & 821  & 6501&  7322\\ \hline
       Total &1372 & 8463 &9835 \\ \hline
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}
\subsection{Interestingness using Lift}
Let A represent Whole milk and B represent yogurt. \\
\begin{equation}
lift(A,B) = \frac{c(A \rightarrow B)} {s(B)} = \frac{s(A \cup B)}{s(A)*s(B)} =  \frac{551/9836}{(1372/9835)*(2513/9835)}
\end{equation}
\begin{equation}
lift(A, B) = \frac{0.05601871}{(0.13950178)(0.25551601)} = \frac{0.05601871}{0.0356449382134978} = 1.5715754552433814 = 1.57
\end{equation}
Since the Lift of A and B is over one they are positively correlated. \\
\begin{equation}
lift(A,\neg B) = \frac{c(A \rightarrow B)} {s(B)} = \frac{s(A \cup B)}{s(A)*s(B)} =  \frac{1962/9836}{(8463/9835)*(2513/9835)}
\end{equation}
\begin{equation}
lift(A, \neg B) =  \frac{0.1994713298088654}{(0.8604982206405694)(0.25551601)} = \frac{0.1994713298088654}{0.21987107195017794} = 0.9072195266054142 = 0.91
\end{equation}
Since the lift of A and $\neg B$ is under one they are negatively correlated.\\
\subsection{Run time}
My run times comparing our implementation in of Apriori in python vs FP-Growth(via pyfpgrowth)
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|c|} \hline
       Transactions  & Apriori(ms) & FP-Growth(ms)  \\ \hline
       500 & 3.13e-5 & 1.58e-4 \\ \hline
       1000 & 6.37e-5 & 5.98e-5 \\ \hline
       2000 & 1.41e-4 & 7.90e-5 \\ \hline
       5000 & 1.74e-4 & 6.35e-5\\ \hline
       Full & 2.51e-4 & 1.09e-4 \\ \hline
    \end{tabular}
    \caption{FP-Growth vs Apriori execution time}
    \label{tab:my_label}
\end{table}
\section{Problem 4: Sequential and Graph Pattern Mining}
\subsection{Sequential database}
\subsubsection{Projections }
for $\langle ab \rangle$ see table \ref{tab:ab}, for $\langle (ab) \rangle$ see table \ref{tab:(ab)}, for $\langle de \rangle$ see table \ref{tab:de}, for $\langle abc \rangle$ see table \ref{tab:abc}, for $\langle acb \rangle$ see table \ref{tab:acb},for $\langle abca \rangle$ see table \ref{tab:acba}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
       SID  & Sequence  \\ \hline
       1 & $\langle (_cf)(ac)b \rangle$ \\ \hline
       2 & $\langle (_)c(bc)ab(ce) \rangle$ \\ \hline
       3 & $\langle _(acf)acd \rangle$ \\ \hline
       4 & $\langle (_c)(ae) \rangle$ \\ \hline
       5 & $\langle (_d)df(ab) \rangle$\\ \hline
       6 & $\langle (_c)eab(cd)f(abd) \rangle$ \\ \hline
    \end{tabular}
    \caption{Projection for $\langle ab \rangle$}
    \label{tab:ab}
\end{table}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
       SID  & Sequence  \\ \hline
       1 & $\langle  \rangle$ \\ \hline
       2 & $\langle c(bc)ab(ce) \rangle$ \\ \hline
       3 & $\langle  \rangle$ \\ \hline
       4 & $\langle (_c)(ae) \rangle$ \\ \hline
       5 & $\langle (_d)df(ab) \rangle$\\ \hline
       6 & $\langle (_c)eab(cd)f(abd) \rangle$ \\ \hline
    \end{tabular}
    \caption{Projection for $\langle (ab) \rangle$}
    \label{tab:(ab)}
\end{table}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
       SID  & Sequence  \\ \hline
       1 & $\langle  \rangle$\\ \hline
       2 & $\langle  \rangle$ \\ \hline
       3 & $\langle _(af)acb(acf)acd \rangle$ \\ \hline
       4 & $\langle _(abc)(ae) \rangle$ \\ \hline
       5 & $\langle  \rangle$\\ \hline
       6 & $\langle  \rangle$ \\ \hline
    \end{tabular}
    \caption{Projection for $\langle de \rangle$}
    \label{tab:de}
\end{table}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
       SID  & Sequence  \\ \hline
       1 & $\langle (_f)(ac)b \rangle$\\ \hline
       2 & $\langle _(bc)ab(ce) \rangle$ \\ \hline
       3 & $\langle (_f)acd \rangle$ \\ \hline
       4 & $\langle (_)(ae) \rangle$ \\ \hline
       5 & $\langle  \rangle$\\ \hline
       6 & $\langle eab(cd)f(abd) \rangle$ \\ \hline
    \end{tabular}
    \caption{Projection for $\langle abc\rangle$}
    \label{tab:abc}
\end{table}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
       SID  & Sequence  \\ \hline
       1 & $\langle  \rangle$\\ \hline
       2 & $\langle (_c)ab(ce) \rangle$ \\ \hline
       3 & $\langle (acf)acd \rangle$ \\ \hline
       4 & $\langle  \rangle$ \\ \hline
       5 & $\langle (_d)df(ab) \rangle$\\ \hline
       6 & $\langle (cd)f(abd) \rangle$ \\ \hline
    \end{tabular}
    \caption{Projection for $\langle acb \rangle$}
    \label{tab:acb}
\end{table}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|} \hline
       SID  & Sequence  \\ \hline
       1 & $\langle _ \rangle$\\ \hline
       2 & $\langle _b(ce) \rangle$ \\ \hline
       3 & $\langle (_cf)acd \rangle$ \\ \hline
       4 & $\langle  \rangle$ \\ \hline
       5 & $\langle (_b) \rangle$\\ \hline
       6 & $\langle (_bd)  \rangle$ \\ \hline
    \end{tabular}
    \caption{Projection for $\langle acba\rangle$}
    \label{tab:acba}
\end{table}
\subsubsection{Sequential Patterns}
Sequential patterns where support = 3 and length $\ge 3$
aca, abc, acd, dea, eab, bca, abd, afa, bce, add
\subsection{Graph mining}
\subsubsection{Support}
P1 support is $\frac{4}{5}$ and is supported by G2, G3, G4, and G5. \\
P2 support is $\frac{3}{5}$ and is supported by G1, G2, and G5. \\
P3 support is $\frac{3}{5}$ and is supported by G1, G3 and G5.
\subsubsection{Apriori-based}
see figure \ref{fig:graph-apri}
\begin{figure}[]
\centering
\includegraphics[width=8cm]{Assignments/Assignment1/graphapri.png}
\caption{Graph sequence apriori mining}
\label{fig:graph-apri}
\end{figure}
\section{Problem 5: SVM, RBF Kernel}
\subsection{Prove all eigenvalues are non negative}
We know from other work that every semidefinite matrix only has non negative eigenvalues.
For a matrix to be semi-definite $x^TAx \ge 0$ for all $x \in \mathbf{R}^N $ . Since we know that $\text{k}(\bold{x}, \bold{x}') = \bold{x}^\top \bold{x}'$ to ensure semi-definite we ensure A > 0. Since A is the transform its always > 0.
\subsection{Prove RBF Kernel is the sum of infinite polynomial kernels}
A kernel is any function in the form $K(x, y) = \langle \psi(x), \psi(y)\rangle$ where $\psi$ projects $x$ into a new vector space. \\
We are trying to prove that $\psi_{RBF}: \mathbf{R}^N \rightarrow \mathbf{R}^\infty$. \\
WLOG we set $\gamma = 1$
\begin{equation}
\begin{split}
K_{RBF}(x, y)  &= exp [-1 \abs{x -y}^2] \\
& = exp [-1 \langle x -y, x-y \rangle] \\
& = exp [-1 (\langle x, x -y \rangle - \langle y, x-y \rangle)] \\
& = exp [-1 (\langle x, x \rangle - \langle x,y \rangle -\langle y, x \rangle + \langle y,y \rangle)] \\
& = exp [-1 (\abs{x}^2 + \abs{y}^2 - 2 \langle x, y \rangle)] \\
& = exp[-1\abs{x}^2-1\abs{y}^2 ]exp[-1 -2 \langle x, y \rangle] \\ \\
c :&= exp[-1\abs{x}^2-1\abs{y}^2 ] \\ \\
K_{RBF}(x, y) &= c*e^{\lange x, y \rangle} \\
&= c \sum_{n=0}^{\infty} \frac{(\langle x, y \rangle)^n}{n!}  \text{via taylor expansion of $e^x$}  \\
&= c \sum_{n=0}^{\infty} \frac{K_{poly(n)}(x,y)}{n!} \\
\end{split}
\end{equation}
Thus we see that RBF is an infinite sum over poly kernels.
\subsection{Decision Boundary}
If we were to use a large $\gamma$ we would likely be able to separate the training data nearly perfectly. We would be over fitting to training but could likely produce results seen in figure \ref{fig:bound}
\begin{figure}[]
\centering
\includegraphics[width=8cm]{Assignments/Assignment1/decisionbound.png}
\caption{Decision Boundary using high $\gamma$}
\label{fig:bound}
\end{figure}
\subsection{Effect of large $\gamma$}
If we are to make the $\gamma$ infinitely large we will completely fit the SVM to the training data and overfit the model. Our training accuracy may reach 100\% but our transfer accuracy will suffer. This is because larger RBF kernel bandwidths(which are smaller $\gamma$ values produce a smoother feature space mapping. As we scale our $\gamma$ value we produce a less smooth kernel which will allow us to learn harder decision boundaries but will overfit to the decision boundary of the training corpus.
\section{Problem 6:Feature Selection}
\subsection{Classification Results}
On the test portion accuracy:0.68, precision:0.76, recall:0.38, F1 score:0.51. More detailed breakdown can be found in table \ref{tab:Accuracy}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|c|} \hline
       Reference Label  & Predicted 0 & Predict 1   \\ \hline
       0 & 60 & 6 \\ \hline
       1 & 31 & 19 \\ \hline
    \end{tabular}
    \caption{SVM}
    \label{tab:Accuracy}
\end{table}
\subsection{Fisher Score Feature Selection}
Using Fisher Score calculation and a threshold of $\ge$ 1 we find that only columns [8, 11, 18, 26] pass the threshold. We then remove all the other indexes and retrain our svm. Performance on train goes from 0.81 to 0.94 and performance on test goes from 0.68 to 0.84!  On the test portion accuracy:0.84, precision:0.88, recall:0.72, F1 score:0.79 . More detailed breakdown can be found in table \ref{tab:Accuracy2}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|c|} \hline
       Reference Label  & Predicted 0 & Predict 1   \\ \hline
       0 & 61 & 5 \\ \hline
       1 & 36 & 14 \\ \hline
    \end{tabular}
    \caption{Fisher Score Augmented SVM}
    \label{tab:Accuracy2}
\end{table}
\section{Problem 7:Self Training}
Using self training we first train an svm based on the regular training corpus(non fisher score adjusted). Then, we label the unlabeled corpus and only keep data where confidence is $\ge$ 0.6. By that we mean there is over a 0.6 difference between the confidence scores and we set the winning label to the self-trained label. Using this threshold of training we include 322 inferred label samples in our training data. \\
Using this amplified training data we find performance improvements on non Fisher-score optimized models and fisher score optimized models. Without using fisher-score optimization the introduction of self-trained data improves F1 score from 0.51 to 0.55, recall goes from 0.38 to 0.42, precision goes from 0.76 to 0.78. More details available on self training model performance are available in table \ref{tab:Accuracy3}. Using fisher score optimization the amplified training data improves F1 from 0.79 to 0.80, recall goes from 0.72 to 0.74, precision goes from 0.88 to 0.86. More details about fisher+self training model performance are available in table \ref{tab:Accuracy4}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|c|} \hline
       Reference Label  & Predicted 0 & Predict 1   \\ \hline
       0 & 60 & 6 \\ \hline
       1 & 29 & 21 \\ \hline
    \end{tabular}
    \caption{Self-Training Augmented SVM}
    \label{tab:Accuracy3}
\end{table}
\begin{table}[]
    \centering
    \begin{tabular}{|c|c|c|} \hline
       Reference Label  & Predicted 0 & Predict 1   \\ \hline
       0 & 60 & 6 \\ \hline
       1 & 13 & 37 \\ \hline
    \end{tabular}
    \caption{Fisher Score and Self Training Augmented SVM}
    \label{tab:Accuracy4}
\end{table}
\section{Random Walk with Restart}
\subsection{Capture multiple weighted relationships}
Starting with the formula $r c*A*r +(1-c)*e$ from the textbook(chapter 8 page 449) we can see that the RWR leverages information in the adjacency matrix but since the $e$ term is kept constant this modifier allows consistent steering of $r$. In doing so we can ensure that we keep tweaking $r$ to have the initial value for the query seed which allows for multiple path explorations.
\subsection{RWR implemented}
Top 10 nodes sorted by importance starting with a seed node of 42: 160, 121, 82, 107, 62, 434, 249, 183, 86, 166
\end{document}


\documentclass[9pt, a4paper, oneside, reqno]{amsart}

\usepackage[final]{pdfpages}
\usepackage{wrapfig}

\usepackage{enumitem}
\usepackage{parskip}
\usepackage{fancyhdr}
\usepackage{color}
\usepackage{multicol}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\newcommand{\hint}[1]{\footnote{\raggedleft\rotatebox{180}{Hint: #1\hfill}}}

\pagestyle{fancy}

\newlist{questions}{enumerate}{1}
\setlist[questions, 1]{label = \bf Q.\arabic*., itemsep=1em}

\lhead{\scshape Apurva Nakade}
\rhead{\scshape Honors Single Variable Calculus}
\renewcommand*{\thepage}{\small\arabic{page}}
\title{Problem Set 10}

\begin{document}

\maketitle
\thispagestyle{fancy}

\section*{Part 1 - Taylor series}
\begin{questions}
	\item For the polynomial $ p(x) = x^3$ compute the Taylor polynomial at $x=1$ of degree 3. Simplify the Taylor polynomial and verify that it equals the original polynomial.

	\item Compute the Taylor polynomial of the following functions:
	\begin{multicols}{2}
		\begin{enumerate}
			\item $ e^{\sin x}$ at $ x=0$, degree 3
			\item $ \dfrac{1}{x+1}$ at $ x=0$, degree $ n$
		\end{enumerate}
	\end{multicols}

	\item In this exercise we'll compute the \textbf{remainder term} of the Taylor polynomial. Assume that the function $ f$ is differentiable enough number of times. Consider the Taylor polynomial of the $ f(x)$ at $ x=0$ of degree $ n$.
	\begin{align*}
		P_{n}(x) = a_0 + a_1 x + a_2 x^2 + \cdots + a_n x^n &   & a_i = \dfrac{f^{(i)}(0)}{i!}
	\end{align*}
	\begin{quote}
		\textbf{Theorem.} The remainder term $ R_{n}(x) = f(x) - P_{n}(x)$ equals
		\begin{align*}
			R_{n}(x)  = \int \limits_0^x \dfrac{f^{(n+1)}(t)}{n!} \cdot (x-t)^n \: dt
		\end{align*}
	\end{quote}
	\begin{enumerate}
		\item Prove the theorem directly for $ n = 0$. (Note: $ 0! = 1$.)
		\item Find the Taylor polynomial of $ f'(x)$ at $ x=a$ of degree $ n-1$.
		\item Assume the following Leibniz's identity:
		      \begin{align*}
		      	\mbox{ If } g(x) = \int \limits_0^x f(x,t) \: dt \mbox{ then } g'(x) = f(x,x) + \int \limits_0^x \dfrac{\partial f(x,t)}{\partial x} \: dt
		      \end{align*}
		      (This very useful trick is called \emph{differentiating under the integral sign}, unfortunately we do not have enough language to prove this.)

		      Use part (2) and induction on the degree $ n$ to prove the Theorem.
	\end{enumerate}

	\item This is a very difficult problem to write down rigorously, for this one it's ok to be vague in your arguments. In this problem $ n,k$ are positive integers and all the Taylor series are at $ x=0$. \hint{It is very crucial here that you're only asked to find the derivatives at $ x=0$.}
	\begin{enumerate}
		\item If $ f(x) = x^ng(x)$. Find the Taylor series of $ f(x)$ in terms of Taylor series of $g(x)$ (Don't think too hard). Hence find $ f^{(k)}(0)$ in terms of the derivatives of $ g$.
		\item If $ f(x) = g(x^2)$ find $ f^{(k)}(0)$ in terms of the derivatives of $ g$. Hence find the Taylor series for $ f$ in terms of $ g$.
		\item Find the Taylor series for $ e^{(x^2)}$.
		\item If $ f(x) = g(x^n)$, find $ f^{(k)}(0)$ in terms of the derivatives of $ g$. Hence find the Taylor series of $ f$ in terms of $ g$.
		\item Find the Taylor series for $ \sin (x^4)$.
	\end{enumerate}

\end{questions}

\section*{Part 2 - Numerical Computations}
For this week's HW you're allowed (and required) to use wolframalpha (or calculator) to do the computations/simplify large fractions.

A table of Taylor series can be found on Pg. 426 in the book.
\begin{questions}[resume]
	\item
	\begin{enumerate}
		\item Suppose the coefficients of Taylor series of $ f$ are $ c_i$ and of $ g$ are $ d_i$ at $ x=a$. Find the Taylor series of $ fg$ at $ x=a$ in terms of $ c_i, d_i$.
		\item Find the general formula for the $ n^{th}$ derivative of the product ${ (fg)^{(n)}}(a) $ in terms of the derivatives of $ f$, $ g$ at $ a$.
	\end{enumerate}

	\item Use estimates on the remainder term of the appropriate Taylor series to compute the following quantities within the prescribed error.
	\begin{multicols}{2}
		\begin{enumerate}
			\item $ \cos 1$, error $ < 10^{-2}$
			\item $ \sin 0.01$, error $ < 10^{-10}$
			\item $ e$, error $ < 10^{-2}$
			\item $ \log 1.1$, error $ < 10^{-4}$
		\end{enumerate}
	\end{multicols}

	\item Show that the remainder terms for the Taylor series of $ \log(1+x)$ and $ \arctan(x)$ at $ x=0$ grows with $ n$ when $ x > 1$. (Hence the standard Taylor series cannot be used to approximate these numbers.)

	\item Taylor series are useful in theory but not so great for numerical approximations in practice.
	\begin{enumerate}
		\item Find the value of $ \pi/4$ correct up to 1 decimal place using Taylor series of $ \arctan(x)$. How many terms of the Taylor series will you need, to determine the value of $ \pi/4$ correct up to 2 decimal places?

		\item Prove the following identities:
		      \begin{align*}
		      	\tan(x+y)               & = \dfrac{\tan x + \tan y}{1 - \tan x \tan y}    \\
		      	\arctan(u) + \arctan(v) & = \arctan \left( \dfrac{u + v}{1 - u v} \right) \\
		      \end{align*}
		\item Show that
		      \begin{align*}
		      	\dfrac{\pi}{4} & = \arctan \dfrac{1}{2} + \arctan \dfrac{1}{3}    \\
		      	\dfrac{\pi}{4} & = 4\arctan \dfrac{1}{5} - \arctan \dfrac{1}{239}
		      \end{align*}
		\item Use the second formula in part (3) to compute $ \pi$ correct up to 4 decimal places.
	\end{enumerate}

\end{questions}

\newpage
\section*{Part 3 - Integral Computations}
\begin{questions}[resume]
	\item For this week do Q.3, and Q.4 problems - i) to v) on Pg. 378-379 from Ch.19. \\\\

\end{questions}

\end{document}


\begin{frame}
\titlepage % Print the title page as the first slide
\end{frame}
\section{Part I: Foundations}
\begin{frame}{Welcome!}
\begin{itemize}
 \item This is a 60-hour, PhD-level course on Bayesian inference.
 \item We have 11 planned weeks. Reading material is posted at~\url{https://github.com/maxbiostat/BayesianStatisticsCourse/}
 \item Assessment will be done via a written exam (70\%) and an assignment ($30\%$);
 \item Tenets:
 \begin{itemize}
  \item Respect the instructor and your classmates;
  \item Read before class;
  \item Engage in the discussion;
  \item Don't be afraid to ask/disagree.
 \end{itemize}
 \item Books are
 \begin{itemize}
  \item  \cite{Robert2007};
  \item \cite{Hoff2009};
  \item \cite{Bernardo2000}.
 \end{itemize}
\end{itemize}
\end{frame}

\begin{frame}{Bayes's Theorem}
What do
\begin{equation}
 \label{eq:BT_1}
 \pr(A \mid B) = \frac{\pr(B \mid A)\pr(A)}{\pr(B)},
\end{equation}
and
\begin{equation}
 \label{eq:BT_2}
 \pr(A_i \mid B) = \frac{\pr(B \mid A)\pr(A)}{\sum_{i=1}^n \pr(B \mid A_i)\pr(A_i)},
\end{equation}
and
\begin{equation}
 \label{eq:BT_3}
  p(\theta \mid \boldsymbol{y}) = \frac{l(\boldsymbol{y} \mid \theta)\pi(\theta)}{\int_{\boldsymbol{\Theta}} l(\boldsymbol{y} \mid t)\pi(t) \, dt},
\end{equation}
and
\begin{equation}
 \label{eq:BT_4}
  p(\theta \mid \boldsymbol{y}) = \frac{l(\boldsymbol{y} \mid \theta)\pi(\theta)}{m(\boldsymbol{y})},
\end{equation}
all have in common?
In this course, we will find out how to use Bayes's rule in order to draw statistical inferences in a coherent and mathematically sound way.
\end{frame}
\begin{frame}{Bayesian Statistics is a complete approach}
Our whole paradigm revolves around the posterior:
$$ p(\theta \mid \boldsymbol{x}) \propto l(\theta \mid \boldsymbol{x})\pi(\theta).$$
Within the Bayesian paradigm, you are able to
\begin{itemize}
 \item Perform point and interval inference about unknown quantities;
 \begin{align*}
  \delta(\boldsymbol{x}) &= E_p[\theta] := \int_{\boldsymbol{\Theta}} t p(t \mid \boldsymbol{x} )\,dt,\\
\pr( a \leq \theta \leq b) &= 0.95 = \int_{a}^{b} p(t \mid \boldsymbol{x} )\,dt;
 \end{align*}
\item Compare models:
$$\operatorname{BF}_{12} = \frac{\pr(M_1 \mid \boldsymbol{x})}{\pr(M_2 \mid \boldsymbol{x})} = \frac{\pr(\boldsymbol{x} \mid M_1)\pr(M_1)}{\pr(\boldsymbol{x} \mid M_2)\pr(M_2)};$$
 \item Make predictions: $g(\tilde{x} \mid \boldsymbol{x}) := \int_{\boldsymbol{\Theta}} f(\tilde{x} \mid t)p(t\mid \boldsymbol{x})\,dt$;
 \item Make decisions: $E_p[U(r)]$.
\end{itemize}
\end{frame}
\begin{frame}{Statistical model: informal definition}
Stuff you say at the bar:
\begin{defn}[Statistical model: informal]
\label{def:statistical_model_informal}
DeGroot, def 7.1.1, pp. 377
A statistical model consists in identifying the random variables of interest (observable and potentially observable), the specification of the joint distribution of these variables and the identification of parameters ($\theta$) that index this joint distribution.
Sometimes it is also convenient to assum that the parameters are themselves random variables, but then one needs to specify a joint distribution for $\theta$ also.
\end{defn}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Statistical model: formal definition}
Stuff you say in a Lecture:
\begin{defn}[Statistical model: formal]
\label{def:statistical_model_formal}
\href{https://projecteuclid.org/download/pdf_1/euclid.aos/1035844977}{McCullagh, 2002}.
Let $\mathcal{X}$ be an arbitrary sample space, $\Theta$ a non-empty set and $\mathcal{P}(\mathcal{X})$ the set of all probability distributions on $\mathcal{X}$, i.e. $P : \Theta \to [0, \infty)$, $P \in \mathcal{P}$.
 A \underline{parametric} statistical model is a function $P : \Theta \to \mathcal{P}(\mathcal{X})$, that associates each point $\theta \in \Theta$ to a probability distribution $P_\theta$ over $\mathcal{X}$.
\end{defn}
\textbf{Examples}:
\begin{itemize}
 \item Put $\mathcal{X} = \mathbb{R}$ and $\Theta = (-\infty, \infty)\times (0, \infty)$.
 We say $P$ is a \textit{normal} (or \textit{Gaussian}) statistical model\footnote{Note the abuse of notation: striclty speaking, $P_\theta$  is a probability~\textbf{measure} and not a ~\textit{density} as we have presented it here.} if for every $\theta = \{\mu, \sigma^2\} \in \Theta$,
 $$P_{\theta}(x) \equiv \frac{1}{\sqrt{2\pi}\sigma}\exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right), \: x \in \mathbb{R}.$$
 \item Put $\mathcal{X} = \mathbb{N}\cup \{0\}$ and $\Theta = (0, \infty)$.
 $P$ is a Poisson statistical model if, for $\lambda \in \Theta$,
 $$P_{\lambda}(k) \equiv \frac{e^{-\lambda}\lambda^k}{k!}, \: k = 0, 1, \ldots$$
\end{itemize}
\end{frame}
% \begin{frame}
% Theorem
% $$ \int_{\mathcal{X}} f_X(t)\,dt$$
%  \begin{theo}[b]
%  a
% \end{theo}
% \end{frame}
% \begin{frame}{Overview}
% \tableofcontents
% \end{frame}


\documentclass[12pt]{amsart}
\usepackage{geometry} % see geometry.pdf on how to lay out the page. There's lots.
\geometry{a4paper} % or letter or a5paper or ... etc
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{amsmath}
\usepackage{amsaddr}
\usepackage{hyperref}
\usepackage{dirtytalk}
\usepackage{float}
\usepackage{listings}
\usepackage{hyperref}
\usepackage{enumerate}

\usepackage{color}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{stringcolor}{rgb}{0.7,0.23,0.36}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\definecolor{keycolor}{rgb}{0.007,0.01,1.0}
\definecolor{itemcolor}{rgb}{0.01,0.0,0.49}

\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=blue,
    urlcolor=blue,
}

\lstdefinestyle{mystyle}{
    %backgroundcolor=\color{backcolour},
    commentstyle=\color{codegreen},
    keywordstyle=\color{keycolor},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{stringcolor},
    basicstyle=\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    numbers=left,
    numbersep=5pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2
}

\lstset{style=mystyle}

\lstdefinelanguage{Swift}{
  keywords={associatedtype, class, deinit, enum, extension, func, import, init, inout, internal, let, operator, private, protocol, public, static, struct, subscript, typealias, var, break, case, continue, default, defer, do, else, fallthrough, for, guard, if, in, repeat, return, switch, where, while, as, catch, dynamicType, false, is, nil, rethrows, super, self, Self, throw, throws, true, try, associativity, convenience, dynamic, didSet, final, get, infix, indirect, lazy, left, mutating, none, nonmutating, optional, override, postfix, precedence, prefix, Protocol, required, right, set, Type, unowned, weak, willSet},
  ndkeywords={class, export, boolean, throw, implements, import, this},
  sensitive=false,
  comment=[l]{//},
  morecomment=[s]{/*}{*/},
  morestring=[b]',
  morestring=[b]"
}

\lstset{emph={Int,count,abs,repeating,Array}, emphstyle=\color{itemcolor}}

\title{Algorithmic Problem Solving}

\date{\today}

\lstset{style=mystyle}

%%% BEGIN DOCUMENT
\begin{document}
\maketitle
\section{Algorithmic Problem Solving Fundamentals}
There are three components to using Algorithms to solve a problem you face. You must choose/create an algorithm, ensure the algorithm produces the desired output, and analyze the algorithm for feasibility.
\subsection{Picking an Existing Algorithm}

  Questions to answer when considering appropriate, existing algorithms;
\begin{itemize}
	\item Which algorithm takes the least amount of time?
  	\item Which one takes the least amount of memory?
  	\item Which is the easiest to program?
\end{itemize}
  Always choose an algorithm that best suits the circumstances.
\subsection{Creating Your Own Algorithm}
The process of creating and evaluating your own algorithm expressed algorithmically is:
\begin{enumerate}
	\item Understand the Problem.
	\item Decide on:
	\begin{itemize}
       		\item computational means,
       		\item exact vs. approximate solving,
       		\item data structure(s),
       		\item algorithm design technique
	\end{itemize}
	\item Design an Algorithm
	\item Check Correctness
       		\begin{itemize}
			\item If not correct go to step 2 or 3
		\end{itemize}
	\item Analyze the Algorithm
       		\begin{itemize}
			\item If not good enough go to step 2 or 3
		\end{itemize}

	\item Code the Algorithm
\end{enumerate}

\subsection{Algorithm Correctness}

   Once an algorithm has been specified, you have to prove its correctness.

   To accomplish this, you must prove that the algorithm yields the required result for
   \textit{every} legitimate input in a finite amount of time. Tracing the algorithm's operation for a few specific inputs does not prove its correctness.

   With some algorithms proving correctness is simple. For others it is complicated. As an example of a non-complicated proof take a look at the end of this document for two proofs of Euclid's gcd algorithm.

   A common method for proving correctness is mathematical induction.

   \subsection{Algorithm Analysis}
No perfect algorithm exists. To be able to choose between algorithms that achieve the same end you must balance these data points:
\begin{itemize}
\item Time efficiency --- how fast each algorithm runs.
\item Space efficiency --- how much memory each algorithm needs.
\item Simplicity
\begin{itemize}
  \item like Beauty, often in the eye of the beholder.
  \item Which is simplest of the three $gcd$ algorithms?
\end{itemize}
\item Generality
\begin{itemize}
  \item of the problem each algorithm solves
  \item of the range of inputs each algorithm accepts
\end{itemize}
\end{itemize}
\section{Common Types of Problems Amenable to Algorithmic Problem Sovling}

\subsection{Sorting}
\begin{itemize}
	\item With all the courses I need/should take, which one should I take next?
\end{itemize}
\subsection{Searching}
\begin{itemize}
	\item Where did I leave my wallet???
\end{itemize}
\subsection{String Processing}
\begin{itemize}
	\item Auto-correcting spelling and grammar along with word suggestion are done with string processing algorithms.
\end{itemize}
\subsection{Graph Problems} This is the oldest area of application of algorithms since graphs can be used to model many kinds of everyday problems.
\begin{itemize}
	\item What is an efficient way to get from the STC to the Snow building? \{transportation and communications networks problems\}
	\item In what order should I work on my homework to get done the soonest? \{project and production scheduling\}
    	\item How do I get my character from point A to point B without dying? \{game problems\}
	\item What is the maximum number of links required to reach a web server from a mobile device by the most direct route between them.\{maxima, minima network/routing problems\}
\end{itemize}
\subsubsection{Easy Graph Problems}
\begin{itemize}
	\item Shortest Path
	\item Minimum Spanning Trees
\end{itemize}
\subsubsection{Hard Graph Problems}
\begin{itemize}
	\item Traveling Salesperson
	\item Map-Coloring
\end{itemize}
\subsection{Problems that ask to find a combinatorial object} These are the most intransigent problems in computing. The size of the solution grows extremely fast when the initial data set size only grows moderately. Also, there are no known algorithms for most of these types of problems that can be to compute a solution in a reasonable amount of time (before the sun dies). Worst of all, most computer scientists believe they are unknown because they  can not exist.
\begin{itemize}
	\item permutation
    	\item combination (subset)
    	\item power set (set of all subsets)
\end{itemize}
\subsection{Geometric Problems}
\begin{itemize}
	\item Which major city is closest to Rexburg? \{closest pair of points out of a set of points problem\}
	\item How can I draw a 3-D map of Idaho? \{polygon finding problem\}
\end{itemize}

\subsection{Numerical Problems}

These problems involve mathematical objects of a \textit{continuous} nature such as :
\begin{itemize}
     	\item If a train leaves Chicago at 3:00 PM heading east\ldots \{solving equations\}
     	\item Finding the optimal path of a product through a factory ignoring physical constraints. \{solving systems of equations\}
     	\item If the economy grows at a rate expressed by what appears to be a non-describable sinusoidal function $f(t)$ for the next 10 years, how much bigger will it be then compared to today? \{computing definite integrals\}
     	\item How efficient is my code? \{evaluating functions\}
\end{itemize}

 \section{How can the correctness of Euclid's GCD algorithm be proven?}
  \textit{GCD Definition}. Given two positive integers $m$ and $n$,
  find their greatest common divisor, i.e., the largest positive integer which
  evenly divides both $m$ and $n$.

\subsection{The Na\"ive Way}

The central claim of Euclid's algorithm is $gcd(m, n) = gcd(n, m\pmod n)$.

  Recall the definition of \textit{division}: an integer $a$ (not zero) \textit{divides} an
  integer $b$ (or equivalently, $b$ is \textit{divisible} by $a$, or $a$ is a \textit{divisor}
  of $b$. All signified by $a|b$) if there is an integer $x$ such that $b = ax.$

  Here's a Lemma (a \textit{helper} to the main proof):\\

  For any pair of positive integers $m$ and $n$, if $d$ divides both $m$ and $n$  then $d$ also divides both $n$ and $r$, where $r = m\pmod n.$

\textbf{Proof of Lemma}

  Another way to write $r$ is $m - qn$ where $q$ is the \textit{quotient} ($q
  = \lfloor m / n \rfloor$). Now ask:

  1. Does $d$ divide $m$? (Yes, it's assumed in the premise of the lemma.)
  2. Does $d$ divide $qn$? (Must prove that since $d$ divides $n$ (also assumed)
     that $d$ divides a multiple of $n$.)
  3. Does $d$ divide $m - qn$? (If it divides both /m/ and /qn/, that is?)

  To prove the Lemma you must prove the answer to 2 and 3 is yes.

  Show that $d$ divides $qn$ given $d$ divides $n$ as follows:
\begin{align}
  n &= dx  \text{(Definition of division)}\\
  qn  &=  q(dx) \text{(Multiply both sides by /q/)}\\
  qn &= d(qx) \text{(Associative law of multiplication)}
  \end{align}

  Show that if $d$ divides $u$, and $d$ divides $v$, then $d$ also divides their
  difference $u - v$ as follows:
\begin{align}
  u &= ds \text{(Definition of division)}\\
  v &= dt \text{(Definition of division)}\\
  u - v &= ds - dt \text{(Equals subtracted from equals are equal)}\\
  u - v &= d(s - t)/ \text{(Distributive law of multiplication)}\\
\end{align}
  Therefore $d$ divides $u - v$ by definition of division (since $s - t$ is an integer).

  Statements 2 and 3 have both been proved, therefore the Lemma is proved.

\textbf{Proof of Euclid's GCD}
  Since $d$ was arbitrarily chosen (it could be any divisor), the above
  shows that $m$, $n$ and $n$, $m\pmod n$ have the same (non-empty)
  set of common divisors, which necessarily includes the largest
  element in the set, which is the GCD.

  QED

  \subsection{The Non-na\"ive Way}

  E1. [Find remainder.] Divide $m$ by $n$ and let $r$ be the remainder. (We will
  have $0 \le r < n$.)

  E2. [Is it zero?] If $r = 0$, the algorithm terminates; $n$ is the answer.

  E3. [Interchange] Set $m\leftarrow n, n \leftarrow r$, and go back to
  step E1.

  After step E1, we have $m = qn + r$ for some integer $q$. If $r = 0$, then
  $m$ is a multiple of $n$, and clearly in such a case $n$ is the greatest
  common divisor of $m$ and $n$. If $r \ne 0$, note that any number which
  divides both $m$ and $n$ must divide $m - qn = r$, and any number which
  divides both $n$ and $r$ must divide $qn + r = m$; so the set of divisors
  of $m, n$ is the same as the set of divisors of $n, r$ and, in particular, the
  \textit{greatest} common divisor of $m, n$ is the same as the greatest common divisor
  of $n, r$. Therefore step E3 does not change the answer to the original
  problem.

  QED

\end{document}


\documentclass[revision-guide.tex]{subfiles}
%% Current Author: LT
\setcounter{chapter}{12}
\begin{document}
\chapter{Gravitation}
\spec{state Kepler's laws of planetary motion}
Before you learn Kepler's laws (which you MUST learn) you should spend
some time looking through the chapter on rotational mechanics and making
absolutely sure that you know how to apply Newton's laws of motion to an
orbiting body. This is vital or you won't get the maths in this chapter.

The specification dictates that you need to be able to state Kepler's
Laws. They are as follows:
\begin{enumerate}
\item
  Planets move in elliptical orbits with the Sun at one focus.
  \emph{(motion in ellipses is not part of the specification, so don't
  worry about the mathematics of this -- we approximate to a circle for
  pre-U)}
\item
  The Sun-planet line sweeps out equal areas in equal times.
\item
  The orbital period squared of a planet is proportional to its mean
  distance from the Sun cubed.
\end{enumerate}
\newpage
\subsection{First Law}
\begin{figure}[h]
  \begin{center}
  \includegraphics[width=0.8\textwidth]{figs/chapt-13/kepler-1.png}
\end{center}
  \caption{Kepler's First Law}
  \label{kepler-1}
\end{figure}

Of course, it looks nothing like this -- this is MASSIVELY exaggerated
for the sake of seeing what is going on. The Earth's orbit around the
Sun is very nearly circular, which is why it took so long for
astronomers to realize that it wasn't.

\subsection{Second Law}

\begin{figure}[h]
  \begin{center}
    \includegraphics[width=0.8\textwidth]{figs/chapt-13/kepler-2.png}
  \end{center}
  \caption{Kepler's Second Law}
  \label{kepler-2}
\end{figure}

Figure \ref{kepler-2} shows the areas swept out in the same amount of time at different parts of the orbit. As you can see from the diagram, areas x and y are the same. The reason
for this, put simply, is that the objects move more quickly when they
are closer to the Sun and more slowly when they are further away.

\subsection{Third Law}

This will be described in more detail below.

\spec{recognise and use $F=-\frac{Gm_1m_2}{r^2}$}

``The gravitational force between two objects is proportional to the
product of their masses and inversely proportional to the square of the
distance between their centres.''

That is a lot of words and it is much more easily explained with an
equation:

\[F = - \frac{Gm_{1}m_{2}}{r^{2}}\]

Where: F is the force, measured in newtons (N)

G is the universal gravitational constant, which has a value of
6.67x10\textsuperscript{-11} Nm\textsuperscript{2}kg\textsuperscript{-2}

m\textsubscript{1} and m\textsubscript{2} are the two masses measured in
kilograms (kg)

r is the distance between their centres, measured in metres (m).

\begin{figure}[h]
  \begin{center}
    \includegraphics{figs/chapt-13/masses.png}
  \end{center}
  \label{masses}
  \caption{Two masses}
\end{figure}

Important things to note:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  The force is negative. This is because it is always attractive and
  attractive forces are always negative, by definition.
\item
  The force exerted by mass 1 on mass 2 is the same magnitude but
  opposite in direction to the force exerted by mass 2 on mass 1. This
  is a direct consequence of Newton's third law. In most cases that we
  study the \textbf{effect} of the force on the smaller mass is much
  greater than it is on the larger mass and we ignore the effects of the
  force on the larger mass.
\end{enumerate}

\spec{use Newton’s law of gravity and centripetal force to derive $ r^3 \propto T^2 $for a circular orbit}

Now that we know the size of the force acting on a body moving in
circular motion due to the gravitational force acting on it, we can
prove Kepler's third law:

For a body orbiting another body, the centripetal force is provided by
the gravitational force.

\[F = - \frac{Gm_{1}m_{2}}{r^{2}}\ \ (1)\]

As the body is moving in circular motion, the gravitational force causes
the body to accelerate towards the centre of the circle, as in the
diagram:

\begin{figure}[h]
  \begin{center}
    \begin{tikzpicture}
        \draw[thick] (0,0) circle (2cm) node[anchor=south] {$m2$};
        \draw[dashed] (0,0) -- (0,-4.5);
        \draw[thick] (7,0) circle (0.6cm) node[anchor=south] {$m1$};
        \draw[dashed] (7,0) -- (7,-4.5);
        \draw[->, thick] (0,-4) -- (7,-4) node [midway,below] {$r$};
        \draw[very thick, red, ->] (7,0) -- (4,0) node[anchor=east] {$F$};
    \end{tikzpicture}
    %\includegraphics{figs/chapt-13/masses-direction.png}
  \end{center}
  \label{masses-2}
  \caption{Two masses and a force}
\end{figure}

Thus we apply F=ma, with F being the gravitational force, as on the
diagram, and the acceleration being equal to $r\omega^2$.

\[F = ma\]

So \[G\frac{m_{1}m_{2}}{r^{2}} = m_{1}r\omega^{2}\]

m\textsubscript{1} is the object that is orbiting, so it is the mass of
m\textsubscript{1} that is feeling the acceleration and thus
m\textsubscript{1} goes into the right hand side of the equation.

Thus we can cancel m\textsubscript{1} and collect the terms in r to
give:

\[Gm_{2} = r^{3}\omega^{2}\ \ (2)\]

But we know from our revision of circular motion that the period of the
orbit is related to the angular velocity by:

\[\omega = \frac{2\pi}{T}\ \ (3)\]

Therefore we substitute equation (3) into equation (2) to give:

\[Gm_{2} = \frac{{4\pi^{2}r}^{3}}{T^{2}}\]

Now re-arrange to make r the subject of the formula:

\[r^{3} = \frac{Gm_{2}}{{4\pi}^{2}}T^{2}\ \ (4)\]

G, m\textsubscript{2} and $\pi$ are all constants, so we can finally write:

\[r^{3} \propto T^{2}\]

You need to be able to do this for your examination, so make sure that
you learn this proof.

\spec{understand energy transfer by analysis of the area under a gravitational force-distance graph}

If you apply a force through a distance, you do work on it. This is a definition.

At GCSE, you learnt that it was given by the equation:

Work done = Force x distance

Later you learned that in fact it was the area under the Force-distance
graph.

\emph{(Of course, it's a little bit more difficult than that. It is
actually given by:}

\[Work\ done = \int_{r}^{\infty}{F{dx\ \ \ \ (8)}}\]

\emph{You use this integral in other parts of the specification, but not
this part.)}

Therefore if we want to know the gravitational potential energy gained
or lost by an object in a gravitational field, we look at the area under
the force-distance graph.

The zero of gravitational potential energy is taken as being at
infinity, which makes sense. If the object isn't in a field, then it
isn't experiencing any force, so it doesn't have any GPE.

This does mean, however, that all gravitational potential energies are
negative as they lose GPE as they fall towards a mass.

For example, if you want to know the GPE gained/lost by an object as it
moves from point $R_1$ to point $R_2$ in the field you look at the area under
the force-distance graph (see figure \ref{gpe-area})

\begin{figure}
  \begin{center}
  \includegraphics[width=0.8\textwidth]{figs/chapt-13/area-energy.png}
\end{center}
  \caption{Graviational PE as area of a graph}
  \label{gpe-area}
\end{figure}

\emph{(Generally, we tend to look at the gravitational potential rather
than the GPE, and use the field strength-distance graph, but the
specification asks for GPE and a force-distance graph, so that is what
we are looking at!)}

\spec{derive and use $g = -\frac{Gm}{r^2}$for the magnitude of the gravitational field strength due to a point mass}

If you look back to chapter 2 on gravitational fields, you will know the
definition of the gravitational field strength. It is given by the
equation:

\[g = \frac{F}{m}\ \ (5)\]

But we now know how the force is provided by a spherical mass from
Newton's Law of Gravitation. It is given by equation (1) as:

\[F = \frac{Gm_{1}m_{2}}{r^{2}}\ \ (6)\]

So we can substitute equation (6) into equation (5) to give us:

\[g = \frac{\text{Gm}}{r^{2}}\ \ (7)\]

This is the gravitational field strength due to a spherical mass m at a
distance r from its centre and you need to be able to derive this
equation.

A graph of the field strength due to a spherical body against distance
looks like this:

\begin{figure}[h]
  \begin{center}
  \includegraphics[width=0.8\textwidth]{figs/chapt-13/g-r.png}
\end{center}
  \caption{Field strength due to a sphere}
  \label{}
\end{figure}

From the centre of the object up to its radius (0 to R) the variation
with field strength inside the body varies linearly \textbf{if the
density is constant.} R is the radius of the body, so therefore the
distance from the centre. After R it drops off as
1/r\textsuperscript{2}.

\spec{recall similarities and differences between electric and gravitational fields}

\begin{figure}[h]
  \includegraphics[width=\textwidth]{figs/chapt-13/table.png}
  \caption{Similarities and Differences}
  \label{tab:sim}
\end{figure}

\spec{recognise and use the equation for gravitational potential energy for point masses $ E = - \frac{Gm_1m_2}{r}$}

There is an equation for the GPE which you need to be able to use. It is
found from integrating the expression for the force as mentioned
earlier, and it is given by:

\[E = - \frac{Gm_{1}m_{2}}{r}\ \ \ \ (9)\]

\spec{calculate escape velocity using the ideas of gravitational potential energy, or area under a force-distance graph and energy transfer}

We can now use these methods of working out the GPE gained by an object
in a gravitational field to calculate a quantity called the
\textbf{escape velocity.}

NB. A lot of people get escape velocity wrong. It is the velocity needed
to be given to an object \textbf{on the surface of the planet} in order
for it to escape the gravitational field of the planet and have zero KE
at that time. Once it has been given this velocity (by, for example, a
cannon) \textbf{no more energy is put into the system}. From that moment
on it is a projectile and is constantly losing KE as it gains GPE.

Of course, this means that when it finally escapes the gravitational
field it has no energy at all, which also means that it has zero overall
energy to start with as well!

Therefore we use the law of conservation of energy to work out what the
escape velocity must be:

Total energy before = Total energy after = 0

Therefore Initial KE + Initial GPE = 0

\[\frac{1}{2}mv_{e}^{2} - \frac{\text{GMm}}{R} = 0\ \ \ \ \left( 10 \right)\]

Where M is the mass of the planet in kg

R is the radius of the planet in m

m is the mass of the projectile in kg

v\textsubscript{e} is the escape velocity in ms\textsuperscript{-1}

You can cancel the mass of the projectile and re-arrange for
v\textsubscript{e} from equation (10) to give:

\[v_{e} = \sqrt{\frac{2GM}{R}}\ \ \ \ \ (11)\ \ \]

This is the escape velocity and you can work it out for the Earth. You
should get about 12 kms\textsuperscript{-1}.

There is a graphical way of looking at this as well. The GPE gained by
the body as it moves from the surface of the planet, radius R, is given
by the area under the force-distance graph from the surface of the
planet to infinity (i.e. as in Figure \ref{gpe-area}, but with $R_2$ at infinity). If it is launched from the surface of the planet
then that also equals its initial KE.

\spec{calculate the distance from the centre of the Earth and the height above its surface required for a geostationary orbit.}

A geostationary orbit is one which stays above the same position on the
Earth's equator at all times.

This means, therefore, that it has a period of 24 hours.

It is therefore possible to calculate, using equation (4), r for a
geostationary orbit.

N.B. A very common mistake is to say that r is the height of the orbit.
This isn't the case -- it is the radius of the orbit, so it is the
distance of the satellite from the \textbf{centre} of the Earth, not the
surface of the Earth.

You should make sure that you can do this. Have a go at working out r,
given the following data:

G = 6.67 x 10\textsuperscript{-11}
Nm\textsuperscript{2}kg\textsuperscript{-2}

M\textsubscript{E} = 5.98 x 10\textsuperscript{24} kg

and remembering that T = 24 hours (but don't forget to convert to
seconds!)

You should have got an answer of 4.23 x 10\textsuperscript{7} m.

If I now tell you that the radius of the Earth is
6.36 x 10\textsuperscript{6} m, you can also write down the height of the
satellite above the surface of the Earth, and this comes to
3.6 x 10\textsuperscript{6} m.

So a geostationary satellite orbits at a height that is about 6 times
greater than the radius of the Earth.
\end{document}

%sagemathcloud={"latex_command":"latexmk -xelatex -f -g -bibtex -synctex=1 -interaction=nonstopmode '13-gravitation.tex'"}