Our final goal is to define complex computational structures through the use of our inference system. The most complex computational structures known to us are programming languages, and as such we will set the mark there: we intend to define the syntax and semantics of a (small) programming language through a series of inference rules. Before we can dive into that, we need the ability to represent some basic algorithms which will prove of fundamental usefulness to defining a programming language. After all, our programming language will have memory of some sort, and as such we need to represent memory somehow.

The first, and perhaps most basic data structure that we can define is the \textit{list}. A list is used to represent a sequence of values which may contain any number of elements: from no elements (the special \textit{empty list}) to hundreds of thousands of elements.

\subsection{Lists of integers}
For our example, we will limit ourselves to lists of integers. It will be possible to extend this definition thanks to the use of inheritance (a list of \texttt{Expr}) or with generic datatypes (which will be explored in a later section), but for now we shall keep things simple.

A list is defined very much like Peano numbers or binary digits. We have a ``termination symbol'' \texttt{nil}, which defines an empty list of integers:

\begin{lstlisting}
Data [] "nil" [] Priority 0 Type ListInt
\end{lstlisting}

Given a list of integers (commonly known as \textit{tail}), we can add an integer to it (commonly known as \textit{head}) and obtain a new list of integers. Head and tail are separated by a symbol such as:

\begin{lstlisting}
Data [<<int>>] ";" [ListInt] Priority 1000 Type ListInt
\end{lstlisting}

Notice that our language assumes the existance of \textit{predefined data types}, which can be accessed with the special brackets \texttt{<<} and \texttt{>>}.

Thanks to this definition, we can now build a few example lists:

\begin{itemize}
\item \texttt{nil}
\item \texttt{1;nil}
\item \texttt{0;(1;(2;(3;nil)))}
\item ...
\end{itemize}

\subsection{List querying}
We will now define a series of list operations that allow us to process a list and extract various properties from it.

\paragraph{Length of a list}
Among the most fundamental operations that we can perform on lists, we have the determination of the length of a list. We define the \texttt{length} symbol that takes a parameter of type list and returns an integer\footnote{Remember that \texttt{<<} and \texttt{>>} identify built-in types, so \texttt{<<int>>} literally means a machine-integer.} as result (the length of the list):

\begin{lstlisting}
Func "length" [ListInt] Priority 100 Type Expr => <<int>>
\end{lstlisting}

Determining the length of the empty list is simple, as we can immediately answer that it has a length of zero:

\begin{lstlisting}
----------------
length nil => 0
\end{lstlisting}

If the input list is not empty, then we compute the length of its tail (\texttt{xs}) and then return this length plus one as the total length of the whole list:

\begin{lstlisting}
length xs => y
--------------------------
length x;xs => <<1 + y>>
\end{lstlisting}

Consider now execution of program \texttt{length 1;2;3;nil}. We start with the initial proposition, which is clearly no instance of \texttt{length nil}:

\begin{lstlisting}
----------------------
length 1;2;3;nil => ?
\end{lstlisting}

The proposition above instances a recursive premise on the tail of the list:

\begin{lstlisting}
length 2;3;nil => y1
-------------------------------
length 1;2;3;nil => <<1 + y1>>
\end{lstlisting}

Proposition \texttt{length 2;3;nil} is, once again, clearly no instance of \texttt{length nil}, and we proceed for a few steps\footnote{Which, with a smile and some handwaving, allows us to skip a couple of boring paragraphs of the book, which you smart reader feel no need for.} until we get to the following derivation tree:

\begin{lstlisting}
length nil => y3
y2 := <<1 + y3>>
------------------------
length 3;nil => y2
y1 := <<1 + y2>>
------------------------
length 2;3;nil => y1
-------------------------------
length 1;2;3;nil => <<1 + y1>>
\end{lstlisting}

The last premise, \texttt{length nil}, is quite obviously an instance of \texttt{length nil}, therefore we can directly jump to the result that \texttt{y3 := 0}:

\begin{lstlisting}
y3 := 0
-----------------
length nil => y3
y2 := <<1 + y3>>
------------------------
length 3;nil => y2
y1 := <<1 + y2>>
------------------------
length 2;3;nil => y1
-------------------------------
length 1;2;3;nil => <<1 + y1>>
\end{lstlisting}

We can now fold back the results, just like a stack unwinding in a series of recursive calls. The first unwinding step yields:

\begin{lstlisting}
length nil => 0
y2 := <<1 + 0>>
------------------------
length 3;nil => y2
y1 := <<1 + y2>>
------------------------
length 2;3;nil => y1
-------------------------------
length 1;2;3;nil => <<1 + y1>>
\end{lstlisting}

We then proceed with the second unwinding step:

\begin{lstlisting}
------------------------
length 3;nil => 1
y1 := <<1 + 1>>
------------------------
length 2;3;nil => y1
-------------------------------
length 1;2;3;nil => <<1 + y1>>
\end{lstlisting}

And so on, until we reach the final expected answer which was \texttt{length 1;2;3;nil => 3}.

\paragraph{Searching}
A slightly more complex operation that we can perform is searching. Search determines whether or not a list \texttt{contains} an element. We define the \texttt{contains} function that takes a list and an integer as parameters:

\begin{lstlisting}
Func "contains" [ListInt <<int>>] Priority 100 Type Expr => <<int>>
\end{lstlisting}

The simplest test we perform is on an empty list. An empty list \texttt{nil} never contains a value \texttt{k}, independently of its value. The \texttt{contains} function in this case will thus return \texttt{no}\footnote{Assume we have defined symbols \texttt{yes} and \texttt{no}, but of course as a sane alternative boolean values can be used.} directly:

\begin{lstlisting}
---------------------
nil contains k => no
\end{lstlisting}

If the input list is not empty, then it means that it is not \texttt{nil}, and therefore it is made up of an element \texttt{x} followed by the rest of the list \texttt{xs}: \texttt{x;xs}. In this case, we check to see whether or not the head of the list is equal to the search element (the single premise \texttt{x == k}). If the premise is positively discharged (it is true) then we can return \texttt{yes} as the final result:

\begin{lstlisting}
x == k
-----------------------
x;xs contains k => yes
\end{lstlisting}

If the input list is not empty, but the first element is not equal to the searched key, then we need to keep searching. The result of the overall search will therefore be the result of searching in the rest of the list \texttt{xs} with the premise \texttt{xs contains k => res}:

\begin{lstlisting}
x != k
xs contains k => res
-----------------------
x;xs contains k => res
\end{lstlisting}

\paragraph{Transforming}
Consider now the problem of transforming a list by incrementing all of its elements by \texttt{k}. This example is interesting because it shows how a new list can be rebuilt and returned, instead of a single value like we did in the previous examples.

We begin by deifning the \texttt{plus} function which takes as input a list and an integer:

\begin{lstlisting}
Func [] "plus" [ListInt <<int>>] Priority 100 Type Expr => ListInt
\end{lstlisting}

The transformation of an empty list remains an empty list, as there are no elements to transform:

\begin{lstlisting}
-------------------
plus nil k => nil
\end{lstlisting}

The transform of the non-empty list proceeds first with the transformation of the rest of the list into \texttt{xs'}, then it computes \texttt{x+k} (the transformed head) into \texttt{x'}, and finally it returns the list \texttt{x';xs'} as the whole transformed list:

\begin{lstlisting}
plus xs k => xs'
<<x+k>> => x'
----------------------
plus x;xs k => x';xs'
\end{lstlisting}

Many useful functions on lists take the general form above: an immediate (often trivial) answer for the case of an empty list, and a recursive step which somehow combines premises on the first element with premises on the remaining elements. In a sense, lists are the embodiement of the simplest principles of recursion.

\paragraph{Sorting}
Let us now consider a slightly more complex algorithm, which allows us to test the algorithmic expressive power of the language. In particular, let us consider a powerful and fast sorting algorithm, the well-known \textit{merge-sort}. Merge sort works by, recursively, dividing the list of elements into two sublists, sorting them separately, and then merging the two sorted lists into a single, final sorted list.

We need two auxiliary symbol definitions: one is the comma, which will be used to represent a pair of lists, and the other is the \texttt{mergeSort} function itself:

\begin{lstlisting}
Data [] [ListInt] "," [ListInt] Priority 900 Type ListIntPair
Func [] "mergeSort" [ListInt] Priority 100 Type Expr => ListInt
\end{lstlisting}

The definition of \texttt{mergeSort} then becomes quite simple. If the list is empty, or contains only one element, then no sorting needs to take place and we can immediately return the sorted list as an answer:

\begin{lstlisting}
---------------------
mergeSort nil => nil

-------------------------
mergeSort x;nil => x;nil
\end{lstlisting}

