\section{The Seifert-van Kampen Theorem}
\subsection{Some Group Theory}
Recall that we can sometimes represent groups using generators and relations, e.g. the dihedral group $D_{2n}$ can be written as $\langle r,s|s^2=r^n=srsr=1\rangle$ meaning it is the group generated by $r,s$ subject to the given relations $s^2=r^n=1,srs=r^{-1}$.
\begin{definition}
    Let $A$ be a set.
    The free group on $A$ is a group $F(A)$ such that there is a function $\phi:A\to F(A)$ satisfying the following universal property:\\
    Whenever there is a group $G$ and a function $h:A\to G$, there exists a unique homomorphism $f:F(A)\to G$ such that
    \[
        \begin{tikzcd}
            F(A)\arrow[dashed]{dr}{f}&\\
            A\arrow{u}{\phi} \arrow[swap]{r}{h}&G
        \end{tikzcd}
    \]
    commutes.
\end{definition}
\begin{example}
    Let $A=\{\alpha\}$ and $\phi:A\to\mathbb Z$ be the map $\alpha\mapsto 1$.
    Then for any $h:A\to G$ mapping $\alpha$ to $g\in G$, we necessarily have $f:\mathbb Z\to G$ via $n\mapsto g^n$ such that $f\circ\phi=h$.
    Hence $\mathbb Z$ is the free group on $\{a\}$.
\end{example}
\begin{remark}
    This definition, as a universal property, does not give an explicit construction of $F(A)$ but captured all of its group theorectical properties.
    As such, if such an $F(A)$ exists it must be unique up to group isomorphism -- that's why we used ``the'' free group instead of ``a'' free group.
\end{remark}
\begin{proposition}
    Let $A$ be a set and $F(A),F'(A)$ be both free groups on $A$, then $F(A)\cong F'(A)$ as groups.
\end{proposition}
\begin{proof}
    Suppose $\phi:A\to F(A),\phi':A\to F'(A)$ be the maps described in the definition.
    Take $G=F'(A)$ gives a unique homomorphism $f:F(A)\to F'(A)$ such that $f\circ\phi=\phi'$ since $F(A)$ s a free group on $A$; $G=F(A)$ also gives a unique homomorphism $g:F'(A)\to F(A)$ such that $g\circ\phi'=\phi$.
    We claim that $f,g$ are inverse to each other.
    Now $f\circ g$ makes the diagram
    \[
        \begin{tikzcd}
            F'(A)\arrow{dr}{f\circ g}&\\
            A\arrow{u}{\phi'}\arrow[swap]{r}{\phi'}&F'(A)
        \end{tikzcd}
    \]
    commute.
    But then since $F'(A)$ is free, $f\circ g$ must equal to $\operatorname{id}_{F'(A)}$ (which also makes the diagram commute when putting it in the place of $f\circ g$) by uniqueness.
    Similarly $g\circ f=\operatorname{id}_{F(A)}$.
    Hence $f,g$ are indeed inverses of each other.
    This shows $F(A)\cong F'(A)$.
\end{proof}
The proof also shows that the isomorphism is uniquely determined if we ask it to be compatible with $\phi,\phi'$.
In other word, it is canonical with respect to this universal property.
\begin{definition}
    If $A$ is a finite set of cardinality $r$, then we write $F_r=F(A)$ to be the free group of rank $r$.
\end{definition}
\begin{definition}
    The words in $A$ are the strings composed of elements in $A$ and their (symbolic) inverses.
\end{definition}
For example, $w=aba^{-1}bba^{-1}a^{-1}b$ is a word in $A$.
We can canonically identify a word in $A$ by an element of $F(A)$ by mapping it to the product (with the same order of elements) of the respective images, e.g. $abba^{-1}b$ can be identified with $\phi(a)\phi(b)^2\phi(a)^{-1}\phi(b)\in F(A)$.\\
It is easy to check that $\phi(A)$ also satisfies the same universal property of a free group on $A$, therefore by uniqueness we can assume $F(A)$ is generated by $\phi(A)$.
So $F(A)$ can be seen as the set of words in $A$, possibly with some identifications (e.g. $aa^{-1}b=b$).
As a recreational exercise, one can precisely construct a free group on any given set in this way.
After the construction, we can happily identify $A$ as a generating subset of $F(A)$.
\begin{definition}
    A presentation is a set $A$ and a subset of relations $R\subset F(A)$ which identifies the group
    $$\langle A|R\rangle=F(A)/\langle\langle R\rangle\rangle$$
    where $\langle\langle R\rangle\rangle$ is the smallest normal subgroup of $F(A)$ containing $R$ (i.e. intersection of all normal subgroups containing $R$).
    The presentation is finite if both $A,R$ are.
\end{definition}
Easily $\langle\langle R\rangle\rangle=\langle\{srs^{-1}:s\in F(A),r\in R\}\rangle$.
\begin{lemma}[Universal Property of Presentation]
    Let $q:F(A)\to\langle A|R\rangle$ be the quotient map.
    Whenever $f:F(A)\to G$ is a group homomorphism such that $R\subset\ker f$, there is a unique homomorphism $g:\langle A|R\rangle\to G$ such that
    \[
        \begin{tikzcd}
            \langle A|R\rangle\arrow[dashed]{dr}{g}&\\
            F(A)\arrow{u}{q}\arrow[swap]{r}{f}&G
        \end{tikzcd}
    \]
    commutes.
\end{lemma}
\begin{proof}
    Necessarily $g(w\langle\langle R\rangle\rangle)=f(w)$ which works since $\langle\langle R\rangle\rangle\le\ker f$ by definition.
\end{proof}
\begin{example}
    1. We know that $F(\{a\})\cong\mathbb Z$ and every subgroup of $\mathbb Z$ is normal, so $\langle\langle a^n\rangle\rangle=\langle a^n\rangle$ corresponds to $n\mathbb Z$, so $\langle a|a^n\rangle\cong\mathbb Z/n\mathbb Z$.\\
    2. We claim that $G=\langle r,s|r^n,s^2,rsrs\rangle$ is isomorphic to $D_{2n}$.
    Indeed, the homomorphism $F(\{r,s\})\to D_{2n}$ sending $r$ to a rotation of $D_{2n}$ and $s$ to a reflection takes $R=\{r^n,s^2,rsrs\}$ to the identity.
    Thus it factors through $G$ via $\phi:G\to D_{2n}$ by the universal property.
    Now $\phi$ is obviously surjective and injective since we can write $G=\{1,r,\ldots,r^{n-1},s,sr,\ldots,sr^{n-1}\}$ which has the correct size.\\
    3. Every group has a presentation.
    The identity map from $G$ as a set to $G$ as a group induces a group homomorphism $F(G)\to G$ which is surjective.
    Let $R$ be the kernel of this map, then $G=\langle G|R\rangle$.
    (This is, however, not very useful since this is a very inefficient choice of generators and relations.)
\end{example}
\begin{definition}[Pushouts]
    Consider a commutative square
    \[
        \begin{tikzcd}
            \Gamma&A\arrow[swap]{l}{k}\\
            B\arrow{u}{l}&C\arrow{l}{j}\arrow[swap]{u}{i}
        \end{tikzcd}
    \]
    It is called a pushout if it satisfies the following universal property:
    If $G$ is a group with homomorphism $f:A\to G,g:B\to G$ such that
    \[
        \begin{tikzcd}
            G&A\arrow[swap]{l}{f}\\
            B\arrow{u}{g}&C\arrow{l}{j}\arrow[swap]{u}{i}
        \end{tikzcd}
    \]
    commutes, then there is a unique $\phi:\Gamma\to G$ such that
    \[
        \begin{tikzcd}
            G&&\\
            &\Gamma\arrow[swap,dashed]{ul}{\exists!\phi}&A\arrow[swap]{l}{k}\arrow[swap, bend right]{ull}{f}\\
            &B\arrow{u}{l}\arrow[bend left]{uul}{g}&C\arrow{l}{j}\arrow[swap]{u}{i}
        \end{tikzcd}
    \]
    commutes.\\
    If this is indeed the case, then we write $\Gamma=A\sqcup_CB$ (the arrows $i,j$ are equipped with $A,B$ and $k,l$ are equipped with $\Gamma$).
\end{definition}
Given $A,B,C,i,j$, one can check that such a $\Gamma$ is unique up to isomorphism.
\begin{definition}
    If $C=\{e\}$ and $i,j$ be the unique homomorphisms from $C$ to $A,B$, then $A\sqcup_CB$ is called the free product, denotes by $A\star B$.\\
    If $i,j$ are injective, then $A\coprod_CB$ is called the amalgamated product and is written as $A\star_CB$.
\end{definition}
\begin{lemma}\label{pushout_onetrivial}
    For $i:C\to A,j:C\to B=\{e\}$, we have $A\sqcup_C\{e\}\cong A/\langle\langle i(C)\rangle\rangle$.
\end{lemma}
\begin{proof}
    Take $q:A\to A/\langle\langle i(C)\rangle\rangle$ to be the quotient map and $\iota:\{e\}\to A/\langle\langle i(C)\rangle\rangle$ the natural inclusion, then the diagram
    \[
        \begin{tikzcd}
            A/\langle\langle i(C)\rangle\rangle&A\arrow[swap]{l}{q}\\
            \{e\}\arrow{u}{\iota}&C\arrow{l}{j}\arrow[swap]{u}{i}
        \end{tikzcd}
    \]
    does commute.
    Now suppose that there are $f,g$ such that $j\circ g=i\circ f$, i.e. the bigger diagram
    \[
        \begin{tikzcd}
            G&&\\
            &\Gamma\arrow[swap,dashed]{ul}{?}&A\arrow[swap]{l}{q}\arrow[swap, bend right]{ull}{f}\\
            &\{e\}\arrow{u}{\iota}\arrow[bend left]{uul}{g}&C\arrow{l}{j}\arrow[swap]{u}{i}
        \end{tikzcd}
    \]
    commutes.
    Then by commutativity, $f\circ i$ is the constant homomorphism since $g$ (hence $j\circ g$) has to be, so $f(i(C))=\{e\}\in G$, therefore $i(C)\subset\ker f$.
    As $f$ is normal, necessarily $\langle\langle i(C)\rangle\rangle\subset\ker f$, so we necessarily have to choose
    $$\phi:A/\langle\langle i(C)\rangle\rangle\to G,w\langle\langle i(C)\rangle\rangle\mapsto f(w)$$
    which works.
\end{proof}
Do pushouts always exist?
\begin{lemma}
    Let $A=\langle S_1|R_1\rangle$ and $B=\langle S_2|R_2\rangle$ and let $T\subset C$ be a generating set for $C$.
    Suppose $\tilde\imath:T\to F(S_1)$ is a lift of a function $i|_T$ and $\tilde\jmath:T\to F(S_2)$ is a lift of $j|_T$ (so $q_1\circ\tilde\imath=i,q_2\circ\tilde\jmath=j$ on $T$ where $q_1:F(S_1)\to A,q_2:F(S_2)\to B$ are the projections), then
    $$\Gamma=\langle S_1\sqcup S_2|R_1\cup R_2\cup \{\tilde\imath(t)^{-1}\tilde\jmath(t):t\in T\}\rangle$$
    is a presentation of $A\sqcup_CB$.
\end{lemma}
\begin{proof}
    Again we check the universal property.
    Suppose there is a group $G$ with $f:A\to G,g:B\to G$ homomorphisms such that $j\circ g=i\circ f$, then we have the commutative diagram
    \[
        \begin{tikzcd}
            G&&&\\
            &\Gamma\arrow[swap,dashed]{ul}{?}&A\arrow[swap]{l}{k}\arrow[swap, bend right]{ull}{f}&F(S_1)\arrow[swap]{l}{q_1}\\
            &B\arrow{u}{l}\arrow[bend left]{uul}{g}&C\arrow{l}{j}\arrow[swap]{u}{i}\arrow[hookleftarrow]{dr}&\\
            &F(S_2)\arrow{u}{q_2}&&T\arrow{ll}{\tilde\jmath}\arrow[swap]{uu}{\tilde\imath}
        \end{tikzcd}
    \]
    where $k,l$ are induced by the natural inclusions $S_1\hookrightarrow S_1\sqcup S_2,S_2\hookrightarrow S_1\sqcup S_2$ via the universal property of presentations.
    Let $\tilde{f}=f\circ q_1$ and $\tilde{g}=g\circ q_2$.
    Then $\tilde{f}(R_1)=\tilde{g}(R_2)=\{e\}\subset G$ and $\tilde{f}\circ\tilde\imath=\tilde{g}\circ\tilde\jmath$.
    Now let $\phi:F(S_1\sqcup S_2)\to G$ induced by $\tilde{f}$ on $S_1$ and $\tilde{g}$ on $S_2$.
    But then we have $\phi(R_1\cup R_2)=0$ by definiton and $\phi(\tilde\imath(t)^{-1}\tilde\jmath(t))=e$ for any $t\in T$ since $\tilde{f}\circ\tilde\imath=\tilde{g}\circ\tilde\jmath$.
    So by the universal property of presentations, $\phi$ induces the desired map.
\end{proof}
\subsection{The Seifert-van Kampen Theorem}
\begin{definition}
    let $(X,x_0),(Y,y_0)$ be based spaces, then the wedge of $X,Y$ is $X\vee Y=(X\sqcup Y)/\sim$ where $\sim$ is the smallest equivalence relations such that $x_0\sim y_0$.
    The equivalence class $[x_0]=[y_0]$ is the wedge point.