If the list contains at least two elements, then:
\begin{inparaenum}[\itshape i\upshape)]
\item we split it into two sub-lists \texttt{l} and \texttt{r};
\item we sort \texttt{l} into \texttt{l'} with a recursive call;
\item we sort \texttt{r} into \texttt{r'} with a recursive call;
\item we merge \texttt{l'} and \texttt{r'}, therefore obtaining the final sorted list.
\end{inparaenum}

\begin{lstlisting}
split x;y;xs => l,r
mergeSort l => l'
mergeSort r => r'
merge l' r' => res
------------------------
mergeSort x;y;xs => res
\end{lstlisting}

Splitting a list is done with function \texttt{split}:

\begin{lstlisting}
Func [] "split" [ListInt] Priority 100 Type Expr => ListIntPair
\end{lstlisting}

If the list to split has less than two elements, then splitting is trivial:

\begin{lstlisting}
---------------------
split nil => nil,nil

-------------------------
split x;nil => x;nil,nil
\end{lstlisting}

If the list to split has at least two elements \texttt{x} and \texttt{y}, then:
\begin{inparaenum}[\itshape i\upshape)]
\item we split the remaining list recursively, obtaining partial splits \texttt{l} and \texttt{r};
\item list \texttt{x;l} is the first item of the result;
\item list \texttt{y;r} is the second item of the result.
\end{inparaenum}

\begin{lstlisting}
split xs => l,r
----------------------------
split x;y;xs => (x;l),(y;r)
\end{lstlisting}

Let us consider a short example of how split works on a list such as:

\begin{lstlisting}
-------------------------
split 0;1;2;3;4;nil => ?
\end{lstlisting}

Since the list contains at least two elements, we apply the recursive rule for \texttt{x=0}, \texttt{y=1}, and \texttt{xs=2;3;4;nil}:

\begin{lstlisting}
split 2;3;4;nil => l,r
-----------------------------------
split 0;1;2;3;4;nil => (0;l),(1;r)
\end{lstlisting}

We apply the same rule again because \texttt{2;3;4;nil} has at least two elements, thus:

\begin{lstlisting}
split 4;nil => l',r'
l := 2;l'
r := 3;r'
-----------------------
split 2;3;4;nil => l,r
-----------------------------------
split 0;1;2;3;4;nil => (0;l),(1;r)
\end{lstlisting}

We end up with list \texttt{4;nil}, which has only one element. This requires us to apply one of the trivial rules above:

\begin{lstlisting}
l' := 4;nil
r' := nil
--------------------
split 4;nil => l',r'
l := 2;l'
r := 3;r'
-----------------------
split 2;3;4;nil => l,r
-----------------------------------
split 0;1;2;3;4;nil => (0;l),(1;r)
\end{lstlisting}

We can now unwind the stack of intermediate results. The first unwind step yields:

\begin{lstlisting}
l := 2;4;nil
r := 3;nil
-----------------------
split 2;3;4;nil => l,r
-----------------------------------
split 0;1;2;3;4;nil => (0;l),(1;r)
\end{lstlisting}

The second and last unwind step returns the final result:

\begin{lstlisting}
---------------------------------------------
split 0;1;2;3;4;nil => (0;2;4;nil),(1;3;nil)
\end{lstlisting}

The role of \texttt{split} is thus to split the list in two, but instead of taking the first half and then the second half of the list, we \textit{interleave} the elements: elements in odd positions go in the first sublist, elements in even positions go in the second sublist.

Merging two lists requires a bit of care, because we take as input two sorted lists and we must give as output a single list which contains all elements of the two lists to merge \textit{in sorted order}. Merging is done with function \texttt{merge}:

\begin{lstlisting}
Func [] "merge" [ListInt ListInt] Priority 100 Type Expr => ListInt
\end{lstlisting}

If any of the input lists to merge is empty, then the answer is trivial to find and return:

\begin{lstlisting}
---------------------
merge nil nil => nil

-----------------------
merge x;xs nil => x;xs

-----------------------
merge nil y;ys => y;ys
\end{lstlisting}

If the first list begins with an element that is smaller than the first element of the second list, then the resulting list will need to start with that element (and vice-versa):

\begin{lstlisting}
x <= y
merge xs y;ys => res
-------------------------
merge x;xs y;ys => x;res

x > y
merge x;xs ys => res
-----------------------
merge x;xs y;ys => y;res
\end{lstlisting}

Consider now the merging of two partial sorted lists \texttt{0;2;nil} and \texttt{1;3;nil} (the lists do not need to be of the same length, nor do the elements need to interleave so strictly):

\begin{lstlisting}
---------------------------
merge 0;2;nil 1;3;nil => ?
\end{lstlisting}

The first element of the first list is smaller than the first element of the second list, thus it will become the first element of the result:

\begin{lstlisting}
merge 2;nil 1;3;nil => res
-------------------------------
merge 0;2;nil 1;3;nil => 0;res
\end{lstlisting}

The first element of the second list is smaller than the first element of the first list, thus it will be selected as the first element of the (intermediate) result:

\begin{lstlisting}
--------------------------
merge 2;nil 3;nil => res'
res := 1;res'
---------------------------
merge 2;nil 1;3;nil => res
-------------------------------
merge 0;2;nil 1;3;nil => 0;res
\end{lstlisting}

We now select \texttt{2} as the new head of the intermediate result:

\begin{lstlisting}
merge nil 3;nil => res''
res' := 2;res''
--------------------------
merge 2;nil 3;nil => res'
res := 1;res'
---------------------------
merge 2;nil 1;3;nil => res
-------------------------------
merge 0;2;nil 1;3;nil => 0;res
\end{lstlisting}

Finally, since the first list is empty, we directly return the second:

\begin{lstlisting}
res'' := 3;nil
-------------------------
merge nil 3;nil => res''
res' := 2;res''
--------------------------
merge 2;nil 3;nil => res'
res := 1;res'
---------------------------
merge 2;nil 1;3;nil => res
-------------------------------
merge 0;2;nil 1;3;nil => 0;res
\end{lstlisting}

Since we have no more intermediate results to process, we can now begin the unwinding. First of all \texttt{res''} is replaced with \texttt{3;nil}:

\begin{lstlisting}
res' := 2;3;nil
--------------------------
merge 2;nil 3;nil => res'
res := 1;res'
---------------------------
merge 2;nil 1;3;nil => res
-------------------------------
merge 0;2;nil 1;3;nil => 0;res
\end{lstlisting}

Then we replace \texttt{res'} with its value of \texttt{2;3;nil}:

\begin{lstlisting}
res := 1;2;3;nil
---------------------------
merge 2;nil 1;3;nil => res
-------------------------------
merge 0;2;nil 1;3;nil => 0;res
\end{lstlisting}

Finally we replace \texttt{res}, therefore obtaining the final answer:

\begin{lstlisting}
merge 0;2;nil 1;3;nil => 0;1;2;3;nil
\end{lstlisting}

At this point we can better discuss what \texttt{mergeSort} does, without doing the full derivation which would take too long. Suppose we wished to sort sequence \texttt{5;4;3;2;1;nil}:

\begin{lstlisting}
split 5;4;3;2;1;nil => l,r
mergeSort l => l'
mergeSort r => r'
merge l' r' => res
------------------------
mergeSort 5;4;3;2;1;nil => res
\end{lstlisting}

Without going (again) into the details of \texttt{split}, we can just assume it will work as expected and obtain:

\begin{lstlisting}
split 5;4;3;2;1;nil => (5;3;1;nil),(4;2;nil)
mergeSort 5;3;1;nil => l'
mergeSort 4;2;nil => r'
merge l' r' => res
------------------------
mergeSort 5;4;3;2;1;nil => res
\end{lstlisting}

At this point we make a strong assumption, which we can safely make because of the principle of induction, that is we assume that \texttt{mergeSort 5;3;1;nil} and \texttt{mergeSort 4;2;nil} will both return a sorted list. The next step is therefore:

\begin{lstlisting}
mergeSort 5;3;1;nil => 1;3;5;nil
mergeSort 4;2;nil => 2;4;nil
merge 1;3;5;nil 2;4;nil => res
-------------------------------
mergeSort 5;4;3;2;1;nil => res
\end{lstlisting}

Without going (again) into the details of \texttt{merge}, we can just assume it will work as expected and obtain:

\begin{lstlisting}
merge 1;3;5;nil 2;4;nil => 1;2;3;4;5;nil
-----------------------------------------
mergeSort 5;4;3;2;1;nil => 1;2;3;4;5;nil
\end{lstlisting}

which is precisely the expected result.

\paragraph{Conclusions}
What we have seen so far extends (with more or less translation work depending on the circumstances) to all known algorithms on lists. It is possible to write algorithms such as insertion sort, various kinds of search, and so on with minimal adjustments. In the coming sections we will dig yet deeper into recursive data structures such as binary trees.


\chapter{Fourier Series}
\section{Series Expansion of Periodic Functions}
The basic fact about Fourier series is as follows.\\
If $f(x)$ is a periodic function of $x$,with a period $L$ . The \textbf{Fundamental interval} is taken to be $(a,b)$, so that $L=(b-a)$\\
Then, $f(x)=f(x+L)=f(x+nL)$ Where $n$ is any integer.\\If the function $f(x)$ also satisfies a set of conditions known as \textbf{Drichlet's  Conditions} given as below\\

\begin{enumerate}
	\item It is single-valued in the interval $(a, b)$
	\item It is bounded in the interval $(a, b)$
	\item It has at most a finite number of maxima and minima in the interval $(a, b)$
	\item It has only a finite number of discontinuity in the interval $(a, b)$
\end{enumerate}
\begin{theorem}\label{geneq}
	Then such a function can be expressed by a sum of a set  sine and cosine functions (or complex exponentials). This series is known as \textbf{Fourier Series Expansion}\index{Fourier Series}.\\
	\begin{equation}
	\begin{array}{c}
	f(x)=\frac{a_{0}}{2}+\sum_{n=1}^{\infty} a_{n} \cos \frac{2n \pi x}{L}+\sum_{n=1}^{\infty} b_{n} \sin \frac{2n \pi x}{L}
	\end{array}
	\end{equation}

	$a_{0}, a_{n}, b_{n}$ are constants, known as Fourier co-efficients.
	\begin{equation}
	a_{0}=\frac{2}{b-a} \int_{a}^{b} f(x) d x
	\end{equation}
	\begin{equation}
	a_{n}=\frac{2}{b-a} \int_{a}^{b} f(x) \cdot \cos \left(\frac{2 n \pi x}{b-a}\right) d x
	\end{equation}
	\begin{equation}
	b_{n}=\frac{2}{b-a} \int_{a}^{b} f(x) \cdot \sin \left(\frac{2 n \pi x}{b-a}\right) d x
	\end{equation}
\end{theorem}
The Fourier expansion of a periodic function $f(x)$ consists of the following term
\begin{enumerate}
	\item $a_{0}: a$ constant term or $D .$ C. term
	\item $a_{1} \cos \frac{\pi x}{L}$ and $b_{1} \sin \frac{\pi x}{L}:$ Fundamental frequency term i.e term having lowest frequency
	\item $a_{2} \cos \frac{2 \pi x}{L}, a_{3} \cos \frac{3 \pi x}{L} \ldots \ldots ., b_{2} \sin \frac{2 \pi x}{L}, b_{3} \sin \frac{3 \pi x}{L} \ldots \ldots .$ Overtones i.e terms having
	frequencies integer multiple of fundamental frequency term.
\end{enumerate}

\subsection{Simplified formulas when $b-a=2\pi$}

We have established the Euler formulas for a function having period $L$ and principal interval $(a,b)$.The formulas connected with fourier series expansion look a bit simpler if one choose the fundamental interval to be $(-\pi,\pi)$ or $(0,2\pi)$, ie Period $L=2\pi$.\\For the case $b-a=2\pi$, the Euler formulas become

\begin{theorem}\label{pareq}

\begin{equation}
a_{0}=\frac{1}{\pi} \int_{a}^{b} f(x) d x
\end{equation}
\begin{equation}
a_{0n}=\frac{1}{\pi} \int_{a}^{b} f(x) \cdot \cos n x d x
\end{equation}
\begin{equation}
b_{n}=\frac{1}{\pi} \int_{a}^{b} f(x) \cdot \sin n x d x
\end{equation}
So that the Fourier expansion becomes
\begin{equation}
f(x)=\frac{a_{0}}{2}+\sum_{n=1}^{\infty} a_{n} \cdot \cos n x+\sum_{n=1}^{\infty} b_{n} \sin n x
\end{equation}
\end{theorem}

\begin{exercise}
	 Find the Fourier series representing $$f(x)=x, \quad 0<x<2 \pi$$
\end{exercise}
\begin{answer}
Here the interval is $(0,2\pi)$ So L=$2\pi$.From theorem \ref{pareq} we have
\begin{equation}
\label{eq1}
f(x)=\frac{a_{0}}{2}+\sum_{n=1}^{\infty} a_{n} \cdot \cos n x+\sum_{n=1}^{\infty} b_{n} \sin n x
\end{equation}
$$h
\text { Hence } \begin{aligned}
a_{0} &=\frac{1}{\pi} \int_{0}^{2 \pi} f(x) d x=\frac{1}{\pi} \int_{0}^{2 \pi} x d x=\frac{1}{\pi}\left[\frac{x^{2}}{2}\right]_{0}^{2 \pi}=2 \pi \\
a_{n} &=\frac{1}{\pi} \int_{0}^{2 \pi} f(x) \cos n x d x=\frac{1}{\pi} \int_{0}^{2 \pi} x \cos n x d x \\
&=\frac{1}{\pi}\left[x \frac{\sin n x}{n}-1 \cdot\left(-\frac{\cos n x}{n^{2}}\right)\right]_{0}^{2 \pi}=\frac{1}{\pi}\left[\frac{\cos 2 n \pi}{n^{2}}-\frac{1}{n^{2}}\right]=\frac{1}{n^{2} \pi}(1-1)=0 \\
b_{n} &=\frac{1}{\pi} \int_{0}^{2 \pi} f(x) \sin n x d x=\frac{1}{\pi} \int_{0}^{2 \pi} x \sin n x d x \\
&=\frac{1}{\pi}\left[x\left(-\frac{\cos n x}{n}\right)-1 \cdot\left(\frac{-\sin n x}{n^{2}}\right)\right]_{0}^{2 \pi}=\frac{1}{\pi}\left[\frac{-2 \pi \cos 2 n \pi}{n}\right]=-\frac{2}{n}
\end{aligned}
$$
Substituting the values of $a_{0}, a_{1}, a_{2} \ldots, b_{1}, b_{2} \ldots$ in Equation \ref{eq1}, we get
$$
x=\pi-2\left[\sin x+\frac{1}{2} \sin 2 x+\frac{1}{3} \sin 3 x+\ldots\right]
$$
\end{answer}
\begin{exercise}
Given that $f(x)=x+x^{2}$ for $-\pi<x<\pi,$ find the Fourier expression of $f(x)$
\end{exercise}

\begin{answer}
	\begin{equation}
\label{eq2}
	\text { Let } x+x^{2}=\frac{a_{0}}{2}+a_{1} \cos x+a_{2} \cos 2 x+\ldots+b_{1} \sin x+b_{2} \sin 2 x+\ldots
	\end{equation}
	$\begin{aligned} a_{0} &=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) d x=\frac{1}{\pi} \int_{-\pi}^{\pi}\left(x+x^{2}\right) d x \\ &=\frac{1}{\pi}\left[\frac{x^{2}}{2}+\frac{x^{3}}{3}\right]_{-\pi}^{\pi}=\frac{1}{\pi}\left[\frac{\pi^{2}}{2}+\frac{\pi^{3}}{3}-\frac{\pi^{2}}{2}+\frac{\pi^{3}}{3}\right]=\frac{2 \pi^{2}}{3} \\ a_{n} &=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \cos n x d x=\int_{-\pi}^{\pi}\left(x+x^{2}\right) \cos n x d x \end{aligned}$\\
	$\begin{aligned} &=\frac{1}{\pi}\left[\left(x+x^{2}\right) \frac{\sin n x}{n}-(2 x+1) \frac{(-\cos n x)}{n^{2}}+(2)\left(-\frac{\sin n x}{n^{3}}\right)\right]_{-\pi}^{\pi} \\ &=\frac{1}{\pi}\left[(2 \pi+1) \frac{\cos n \pi}{n^{2}}-(-2 \pi+1) \frac{\cos (-n \pi)}{n^{2}}\right]=\frac{1}{\pi}\left[4 \pi \frac{\cos n \pi}{n^{2}}\right]=\frac{4(-1)^{n}}{n^{2}} \\ b_{n} &=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin n x d x=\frac{1}{\pi} \int_{-\pi}^{\pi}\left(x+x^{2}\right) \sin n x d x \\ &=\frac{1}{\pi}\left[\left(x+x^{2}\right)\left(-\frac{\cos n x}{n}\right)-(2 x+1)\left(\frac{-\sin n x}{n^{2}}\right)+2 \frac{\cos n x}{n^{3}}\right]_{-\pi}^{\pi} \\ &=\frac{1}{\pi}\left[-\left(\pi+\pi^{2}\right) \frac{\cos n \pi}{n}+2 \frac{\cos n \pi}{n^{3}}+\left(-\pi+\pi^{2}\right) \frac{\cos n \pi}{n}-2 \frac{\cos n \pi}{n^{3}}\right] \\ &=\frac{1}{\pi}\left[-\frac{2 \pi}{n} \cos n \pi\right]=-\frac{2}{n}(-1)^{n} \end{aligned}$\\
	Substituting the values of $a_{0}, a_{n}, b_{n},$ in Equation \ref{eq2}, we get
	\begin{equation}
	\begin{array}{r}
	x+x^{2}=\frac{\pi^{2}}{3}+4\left[-\cos x+\frac{1}{2^{2}} \cos 2 x-\frac{1}{3^{2}} \cos 3 x+\ldots\right]
	-2\left[-\sin x+\frac{1}{2} \sin 2 x-\frac{1}{3} \sin 3 x+\ldots\right]
	\end{array}
	\end{equation}
\end{answer}
\section{Even and Odd Functions}
\subsection{Even Function}
A function $f(x)$ is said to be \textbf{even} (or \textbf{symmetric}) function if, $f(-x)=f(x)$ The graph of such a function is symmetrical with respect to $y$ -axis . Here $y$ -axis is a mirror for the reflection of the curve.
\begin{example}
	$\cos x,\sec x ,x^2$ etc

\end{example}
The area under such a curve from $-\pi$ to $\pi$ is double the area from 0 to $\pi$, ie\\
$$\quad \int_{-\pi}^{\pi} f(x) d x=2 \int_{0}^{\pi} f(x) d x$$
\subsection{Odd Function}
A function $f(x)$ is called \textbf{odd} (or \textbf{skew symmetric}) function if
$$
f(-x)=-f(x)
$$ Odd functions will be symmetric about origin.\\
Here the area under the curve from $-\pi$ to $\pi$ is zero.
$$
\int_{-\pi}^{\pi} f(x) d x=0
$$

\begin{note}
	\[
	\boxed{
		\!\begin{aligned}
		&Even \times Even= Odd \times Odd = Even\\
		&Odd \times Even= Even \times Odd = Odd
		\end{aligned}
	}
	\]
\end{note}
\section{Fourier Expansion of Even and Odd Functions}
\subsection{Even Function}
$$
a_{0}=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) d x=\frac{2}{\pi} \int_{0}^{\pi} f(x) d x
$$
$$
a_{n}=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \cos n x d x=\frac{2}{\pi} \int_{0}^{\pi} f(x) \cos n x d x
$$
As $f(x)$ and $\cos n x$ are both even functions, therefore, the product of $f(x) . \cos n x$ is also an even function.
$$
b_{n}=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin n x d x=0
$$
\textbf{So if $f(x)$ is an even function then Fourier coefficient $b_n$ will be zero in the expansion. }\\
The series of the even function will contain only cosine and DC terms.
\begin{exercise}
	Find the Fourier series expansion of the periodic function of period $2 \pi$
	$$
	f(x)=x^{2},-\pi \leq x \leq \pi
	$$
\end{exercise}
\begin{answer}
	This is an even function. $\therefore b_{n}=0$
	$$
	\begin{aligned}
	b_{n} &=0 \quad[f(-x)=f(x)] \\
	a_{0} &=\frac{2}{\pi} \int_{0}^{\pi} f(x) d x=\frac{2}{\pi} \int_{0}^{\pi} x^{2} d x=\frac{2}{\pi}\left[\frac{x^{3}}{3}\right]_{0}^{\pi}=\frac{2 \pi^{2}}{3} \\
	a_{n} &=\frac{2}{\pi} \int_{0}^{\pi} f(x) \cos n x d x=\frac{2}{\pi} \int_{0}^{\pi} x^{2} \cos n x d x \\
	&=\frac{2}{\pi}\left[x^{2}\left(\frac{\sin n x}{n}\right)-(2 x)\left(-\frac{\cos n x}{n^{2}}\right)+(2)\left(-\frac{\sin n x}{n^{3}}\right)\right]_{0}^{\pi} \\
	=& \frac{2}{\pi}\left[\frac{\pi^{2} \sin n \pi}{n}+\frac{2 \pi \cos n \pi}{n^{2}}-\frac{2 \sin n \pi}{n^{3}}\right]=\frac{4(-1)^{n}}{n^{2}}
	\end{aligned}
	$$
	$\begin{aligned} \text { Fourier series is } & f(x)=\frac{a_{0}}{2}+a_{1} \cos x+a_{2} \cos 2 x+a_{3} \cos 3 x+\ldots+a_{n} \cos n x+\ldots \\ x^{2} &=\frac{\pi^{2}}{3}-4\left[\frac{\cos x}{1^{2}}-\frac{\cos 2 x}{2^{2}}+\frac{\cos 3 x}{3^{2}}-\frac{\cos 4 x}{4^{2}}+\ldots\right] \end{aligned}$
\end{answer}
\subsection{Odd Function}
$$\begin{aligned}
	&a_{0}=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) d x=0\\
	&a_{n}=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \cos n x d x=0