\end{definition}
So we are basically just glueing $X,Y$ together by attaching $x_0$ to $y_0$.
\begin{theorem}[Seifert-van Kampen Theorem for Wedges]\label{s-vk_wedge}
    Suppose $X=Y_1\vee Y_2$ where $Y_1,Y_2$ are path connected and let $x_0\in X$ be the wedge point.
    Then $\pi_1(X,x_0)\cong\pi_1(Y_1,x_0)\star\pi_1(Y_2,x_0)$.
\end{theorem}
\begin{proof}[Sketch of proof]
    Let $i_1:Y_1\to X,i_2:Y_2\to X$ be the natural inclusions which are continuous.
    We shall attempt to show
    \[
        \begin{tikzcd}
            \pi_1(X,x_0)&\pi_1(Y_1,x_0)\arrow[swap]{l}{(i_1)_\ast}\\
            \pi_1(Y_2,x_0)\arrow{u}{(i_2)_\ast}&\{e\}\arrow{u}\arrow{l}
        \end{tikzcd}
    \]
    is a pushout.
    Suppose we are given $f_1:\pi_1(Y_1,x_0)\to G$ and $f_2:\pi_1(Y_2,x_0)\to G$ for some group $G$.
    We need to prove that there is a unique map $g:\pi_1(X,x_0)\to G$ such that $g\circ (i_1)_\ast=f_1,g\circ (i_2)_\ast=f_2$.
    Given a loop in $X$, write it as a concatenation $\gamma=\alpha_1\beta_1\alpha_2\beta_2\cdots\alpha_n\beta_n$ with $\alpha_i$ loops in $Y_1$ and $\beta_i$ loops in $Y_2$.
    We leave out the details of the proof that it is always possible.
    Hence we necessarily have $g([\gamma])=f_1([\alpha_1])f_2([\beta_1])\cdots f_1([\alpha_n])f_2([\beta_n])$, which one can check is well-defined and works.