\end{aligned}$$
(Since $f(x)$ is an odd function and $cos(x)$ is an even function their product will be odd and the integral vanishes)
$$\begin{aligned}
b_{n}&=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin n x d x\\
\therefore b_{n}&=\frac{2}{\pi} \int_{0}^{\pi} f(x) \sin n x d x
\end{aligned}$$
\textbf{So if $f(x)$ is an odd function then Fourier coefficient $a_0$ and $a_n$ will be zero in the expansion. }\\
The series of the odd function will contain only sine  terms.

\begin{exercise}
	Obtain a Fourier expression for
	$$
	f(x)=x^{3} \quad \text { for }-\pi<x<\pi
	$$
\end{exercise}
\begin{answer}
	$f(x)=x^{3}$ is an odd function.
	$$
	\begin{aligned}
	\therefore \quad a_{0} & =0 \text { and } a_{n}=0 \\
	\text{ Use tabular integration }\\
	b_{n} & =\frac{2}{\pi} \int_{0}^{\pi} f(x) \sin n x d x=\frac{2}{\pi} \int_{0}^{\pi} x^{3} \sin n x d x \\
	& =\frac{2}{\pi}\left[x^{3}\left(-\frac{\cos n x}{n}\right)-3 x^{2}\left(-\frac{\sin n x}{n^{2}}\right)+6 x\left(\frac{\cos n x}{n^{3}}\right)-6\left(\frac{\sin n x}{n^{4}}\right)\right]_{0}^{\pi} \\
	& =\frac{2}{\pi}\left[-\frac{\pi^{3} \cos n \pi}{n}+\frac{6 \pi \cos n \pi}{n^{3}}\right]=2 \cdot(-1)^{n}\left[-\frac{\pi^{2}}{n}+\frac{6}{n^{3}}\right] \\
 \text{ We have }f(x)&=b_{1} \sin x+b_{2} \sin 2 x+b_{3} \sin 3 x+\ldots \ldots \\
	 x^{3}&=2\left[-\left(-\frac{\pi^{2}}{1}+\frac{6}{1^{3}}\right) \sin x+\left(-\frac{\pi^{2}}{2}+\frac{6}{2^{3}}\right) \sin 2 x-\left(-\frac{\pi^{2}}{3}+\frac{6}{3^{3}}\right) \sin 3 x+\ldots\right]
	\end{aligned}
	$$
\end{answer}

\newpage
\begin{abox}
	Practise Set-1
\end{abox}
\begin{enumerate}[label=\color{ocre}\textbf{\arabic*.}]
	\item   The first few terms in the Laurent series for $\frac{1}{(z-1)(z-2)}$ in the region $1 \leq|z| \leq 2$ and around $z=1$ is
	{\exyear{NET/JRF(JUNE-2012)}}
	\begin{tasks}(1)
		\task[\textbf{A.}] $\frac{1}{2}\left[1+z+z^{2}+\ldots\right]\left[1+\frac{z}{2}+\frac{z^{2}}{4}+\frac{z^{3}}{8}+\ldots .\right]$
		\task[\textbf{B.}] $\frac{1}{1-z}-z-(1-z)^{2}+(1-z)^{3}+\ldots .$
		\task[\textbf{C.}] $\frac{1}{\mathrm{z}^{2}}\left[1+\frac{1}{\mathrm{z}}+\frac{1}{\mathrm{z}^{2}}+\ldots .\right]\left[1+\frac{2}{\mathrm{z}}+\frac{4}{\mathrm{z}^{2}}+\ldots . .\right]$
		\task[\textbf{D.}]  $2(z-1)+5(z-1)^{2}+7(z-1)^{3}+\ldots$
	\end{tasks}
	\item Consider a sinusoidal waveform of amplitude $1 V$ and frequency $f_{0}$. Starting from an arbitrary initial time, the waveform is sampled at intervals of $\frac{1}{2 f_{0}}$. If the corresponding Fourier spectrum peaks at a frequency $\bar{f}$ and an amplitude $\bar{A}$, them
	{\exyear{NET/JRF(JUNE-2012)}}
	\begin{tasks}(2)
		\task[\textbf{A.}] $\bar{f}=2 f_{0}$ and $\bar{A}=1 V$
		\task[\textbf{B.}] $\bar{f}=2 f_{0}$ and $0 \leq \bar{A} \leq 1 V$
		\task[\textbf{C.}] $\bar{f}=0$ and $\bar{A}=1 V$
		\task[\textbf{D.}] $\bar{f}=\frac{f_{0}}{2}$ and $\bar{A}=\frac{1}{\sqrt{2}} V$
	\end{tasks}
	\item The Fourier transform of the derivative of the Dirac $\delta-$ function, namely $\delta^{\prime}(x)$, is proportional to
	{\exyear{NET/JRF(DEC-2013)}}
	\begin{tasks}(4)
		\task[\textbf{A.}] 0
		\task[\textbf{B.}] 1
		\task[\textbf{C.}] $\sin k$
		\task[\textbf{D.}] $i k$
	\end{tasks}
	\item The Laplace transform of $6 t^{3}+3 \sin 4 t$ is
	{\exyear{NET/JRF(JUNE-2015)}}
	\begin{tasks}(4)
		\task[\textbf{A.}] $\frac{36}{s^{4}}+\frac{12}{s^{2}+16}$
		\task[\textbf{B.}] $\frac{36}{s^{4}}+\frac{12}{s^{2}-16}$
		\task[\textbf{C.}] $\frac{18}{s^{4}}+\frac{12}{s^{2}-16}$
		\task[\textbf{D.}] $\frac{36}{s^{3}}+\frac{12}{s^{2}+16}$
	\end{tasks}
	\item  The Fourier transform of $f(x)$ is $\tilde{f}(k)=\int_{-\infty}^{+\infty} d x e^{i k x} f(x)$.
	If $f(x)=\alpha \delta(x)+\beta \delta^{\prime}(x)+\gamma \delta^{\prime \prime}(x)$, where $\delta(x)$ is the Dirac delta-function (and prime denotes derivative), what is $\tilde{f}(k) ?$
	{\exyear{NET/JRF(DEC-2015)}}
	\begin{tasks}(2)
		\task[\textbf{A.}] $\alpha+i \beta k+i \gamma k^{2}$
		\task[\textbf{B.}] $\alpha+\beta k-\gamma k^{2}$
		\task[\textbf{C.}]  $\alpha-i \beta k-\gamma k^{2}$
		\task[\textbf{D.}] $i \alpha+\beta k-i \gamma k^{2}$
	\end{tasks}
	\item  What is the Fourier transform $\int d x e^{i l x} f(x)$ of
	$$
	f(x)=\delta(x)+\sum_{n=1}^{\infty} \frac{d^{n}}{d x^{n}} \delta(x)
	$$
	where $\delta(x)$ is the Dirac delta-function?
	{\exyear{NET/JRF(JUNE-2016)}}
	\begin{tasks}(4)
		\task[\textbf{A.}]  $\frac{1}{1-i k}$
		\task[\textbf{B.}] $\frac{1}{1+i k}$
		\task[\textbf{C.}] $\frac{1}{k+i}$
		\task[\textbf{D.}] $\frac{1}{k-i}$
	\end{tasks}
	\item The Laplace transform of
	$$
	f(t)=\left\{\begin{array}{cc}
	\frac{t}{T}, & 0<t<T \\
	1 & t>T
	\end{array}\right.
	$$
	is
	{\exyear{NET/JRF(DEC-2016)}}
	\begin{tasks}(4)
		\task[\textbf{A.}] $\frac{-\left(1-e^{-s T}\right)}{s^{2} T}$
		\task[\textbf{B.}] $\frac{\left(1-e^{-s T}\right)}{s^{2} T}$
		\task[\textbf{C.}] $\frac{\left(1+e^{-s T}\right)}{s^{2} T}$
		\task[\textbf{D.}] $\frac{\left(1-e^{s T}\right)}{s^{2} T}$
	\end{tasks}
	\item The Fourier transform $\int_{-\infty}^{\infty} d x f(x) e^{i k x}$ of the function $f(x)=\frac{1}{x^{2}+2}$ is
	{\exyear{NET/JRF(DEC-2016)}}
	\begin{tasks}(4)
		\task[\textbf{A.}] $\sqrt{2} \pi e^{-\sqrt{2}|| \mid}$
		\task[\textbf{B.}] $\sqrt{2} \pi e^{-\sqrt{2 k}}$
		\task[\textbf{C.}] $\frac{\pi}{\sqrt{2}} e^{-\sqrt{2 k}}$
		\task[\textbf{D.}] $\frac{\pi}{\sqrt{2}} e^{-\sqrt{2}|k|}$
	\end{tasks}
	\item Consider the differential equation $\frac{d y}{d t}+a y=e^{-b t}$ with the initial condition $y(0)=0$. Then the Laplace transform $Y(s)$ of the solution $y(t)$ is
	{\exyear{NET/JRF(DEC-2017)}}
	\begin{tasks}(4)
		\task[\textbf{A.}] $\frac{1}{(s+a)(s+b)}$
		\task[\textbf{B.}] $\frac{1}{b(s+a)}$
		\task[\textbf{C.}] $\frac{1}{a(s+b)}$
		\task[\textbf{D.}] $\frac{e^{-a}-e^{-b}}{b-a}$
	\end{tasks}
	\item  The Fourier transform $\int_{-\infty}^{\infty} d x f(x) e^{i k x}$ of the function $f(x)=e^{-|x|}$
	{\exyear{NET/JRF(JUNE-2018)}}
	\begin{tasks}(4)
		\task[\textbf{A.}] $-\frac{2}{1+k^{2}}$
		\task[\textbf{B.}] $-\frac{1}{2\left(1+k^{2}\right)}$
		\task[\textbf{C.}] $\frac{2}{1+k^{2}}$
		\task[\textbf{D.}] $\frac{2}{\left(2+k^{2}\right)}$
	\end{tasks}
	\item The function $f(t)$ is a periodic function of period $2 \pi$. In the range $(-\pi, \pi)$, it equals $e^{-t}$. If $f(t)=\sum_{-\infty}^{\infty} c_{n} e^{\text {int }}$ denotes its Fourier series expansion, the sum $\sum_{-\infty}^{\infty}\left|c_{n}\right|^{2}$ is
	{\exyear{NET/JRF(DEC-2019)}}
	\begin{tasks}(4)
		\task[\textbf{A.}] 1
		\task[\textbf{B.}] $\frac{1}{2 \pi}$
		\task[\textbf{C.}] $\frac{1}{2 \pi} \cosh (2 \pi)$
		\task[\textbf{D.}]  $\frac{1}{2 \pi} \sinh (2 \pi)$
	\end{tasks}
	\end{enumerate}
 \colorlet{ocre1}{ocre!70!}
\colorlet{ocrel}{ocre!30!}
\setlength\arrayrulewidth{1pt}
\begin{table}[H]
	\centering
	\arrayrulecolor{ocre}
	\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}
		\hline
		\multicolumn{4}{|c|}{\textbf{Answer key}}\\\hline\hline
		\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\hline
		1&\textbf{B} &2&\textbf{B}\\\hline
		3&\textbf{D} &4&\textbf{A} \\\hline
		5&\textbf{C} &6&\textbf{B} \\\hline
		7&\textbf{B}&8&\textbf{D}\\\hline
		9&\textbf{A}&10&\textbf{C}\\\hline
		11&\textbf{D} &&\textbf{}\\\hline

	\end{tabular}
\end{table}

\newpage
\begin{abox}
	Practise Set-2
\end{abox}
\begin{enumerate}[label=\color{ocre}\textbf{\arabic*.}]
\item If $f(x)=\left\{\begin{array}{ll}0 & \text { for } x<3, \\ x-3 & \text { for } x \geq 3\end{array}\right.$ then the Laplace transform of $f(x)$ is
{\exyear{GATE 2010}}
\begin{tasks}(4)
	\task[\textbf{A.}] $s^{-2} e^{3 s}$
	\task[\textbf{B.}] $s^{2} e^{3 s}$
	\task[\textbf{C.}] $s^{-2}$
	\task[\textbf{D.}] $s^{-2} e^{-3 s}$
\end{tasks}
\item The coefficient of $e^{i k x}$ in the Fourier expansion of $u(x)=A \sin ^{2}(\alpha x)$ for $k=-2 \alpha$ is
{\exyear{GATE 2017}}
\begin{tasks}(4)
	\task[\textbf{A.}] $\frac{A}{4}$
	\task[\textbf{B.}] $\frac{-A}{4}$
	\task[\textbf{C.}] $\frac{A}{2}$
	\task[\textbf{D.}] $\frac{-A}{2}$
\end{tasks}
\item Given the fundamental constants $\hbar$ (Planck's constant), $G$ (universal gravitation constant) and $c$ (speed of light), which of the following has dimension of length?
{\exyear{JEST 2014}}
 \begin{tasks}(2)
	\task[\textbf{A.}]$\sqrt{\frac{\hbar G}{c^{3}}}$
	\task[\textbf{B.}] $\sqrt{\frac{\hbar G}{c^{5}}}$
	\task[\textbf{C.}]$\frac{\hbar G}{c^{3}}$
	\task[\textbf{D.}] $\sqrt{\frac{\hbar c}{8 \pi G}}$
\end{tasks}
\item The Fourier transform of the function $\frac{1}{x^{4}+3 x^{2}+2}$ up to proportionality constant is
{\exyear{JEST 2017}}
 \begin{tasks}(2)
	\task[\textbf{A.}]$\sqrt{2} \exp \left(-k^{2}\right)-\exp \left(-2 k^{2}\right)$
	\task[\textbf{B.}]$\sqrt{2} \exp (-|k|)-\exp (-\sqrt{2}|k|)$
	\task[\textbf{C.}]$\sqrt{2} \exp (-\sqrt{|k|})-\exp (-\sqrt{2|k|})$
	\task[\textbf{D.}]  $\sqrt{2} \exp \left(-\sqrt{2} k^{2}\right)-\exp \left(-2 k^{2}\right)$
\end{tasks}
\item The function $f(x)=\cosh x$ which exists in the range $-\pi \leq x \leq \pi$ is periodically repeated between $x=(2 m-1) \pi$ and $(2 m+1) \pi$, where $m=-\infty$ to $\infty$. Using Fourier series, indicate the correct relation at $x=0$
{\exyear{JEST 2017}}
 \begin{tasks}(2)
	\task[\textbf{A.}] $\sum_{n=-\infty}^{\infty} \frac{(-1)^{n}}{1-n^{2}}=\frac{1}{2}\left(\frac{\pi}{\cosh \pi}-1\right)$
	\task[\textbf{B.}]$\sum_{n=-\infty}^{\infty} \frac{(-1)^{n}}{1-n^{2}}=2 \frac{\pi}{\cosh \pi}$
	\task[\textbf{C.}]$\sum_{n=-\infty}^{\infty} \frac{(-1)^{-n}}{1+n^{2}}=2 \frac{\pi}{\sinh \pi}$
	\task[\textbf{D.}] $\sum_{n=1}^{\infty} \frac{(-1)^{n}}{1+n^{2}}=\frac{1}{2}\left(\frac{\pi}{\sinh \pi}-1\right)$
\end{tasks}
\item The Laplace transform of $\frac{(\sin (a t)-a t \cos (a t))}{\left(2 a^{3}\right)}$ is
{\exyear{JEST 2018}}
 \begin{tasks}(2)
	\task[\textbf{A.}]$\frac{2 a s}{\left(s^{2}+a^{2}\right)^{2}}$
	\task[\textbf{B.}]$\frac{s^{2}-a^{2}}{\left(s^{2}+a^{2}\right)^{2}}$
	\task[\textbf{C.}]$\frac{1}{(s+a)^{2}}$
	\task[\textbf{D.}] $\frac{1}{\left(s^{2}+a^{2}\right)^{2}}$
\end{tasks}
\end{enumerate}
 \colorlet{ocre1}{ocre!70!}
\colorlet{ocrel}{ocre!30!}
\setlength\arrayrulewidth{1pt}
\begin{table}[H]
	\centering
	\arrayrulecolor{ocre}
	\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}
		\hline
		\multicolumn{4}{|c|}{\textbf{Answer key}}\\\hline\hline
		\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\hline
		1&\textbf{D} &2&\textbf{B}\\\hline
		3&\textbf{A} &4&\textbf{B} \\\hline
		5&\textbf{D} &6&\textbf{D} \\\hline

	\end{tabular}
\end{table}
\newpage
\begin{abox}
	Practise Set-3
\end{abox}
\begin{enumerate}[label=\color{ocre}\textbf{\arabic*.}]
	\item  Find the fourier series to represent the function $f(x)$ given by
	$$
	f(x)=\left[\begin{array}{ll}
	-k & \text { for }-\pi<x<0 \\
	k & \text { for } 0<x<\pi
	\end{array}\right.
	$$
	hence show that $1-\frac{1}{3}+\frac{1}{5}+\frac{1}{7}+\ldots \ldots=\frac{\pi}{4}$
	\begin{answer}
		Given function is odd in nature, so $a_{0}=0$ and $a_{n}=0$

		\begin{align*}
		b_{n} &=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin n x d x=\frac{1}{\pi}\left[\int_{-\pi}^{0}-k \sin n x d x+\int_{0}^{\pi} k \sin n x d x\right] \\
		&=\frac{1}{\pi} k\left\lbrace \left[ \frac{\cos n x}{n}\right] _{-\pi}^{0}-\left[ \frac{\cos n x}{n}\right] _{0}^{\pi}\right\rbrace  \\
		&=\frac{1}{\pi} k\left\lbrace \frac{1}{n}-\frac{(-1)^{n}}{n}-\frac{(-1)^{n}}{n}+\frac{1}{n}\right\rbrace =\frac{1}{\pi} k\left[\frac{2}{n}-\frac{2(-1)^{n}}{n}\right\rbrace \\
		\text{If $n$ is even}\ b_{n}&=0\\
	\text{	If $\mathrm{n}$ is odd }\ b_{n}&=\frac{4 k}{n \pi}\\
	f(x)&=\frac{4 k}{\pi} \sin x+\frac{4 k}{3 \pi} \sin 3 x+\frac{4 k}{5 \pi} \sin 5 x+\cdots\\
	f(x)&=\frac{4 k}{\pi}\left[\sin x+\frac{1}{3} \sin 3 x+\frac{1}{5} \sin 5 x+\ldots\right]\\
	\text { At}\ x&=\frac{\pi}{2} \\
	k&=\frac{4 k}{\pi} \left[  \sin \frac{\pi}{2}+\frac{1}{3} \sin \frac{3 \pi}{2} +\frac{1}{5} \sin \frac{5 \pi}{2}\right]   \\
	1&=\frac{4}{\pi}\left[1+\frac{1}{3}(-1)+\frac{1}{5}(1)+\frac{1}{7}(-1)+\ldots \cdots\right]\\&=\frac{4}{\pi}\left[1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\ldots . .\right] \\ \frac{\pi}{4}&=1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\ldots \ldots
		\end{align*}

	\end{answer}

\item Find the fourier series of the function defined as
$$
f(x)=\left\{\begin{array}{ll}
 \left.  \right. \ x+\pi, & \text { for } 0 \leq x \leq \pi \\
-x-\pi, & \text { for }-\pi \leq x<0
\end{array} \text { and } f(x+2 \pi)=f(x)\right.
$$
\begin{answer}
	\begin{align*}
		a_{0} &=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) d x=\frac{1}{\pi} \int_{-\pi}^{0} f(x) d x+\frac{1}{\pi} \int_{0}^{\pi} f(x) d x \\
		&=\frac{1}{\pi} \int_{-\pi}^{0}(-x-\pi) d x+\frac{1}{\pi} \int_{0}^{\pi}(x+\pi) d x\\&=\frac{1}{\pi}\left(-\frac{x^{2}}{2}-\pi x\right)_{-\pi}^{0}+\frac{1}{\pi}\left(\frac{x^{2}}{2}+\pi x\right)_{0}^{\pi} \\
		&=\frac{1}{\pi}\left(\frac{\pi^{2}}{2}-\pi^{2}\right)+\frac{1}{\pi}\left(\frac{\pi^{2}}{2}+\pi^{2}\right)\\&=\pi\left(\frac{1}{2}-1\right)+\pi\left(\frac{1}{2}+1\right)\\&=\pi
	\end{align*}
	\begin{align*}
		a_{n} &=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \cos n x d x\\&=\frac{1}{\pi} \int_{-\pi}^{0} f(x) \cos n x d x+\frac{1}{\pi} \int_{0}^{\pi} f(x) \cos n x d x \\
		&=\frac{1}{\pi} \int_{-\pi}^{0}(-x-\pi) \cos n x d x+\frac{1}{\pi} \int_{0}^{\pi}(x+\pi) \cos n x d x \\
		&=\frac{1}{\pi}\left[(-x-\pi) \frac{\sin n x}{n}-(-1)\left\{-\frac{\cos n x}{n^{2}}\right\}\right]_{-\pi}^{0}+\frac{1}{\pi}\left[(x+\pi) \frac{\sin n x}{n}-(1)\left\{-\frac{\cos n x}{n^{2}}\right\}\right]_{0}^{\pi}\\
		&=\frac{1}{\pi}\left[-\frac{1}{n^{2}}+\frac{(-1)^{n}}{n^{2}}\right]+\frac{1}{\pi}\left[\frac{(-1)^{n}}{n^{2}}-\frac{1}{n^{2}}\right]=\frac{2}{n^{2} \pi}\left[(-1)^{n}-1\right]\\
		&=\frac{-4}{n^{2} \pi}\quad \text{if $n$ is odd}\\
		&=0 \quad \text{if $n$ is even}
	\end{align*}
	\begin{align*}
		b_{n} &=\frac{1}{\pi} \int_{-\pi}^{\pi} f(x) \sin n x d x=\frac{1}{\pi} \int_{-\pi}^{0} f^{\prime}(x) \sin n x d x+\frac{1}{\pi} \int_{0}^{\pi} f(x) \sin n x d x \\
		&=\frac{1}{\pi} \int_{-\pi}^{0}(-x-\pi) \sin n x d x+\frac{1}{\pi} \int_{0}^{\pi}(x+\pi) \sin n x d x \\
		&=\frac{1}{\pi}\left[(-x-\pi)\left(\frac{-\cos n x}{n}\right)-(-1)\left(-\frac{\sin n x}{n^{2}}\right)\right]_{-\pi}^{0}+\frac{1}{\pi}\left[(x+\pi)\left(-\frac{\cos n x}{n}\right)-(1)\left(-\frac{\sin n x}{n^{2}}\right)\right]_{0}^{\pi} \\
		&=\frac{1}{\pi}\left[\frac{\pi}{n}\right]+\frac{1}{\pi}\left[-\frac{2 \pi}{n}(-1)^{n}+\frac{\pi}{n}\right]=\frac{1}{n}\left[(1)-2(-1)^{n}\right]=\frac{2}{n}\left[1-(-1)^{n}\right]\\
		&=\frac{4}{n}\quad \text{if $n$ is odd}\\
		&=0 \quad \text{if $n$ is even}
	\end{align*}
	The fourier series expansion of the function is
	\begin{align*}
	f(x)&=\frac{a_{0}}{2}+a_{1} \cos x+a_{2} \cos 2 x+\ldots+b_{1} \sin x+b_{2} \sin 2 x+\ldots \\
	f(x)&=\frac{\pi}{2}-\frac{4}{\pi}\left(\frac{\cos x}{1^{2}}+\frac{\cos 3 x}{3^{2}}+\ldots . .\right)+4\left(\frac{\sin x}{1}+\frac{\sin 3 x}{3}+\ldots\right)
	\end{align*}

\end{answer}
\item  Find the Fourier sine series for the function
$$
f(x)=e^{a x} \quad \text { for }-\pi \leq x \leq \pi
$$
where $a$ is constant.
\begin{answer}
	\begin{align*}
		\int e^{a x} \sin b x d x&=\frac{e^{a x}}{a^{2}+b^{2}}[a \sin b x-b \cos b x] \\
		b_{n}&=\frac{2}{\pi} \int e^{a x} \sin n x d x \\
		&=\frac{2}{\pi}\left[\frac{e^{a x}}{a^{2}+n^{2}}(a \sin n x-n \cos n x)\right]_{0}^{\pi} \\
		&=\frac{2}{\pi}\left[\frac{e^{a \pi}}{a^{2}+n^{2}}(a \sin n \pi-n \cos n \pi)+\frac{n}{a^{2}+n^{2}}\right] \\
		&=\frac{2}{\pi}\left(\frac{n}{a^{2}+n^{2}}\right)\left[-(-1)^{n} e^{a \pi}+1\right]\\&=\frac{2 n}{\left(a^{2}+n^{2}\right) \pi}\left[1-(-1)^{n} e^{a \pi}\right] \\\\
		b_{1}&=\frac{2\left(1+e^{a \pi}\right)}{\left(a^{2}+1^{2}\right) \pi} \quad ; \quad b_{2}=\frac{2 \cdot 2 \cdot\left(1-e^{a \pi}\right)}{\left(a^{2}+2^{2}\right) \pi} \\\\
		e^{a x}&=\frac{2}{\pi}\left[\frac{1+e^{a \pi}}{a^{2}+1^{2}} \sin x+\frac{2\left(1-e^{a \pi}\right)}{a^{2}+2^{2}} \sin 2 x+\ldots .\right]
	\end{align*}
\end{answer}
\item Obtain the half range cosine series for $\mathrm{f}(\mathrm{x})=(\mathrm{x}-2)^{2}$ in the interval $(0,2)$.
\begin{answer}
	$f(x)=(x-2)^{2}$
	We know that the Fourier half range cosine series is
	$$
	f(x)=\frac{a_{0}}{2}+\sum_{n=1}^{\infty} a_{n} \cos \frac{n x \pi}{l}
	$$

	\begin{align*}
	\text { Where } \\
	a_{0}&=\frac{2}{l} \int_{0}^{l} f(x) d x \\
	a_{n}&=\frac{2}{l} \int_{0}^{l} f(x) \cos \frac{n \pi x}{l} d x
	\end{align*}

	Here $l=2$
	\begin{align*}
	a_{0}&=\frac{2}{2} \int_{0}^{2}(x-2)^{2} d x=\left[\frac{(x-2)^{3}}{3}\right]_{0}^{2}\\
	&=\left[0-\frac{(-2)^{3}}{3}\right]=\frac{8}{3} \\
	a_{0}&=\frac{8}{3}\\
	a_{n}&=\frac{2}{2} \int_{0}^{2}(x-2)^{2} \cos \frac{n \pi x}{2} d x \\
	a_{n}&=\left[(x-2)^{2}\left(\frac{\sin \frac{n \pi x}{2}}{\frac{n \pi}{2}}\right)-2(x-2)\left(\frac{-\cos \frac{n \pi x}{2}}{\frac{n^{2} \pi^{2}}{2^{2}}}\right)+2\left(\frac{-\sin \frac{n \pi x}{2}}{\frac{n^{3} \pi^{3}}{2^{3}}}\right)\right]_{0}^{2} \\
	a_{n}&=\left[0+0-2 \frac{8}{n^{3} \pi^{3}} \sin n \pi-0-2(-2) \frac{4}{n^{2} \pi^{2}}+0\right] \\
	a_{n}&=\frac{8}{n^{2} \pi^{2}}
	\end{align*}

	$$
	\begin{array}{l}
	f(x)=\frac{8}{2 x^3}+\sum_{n=1}^{\infty} \frac{8}{n^{2} \pi^{2}} \cos \frac{n x \pi}{2} \\\\
	f(x)=\frac{4}{3}+\frac{8}{\pi^{2}} \sum_{n=1}^{\infty} \frac{1}{n^{2}} \cos \frac{n x \pi}{2}
	\end{array}
	$$
\end{answer}
\end{enumerate}


\documentclass[12pt]{amsart}
\usepackage{amssymb,amsmath}
\usepackage{graphicx}
\usepackage{geometry} % see geometry.pdf on how to lay out the page. There's lots.
\geometry{a4paper} % or letter or a5paper or ... etc
% \geometry{landscape} % rotated page geometry

\newcommand{\bigzero}{\mbox{\normalfont\Large\bfseries 0}}
\newcommand{\rvline}{\hspace*{-\arraycolsep}\vline\hspace*{-\arraycolsep}}

% See the ``Article customise'' template for come common customisations

\title{Visualizing Grover's Search Algorithm}
\author{James Weaver \& Paul Kassebaum}
\date{} % delete this line to display the current date

%%% BEGIN DOCUMENT
\begin{document}

\maketitle

\section{Oracle operators}

If we want an operator $U_x$ with the following behavior

\begin{equation}
	\begin{split}
		U_x |x\rangle & = - |x\rangle \\
		U_x |x_\perp\rangle & = |x_\perp\rangle
	\end{split}
\end{equation}

where all $|x_\perp\rangle$ are orthogonal to $|x\rangle$, then the operator takes the form

\begin{equation}
	U_x = I - 2 |x\rangle\langle x|
\end{equation}

Let's demonstrate this with a couple of examples.

\begin{equation}
	\begin{split}
		U_x |x\rangle & = (I - 2 |x\rangle\langle x| ) |x\rangle \\
		& = |x\rangle - 2 |x\rangle\langle x | x\rangle \\
		& = |x\rangle - 2 |x\rangle \\
		& = - |x\rangle
	\end{split}
\end{equation}

because $\langle x | x\rangle = 1$.

\begin{equation}
	\begin{split}
		U_x |x_\perp\rangle & = (I - 2 |x\rangle\langle x| ) |x_\perp\rangle \\
		& = |x_\perp\rangle - 2 |x\rangle\langle x | x_\perp\rangle \\
		& = |x_\perp\rangle - 2 \langle x | x_\perp\rangle  |x_\perp\rangle \\
		& = |x_\perp\rangle
	\end{split}
\end{equation}

because $\langle x | x_\perp\rangle = 0$.

Now let's look at the result of acting on an arbitrary state $|\alpha\rangle$, that is not completely orthogonal to $|x\rangle$.

\begin{equation}
	\begin{split}
		U_x |\alpha\rangle & = (I - 2 |x\rangle\langle x| ) |\alpha\rangle \\
		& = |\alpha\rangle - 2 |x\rangle\langle x | \alpha\rangle \\
		& = (1 - 2 \langle x | \alpha\rangle)  |\alpha\rangle \\
	\end{split}
\end{equation}

In words, the result is the original state vector minus twice the overlap or projection of $|\alpha\rangle$ on $|x\rangle$. We can draw this out geometrically.
\begin{figure}[h]
   \centering
   \includegraphics[width=0.5\textwidth]{./img/fig-00} % requires the graphicx package
   \caption{Geometric demonstration that the operator $U_x$ has the effect of reflecting $|\alpha\rangle$ across $|x_\perp\rangle$, the vector orthogonal to $|x\rangle$.}
   \label{fig:example}
\end{figure}

\section{Symmetries of a single qubit system}
A single qubit's state $|s\rangle$

\begin{equation}
	|s\rangle = (a+ib)|0\rangle + (c + id)|1\rangle
\end{equation}

written in terms of the 4 real numbers $a,b,c,d$ can be fully described by 3 real numbers, since the state must be normalized,

\begin{equation}
	\langle s | s\rangle = a^2 + b^2 + c^2 + d^2 = 1,
\end{equation}

which makes one of the real numbers dependent on the other three.

A single qubit's rotational symmetries can be described by the matrices

\begin{equation}
	\begin{pmatrix}
		a + i b & -(c - id) \\
		c + id & -(a + i b)
	\end{pmatrix}
\end{equation}

where $a,b,c,d$ are real numbers. The normalization condition on the state of the qubit requires that the determinant of this matrix be 1.

Another way to describe a single qubit's rotational symmetries is by the quaternion:

\begin{equation}
	a +bi + cj + dk
\end{equation}

where the real numbers $a,b,c,d$ of the matrix and quaternion are equal respectively. The determinant of the matrix is the norm of the corresponding quaternion. Since the matrix has determinant 1 as a consequence of the normalization condition of the qubit's state, the corresponding quaternion has norm 1.

\section{Symmetries of a two qubit system}

A system of two qubits can be described by $2\times3 = 6$ real numbers. The system transforms as the tensor product of two independent matrices that each describe a single qubit, as explained above.

\begin{equation}
	\begin{pmatrix}
  \begin{matrix}
  i a & -\bar{z} \\
  z & - i a
  \end{matrix}
  & \rvline & \bigzero \\
\hline
  \bigzero & \rvline &
  \begin{matrix}
  i b & -\bar{w} \\
  w & -i b
  \end{matrix}
\end{pmatrix}
\end{equation}

where $a,b$ are real numbers and $z,w$ are complex numbers. The numbers $a,z,b,w$ are made up of 6 independent real numbers. Each of the two block matrices can be related to independent quaternions.

The dynamics of a two qubit system can be thought of geometrically in 4D euclidean space where each of the two quaternions is acted upon independently by operators associated with each spin respectively.

\end{document}


\chapter{Luminosity Calculation}
\label{lumi}

The probability of n interactions per bunch crossing is ( because a collision is a random process, the distribution will follow Poisson statistics.
\begin{equation}
P = \frac{\mu^{N}}{N!} \times e^{-\mu}
\end{equation}
The probability of at least one bunch crossing is
\begin{equation}
P = 1 -  e^{-\mu}
\end{equation}
The average number of bunch crossings, $\mu$, is defined as
\begin{equation}
\mu = \frac{\mathcal{L} \times \sigma_{\rm{eff}}}{f_{\rm{beam}}}
\end{equation}
Thus, the luminosity can be written as
\begin{equation}
\mathcal{L} = - \frac{f_{\rm{beam}}}{\sigma_{\rm{eff}}} \rm{ln}(1-P(n>0))
\end{equation}
By recording the number of bunch crossings without an inelastic collision, the luminosity can be calculated.


\chapter{Introduction}
In this course we will be concerned with ordinary differential equations, ODEs.

\begin{defin}
An ordinary differential equation (ODE) is a differential equation containing one or more functions of \underline{\textbf{exactly one}} independent variable and its derivatives.
\end{defin}

ODEs relate the change of one variable to changes in another variable and can be used to model and understand a wide variety of phenomena, such as projectile motion, animal population interactions and the progression of chemical reactions.

In these notes we consider two important aspects in the theory of ordinary differential equations. Specifically, we seek to
\begin{enumerate}
\item develop methods of modelling physical phenomena;
\item understand the properties of the equations without explicitly solving them.
\end{enumerate}

Point 2 may seem counter-intuitive as we have a variety of techniques that enable us to solve ODEs in closed form. Further, even if an explicit solution is not available, we can use numerical simulations to illustrate the dynamics of the ODEs. However, direct solutions are not always possible and, even when they are, they may not always enable clear interpretations and understanding of the underlying system. Equally, our analytical techniques will give us confidence in the solutions produced by numerical software.

Critically, what we gain in analytical specificity, we lose in global accuracy. Namely, we are going to learn techniques that will allow us to rigorously examine small regions of the ODE space at the expense of losing knowledge of the global dynamics. However, by the end of the course we will be able to patch together multiple parts of the local analysis in order to give us an approximate understanding of the entire dynamical system.

\section{Preliminary definitions}
We will be considering the rate of change of a variable, $u$, with respect to another variable, $t$. This dependence will be denoted
\bb
u(t).
\ee
Here, $u$ is a scalar function (\ie one-dimensional), but more generally, we will be considering systems of variables
\bb
\bm{u}(t)=\l u_1(t),u_2(t),\dots,u_k(t)\r.
\ee
On the board we will usually write bold symbols with an underline\footnote{I was once told that we use underlines to illustrate bold variables because when typesetting a document an underline would tell the printer that that symbol needed to be bold. However, if this is true, how did the writer indicate that they wanted a symbol underlined?} as it is easier to see, thus, $\bm{u}=\underline{u}$.

The values of $u$ or $\bm{u}$ define quantities of interest. For example they could be an animal population density, a distance or a speed. Further, $t$ can be any variable which these quantities are dependent on. Generally, however, we will take $t$ to be time and we will be considering how these values temporally evolve.

In order to link the changes in these quantities we define a system of ODEs in the most general way possible,
\bb
\bm{F}\l t,\bm{u},\frac{\rd \bm{u}}{\rd t},\frac{\rd^2 \bm{u}}{\rd t^2},\dots,\frac{\rd^n \bm{u}}{\rd t^n}\r=0,
\ee
with initial condition given by
\bb
\bm{u}(0)=\bm{u}_0.
\ee
Note that the initial condition is kept general as we will usually be interested in how the dynamics of the system change for different starting points.

\begin{example}[frametitle=Bacteria population growth]
\label{Expo_growth}
\COL{In this case we are only considering one population, thus, $\bm{u}=u$ and we specify $u(t)$ to be the population of E.Coli at time $t$. Initially, the population is $u_0$ and resources are abundant, thus, each E.Coli is able to double itself at a rate $r$/s. Explicitly, the population grows at a rate proportional to the population already present, \ie
\bb
\frac{\rd u}{\rd t}=ru.
\ee
This equation can be trivially solved to give
\bb
u(t)=u_0\exp(rt),\label{Intro_exp}
\ee
see \fig{Exponential}.

Note instead of specifying the time at which a population takes an arbitrary value, we can consider the more general time scale of how long does it take the population to double? Namely, at what point, $t_2$, is $u(t_2)=2u_0$. Rearranging \eqn{Intro_exp} we derive that
\bb
t_2=\frac{1}{r}\log\l 2\r.
\ee

Critically, once a model is constructed and an answer is found, we must consider whether if it is a good model or not. Clearly this model has problems because it predicts the population will grow exponentially quickly, without bound. The key problematic assumption that we have made is that the resources (\eg space, nutrients, etc.) do not run out. Although this may be a fine assumption to begin with, eventually the bacteria will be limited by competition.}
%\begin{figure}[!!!h!!!tb]
{\centering
\includegraphics[width=\textwidth]{../Pictures/Bacteria.png}}
%\end{figure}
\end{example}

\begin{example}[frametitle=Bacteria and nutrient populations.]\label{Logi_growth}
\COL{Imagine a case similar to the one above, but we introduce a nutrient population, $v$. We assume that a bacterium can divide at a rate $r$ if and only if it can interact with enough nutrient. However, the nutrient is depleted at a rate $r$ as the bacteria interacts with it.

Here, the equation governing this system is going to be provided. However, later on we will learn how to write down and interpret interaction equations of the form
\bb
u+v \stackrel{r}{\longrightarrow} 2u.
\ee

The governing equations are
\begin{align}
\frac{\rd u}{\rd t}&=ruv,\quad u(0)=u_0,\label{Pop_u}\\
\frac{\rd v}{\rd t}&=-ruv,\quad v(0)=v_0.
\end{align}}
\COL{We notice that we can add the two equations and integrate to provide a conserved quantity,
\bb
u+v=c.\label{Conserved_c}
\ee
We can substitute \eqn{Conserved_c} into \eqn{Pop_u} to get
\bb
\frac{\rd u}{\rd t}=ru(c-u).\label{Log_1}
\ee
This is known as the logistic equation and we will see it many times throughout these notes, it is a simple example of competition between species for resources.}

\COL{Using partial fractions, we can directly solve \eqn{Log_1}. Specifically,
\begin{align}
\frac{\rd u}{\rd t}&=rcu\l 1-\frac{u}{c}\r,\nonumber\\
\Rightarrow\int_0^T\frac{\rd u}{u(1-u/c)}&=\int_0^Trc \rd t,\nonumber\\
\Rightarrow\int_0^T \frac{1}{u}+\frac{1/c}{1-u/c}  \rd u&=rcT,\nonumber\\
\Rightarrow\left[\ln(u)-\ln\l 1- \frac{u}{c} \r \right]^T_0&=rcT,\nonumber\\
\Rightarrow\ln\l\frac{u}{1- \frac{u}{c}} \r-\ln\l\frac{u_0}{1- \frac{u_0}{c}} \r&=rcT,\nonumber\\
\Rightarrow u(T)=\frac{c}{1+\frac{c-u_0}{u_0}\exp\l{-rcT}\r},
\end{align}
see \fig{Logistic}.

Comparing the models of bacteria growth, illustrated in \fig{Growth_examples}, we see that \eqn{Log_1} is a more realistic model for growth because there is a maximum population value which can be supported by the experiment. This maximum value is given by $c$ and is known as the carrying capacity. The parameter grouping $rc$ is also important as this control the time scale over which this maximum is obtained.}
\end{example}
\begin{figure}[!!!h!!!tb]
{\centering
\subfigure[\label{Exponential}]{\includegraphics[width=\ttp]{../Pictures/Exponential.png}}
\subfigure[\label{Logistic}]{\includegraphics[width=\ttp]{../Pictures/Logistic.png}}
\caption{(a) Exponential growth. Parameters are $r=u_0=0.1$. See example \ref{Expo_growth}. (b) Logistic growth. Parameters are $c=10$, $r=u_0=0.1$. See example \ref{Logi_growth}.}\label{Growth_examples}}
\end{figure}

\begin{example}[frametitle=Duffing's equations.]\label{Duffing_example}
For our last example, consider the Duffing oscillator. The equation is simply a toy example that can be used to examine complex phenomena in a simple equation. In terms of interpretation, you can think of the equation as modelling the displacement of a beam near two magnetics. Critically, the beam and magnets are being forced to oscillate with amplitude $\gamma$ and frequency $\omega$ \see{Duffing_beam}.
\bb
\underbrace{\frac{\rd^2 x}{\rd t^2}}_{\textrm{Acceleration}}+\underbrace{2\delta\frac{\rd x}{\rd t}}_{\textrm{Air resistance}}+\underbrace{\beta x+\alpha x^3}_{\textrm{Beam's restorative force}}=\underbrace{\gamma\cos(\omega t)}_{\textrm{Forcing term}}.\label{Duffing_eqn}
\ee

We are not going to try and analytically solve or analyse Duffing's equation. Instead, we illustrate the dynamics that the equation produces as the amplitude of oscillation, $\gamma$, increases. Specifically, as $\gamma$ is increased the system becomes chaotic \see{Duffing_equation}.
\end{example}
\begin{figure}[!!!h!!!tbp]
\centering
\subfigure[\label{Duffing_beam}]{\includegraphics[width=.3\textwidth]{../Pictures/Duffing_beam.png}}
\subfigure[\label{Duffing_equation}]{\includegraphics[width=\textwidth]{../Pictures/Duffing.png}}
\caption{\label{Duffing}(a) Schematic diagram of the system underlying Duffing's equation. (b) Three simulations of \eqn{Duffing_eqn} with increasing values of $\gamma$.}
\end{figure}

\begin{defin}
The \textbf{order} of a differential equation is the value of the highest derivative in the equation.
\end{defin}
Examples \ref{Logi_growth} and \ref{Expo_growth} are both first order equations, whilst example \ref{Duffing_example} is a second order equation. Generally (like polynomial equations of order) a differential equation of order $n$ will have $n$ linearly independent solutions.

\begin{defin}
A system of differential equations is \textbf{autonomous} if the system does not explicitly depend on the independent variable.
\end{defin}
When the variable is time, they are also called time-invariant systems, this simply means that we are assuming that the defined underlying laws of the system are identical to those for any point in the past, or future.

\begin{defin}
To save time we use a dot or prime mark to denote a derivative with respect to the argument, thus,
\bb
\dot{\bm{u}}(t)=\bm{u}'(t)=\frac{\rd \bm{u}}{\rd t}.
\ee
\end{defin}
Traditionally, dots are primarily used when the variable is time and primes are used otherwise. Note that higher orders derivatives are signified by the appropriate number of dots or primes. Namely, a second derivative would be denoted by two dots or primes, etc.

\begin{defin}
A \textbf{trajectory} is a solution, $u(t)$.
\end{defin}
The graphs in \figs{Growth_examples}{Duffing} illustrate single trajectories of their respective systems.

In this course we are going to occupy ourselves with systems of autonomous first order equations, of the form
\bb
\frac{\rd \bm{u}}{\rd t}=\dot{\bm{u}}=\bm{F}(\bm{u}).\label{ODE}
\ee
This may seem highly restrictive. However, systems of first order equations can have extremely complicated properties, such as oscillations and chaos, which we will try to understand.

\COL{Critically, equations of higher order can be written as a system of first order equations. For example, if
\bb
\bm{G}\l \bm{u},\frac{\rd \bm{u}}{\rd t},\frac{\rd^2 \bm{u}}{\rd t^2},\dots,\frac{\rd^n \bm{u}}{\rd t^n}\r=0
\ee
then we can define $n-1$ new equations of the form $\bm{v}_1=\rd \bm{u}/\rd t$ and $\bm{v}_i=\rd \bm{v}_{i-1}/\rd t=\rd^{i} \bm{u}/\rd t^{i}$ for $2\leq i \leq n-1$ to produce the first order system
\begin{align}
&\bm{G}\l \bm{u},\bm{v}_1,\dots,\bm{v}_{n-1},\frac{\rd \bm{v}_{n-1}}{\rd t}\r=0,\\
&\frac{\rd \bm{u}}{\rd t}=\bm{v}_1,\\
&\vdots\nonumber\\
&\frac{\rd \bm{v}_{n-2}}{\rd t}=\bm{v}_{n-1}.
\end{align}}
\begin{example}[frametitle=Duffing's equations without forcing.]\label{Duffing_example2}
\COL{Setting $\gamma=0$ in Duffing's equation and letting
\bb
v=\frac{\rd x}{\rd t}
\ee
then we are able to convert the single second order equation seen in \eqn{Duffing_equation} to two first}\COL{ order ODEs,
\begin{align}
\frac{\rd v}{\rd t}&=-2\delta v-(\beta x+\alpha x^3)\\
\frac{\rd x}{\rd t}&=v.
\end{align}
Note that $v$ is an apt variable name for the variable, because, as discussed in example \ref{Duffing_example}, $x$ can be thought of as position, making $v$ a velocity.}
\end{example}
\begin{thm}
A solution trajectory, $\bm{u}(t)$, of \eqn{ODE} cannot self-intersect \see{Trisectrix}.
\end{thm}
\begin{proof}
\COL{Suppose there is an intersection. Hence, there exist two points, $t_1$ and $t_2$, such that $\bm{u}(t_1)=\bm{u}(t_2)$ then we will also have that $\bm{F}(\bm{u}(t_1))=\bm{F}(\bm{u}(t_2))$. However, the curves intersect, thus, the curves must be travelling in different directions at $t_1$ and $t_2$ \see{Intersect}, meaning that the derivatives are different there, \ie $\dot{\bm{u}}(t_1)\neq\dot{\bm{u}}(t_2)$. But
\bb
\dot{\bm{u}}(t_1)=\bm{F}(\bm{u}(t_1))=\bm{F}(\bm{u}(t_2))=\dot{\bm{u}}(t_2),
\ee
which produces a contradiction. Hence the curves cannot intersect.}
\end{proof}
\begin{figure}[!!!h!!!tb]
\centering
\includegraphics[width=\ttp]{../Pictures/Trisectrix.png}
\caption{\label{Trisectrix} A solution of \eqn{ODE} cannot look like this.}
\end{figure}

\subsection{Existence and uniqueness}
With this being an applied mathematics course we are often very `fast and loose' with our rigour. However, it is good to know that theorems have been proven regarding the existence and unique of solution to \eqn{ODE}. Here we will quote the theorem in one dimension, but the theorem can be expanded to any number of variables.
\begin{thm}Existence-Uniqueness theorem.

Suppose the function $F(u)$ is differentiable and the derivative, $F'(u)$, is continuous for all values of $u$ then there will exist some constant $c>0$ such that
\bb
\dot{u}=F(u),\quad u(t_0)=u_0,
\ee
has a solution and it is guaranteed to exist and be unique in some finite time interval $|t-t_0|<c$.\label{Existence_Uniqueness}
\end{thm}
Note that:\COL{
\begin{itemize}
\item we will not consider the proof here. For those who are interested look up ``Picard's theorem''. Picard's theorem is actually weaker than the one specified above, but theorem \ref{Existence_Uniqueness} expresses the statement in the most useful form for us.
\item in many cases solutions will exist and be unique for all time, but, the theorem hardly ever provides an optimal value for $c$. However, the theorem is general enough to include cases where `blow up' occurs. Namely, blow up occurs when a solution tends to infinity in finite time.
\item without loss of generality we can always take $t_0=0$ (why?). \textbf{This is only true in autonomous systems}.
\item solution curves cannot intersect, otherwise there would be two different solutions going through the same point and there would not be uniqueness around the intersection \see{Intersect}.
\item the case for higher dimensional systems is effectively the same except we need the function
\bb
\bm{F}(\bm{u})=\left(
\begin{array}{c}
{F_1}(u_1,u_2,u_3,\dots,u_n)\\
{F_2}(u_1,u_2,u_3,\dots,u_n)\\
\vdots\\
{F_n}(u_1,u_2,u_3,\dots,u_n)
\end{array}
\right)
\ee to be continuous in all of its derivatives.
\end{itemize}}
\begin{figure}[!!!h!!!tb]
\centering
\includegraphics[width=\ttp]{../Pictures/Intersection.png}
\caption{\label{Intersect}Two different solution curves of a one-dimensional ODE cannot intersect.}
\end{figure}

\begin{defin}\label{Monotonic_def}
A differentiable function is \textbf{monotonic} if its derivative never changes sign. Moreover, the function is monotonically increasing (decreasing) if the derivative is positive (negative).
\end{defin}
\begin{defin}\label{Strict_monotonic_def}
A differentiable function is \textbf{strictly monotonic} if its derivative never changes sign and is never zero.
\end{defin}
See \fig{Monotonics} for examples of definitions \ref{Monotonic_def} and \ref{Strict_monotonic_def}.
\begin{figure}[!!!h!!!tb]
\centering
\subfigure[\label{Non_monotonic}]{\includegraphics[width=\tttp]{../Pictures/Non_monotonic.png}}
\subfigure[\label{Monotonic}]{\includegraphics[width=\tttp]{../Pictures/Monotonic.png}}
\subfigure[\label{Strictly_monotonic}]{\includegraphics[width=\tttp]{../Pictures/Strictly_monotonic.png}}
\caption{\label{Monotonics}(a)\COL{ A non-monotonic function.} (b) \COL{A monotonic function.} (c) \COL{A strictly monotonic function.}}
\end{figure}

\begin{cor}
Suppose $F(u)$ is a scalar function that is continuously differentiable. The solution, $u(t)$, of the one dimensional ODE,
\bb
\dot{u}=F(u),\quad u(t_0)=u_0,
\ee
cannot oscillate. Specifically, $u(t)$ must either be constant, or a monotonically increasing, or decreasing function.
\end{cor}
\begin{proof}
\COL{Suppose that $u^*(t)$ is non-monotonic. By definition its derivative changes sign. By continuity there is somewhere, $t_c$, such that $\rd u^*(t_c)/\rd t=0$.
Thus, $u^*$ is a solution of
\bb
\dot{u^*}=F(u^*),\quad u^*(t_c)=u^*_c.\label{Starred}
\ee
Let us construct the constant function $u\equiv u^*_c$. We note that, $F(u^*(t_c))=0$ and, thus,  $u$ is also a solution to \eqn{Starred}. However, this means that we have two different solutions to \eqn{Starred} violating theorem \ref{Existence_Uniqueness}. By contradiction $u^*(t)$ has to be monotonic.}
\end{proof}
This means that to have oscillatory phenomena in a system either we need more than one population, or the system has to be non-autonomous. See example \ref{Duffing_example} for a case where both of these factors are present and do indeed produce oscillations (and chaos).

\section{Taylor expansions}
This section is to remind you of the Taylor expansion technique. The Taylor expansion is one of the most powerful tools for an applied mathematician because very often we want to know what happens to a trajectory near some critical point. Although the kinetics maybe very non-linear and difficult to understand globally we can use the Taylor expansion to simplify the dynamics in a small region around the critical point in order to gain knowledge about the dynamics in this region.

\begin{thm}\label{Taylor}
Suppose $f(x)$ is infinitely differentiable at a point $a$ then the Taylor series of $f$ at $a$ is the power series
\bb
f(x)=\sum _{n=0}^{\infty }{\frac{f^n(a)}{n!}(x-a)^n},
\ee
which is explicitly
\bb
f(x)=f(a)+{\frac {f'(a)}{1!}}(x-a)+{\frac {f''(a)}{2!}}(x-a)^{2}+{\frac {f'''(a)}{3!}}(x-a)^{3}+\cdots,
\ee
where $n!$ denotes the factorial of $n$ and $f^{(n)}(a)$ denotes the $n^{th}$ derivative of $f$ evaluated at the point $a$. The derivative of order zero of $f$ is defined to be $f$ itself and $(x-a)^0$ and $0!$ are both defined to be 1.
\end{thm}
\begin{example}[frametitle=Taylor expansions.]
\begin{itemize}
\item $\exp(x)$ at $x=0$ \see{Taylor_approximations}.
\COL{
\bb
\exp(x)=1+x+{\frac {1}{2}}{x}^{2}+{\frac {1}{6}}{x}^{3}+O \left( {x}^{4}
 \right) .
 \ee}
\item $\cos(x)$ at $x=0$.
\COL{
\bb
\cos(x)=1-{\frac {1}{2}}{x}^{2}+O \left( {x}^{4} \right) .
\ee}
\item $1/\l 1+x\r$ at $x=0$
\COL{
\bb
\frac{1}{1+x}=1-x+{x}^{2}-{x}^{3}+O \left( {x}^{4} \right) .
\ee}
\item $\sin(x)$ at $x=\pi/2$.
\COL{
\bb
\sin(x)=1-{\frac{1}{2}} \left( x-{\frac {\pi}{2}} \right) ^{2}+O \left(
 \left( x-{\frac {\pi}{2}} \right) ^{4} \right)  .
\ee}
\end{itemize}
\end{example}
\begin{figure}[!!!h!!!tb]
\centering
\includegraphics[width=\textwidth]{../Pictures/Taylor_approximations.png}
\caption{\label{Taylor_approximations} Approximating the exponential function with different orders of Taylor series.}
\end{figure}

\COL{Although Theorem \ref{Taylor} is the most general form of Taylor's theorem we are frequently going to want to know what happens near a specific point. Namely, if $x$ is the point of interest, what does the function look like at $x+\epsilon$, where $\epsilon \ll 1$. Specifically, this simply comes down to redefining $x\coloneqq x+\epsilon$ and $a\coloneqq x$ in Theorem \ref{Taylor}, namely
\bb
f(x+\epsilon)=f \left( x \right) +\epsilon{\frac {\rm d}{{\rm d}x}}f \left( x \right)
+{\frac {{\epsilon}^{2}}{2}{\frac {{\rm d}^{2}}{{\rm d}{x}^{2}}}f \left( x
 \right) }+{\frac {{\epsilon}^{3}}{6}{\frac {{\rm d}^{3}}{{\rm d}{x}^{
3}}}f \left( x \right) }+O \left( {\epsilon}^{4}
 \right).
\ee}\COL{
Since $\epsilon\ll 1$ we can truncate this series to obtain a good estimate after only a first term in $\epsilon$,
\bb
f(x+\epsilon)\approx f \left( x \right) +\epsilon{\frac {\rm d}{{\rm d}x}}f \left( x \right).
\ee
This is known as linearisation. You are taking the (possibly complicated) function $f$ and rewriting it as a linear function in $\epsilon$.}

Courses in the third year will deal with what information you get in the case that you truncate at $\epsilon^2$, or higher. This is non-linear analysis.

\subsection{Multivariate Taylor expansion}
A similar theorem can be stated when the function $f$ has more than one argument.
\begin{defin}
If $f$ is a function of more than one variable it is called \textbf{multivariate}.
\end{defin}

\COL{Here we simply state the expansion to first order expansion that we will be concerned with throughout the course.
\bb
f(x+\epsilon_1,y+\epsilon_2)\approx f(x,y)+\epsilon_1 f_x+\epsilon_2 f_y,
\ee
where we observe that we have used a subscript $f_x$ to denote the partial derivative $\partial f/\partial x$ and similarly for $f_y$.}
\begin{defin}
For brevity we use subscripts to stand for partial derivatives,
\bb
f_{x_1x_2\dots x_n}=\frac{\partial^n f}{\partial x_1\partial x_2\dots\partial x_n}.
\ee
\end{defin}
\begin{example}[frametitle=Multivariate Taylor expansion.]
\begin{itemize}
\item $\sin(x+y)$ at $x=y=0$.
\COL{
\bb
\sin(x+y)\approx x+y.
\ee}
\item $\sin(x)\cos(y)$ at $x=y=0$.
\COL{
\bb
\sin(x)\cos(y)\approx x.
\ee}
\end{itemize}
\end{example}

\section{Polar coordinates}
Many phenomena that we will model will fall under the consideration of spatial movement, for example in Chapter \ref{How to model a system} and question sheet two we will be considering planetary movement. Critically, in many of these cases the objects tend to move in circular trajectories orbiting a single point. Thus, it is more natural to use polar coordinates $(r,\theta)$ to describe the motion, rather than Cartesian coordinates $(x,y)$ \see{Polars}. However, it may be easier to model the system in Cartesian coordinates. Thus, we need to know how to convert between one set and another.
\begin{figure}[h!!!tb]
\centering
\includegraphics[width=\ttp]{../Pictures/Polars.png}
\caption{\label{Polars} Cartesian and polar coordinates.}
\end{figure}

\fig{Polars} illustrates the fundamental relationships between the Cartesian and the polar coordinates, namely:
\begin{align}
x=r\cos(\theta),\\
y=r\sin(\theta).
\end{align}
Critically, these specify $x$ and $y$ singly as functions $(r,\theta)$. These, in turn, can be used to construct equations for $r$ and $\theta$ separately as functions of $(x,y)$, namely,
\bb
r^2=x^2+y^2,
\ee
and
\bb
\theta=\arctan\l\frac{y}{x}\r,\quad \textrm{or}\quad\theta=\arccos\l\frac{x}{\sqrt{x^2+y^2}}\r,\quad \textrm{or}\quad\theta=\arcsin\l\frac{y}{\sqrt{x^2+y^2}}\r.\label{theta_eqns}
\ee
where the appropriate function $\theta(x,y)$ is chosen depending on which ever is easiest to use.

\begin{example}[frametitle=Cartesian to polar conversion.]
\COL{Suppose
\begin{align}
\dot{x}&=f(x,y),\\
\dot{y}&=g(x,y)
\end{align}
how do we convert the system from Cartesian coordinates to polar coordinates?

First we use the condition that $r^2=x^2+y^2$. Taking derivatives we get
\bb
2r\dot{r}=2x\dot{x}+2y\dot{y}.
\ee
At which point we can exchange all Cartesian coordinates for their polar analogues, namely:
\bb
\dot{r}=\cos(\theta)f(r\cos(\theta),r\sin(\theta))+\sin(\theta)g(r\cos(\theta),r\sin(\theta)).
\ee
Next we need $\dot{\theta}$. Since there are multiple (equivalent) ways of representing $\theta$ there are multiple (equivalent) forms of the derivative, here only one will be presented. Other forms follow exactly the same procedure. We note that
\bb
\dot{x}=f(r\cos(\theta),r\sin(\theta))=\frac{\rd \l r\cos(\theta)\r}{\rd t}=\dot{r}\cos(\theta)-r\sin(\theta)\dot{\theta}.\label{xdot_to_r}
\ee
}\COL{Rearranging \eqn{xdot_to_r} gives
\begin{align}
\dot{\theta}&=\frac{\cos(\theta)^2f+\sin(\theta)\cos(\theta)g-f}{r\sin(\theta)},\\
&=\frac{-\sin(\theta)f+\sin(\theta)\cos(\theta)g}{r\sin(\theta)},\\
&=\frac{\cos(\theta)g-f\sin(\theta)}{r}.
\end{align}
where the arguments of $f$ and $g$ have been suppressed for brevity.}
\end{example}

In the above example we created $\dot{r}$ first and then used this to produce $\dot{\theta}$. In following example we show how to do the substitution all in one go.
\begin{example}[frametitle= A quicker conversion]
\COL{From
\begin{align}
x=r\cos(\theta),\\
y=r\sin(\theta).
\end{align}
we generate
\begin{align}
&\dot{x}=f(x,y)=\dot{r}\cos(\theta)-r\sin(\theta)\dot{\theta},\\
&\dot{y}=g(x,y)=\dot{r}\sin(\theta)+r\cos(\theta)\dot{\theta}.
\end{align}
This can be seen as a set of simultaneous equations and, thus, solved as a matrix problem
\bb
\colvec{2}{f}{g}=\begin{pmatrix}
\cos(\theta)& -r\sin(\theta) \\
\sin(\theta) & r\cos(\theta)
\end{pmatrix}
\colvec{2}{\dot{r}}{\dot{\theta}}.
\ee
The matrix can be inverted to produce
\bb
\frac{1}{r}\begin{pmatrix}
r\cos(\theta)& r\sin(\theta) \\
-\sin(\theta) & \cos(\theta)
\end{pmatrix}\colvec{2}{f}{g}=
\colvec{2}{\dot{r}}{\dot{\theta}},
\ee
which allows us to reproduce
\bb
\dot{r}=\cos(\theta)f+\sin(\theta)g.
\ee
\bb
\dot{\theta}=\frac{\cos(\theta)g-f\sin(\theta)}{r}.
\ee
}
\end{example}
Generally, nonlinear equations are not solvable however, we will see in the next example the polar coordinates can convert nonlinearities in $(x,r)$ to linearities in $(r,\theta)$
\begin{example}[frametitle= Solving ODEs in polar coordinates]
\COL{Consider the following system
\begin{align}
\dot{x}=y+x\l 1-x^2-y^2\r,\label{x_polar}\\
\dot{y}=-x+y\l 1-x^2-y^2\r\label{y_polar}.
\end{align}
Convert to polar coordinates
\begin{align}
\dot{r}&=\frac{xy+x^2\l 1-x^2-y^2\r-xy+y^2\l 1-x^2-y^2\r}{r},\\
&=\frac{(x^2+y^2)\l 1-x^2-y^2\r}{r},\\
&=r(1-r^2).
\end{align}
and
\bb
\dot{x}=y+x\l 1-x^2-y^2\r=\dot{r}\cos(\theta)-r\sin(\theta)\dot{\theta},
\ee
which implies
\begin{align}
\dot{\theta}&=\frac{\dot{r}\cos(\theta)-y-x\l 1-x^2-y^2\r}{r\sin(\theta)},\\
&=\frac{r(1-r^2)\cos(\theta)-r\sin(\theta)-r\cos(\theta)(1+r^2)}{r\sin(\theta)},\\
&=-1.
\end{align}
Assuming initial conditions $\theta(0)=0$ and $r(0)=r_0>0$ we can immediately integrate to get $\theta=-t$ and
\begin{align}
t&=\int^r_{r_0}\frac{1}{r'(1-r'^2)}\rd r',\\
&=\int^r_{r_0}\frac{1}{r'}+\frac{1/2}{1-r'}-\frac{1/2}{1+r'}\rd r',\\
&=\left[\frac{1}{r'}+\frac{1/2}{1-r'}-\frac{1/2}{1+r'}\right]^r_{r_0},\\
&=\left[\ln(r')-1/2\ln(1-r')-1/2\ln(1+r')\right]^r_{r_0},\\
&=\left[\ln\l \frac{r'}{\sqrt{1-r'^2}}\r\right]^r_{r_0},\\
&=\ln\l \frac{r}{\sqrt{1-r^2}}\frac{\sqrt{1-r_0^2}}{r_0}\r,
\end{align}

Rearranging this gives,
\bb
r(t)=\frac{r_0}{\sqrt{r_0^2+e^{-2t}\l 1-r_0^2\r}}.\label{r_lim}
\ee
From \eqn{r_lim} we can see that $r(t)\rightarrow 1$ as $t\rightarrow \infty$. Critically, we can reconstruct the Cartesian solution by considering the polar identities. Firstly, since $\theta=-t$ the solutions spiral at a constant rate. Note the spirals go clockwise as we normally take positive angles to be anticlockwise. Further, any trajectory must head towards the circle $r=1$.

The full dynamics are simulated in \fig{Polar_plot}
}
\end{example}
\begin{figure}[h!!!tb]
\centering
\includegraphics[width=\ttp]{../Pictures/Polar_plot.png}
\caption{\label{Polar_plot} Full dynamics of \eqns{x_polar}{y_polar}.}
\end{figure}
\section{Check list}
By the end of this chapter you should be able to:
\begin{todolist}
\item reproduce all the definitions;
\item state all theorems;
\item solve simple linear ODE systems;
\item prove trajectories of autonomous systems cannot cross themselves;
\item prove that an ODE of one variable cannot oscillate;
\item derive single variable Taylor series of any order;
\item derive multivariate Taylor series up to first order;
\item convert systems of ODE equations of Cartesian variables in to polar variables and back again.
\end{todolist}


\chapter{Network Analysis}

\newthought{Network analysis can tell us a lot about the most imporant elements of the graph and how well-connected each element is.} A common way is to count the number of connections, shortest paths to neighbors, and shapes that the network takes (i.e. number of triangles).

Some common measures include:
\begin{itemize}
    \item \emph{average degree}, which corresponds to the average number of edges per node. For lastfm, this would mean the average number of artists with whom the genre tag is shared. The higher the number, the more densely connected the network is. A similar measure is graph density, which corresponds to the ratio between number of edges and all possible number of edges.
    \begin{marginfigure}
        \centering
        \includegraphics[scale=0.3]{graph.png}
        \caption{The average degree of the above graph is 2.5 (The number of edges for each node divided by the number of nodes.). The degree of the blue node is 5, while the degree for the red node is 3. The degree centrality for the blue node is 0.5 (half of all edges are connected to it!), while for the red node it is 0.3.}
    \end{marginfigure}
    \item \emph{degree}, which is the number of edges per node. The higher the number, the better connected the node is. For lastfm, this would mean the artist with the highest degree would be the one that shares the most genre tags with other artists.
    \item \emph{degree centrality}, which is the ratio of nodes that connect to the given node. A high ratio would mean a node that can reach the most other nodes and that the node is very important in graph structure. In the case of lastfm, this would be the artist that represents the most widely used genre (perhaps pop, rock, jazz).
\end{itemize}

But enough talk, let us observe this in practice! A widget that computes these statistics is called \widget{Network Analysis}.

\begin{figure*}[h!]
    \centering
    \newcommand{\hierclust}{\includegraphics[scale=0.45]{net-analysis-graph.png}}
    \newcommand{\imageview}{\includegraphics[scale=0.45]{net-analysis-node.png}}
    \infinitewidthbox{
    \stackinset{r}{-0.45\linewidth}{t}{0.0\linewidth}{\imageview}{\hierclust}\hspace{6cm}
    }
\end{figure*}

\newpage

\begin{wrapfigure}{o}{0.8\textwidth}
    \includegraphics[scale=0.6]{workflow.png}
    \label{fig:embedding}
\end{wrapfigure}

Some statistics relate to graph properties, while others relate to node properties. Select the above three measures. Node statistics will be added to the data table, which means we can observe it in \widget{Network Explorer}.

Sending additional node data to Network Explorer enables us to use the computed statistics in a visualization. We can color the nodes and set their size to degree centrality. This will expose the most central nodes - the ones that share the most tags with their neighbors. Unsurprisingly, we find The Rolling Stones and Britney Spears in the bunch.

\vspace{-0.2cm}
\begin{figure*}[h]
  \centering
  \includegraphics[width=\linewidth]{network-explorer.png}%
  \caption{$\;$}
\end{figure*}
\vspace{-0.3cm}


\chapter{Vector-valued Functions}

In the last chapter, you calculated the flight of the shell.  For any
time $t$, you could find a vector $[distance, height]$. This can be
thought of as a function $f$ that takes a number and returns a
2-dimensional vector.  We call this a \newterm{vector-valued} function
from $\mathbb{R} \rightarrow \mathbb{R}^2$.

We often make a vector-valued function by defining several real-valued
functions.  For example, if you threw a hammer with an initial upward
speed of 12 m/2 and a horizontal speed of 4 m/s along the $x$ axis from
the point $(1, 6, 2)$, its position at time $t$ (during its flight) would be given by:

$$f(t) = [4t + 1, 6, -4.8t^2 + 12t + 2]$$

That is, $x$ is increasing with $t$, $y$ is constant, and $z$ is a parabola.

\tdplotsetmaincoords{80}{20}
\begin{tikzpicture} [scale=0.5, tdplot_main_coords, axis/.style={->,sdkblue},
vector/.style={-stealth,black,very thick},
vector guide/.style={dashed,sdkblue}]

%standard tikz coordinate definition using x, y, z coords
\coordinate (O) at (0,0,0);

%draw axes
\draw[axis] (0,0,0) -- (12,0,0) node[anchor=north east]{$x$};
\draw[axis] (0,0,0) -- (0,7,0) node[above]{$y$};
\draw[axis] (0,0,0) -- (0,0,10) node[anchor=south]{$z$};

\draw[thick,draw=black,
      domain=0:2.60563,samples=300,variable=\t]
      plot ({4*\t + 1},6, {-4.9*\t^2 + 12*\t + 2});
\draw[dashed,draw=sdkblue] (1, 6, 0) -- (11.42252, 6, 0);
\draw[dashed,draw=sdkblue] (11.42252, 0, 0) -- (11.42252, 6, 0);
\draw[dashed,draw=sdkblue] (1, 6, 0) -- (1, 6, 2);
\draw[dashed,draw=sdkblue] (1, 6, 0) -- (1, 6, 2);
\draw[dashed,draw=sdkblue] (1, 6, 0) -- (1, 0, 0);

\filldraw[black] (1,6,2) circle(4pt) node [left]{$f(0) = [1,6,2]$};
\filldraw[black] (5,6,9.1) circle(4pt) node [above]{$f(1) = [5, 6, 9.1]$};
\draw[dashed,draw=sdkblue] (5, 6, 0) -- (5, 6, 9.1);
\filldraw[black] (9,6,6.4) circle(4pt) node [right]{$f(2) = [9, 6, 6.4]$};
\draw[dashed,draw=sdkblue] (9, 6, 0) -- (9, 6, 6.4);
\filldraw[black] (11.42252,6,0) circle(4pt) node [right] {$f(2.6) = [11.4, 6, 0]$};
\end{tikzpicture}

\section{Finding the velocity vector}

Now that we have its position vector, we can differentiate each
component separately to get its velocity as a vector-valued function:

$$f'(t) = [4, 0, -9.8t + 12]$$

That is, the velocity is constant along the $x$-axis, zero along the
$y$-axis, and decreasing with time along the $z$ axis.

\tdplotsetmaincoords{80}{20}
\begin{tikzpicture} [scale=0.5, tdplot_main_coords, axis/.style={->,sdkblue},
vector/.style={-stealth,black,very thick},
vector guide/.style={dashed,sdkblue}]

%standard tikz coordinate definition using x, y, z coords
\coordinate (O) at (0,0,0);

%draw axes
\draw[axis] (0,0,0) -- (14,0,0) node[anchor=north east]{$x$};
\draw[axis] (0,0,0) -- (0,7,0) node[above]{$y$};
\draw[axis] (0,0,0) -- (0,0,10) node[anchor=south]{$z$};

\draw[thick,dashed,draw=black,
      domain=0:2.60563,samples=300,variable=\t]
      plot ({4*\t + 1},6, {-4.9*\t^2 + 12*\t + 2});

\filldraw[black] (1,6,2) circle(4pt);
\draw[->, thick, draw=black] (1,6,2) -- (5, 6, 14) node [right] {$f'(0) = [4,0,12]$};
\draw[dashed, draw=sdkblue] (1,6,2) -- (5,6,2) -- (5,6,14);
\filldraw[black] (5,6,9.1) circle(4pt);
\draw[->, thick, draw=black] (5,6,9.1) -- (9, 6, 11.3) node [right] {$f'(1) = [4,0,2.2]$};
\draw[dashed, draw=sdkblue] (6,6,9.1) -- (9,6,9.1) -- (9,6,11.3);
\filldraw[black] (9,6,6.4) circle(4pt);
\draw[->, thick, draw=black] (9,6,6.4) -- (13, 6, -1.2) node [right] {$f'(2) = [4,0,-7.6]$};
\filldraw[black] (11.42252,6,0) circle(4pt);
\draw[dashed, draw=sdkblue] (9,6,6.4) -- (13,6,6.4) -- (13,6,-1.2);
\end{tikzpicture}

\section{Finding the acceleration vector}

Now that we have its velocity, we can get its acceleration as a vector-valued function:

$$f''(t) = [0, 0, -9.8]$$

There is no acceleration along the $x$ or $y$ axes. It is accerating
down at a constant $9.8 m/s^2$.

\tdplotsetmaincoords{80}{20}
\begin{tikzpicture} [scale=0.5, tdplot_main_coords, axis/.style={->,sdkblue},
vector/.style={-stealth,black,very thick},
vector guide/.style={dashed,sdkblue}]

%standard tikz coordinate definition using x, y, z coords
\coordinate (O) at (0,0,0);

%draw axes
\draw[axis] (0,0,0) -- (14,0,0) node[anchor=north east]{$x$};
\draw[axis] (0,0,0) -- (0,7,0) node[above]{$y$};
\draw[axis] (0,0,0) -- (0,0,10) node[anchor=south]{$z$};

\draw[thick,dashed,draw=black,
      domain=0:2.60563,samples=300,variable=\t]
      plot ({4*\t + 1},6, {-4.9*\t^2 + 12*\t + 2});

\filldraw[black] (1,6,2) circle(4pt);
\draw[->, thick, draw=black] (1,6,2) -- (1, 6, -7.8) node [right] {$f''(0) = [0,0,-9.8]$};
\filldraw[black] (5,6,9.1) circle(4pt);
\draw[->, thick, draw=black] (5,6,9.1) -- (5, 6, -0.7) node [below] {$f''(1) = [0,0,-9.8]$};
\filldraw[black] (9,6,6.4) circle(4pt);
\draw[->, thick, draw=black] (9,6,6.4) -- (9, 6, -3.4) node [right] {$f''(2) = [0,0,-9.8]$};
\filldraw[black] (11.42252,6,0) circle(4pt);
\end{tikzpicture}


%================================
\section{Metrics versus Topologies}
%================================

%--------------------------------
\begin{definition}
	Let $X$ be a set, and let $\rho$ and $\rho'$ be metrics on $X$. We say that $\rho$ and $\rho'$ are \textit{topologically equivalent} if they induce the same topology on $X$.
\end{definition}
%--------------------------------

%--------------------------------
\begin{definition}
	$\rho $ and $\rho'$ are \textit{Lipschitz equivalent} iff there exist $c, C \in \mathbb R_{>0}$ such that for all $x,y \in X$,
	$$
	c \rho(x,y) \le \rho'(x,y) \le C\rho(x,y).
	$$
\end{definition}
%--------------------------------

%--------------------------------
\begin{lemma}
	Lipschitz equivalence implies topological equivalence.
\end{lemma}
%--------------------------------

%--------------------------------
\begin{proof}
	As $\rho$ and $\rho'$ are Lipschitz equivalent, by definition, there exist $c \in \mathbb R_{>0}$ such that for all $x,y \in X$,
	$$
	c \rho(x, y) \le \rho'(x, y).
	$$

	Given $r > 0$ and $x \in X$,
	$$
	B_{c\rho}(x, r) = \left\{ y \in X : c\rho(x, r) < r \right\}
	$$
	and
	$$
	B_{\rho'}(x,r) = \{ y \in X : \rho'(x,r) < r \}.
	$$

	As $r$ is non-underestimated compared to $\rho'$, then
	$$
	B_{\rho'}(x,r) \supseteq B_{c\rho}(x, r) = B_{\rho}\left(x, \frac{1}{c}r \right)
	$$
	is an open neighbourhood of $x$ in $(X, \rho')$ and is a subset

	Let $U \in \mathcal T_{\rho'}$, then for some $\varepsilon > 0$,
	$$
	U \supseteq B_{\rho'} (x, \varepsilon) \supseteq B_{\rho}\left( x, \frac{1}{c}r \right).
	$$
	Thus $U$ is open with respect to $\rho$, i.e., $U \in \mathcal T_{\rho}$.

	It is not necessary to prove converse for there always exists $C \in \mathbb R_{>0}$ such that $c = \frac{1}{C}$.
\end{proof}
%--------------------------------

%--------------------------------
\begin{note} \
	\begin{enumerate}
		%--------------------------------
		\item For all $p \ge 0$, $\rho_p: \mathbb R^n \times \mathbb R^n \to \mathbb R_{\ge 0}$ are topologically equivalent.
		%--------------------------------

		%--------------------------------
		\item On $C[a,b]$, $\rho_1$ and $\rho_\infty$ induce different topologies, hence they are not topologically equivalent, and in particular, they are not Lipschitz equivalent. As Lipschitz equivalence implies topological equivalence, but not vice versa. So Lipschitz in-equivalence do nothing to the proof the topological in-equivalence between $\rho_1$ and $\rho_\infty$.
		%--------------------------------

		%--------------------------------
		\item $\rho_p$ and $\rho_\text{disc}$ on $\mathbb Z$ are topologically equivalent. Firstly, topology $\mathcal T_{\rho_p} = \mathcal P(\mathbb Z)$, because for all $B_{\rho_p} (x, \varepsilon)$ for all $x \in \mathbb Z$ and $\varepsilon \in \mathbb R_{(0,1)}$,  $B_{\rho_p}(x, \varepsilon) = \{x\}$. Thus, for all, $U \in \mathcal P(\mathbb Z)$,
			$$
			U = \bigcup_{x \in U} B_{\rho_p}(x, \varepsilon) = \bigcup_{x \in U} \{x\} \in \mathcal T_{\rho_p}.
			$$
			Thus $\mathcal P(\mathbb Z) \subseteq \mathcal T_{\rho_p}$, but $\mathcal T_{\rho_p} \subseteq \mathcal P(\mathbb Z)$, so $\mathcal P(\mathbb Z) = \mathcal T_{\rho_p}$. Thus $\mathcal T_{\rho_p} = \mathcal T_\text{disc}$.
		%--------------------------------
	\end{enumerate}
\end{note}
%--------------------------------

%--------------------------------
\begin{definition}
	A topological space $(X, \mathcal T)$ is \textit{metrizable} iff $\mathcal T$ is induced by some metric on $X$.
\end{definition}
%--------------------------------

%--------------------------------
\begin{note} \
	\begin{enumerate}
		\item Let $(\mathbb Z, \mathcal T)$ with
		$$
		\mathcal T = \{ U \in \mathcal P(\mathbb Z) : |U| \le 1 \},
		$$
		Then $\mathcal T$ is not induced by any metric. Suppose it were, then all open set $U \in \mathcal T$ should be monotone, and for all $\varepsilon > 0$, and for all $x \in \mathbb Z$, $B(x, \varepsilon)$ should be monotone. But if $\mathcal T$ is induced by some metric, then for all $I \in \mathcal P(X)$ with $|I| > 1$, a set
		$$
		W = \bigcup_{x \in I} B(x, \varepsilon) \in \mathcal T,
		$$
		then $|W| > 1$, which is contradicted to the conditions.
	\end{enumerate}
\end{note}
%--------------------------------

%--------------------------------
\begin{definition} \
	\begin{enumerate}[(i)]
		\item A topological space $(X, \mathcal T)$ is said to be $T_1$ iff every monotone in $\mathcal P(X)$ is closed.
		\item A topological space $(X, \mathcal T)$ is said to be $T_2$ or \textit{Hausdorff} iff
			$$
			\forall x, y \in X \ (x \ne y), \ \exists U, W \in \mathcal T \ (U \cap W = \emptyset), \quad x \in U \land y \in W.
			$$
	\end{enumerate}
\end{definition}
%--------------------------------

%--------------------------------
\begin{note} \
	\begin{enumerate}
		\item $(X, \mathcal T_{\rho_\text{disc}})$ is $T_1$, for as any set $U \subseteq X$ is closed for $X \setminus U \in \mathcal T_{\rho_\text{disc}}$ as well. It is also Hausdorff, because for all $x,y \in X$, $\{x\}, \{y\} \in \mathcal T_{\rho_\text{disc}}$ and $\{x\} \cap \{y\} = \emptyset$ if $x \ne y$.
		\item On the other hand, $(X, \{\emptyset, X\})$ is $T_1$ iff $|X| = 1$. And $(X, \{\emptyset, X\})$ is not Hausdorff, because there exist $x,y \in X$ with $x \ne y$, the only open set contains $x$ is $X$, and the only open set contains $y$ is $X$. Clearly, $X \cap X$
	\end{enumerate}
\end{note}
%--------------------------------

%--------------------------------
\begin{lemma} \
	\begin{enumerate}[(i)]
		\item Every metrizable space is Hausdorff.
		\item Every Hausdorff topological space is $T_1$.
	\end{enumerate}
\end{lemma}
%--------------------------------

%--------------------------------
\begin{proof} \
	\begin{enumerate} [(i)]
		\item Let $(X, \rho)$ be metric space, then for all $x, y \in X$, let $r = \frac{\rho(x,y)}{2}$. Suppose $(X, \rho)$ is not Hausdorff, i.e., there is $z \in B(x, r) \cap B(y, r)$. By metric axioms, we have
			$$
			\rho(x, z) + \rho(y, z) \ge \rho (x,y) = 2r.
			$$
			But $z \in B(x, r)$ implies that $\rho(x,z) < r$, and $z \in B(y, r)$ implies that $\rho(y,z) < r$, then we have
			$$
			\rho(x, z) + \rho(y, z) < \rho(x,y),
			$$
			which is contradicted to the metric axioms.

		\item (Just an outline...) Let $(X, \mathcal T)$ be Hausdorff. Suppose $X$ is not $T_1$, then there is $\{x\} \subseteq X$ which is not closed. Then there must be a smallest $V \supsetneq \{x\}$ which is closed (Why?). Then there must be a smallest $U \in \mathcal T$ with $U \supseteq V$ (Why?). Then for all $x, y \in U$, there is no disjoint $U_x, U_y$ such that $U_x \ni x$ and $U_y \ni y$.
	\end{enumerate}
\end{proof}
%--------------------------------

%--------------------------------
\begin{definition}
	Let $(X, \mathcal T)$ be a topological space, let $\{x_n\}_{n = 1}^\infty$ be a sequence in $X$, and let $x \in X$. Then $\{x_n\}$ \textit{converges} in $X$ iff there is an $x \in X$, for all $U \in \mathcal T$ with $x \in U$, $U$ contains all but finite elements in $\{x_n\}$.
\end{definition}
%--------------------------------

%--------------------------------
\begin{note} \
	\begin{enumerate}
		\item If $(X, \mathcal T)$ is metrizable, i.e., there is a metric $\rho$ can induce $\mathcal T$. If $\{x_n\} \subseteq X$ converges in $X$, then there exists $x \in X$, for all $\varepsilon > 0$, $B(x, \varepsilon)$ contains all but finite elements in $\{x_n\}$.
		\item If $\mathcal T$ is a discrete topology, a sequence $\{x_n\}$ converges in $(X, \mathcal T)$ iff there is an $N$ such that for all $n \ge N$, $x_n = x_{n + 1}$.
		\item If $\mathcal T$ is an indiscrete topology, then any $\{x_n\} \subseteq X$ converges to any point in $X$, for there is only one non-empty open set which is $X$ itself.
	\end{enumerate}
\end{note}
%--------------------------------

%--------------------------------
\begin{lemma}
	In Hausdorff topological space, any convergent sequence converges to at most one point.
\end{lemma}
%--------------------------------

%--------------------------------
\begin{proof}
	Let $(X, \mathcal T)$ be a Hausdorff topological space. Suppose there is a sequence $\{x_n\}$ converges to $x,y \in X$ with $x \ne y$. By the definition of topological convergence, there are $U_x, U_y \in \mathcal T$ both contains all but finite elements in $\{x_n\}$. $U_x \cap U_y$ must be non-empty (Explain!). $x,y \in U_x \cap U_y$, for if they were not, by Hausdorff property, there must be open $V_x \subseteq U_x$ and $V_y \subseteq U_x$ with $V_x \ni x$ and $V_y \ni y$, and they both contains all but finite elements in $\{x_n\}$, which is not possible. Thus, there is no such open sets $V_x \ni x$ and $V_y \ni y$ with $V_x \cap V_y = \emptyset$, which implies $(X, \mathcal T)$ is not Hausdorff. This is a contradition.
\end{proof}
%--------------------------------

%--------------------------------
\begin{definition} \
	\begin{enumerate}[(i)]
		\item A topological space $(X, \mathcal T)$ is \textit{regular} iff for all closed sets $V \subseteq X$ and $x \in X$ with $x \notin V$, there exist disjoint open sets $U,W \subseteq X$ such that $V \subseteq U$ and $x \in W$.
		\item $(X, \mathcal T)$ is \textit{normal} iff for all disjoint closed sets $V, Z \subseteq X$, there exist disjoint open sets $U, W \subseteq X$ such that $V \subseteq U$ and $Z \subseteq W$.
	\end{enumerate}
\end{definition}
%--------------------------------

%--------------------------------
\begin{note}
	[To do] \
	\begin{enumerate}
		\item Can I find a regular space which is not normal?
		\item Can I find a normal space which is not regular?
		\item Does regular implies normal or normal implies regular?
	\end{enumerate}
\end{note}
%--------------------------------

%


\chapter{Pythagorean Theorem}

Watch's Khan Academy's Intro to the Pythagorean Theorem video at \url{https://youtu.be/AA6RfgP-AHU}.

If you have a right triangle, the edges that touch the right angle are
called \emph{the legs}.  The third edge, which is always the longest,
is known as \emph{the hypotenuse}. The Pythagorean Theorem gives us
the relationship between the length of the legs and the length of the
hypotenuse.

\begin{tikzpicture}[scale=1.2]
  \coordinate [circle, fill, inner sep=1pt] (a) at (0,0) ;
  \coordinate [circle, fill, inner sep=1pt] (b) at (0,4) ;
  \coordinate [circle, fill, inner sep=1pt] (c) at (3,0) ;
  \draw (a)--node [outer sep=3pt, left]{Length $a$}(b);
  \draw (b)--node[outer sep=3pt, right]{Length $c$}(c) ;
  \draw (c)--node[outer sep=3pt, below]{Length $b$}(a) ;
  \pic [draw, angle eccentricity=1.5] {right angle = c--a--b};
\end{tikzpicture}

The Pythagorean Theorem tells us that $a^2 + b^2 = c^2$.\index{Pythagorean theorem}

For example, if one leg has length 3 and the other has length 4, then
$a^2 + b^2 = 3^2 + 4^2 = 25$. Thus $c^2$ must equal 25. So you know
the hypotenuse must be of length 5.

(In reality, it almost never works out to be such a tidy number. For
example, what is the length of the hypotenuse if the two legs are 3
and 6? $a^2 + b^2 = 3^2 + 6^2 = 45$.  The length of the hypotenuse is
the square root of that: $\sqrt{45} = \sqrt{9 \times 5} = 3 \sqrt{5}$,
which is approximately 6.708203932499369.)

\begin{Exercise}[title={Find the Missing Length}, label=missingsides]
  What is the missing measure?
  \begin{multicols}{2}
Leg 1 = 6, Leg 2 = 8, Hypotenuse = ? \\(It should be a whole number.)

Leg 1 = 5, Leg 2 = ?, Hypotenuse = 13 \\(It should be a whole number.)

Leg 1 = ?, Leg 2 = 15, Hypotenuse = 17 \\(It should be a whole number.)

Leg 1 = 3, Leg 2 = 3, Hypotenuse = ? \\(It is an irrational number. Give the exact answer and then use a calculator to get an approximation.)
\end{multicols}
\end{Exercise}
\begin{Answer}[ref=missingsides]
  10 because $6^2 + 8^2 = 10^2$

  12 because $5^2 + 12^2 = 13^2$

  8 because $8^2 + 15^2 = 17^2$

  $3\sqrt{2} \approx 4.24$ because $3^2 + 3^2 = \left(3 \sqrt{2}\right)^2$
\end{Answer}

\section{Distance between Points}

What is the distance between these two points?\index{distance using Pythagorean theorme}

\begin{tikzpicture}
  % axis
  \draw[thick, <->] (0, -4.1) -- (0, 4.1);
  \draw[thick, <->] (-4.1, 0) -- (4.1, 0);
  \coordinate [circle, fill, inner sep=2pt] (a) at (-1,-2) ;
  \coordinate [circle, fill, inner sep=2pt] (b) at (1,3) ;
  \node [left] at (a) {(-1,-2)};
  \node [right] at (b) {(1,3)};
  % grid
  \draw[help lines, step = 1cm] (-4, -4) grid (4, 4);

\end{tikzpicture}

We can draw a right triangle and use the Pythagorean Theorem:

\begin{tikzpicture}
  % axis
  \draw[thick, <->] (0, -4.1) -- (0, 4.1);
  \draw[thick, <->] (-4.1, 0) -- (4.1, 0);
  \coordinate [circle, fill, inner sep=2pt] (a) at (-1,-2) ;
  \coordinate [circle, fill, inner sep=2pt] (b) at (1,3) ;
    \node [left] at (a) {(-1,-2)};
  \node [right] at (b) {(1,3)};
  \coordinate (c) at (1, -2);

  \draw [thick] (a) -- (b);
  \draw [thick] (a) -- node[outer sep = 3pt, below]{Length 2}(c);
  \draw [thick] (c) -- node[rotate=90, outer sep = 3pt, below]{Length 5}(b);
  \draw[help lines, step = 1cm] (-4, -4) grid (4, 4);

\end{tikzpicture}

The distance between the two points is $\sqrt{2^2 + 5^2} = \sqrt{29}
\approx 5.385165$. That is, you square the change in $x$ and add it to
the square of the change in $y$. The distance is the square root of
that sum.

\section{Distance in 3 Dimensions}

What if the point is in three dimensional space?  That is, you move 2
meters East, 8 meters North, and 4 meters up in the air. How far are
you from where you started?  You just square each, sum them and take the square root:
$\sqrt{2^2 + 8^2 + 4^2} = \sqrt{84} = 2\sqrt{21} \approx 9.165$ meters.\index{distance!in 3 dimensions}

\begin{tikzpicture}
  \draw [thick, ->] (0,0,0) -- (9,0,0) node[outer sep = 1pt, right]{North} ;
  \draw [thick, ->]  (0,0,0) -- (0,3,0) node[outer sep = 1pt, above]{Up} ;
  \draw [thick, ->] (0,0,0) -- (0,0,4) node[outer sep = 1pt, below]{East} ;

    \draw [dashed]  (8,0,0) -- node[outer sep = 1pt, right]{2}  (8,0,2);

  \draw [dashed]  (0,0,2) -- node[outer sep = 1pt, below]{8} (8,0,2);
  \draw [dashed]  (8,0,2) -- node[outer sep = 1pt, right]{4} (8,4,2);
  \draw [thick]  (0,0,0) --  (8,4,2) node[circle, fill, inner sep=2pt]{};
  \node [left] at (5, 2.7, 1){$\sqrt{2^2 + 8^2 + 4^2} \approx 9.165$};

\end{tikzpicture}