\end{proof}
\begin{example}
    1. The figure 8 has fundamental group $\pi_1(S^1\vee S^1)\cong\pi_1(S^1)\star\pi_1(S^1)\cong\mathbb Z\star\mathbb Z\cong F_2$.
    Worth noting that this group is nonabelian.\\
    2. Let $A$ be any finite set, then define $\bigvee_AS^1=(A\times S^1)/\sim$ where $\sim$ is the smallest equivalence relation such that $(a,1)\sim (a',1)$ for any $a,a'\in A$.
    Then inductively $\pi_1(\bigvee_AS^1,1)\cong F_{|A|}$.
    In particular, there exists spaces whose fundamental group is $F_n$ for any positive integer $n$.
\end{example}
\begin{theorem}[Seifert-van Kampen Theorem]\label{s-vk_open}
    Suppose $Y_1,Y_2\subset X$ are open, $X=Y_1\cup Y_2$ and $Z=Y_1\cap Y_2$ is nonempty.
    Suppose also that they are all path-connected.
    Let $i_k:Z\hookrightarrow Y_k$ and $j_k:Y_k\hookrightarrow X$ be the inclusions and fix $x_0\in Z$.
    Then the diagram
    \[
        \begin{tikzcd}
            \pi_1(X,x_0)&\pi_1(Y_2,x_0)\arrow[swap]{l}{(j_2)_\ast}\\
            \pi_1(Y_1,x_0)\arrow{u}{(j_1)_\ast}&\pi_1(Z,x_0)\arrow[swap]{u}{(i_2)_\ast}\arrow{l}{(i_1)_\ast}
        \end{tikzcd}
    \]
    is a pushout.
\end{theorem}
\begin{proof}
    Omitted.
\end{proof}
\begin{example}
    We want to calculate the fundamental group of the $n$-sphere $S^n$ for $n\ge 2$.
    Let $x_\pm=(\pm 1,0,\ldots,0)$ and $U_\pm=S^n\setminus\{x_\pm\}$ and $V=U_+\cap U_-$.
    Now that $V=S^n\setminus\{x_+,x_-\}\cong S^{n-1}\times (-1,1)$ via
    $$(x_1,\ldots,x_{n+1})\mapsto\left( \frac{(x_2,\ldots,x_{n+1})}{|(x_2,\ldots,x_{n+1})|},x_1 \right)$$
    which is path-connected for $n\ge 2$.
    Also, $U_\pm$ are both homeomorphic to $\mathbb R^n$ via stereographic projection.
    We know that $X=U_+\cup U_-$, so by Seifert-van Kampen the diagram
    \[
        \begin{tikzcd}
            \pi_1(S^n)&\{e\}\arrow{l}\\
            \{e\}\arrow{u}&\pi_1(V)\arrow{u}\arrow{l}
        \end{tikzcd}
    \]
    is a pushout.
    But then $\pi_1(S^n)$ is necessarily the trivial group.
    Therefore $S^n$ is simply connected for $n\ge 2$.
    Note that this argument breaks down for $n=1$ since $V$ is not path-connected in that case.
\end{example}
Note that this version of Seifeit-van Kampen does not directly generalise Theorem \ref{s-vk_wedge}.
But of course we want to have a version that generalises it, so here goes.
\begin{definition}
    A subset $Y\subset X$ is called a neighbourhood retract if there is some $V\subset X$ open and contains $Y$ such that $Y$ is a deformation retract of $V$.
\end{definition}
\begin{theorem}[Seifert-van Kampen Theorem for Closed Sets]\label{s-vk_closed}
    Suppose $Y_1,Y_2\subset X$ are closed and $Y_1\cup Y_2=X$, $Y_1\cap Y_2=Z\neq\varnothing$.
    Assume everything is path-connected and $Z$ is a neighbourhood retract in both $Y_1$ and $Y_2$, then the diagram
    \[
        \begin{tikzcd}
            \pi_1(X,x_0)&\pi_1(Y_2,x_0)\arrow[swap]{l}{(j_2)_\ast}\\
            \pi_1(Y_1,x_0)\arrow{u}{(j_1)_\ast}&\pi_1(Z,x_0)\arrow[swap]{u}{(i_2)_\ast}\arrow{l}{(i_1)_\ast}
        \end{tikzcd}
    \]
    is a pushout where as usual $i_k:Z\hookrightarrow Y_k$ and $j_k:Y_k\hookrightarrow X$ are the inclusions and $x_0\in Z$.
\end{theorem}
\begin{proof}
    Also omitted.
\end{proof}
\subsection{Attaching Cells}
\begin{definition}
    Let $X$ be a space and let $\alpha:S^{n-1}\to X$ be a map.
    The space obtained by attaching an $n$-cell to $X$ is $X\cup_\alpha D^n=(X\sqcup D^n)/\sim$ where $\sim$ is the smallest equivalence relation that identifies $x\sim \alpha(x)$ for $x\in S^{n-1}$.
\end{definition}
\begin{example}
    For $n=1$, we are just attaching a string to two (possibly one) points on $X$.
    For $n=2$, things can get pretty complicated.
    Although we are just identifying $S^1$ with a loop in $X$ and attach $D^n$ there accordingly, this can give many varieties as the loop can intersect and/or wind itself.
\end{example}
We want to study what happen to the fundamental group when we attach an $n$-cell.
\begin{lemma}
    If $n\ge 3$ and $i:X\to X\cup_\alpha D^n$ be the natural inclusion.
    The $i_\ast$ is an isomorphism of fundamental groups.
\end{lemma}
\begin{proof}
    We are going to construct something called the mapping cylinder of $\alpha$, which is the space
    $$M_\alpha=(X\sqcup(S^{n-1}\times I))/\sim$$
    where $\sim$ is the smallest equivalence relation containing $(\theta,0)\sim\alpha(\theta)$ where $\theta\in S^{n-1}$.
    Now identify $S^{n-1}$ with $S^{n-1}\times \{1\}\subset M_\alpha$ which is now a neighbourhood retract of $M_\alpha$.
    Note that $X\cup_\alpha D^n\cong M_\alpha\cup_{\operatorname{id}_{S^{n-1}}}D^n$.
    Also, $S^{n-1}$ is a neighbourhood retract in $D^n$.
    Now by Theorem \ref{s-vk_closed} with basepoint $x\in S^{n-1}\subset M_\alpha\cup_{\operatorname{id}_{S^{n-1}}}D^n$ and take $Y_1=M_\alpha$, $Y_2=D^n$ and $Z=Y_1\cap Y_2=S^{n-1}$.
    This gives us the pushout
    \[
        \begin{tikzcd}
            \pi_1(X\cup_\alpha D^n,x_0)&\pi_1(M_\alpha,x_0)\arrow{l}\\
            \pi_1(D^n,x_0)\arrow{u}&\pi_1(S^{n-1},x_0)\arrow{u}\arrow{l}
        \end{tikzcd}
    \]
    Now for $n\ge 3$, $\pi_1(S^{n-1},x_0)=\pi_1(D^n,x_0)=\{e\}$.
    which means that $\pi_1(X\cup_\alpha D^n,x_0)\cong\pi_1(M_\alpha,x_0)$.
    But $X$ is obviously a deformation retract of $M_\alpha$, therefore $\pi_1(X,x_0')\cong\pi_1(M_\alpha,x_0)\cong\pi_1(X\cup_\alpha D^n,x_0)$ where $x_0'$ is the image of $x_0$ under the deformation retract.
\end{proof}
What if we attach a $2$-cell?
\begin{lemma}
    Let $\alpha:S^1\to X$  be a map and $x_0=\alpha(\theta_0)$ for some $\theta_0\in S^1$.
    Then
    $$\pi_1(X\cup_\alpha D^2,x_0)\cong\pi_1(X,x_0)/\langle\langle [\alpha]\rangle\rangle$$
    viewing $\alpha$ as a loop based at $x_0$.
    The quotient map, in particular, is induced by the inclusion map $i:X\to X\cup_\alpha D^2$.
\end{lemma}
\begin{proof}
    By the same procedure as above we obtain the pushout
    \[
        \begin{tikzcd}
            \pi_1(X\cup_\alpha D^n,x_0)&\pi_1(X,x_0)\arrow{l}\\
            \pi_1(D^2,\theta_0)=\{e\}\arrow{u}&\pi_1(S^1,\theta_0)=\mathbb Z\arrow{l}\arrow[swap]{u}{1\mapsto [\alpha]}
        \end{tikzcd}
    \]
    The result then follows from Lemma \ref{pushout_onetrivial}.
\end{proof}
\begin{theorem}
    For any finitely presented group $G$, i.e. $G\cong\langle A|R\rangle$ where $A,R$ are both finite, there exists a compact space $X$ with $\pi_1(X,x_0)\cong G$ for some $x_0\in X$.
\end{theorem}
\begin{proof}
    Let $Y=\bigvee_AS^1$ and let $y_0$ be the common wedge point.
    We already know that $\pi_1(Y,y_0)\cong F(A)$.
    Now for each relation $r\in R$, we get a loop $\alpha_r:S^1\to Y$ representing it in the obvious way.
    Then attach $D^2$ to $Y$ via $\alpha_r$ for each $r\in R$ gives a (necessarily compact) space with fundamental group isomorphic to $G$.
\end{proof}
\subsection{Classification of Surfaces}
\begin{definition}
    An $n$ dimensional (topological) manifold (or $n$-manifold) is a Hausdorff space $M$ such that every point $x\in M$ has a neighbourhood $U$ homeomorphic to an open set of $\mathbb R^n$.
\end{definition}
\begin{example}
    1. The $S^n$ is an $n$-manifold.\\
    2. (non-example) The figure 8 is not a manifold since the wedge point does not have a neighbourhood that is locally homeomorphic to $\mathbb R^n$.\\
    3. Take $\alpha:S^1\to X=\{\ast\}$, then $Y=X\cup_\alpha D^2\cong S^2$ is a $2$-manifold.
\end{example}
There is a more interesting and influential example:
Let $g$ be a positive integer and let
$$\Gamma_{2g}=\bigvee_{i=1}^{2g}S^1_i$$
be the wedge product of $2g$ copies $S_i^1$ of the circle with a common wedge point $x_0$.
Let $\alpha_i:I\to S_i^1,\beta_i:I\to S_{i+g}^1$ be simple loops with basepoint $x_0$ for $i=1,\ldots,g$ and consider the loop
$$\rho_g=\alpha_1\beta_1\bar\alpha_1\bar\beta_1\cdots\alpha_g\beta_g\bar\alpha_g\bar\beta_g$$
If we think of $\rho_g$ as a map $S^1\to \Gamma_{2g}$ and define $\Sigma_g=\Gamma_{2g}\cup_{\rho_g}D^2$.
We claim that $\Sigma=\Sigma_g$ is a compact $2$-manifold.
Obviously any interior points of $D^2$ has an open neighbourhood homeomorphic to an open set in $\mathbb R^2$.
At non-wedge point in $S_i^1$, the path $\alpha_i$ (if $i\le g$) or $\beta_{i-g}$ (if $i>g$) appears with its inverse in $\rho_g$, so we can obtain a neighbourhood we want near that point as well.
At wedge point, note that $g=1$ gives the standard identification of the torus on a square, in which case the wedge point is simply the corners (which are identified as the same point) which obviously has a neighbourhood homeomorphic to an open set in $\mathbb R^2$.
An analogy works for higher $g$.
$\Sigma_g$ is called the orientable surface of genus $g$.\\
Now easily $g=1$ just gives the torus.
For $g=2$, we can think of the disk as an octagon and do a little bit of imagination by gluing the respective edges, which will give a $2$-torus, i.e. a torus with two holes.
A little bit more of imagination shows that $\Sigma_n$ is the $n$-torus.
Their fundamental groups are clear by our previous discussion:
$$\pi_i(\Sigma_g)=\langle a_1,\ldots,a_g,b_1,\ldots b_g|a_1b_1a_1^{-1}b_1^{-1}\cdots a_gb_ga_g^{-1}b_g^{-1}\rangle$$
Now take $\Gamma_{g+1}=\sum_{i=0}^gS_i^1$ as the wedge of $g+1$ circles and $\alpha_i:I\to S_i^1$ be the loop around the $i^{th}$ circle and $\sigma_g=\alpha_0\alpha_0\alpha_1\alpha_1\cdots\alpha_g\alpha_g$ viewed as a map $\sigma_g:\partial D^2\to\Gamma_{g+1}$.
Then take $S_g=\Gamma_{g+1}\cup_{\sigma_g}D^2$ which is a $2$=manifold called the non-orientable surface of genus $g$.
As one can see, $S_0$ is simply the real projective plane, and $S_1$ the Klein bottle.
$S_g$ for $g>1$ would shaped like attaching some orientable surface to the Klein bottle.
The fundamental groups are
$$\pi_1(S_g)\cong\langle a_0,\ldots,a_g|a_0^1a_1^2\cdots a_g^2\rangle$$
So for example $\pi_1(S_0)\cong\mathbb Z/2\mathbb Z$.
\begin{theorem}
    Any compact surface $S$ is homeomorphic to $S_g$ or $\Sigma_g$ for some $g$.
\end{theorem}
\begin{proof}
    Omitted.
\end{proof}
But how do we know that they are topologically distinct?
\begin{lemma}
    Let $g\in\mathbb N$, then $\pi_1(\Sigma_g)$ surjects onto $\mathbb Z^{2g}$ but not $\mathbb Z^{2g}\oplus(\mathbb Z/2\mathbb Z)$ and $\pi_1(S_g)$ surjects onto $\mathbb Z^g\oplus(\mathbb Z/2\mathbb Z)$ but not $\mathbb Z^{g+1}$.
\end{lemma}
\begin{proof}
    Let $\{\bar{a}_i,\bar{b}_i\}$ be the standard basis of $\mathbb Z^{2g}$.
    Then the map $a_i\mapsto\bar{a}_i,b_i\mapsto \bar{b}_i$ respects the relation, therefore by the universal property there is a surjective homomorphism from $\pi_1(\Sigma_g)$ to $\mathbb Z^{2g}$.
    Now suppose we have a surjective homomorphism $f:\pi_1(\Sigma_g)\to\mathbb Z^{2g}\oplus(\mathbb Z/2\mathbb Z)$.
    Compose it with the reduction $\mathbb Z^{2g}\oplus(\mathbb Z/2\mathbb Z)\to(\mathbb Z/2\mathbb Z)^{2g+1}$ gives a surjective homomorphism $f':\pi_1(\Sigma_g)\to(\mathbb Z/2\mathbb Z)^{2g+1}$.
    Therefore $f'(a_1),\ldots,f'(a_g),f'(b_1),\ldots,f'(b_g)$ should generate $(\mathbb Z/2\mathbb Z)^{2g+1}$, which is impossible by viewing $(\mathbb Z/2\mathbb Z)^{2g+1}$ as a vector space over $\mathbb Z/2\mathbb Z$ with dimension $2g+1$.\\
    For $\pi_1(S_g)$, let $\{\bar{a}_i\}$ be a basis for the $\mathbb Z^g$ part of $\mathbb Z^g\oplus(\mathbb Z/2\mathbb Z)$ and let $\bar{c}_0$ generate the $\mathbb Z/2\mathbb Z$ part.
    Then the map $a_0\mapsto \bar{c}_0-\sum_{i=1}^g\bar{a}_i, a_i\mapsto \bar{a}_i$ respects the relation, hence induces the desired surjective homomorphism $\pi_1(S_g)\to\mathbb Z^g\oplus(\mathbb Z/2\mathbb Z)$ via the universal property.
    Now if there is a surjective homomorphism $f:\pi_1(S_g)\to\mathbb Z^{g+1}$, then $\mathbb Z^{g+1}$ is generated by $f(a_0),\ldots,f(a_g)$.
    But then $0=f(\sigma_g)=2f(a_0)+\cdots+2f(a_g)$ which is a nontrivial relation between the generators $f(a_0),\ldots,f(a_g)$.
    This is a contradiction.
\end{proof}
\begin{corollary}
    $\Sigma_g$ and $S_g$ have mutually distinct fundamental groups.
\end{corollary}
In particular, they are mutually distinct in terms of homotopy equivalence and hence in terms of homeomorphism.
\begin{proof}
    If $\Sigma_g$ and $\Sigma_{g'}$ have the same fundamental group but $g<g'$, then by the preceding lemma, there is a surjection $\pi_1(\Sigma_g)=\pi_1(\Sigma_{g'})\to\mathbb Z^{g'}\to\mathbb Z^g\oplus(\mathbb Z/2\mathbb Z)$, contradiction.
    The other cases can be argued similarly.
\end{proof}
\begin{remark}
    We can easily generalise the fundamental group $\pi_1$ to higher dimension, which are known as the $n^{th}$ homotopy groups $\pi_n$ which is the set of homotopy classes of maps from the $n$-sphere $S^n$ to a based space with a slightly more complicated but analogous concatenation law that induces a group operation.
    Turns out, $\pi_n$ is always abelian for $n>1$.
    The problem, however, with this sort of groups is that they are hard to calculate.
    Even $\pi_n(S^m)$ for general $n,m$ are still unknown.
    So they are not an effective algebraic invariant -- we need a different approach called homology (and cohomology).
\end{remark}


%
% Chapter 2
%
\chapter {Basics of Quantum Computing}

\section{Dirac Notation}

Also known as bra-ket notation, Dirac notation provides a convenient way of expressing the vectors used in quantum mechanics.

Dirac notation defines two elements:

\begin{itemize}
    \item The \textit{ket} ($\ket{\psi}$), which denotes a column vector in a complex vector space that represents a quantum state.
    $$\ket{\psi}=\left[\begin{array}{c}\psi_{1} \\ \psi_{2} \\ \cdots \\ \psi_{n} \end{array}\right]$$
    \item The \textit{bra} ($\bra{\psi}$), which denotes a row vector that is the conjugate transpose, or adjoint, of a corresponding \textit{ket} ($\ket{v}$).
    $$\bra{\psi}=\left[\begin{array}{cccc}\psi_{1}^{*} & \psi_{2}^{*} & \cdots & \psi_{n}^{*}\end{array}\right]=\left[\begin{array}{c}\psi_{1} \\ \psi_{2} \\ \cdots \\ \psi_{n} \end{array}\right]^{\dagger}$$
\end{itemize}

An \textit{operator} $\bf{A}$, represented by a $n \times n$ matrix, acting on a \textit{ket} $\ket{\psi}$ produces another \textit{ket} $\ket{\psi'}$ such that the produced \textit{ket} can be computed by matrix multiplication:
$$\ket{\psi'}=\textbf{A}\ket{\psi}=\left[\begin{array}{cc}A_{11} & A_{12} \\ A_{21} & A_{22}\end{array}\right]\left[\begin{array}{c}\psi_{1} \\ \psi_{2}\end{array}\right]=\left[\begin{array}{c}A_{11}\psi_{1}+A_{12}\psi_{2} \\ A_{21}\psi_{1}+A_{22}\psi_{2}\end{array}\right]$$

The \textit{inner product} is denoted as a bra-ket pair $\braket{\phi}{\psi}$ and represents the probability amplitude that a quantum state $\psi$ would be subsequently found in state $\phi$:
$$\braket{\phi}{\psi}=\left[\begin{array}{cc}\phi_{1}^{*} & \phi_{2}^{*} \end{array}\right]\left[\begin{array}{c}\psi_{1} \\ \psi_{2} \end{array}\right]=\phi_{1}^{*}\psi_{1}+\phi_{2}^{*}\psi_{2}$$

This notation also provides a way to describe the state vector of $n$ uncorrelated quantum states, the \textit{tensor product}:
$$\ket{\phi}\otimes\ket{\psi}=\ket{\phi}\ket{\psi}=\ket{\phi\psi}=\left[\begin{array}{c}\phi_{1} \\ \phi_{2}\end{array}\right]\otimes\left[\begin{array}{c}\psi_{1} \\ \psi_{2}\end{array}\right]=\left[\begin{array}{c}\phi_{1}\psi_{1} \\ \phi_{1}\psi_{2} \\ \phi_{2}\psi_{1} \\ \phi_{2}\psi_{2}\end{array}\right]$$

Note that $\ket{\psi}^{\otimes n}$ represents the tensor product of $n$ $\ket{\psi}$ quantum states:
$$\ket{\psi}^{\otimes n}=\ket{\psi}\otimes\cdots\otimes\ket{\psi}=\ket{\psi}\cdots\ket{\psi}=\ket{\psi\cdots\psi}=\left[\begin{array}{c}\psi_{1} \\ \psi_{2} \end{array}\right]\otimes\cdots\otimes\left[\begin{array}{c}\psi_{1} \\ \psi_{2} \end{array}\right]$$

\section{Quantum Systems}

\todo{Explain the Schrodinger equation, describe what a quantum system is and mention basic postulates of quantum mechanics (similar to what Nielsen and Chuang explain).}

\todo{Add an introduction before explaining the postulates of quantum mechanics.}

Postulate 1: The state of a physical system is fully described by a normalized vector $\ket{\psi}$ in Hilbert space.

Postulate 2:

Postulate 3:

Postulate 4:

\todo{This is a good place to introduce the concept of coherence.}

\section{Qubits}

In classical information theory and classical computing, a bit is the fundamental building block.
Analogously, in quantum information theory and quantum computing, a quantum bit or qubit is the fundamental building block.

Physically, a quibit is a two-level quantum-mechanical system. The polarization of a single photon and the spin of the electron are examples of such systems.

Mathematically, a qubit is a linear combination of states $\ket{\psi}=\alpha\ket{0}+\beta\ket{1}$ where $\alpha$ and $\beta$ are complex numbers known as amplitudes, and $\ket{0}$ and $\ket{1}$ are the computational basis states.

When a qubit is measured, the result is either $\ket{0}$ with probability $|\alpha|^2$ or $\ket{1}$ with probability $|\beta|^2$.
Since the probabilities must sum to one, the qubit's state is normalized:
$$|\alpha|^2+|\beta|^2=1$$

The computational basis states, which are analogous to the two values ($0$ and $1$) that a classical bit may take, form an orthonormal basis represented by the following vectors:
$$\ket{0}=\left[\begin{array}{c}1 \\ 0\end{array}\right]$$
$$\ket{1}=\left[\begin{array}{c}0 \\ 1\end{array}\right]$$

Using the previous definitions, we can see a qubit as a unit vector in two-dimensional complex vector space:
\[\ket{\psi}=\left[\begin{array}{c}\alpha \\ \beta\end{array}\right]\]

\section{Multi-Qubit Systems}

\todo{Explain how multi-qubit systems are represented. Describe what a state vector is.}

\section{Superposition}

The principle of quantum superposition states that the most general state of a quantum-mechanical system is a linear combination of all distinct valid quantum states. A qubit is an example of a quantum superposition of the basis states $\ket{0}$ and $\ket{1}$.

A concrete example of a qubit in superposition that has the same probability of being measured as $\ket{0}$ or $\ket{1}$ is the following:
$$\ket{\psi}=\frac{1}{\sqrt{2}}\left(\ket{0}+\ket{1}\right)$$

\todo{Expand this section to show multi-qubit superposition.}

\section{Quantum Logic Gates}

In classical digital circuits, logic gates are the building blocks. Analogously, in the quantum circuit model of computation, quantum logic gates are the building blocks of quantum algorithms. Quantum gates act on qubits, transform them in different ways, and can be applied sequentially to perform complex quantum computations.

Quantum gates are unitary operators represented as $2^n \times 2^n$ unitary matrices where $n$ is the number of qubits the gate operates on. Unitary matrices are complex square matrices $\bf{U}$ which have the property that its conjugate transpose or adjoint $\bf{U^{\dagger}}$ is also its inverse $\bf{U^{-1}}$:
$$\bf{U^{\dagger}U}=\bf{UU^{\dagger}}=\bf{UU^{-1}}=I$$

A quantum gate is applied to a qubit system by multiplying the gate's matrix representation by the qubits' state vector. This operation transforms the qubit system:
$$\ket{\psi_1}=\bf{U}\ket{\psi_0}$$

Applying a sequence of quantum gates is equivalent to performing a series of these multiplications. For example, applying gate $\bf{U_a}$ followed by a gate $\bf{U_b}$ to a state vector $\ket{\psi}$ is represented by the follwing expression where the gates closest to the state vector are applied first:
$$\bf{U_b}\bf{U_a}\ket{\psi}$$

Since matrix multiplication is associative, multiplying $\bf{U_a}$ by $\bf{U_b}$ produces a compund gate $\bf{U_{b}U_{a}}$ that is equivalent to applying $\bf{U_a}$ followed by $\bf{U_b}$:
$$\bf{U_b}\bf{U_a}\ket{\psi}=\bf{U_b}(\bf{U_a}\ket{\psi})=(\bf{U_b}\bf{U_a})\ket{\psi}$$

Note that all quantum gates are reversible since they are represented by unitary matrices. This means that for any gate, another gate exists that reverts the gate's transformation on a state vector:
$$\ket{\psi}=\bf{U^{\dagger}}(\bf{U}\ket{\psi})=\bf{U^{\dagger}}\bf{U}\ket{\psi}=\bf{I}\ket{\psi}$$

\todo{Describe and show how gates are represented in graphical circuits.}

\section{Single-Qubit Gates}

Single-qubit gates are represented by $2 \times 2$ matrices.

\todo{List the most commonly used single-qubit gates and show how they transform a qubit.}

\section{Multi-Qubit Gates}

\todo{List the most commonly used multi-qubit gates and show how they transform the qubits they act upon.}

\section{Entanglement}

\todo{Define what entanglement is, describe why it is important, and show how qubits are entangled.}

\section{Interference}

\todo{Define what interference is, describe why it is important, and show an example of interference.}

\section{Measurement}

\todo{Define what it means to measure a qubit or a qubit system and show examples of measurements using different basis.}

\section{Quantum Advantage}

\todo{Explain how quantum computers can solve a problem that a classical computer can't efficiently by exploiting superposition, entanglement, and interference.}


% Every Latex document starts with a documentclass command
\documentclass[a4paper, 11pt]{article}

% Load some packages
\usepackage{graphicx} % This allows you to put figures in
\usepackage{natbib}   % This allows for relatively pain-free reference lists
\usepackage[left=3cm,top=3cm,right=3cm]{geometry} % The way I like the margins
\usepackage{dsfont}
\usepackage{amsmath}

% This helps with figure placement
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}

% Set values so you can have a title
\title{New Paper}
\author{Me}
\date{\today}

% Document starts here
\begin{document}

%% Actually put the title in
%\maketitle

%\abstract{This is the abstract}

% Need this after the abstract
\setlength{\parindent}{0pt}
\setlength{\parskip}{8pt}

\section{Truncated Exponential Example}
This example is inspired by Steve Gull, via David MacKay.
Suppose an astronomical transient
occurs at time $t=0$, and has a brightness that
decays exponentially over time:

\begin{align}
\textnormal{Brightness}(t) &=
\left\{
\begin{array}{lr}
Ae^{-\frac{t}{L}}, & t \geq 0\\
0,                 & \textnormal{otherwise}.
\end{array}
\right.
\end{align}

Suppose we observe the object between times $t=t_{\rm min}$ and
$t=t_{\rm max}$, and we want to know the value of $L$, but don't
particularly care about $A$. We observe $N$ photons, and their
arrival times $\{t_1, t_2, ..., t_N\}$.
The probability distribution for the arrival times
$\{t_i\}$
given $L$ (and $N$, which we consider to be prior information)
is
\begin{align}
p(t_1, t_2, ..., t_N | L)
&\propto \prod_{i=1}^N e^{-t_i/L}.
\end{align}
This is the probability distribution for the data given the
parameters, which will give us the likelihood function once
we plug in the observed data. However, we need to normalise
it first, as the observed photon arrival times must be between
$t_{\rm min}$ and $t_{\rm max}$:
\begin{align}
p(t_1, t_2, ..., t_N | L)
&= \prod_{i=1}^N
\frac{e^{-t_i/L}}
     {\int_{t_{\rm min}}^{t_{\rm max}} e^{-t_i/L} dt_i}\\
&= \prod_{i=1}^N
\frac{e^{-t_i/L}}
     {L\left[e^{-t_{\rm min}/L} - e^{-t_{\rm max}/L}\right]}\\
&= L^{-N}\left[e^{-t_{\rm min}/L} - e^{-t_{\rm max}/L}\right]^{-N}
e^{-\frac{\sum_{i=1}^N t_i}{L}}.
\end{align}

\bibliographystyle{plainnat}
\bibliography{references}{}

\end{document}


\subsubsection{Toy Example}
\noindent
Say we wish to maximize $f(x,y) = x+y$ subject to the constraint $g(x,y) = x^2 + y^2 = 1$. We can do this y finding the C-level curve that is tangent to our constraint, as this curve will have the extrema.\\
At this point, $\nabla f$ will be in the same direction as $\nabla g$. That is,
\begin{equation*}
	\begin{cases}
		f_x = \lambda g_x \\
		f_y = \lambda g_y
	\end{cases}
\end{equation*}
We also add the constraint itself, $g(x,y) = k$, giving us a system of equations
\begin{equation*}
	\begin{cases}
		f_x = \lambda g_x \\
		f_y = \lambda g_y \\
		g(x,y)=k
	\end{cases}
\end{equation*}

[INSERT IMAGES]


\section{Covariance Matrix}
Let $X$  be a random vector of dimension $d \times 1$ with expectation $\mu _{X}$.

Matrix outer products!\\

$\Sigma =\mathbb E[(X- \mu _{X})(X- \mu _{X})^ T] \\= \mathbb {E}[XX^ T] - \mathbb {E}[X]\mathbb {E}[X]^ T
\\= \mathbb {E}[XX^ T] - \mu _{X}\mu _{X}^ T$


\sec{The Method of Undetermined Coefficients \label{sec:undcoeff}}
\subsection{The first challenge} \label{ssec:undcoeffhomo}
\begin{mdframed}[style=boxstyle, frametitle={The Setup}]
	Consider a linear ODE of the form
	\begin{equation}\label{eq:const}
		y^{(n)} + a_{n-1}y^{(n - 1)} + \cdots + a_0y = 0,
	\end{equation}
	where $a_0, \ldots, a_{n-1}$ are constants. (Real or complex.)\\
	This is a \defin{constant coefficients ODE}.
\end{mdframed}
\begin{mdframed}[style=boxstyle, frametitle={Solving it}]
	We plug the trial solution $y = e^{mx}.$ This gives us the polynomial equation:
	\begin{equation}\label{eq:char}
		m^n + a_{n-1}m^{n-1} + \cdots + a_0 = 0
	\end{equation}
	If $m_1, \ldots, m_n$ are \emph{distinct} solutions to the above equation, then $e^{m_1x}, \ldots, e^{m_nx}$ are $n$ linearly independent solutions of the ODE and thus, we are done.
\end{mdframed}
\begin{mdframed}[style=boxstyle, frametitle={Repeated roots}]
	Suppose $m_0$ is a repeated root of (\ref{eq:char}). Suppose that it is repeated $k$ times. Then, one can show that the following $k$ functions are solutions of the original ODE:
	\begin{equation*}
		e^{m_0x}, xe^{m_0x}, \ldots, x^{k-1}e^{m_0x}.
	\end{equation*}
	These are linearly independent as well.\\
	Thus, we are now done for any case as the total number of roots is always going to be $n$ when counted with multiplicity. (This is assuming that we work in $\mathbb{C},$ which we shall do.)
\end{mdframed}
\begin{mdframed}[style=boxstyle, frametitle={Getting real}]
	Suppose we are in the case where each $a_i$ is real.\\
	In this case, if $m = a + ib$ is a solution, then so is $m' = a - ib.$ Moreover, the ``amount of repetition'' will also be same.\\
	Thus, we can replace solutions having $\{e^{(a + ib)x}, e^{(a - ib)x}\}$ with \\
	$\{e^{ax}\sin bx, e^{ax}\cos bx\}.$\\~\\
	Similarly considerations apply to functions like $x^ke^{(a + ib)x}.$
\end{mdframed}
\exercise{%
Solve the following ODEs.
\begin{enumerate}[leftmargin=*]
	\item $y'' - 3y' + 2y = 0.$
	\item $y^{(4)} + y = 0.$
	\item $y^{(4)} + y^{(2)} + y = 0.$
\end{enumerate}}
\subsection{Annihilators}
Before going into the main problem, let us study annihilators. \\
In the following we shall use the following notation:
\begin{mdframed}[style=boxstyle, frametitle={Notation}]
	From here on, we shall write $D$ to mean $\dfrac{d}{dx}.$\\
	Similarly, we have $D^n = \dfrac{d^n}{dx^n}.$ \\~\\
	Note that $D$ is an ``operator'' which ``acts'' on smooth\footnote{Recall that a smooth function is a function that is infinitely differentiable.} functions to give another smooth function.
\end{mdframed}

\begin{mdframed}[style=boxstyle, frametitle={Some arithmetic}]
	The operator follows the usual rules like $DD = D^2$ which is the same as saying
	\begin{equation*}
		\dfrac{d}{dx}\left(\dfrac{d}{dx}(f)\right) = \dfrac{d^2f}{dx^2}.
	\end{equation*}
	We also have things like
	\begin{equation*}
		(D + 1)^2 = D^2 + 2D + 1.
	\end{equation*}
	Note that the $1$ above is the operator $1,$ that is, $1f = f$ for any function $f.$\\
	(Don't make the mistake of thinking something like $D(D + 1) = D^2$ because $D1 = 0;$ the $1$ here is not the constant function.)\\
	This also shows how the original ODE (\ref{eq:const}) relates to the polynomial (\ref{eq:char}). To make it clearer, note that the ODE can simply be written as
	\begin{equation*}
		(D^n + a_{n-1}D^{n-1} + \cdots + a_0)y = 0.
	\end{equation*}
\end{mdframed}
\newpage
\begin{mdframed}[style=boxstyle, frametitle={Annihilators of special functions}]
	From the discussion in the previous section, we can already see annihilators of some special functions as follows:
	\begin{center}
	\bgroup
	\def\arraystretch{1.25}
	\begin{tabular}{|l|l|}
		\hline
		Function & Annihilator\\
		\hline
		$e^{mx}$ & $D - m$\\
		$x^{k}e^{mx}$ & $(D - m)^{k+1}$\\
		$\sin bx, \cos bx$ & $D^2 + b^2$\\
		$x^k\sin bx, x^k\cos bx$ & $(D^2 + b^2)^{k+1}$\\
		$e^{ax}\sin bx, e^{ax}\cos bx$ & $(D - a)^2 + b^2$\\
		$x^ke^{ax}\sin bx, x^ke^{ax}\cos bx$ & $((D - a)^2 + b^2)^{k+1}$\\
		\hline
	\end{tabular}
	\egroup
	\end{center}
\end{mdframed}
Note that all the annihilators in the above table are polynomials in $D,$ we will usually write an arbitrary such operator as $P(D).$\\
With the above things in mind, we proceed to the next subsection.

\newpage

\subsection{The main problem}
\begin{mdframed}[style=boxstyle, frametitle={The Setup}]
	We consider a linear ODE of the form
	\begin{equation} \label{eq:constQ}
		(D^n + a_{n-1}D^{n-1} + \cdots + a_0)y = Q(x),
	\end{equation}
	where each $a_i$ is a constant and $Q(x)$ is one of the special functions listed in the table earlier.
\end{mdframed}
\begin{mdframed}[style=boxstyle, frametitle={The Solution}]
	We do this quite systematically.
	\begin{enumerate}[leftmargin=*, label = \Roman*.]
		\item First, we consider the associated homogeneous equation
		\begin{equation*}
			(D^n + a_{n-1}D^{n-1} + \cdots + a_0)y = 0.
		\end{equation*}
		This can be solved completely by the methods we saw in \S\S\ref{ssec:undcoeffhomo}.\\
		Let the \emph{general} solution of this be $y_g(x).$
		\item As $Q(x)$ was a special function, we take its annihilator $P(D)$ from the table and apply it to both sides of (\ref{eq:constQ}). This gives us an equation of the form
		\begin{equation} \label{eq:temp1}
			P(D)(D^n + a_{n-1}D^{n-1} + \cdots + a_0)y = 0.
		\end{equation}
		Note that (\ref{eq:temp1}) is again a constant coefficients ODE (why? Recall the arithmetic.) and hence, we can solve it completely.\\
		Let this solution by $y_{g'}(x).$
		\item This $y_{g'}$ will be a sum of special functions. It will have all $n$ of the original special functions in $y_g$ and $k$ more. ($k = \deg P(D).$)\\
		Thus,
		\[y_{g'}(x) = y_g(x) + c_1y_1(x) + \cdots + c_ky_k(x),\]
		where the $y_i$s are the $k$ new functions. We now solve for \textbf{undetermined coefficients} $c_i$s by substituting the above solution back in (\ref{eq:constQ}). (Note that $y_g$ will get completely annihilated and can be ignored for better calculations.)\\
		Thus, once we solve for the $c_i$s, we are done and the final \emph{general} solution is
		\[y(x) = y_g(x) + c_1y_1(x) + \cdots + c_ky_k(x).\]
	\end{enumerate}
\end{mdframed}
\begin{mdframed}[style=boxstyle, frametitle={Slightly more general}]
	Note that the original restriction that $Q(x)$ be a special function was unnecessary. Indeed, we can do better and allow $Q(x)$ to be a \emph{linear combination} of the special functions.\\
	We can solve the smaller equations individually and finally add them (with appropriate scaling) to get the final solution.\\
	To be more explicit in terms of an example:\\
	Consider the ODE $(D^2 + 1)y = e^x + 2\sin x.$\\
	We shall first solve to get the general solution $y_g$ of $(D^2 + 1)y = 0.$\\
	Then, we get a particular solution $y_{p_1}$ of $(D^2 + 1)y = e^x$ using II and III from above.\\
	Similarly, we get a particular solution $y_{p_2}$ of $(D^2 + 1)y = \sin x.$\\ Then, the final solution is $y_g + y_{p_1} + 2y_{p_2}.$
\end{mdframed}
\begin{mdframed}[style=boxstyle2, frametitle={A note about calculations}]
	Sometimes, it may be computationally easier to \emph{not} break $Q(x)$ into all of its components.\\
	For example, if $Q(x) = e^x + xe^x + e^{2x},$ it would be better to break the problem into that for $(e^x + xe^x)$ and that for $e^{2x}.$\\
	The reason for this is that $(D - 1)^2$ is an annihilator for the former and would minimise repeated calculations.\\
	(Try some problems yourself, it's easier to just do it and realise what's best!)
\end{mdframed}