\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}

\title{Chapter 8\\Sturm-Liouville Theory}
\author{solutions by Hikari}
\date{September 2021}

\begin{document}

\newcommand{\pdv}[2]{\frac{\partial#1}{\partial#2}}
\newcommand{\V}{\mathbf}
\newcommand{\M}{\mathrm}
\newcommand{\VE}{\hat{\V{e}}}
\newcommand{\br}[2]{\langle#1|#2\rangle}

\maketitle

\section*{8.2 Hermitian Operators}

\paragraph{8.2.1}
When multiplied by $e^{-x}$, the Laguerre’s ODE becomes
\[
e^{-x}xy''+e^{-x}(1-x)y'+e^{-x}ay=0
\]
Then $\frac{d}{dx}(e^{-x}x)=e^{-x}(1-x)$, so the ODE is self-adjoint if the boundary term $e^{-x}x\big[v^*u'-(v^*)'u\big]_a^b$ vanishes.
The inner product becomes
\[
\br{v}{u}=\int_a^bv^*(x)e^{-x}\mathcal{L}(x)u(x)dx=\int_a^b\big[v^*(x)\mathcal{L}(x)u(x)\big]e^{-x}dx
\]
which means the ODE will be self-adjoint if we let $e^{-x}$ be the weighting function.

\paragraph{8.2.2}
When multiplied by $e^{-x^2}$, the Hermite ODE becomes
\[
e^{-x^2}y''-2xe^{-x^2}y'+2\alpha e^{-x^2}y=0
\]
Then $\frac{d}{dx}(e^{-x^2})=-2xe^{-x^2}$, so the ODE is self-adjoint if the boundary term $e^{-x^2}\big[v^*u'-(v^*)'u\big]_a^b$ vanishes.
The inner product becomes
\[
\br{v}{u}=\int_a^bv^*(x)e^{-x^2}\mathcal{L}(x)u(x)dx=\int_a^b\big[v^*(x)\mathcal{L}(x)u(x)\big]e^{-x^2}dx
\]
which means the ODE will be self-adjoint if we let $e^{-x^2}$ be the weighting function.

\paragraph{8.2.3}
When multiplied by $\frac{1}{\sqrt{1-x^2}}$, the Chebyshev ODE becomes
\[
\sqrt{1-x^2}\,y''-\frac{x}{\sqrt{1-x^2}}y'+\frac{n^2}{\sqrt{1-x^2}}y=0
\]
Then $\frac{d}{dx}(\sqrt{1-x^2})=-\frac{x}{\sqrt{1-x^2}}$, so the ODE is self-adjoint if the boundary term $\sqrt{1-x^2}\big[v^*u'-(v^*)'u\big]_a^b$ vanishes.
The inner product becomes
\[
\br{v}{u}=\int_a^bv^*(x)\frac{1}{\sqrt{1-x^2}}\mathcal{L}(x)u(x)dx=\int_a^b\big[v^*(x)\mathcal{L}(x)u(x)\big]\frac{1}{\sqrt{1-x^2}}dx
\]
which means the ODE will be self-adjoint if we let $\frac{1}{\sqrt{1-x^2}}$ be the weighting function.

\paragraph{8.2.4}
The boundary condition for $p_0(x)y''+p_1(x)y'+p_2(x)=0$ to be self-adjoint is
\[
w(x)p_0(x)\big[v^*u'-(v^*)'u\big]_a^b=0
\]
for every $u,v$, with $w(x)$ being the weighting function.
\begin{alignat*}{3}
    & \textit{Legendre:}\qquad &&  (1-x^2)\big[v^*u'-(v^*)'u\big]_{-1}^{1}=0 && \qquad \textit{because $1-x^2=0$ at $x=-1,1$}\\
    & \textit{Chebyshev:}\qquad &&  \sqrt{1-x^2}\big[v^*u'-(v^*)'u\big]_{-1}^{1}=0 && \qquad \textit{because $\sqrt{1-x^2}=0$ at $x=-1,1$}\\
    & \textit{Hermite:}\qquad &&  e^{-x^2}\big[v^*u'-(v^*)'u\big]_{-\infty}^{\infty}=0 && \qquad \textit{because $e^{-x^2}$ approach to zero faster than}\\
    & && &&\qquad \textit{polynomial $v^*u'-(v^*)'u$ at $-\infty,\infty$}\\
    & \textit{Laguerre:}\qquad &&  e^{-x}x\big[v^*u'-(v^*)'u\big]_{0}^{\infty}=0 && \qquad \textit{because $x=0$, and $e^{-x}$ approach to zero}\\
    & && &&\qquad \textit{faster than polynomial $x\big[v^*u'-(v^*)'u\big]$ at $\infty$}
\end{alignat*}

\paragraph{8.2.5}
The eigenvectors of an Hermitian operator with different eigenvalues are orthogonal (chapter 6) and therefore linearly independent (because if $au_1+bu_2=0$, then $\br{au_1+bu_2}{au_1+bu_2}=|a|^2\br{u_1}{u_1}+|b|^2\br{u_2}{u_2}=0$, which means $a=b=0$).

\paragraph{8.2.6}
(a)
Let $u=\frac{1+x}{1-x}$, so $x=\frac{u-1}{u+1}$, $dx=\frac{2}{(u+1)^2}du$, and $u=0,\infty$ when $x=-1,1$. The integral becomes
\[
\int_0^\infty\frac{1}{2}\frac{u-1}{u+1}(\ln u)\frac{2}{(u+1)^2}du
=\int_0^\infty\frac{u-1}{(u+1)^3}\ln u\,du
\]
\[
=\frac{-u}{(u+1)^2}\ln u\Big|_0^\infty-\int_0^\infty\frac{-u}{(u+1)^2}\frac{1}{u}du
=\frac{-u}{(u+1)^2}\ln u\Big|_0^\infty-\frac{1}{u+1}\Big|_0^\infty
=(0-0)-(0-1)=1
\]

(b)
The boundary term
\[
(1-x^2)\left[x\frac{1}{1-x^2}-\frac{1}{2}\ln\left(\frac{1+x}{1-x} \right) \right]_{-1}^1
\]
does not vanish (diverges), so the proof of the ODE being self-adjoint failed, and therefore the eigenfunctions are not necessarily orthogonal.

\paragraph{8.2.7}
The boundary term
\[
\sqrt{1-x^2}\left[\frac{-x}{\sqrt{1-x^2}}-0 \right]_{-1}^1=-2
\]
does not vanish, so the proof of the ODE being self-adjoint failed, and therefore the eigenfunctions are not necessarily orthogonal.

\paragraph{8.2.8}
(We prove the case when $w(x)=1$ (or similarly a constant), while I'm not sure the correctness when $w(x)$ is a function of $x$. But if $w(x)$ is the weighting function, which means $\br{u_m}{u_n}=\int_a^bu_m^*u_nw\,dx$, then there is no problem in the following proof.)

We have $(pu_n')'=-\lambda_nwu_n$ from the equation, and $\br{u_m}{u_n}=\int_a^bu_m^*u_ndx=\delta_{mn}$ by the orthogonality.
Integrating $\br{u_m'}{u_n'}$ by parts:
\[
\br{u_m'}{u_n'}=\int_a^b(u_m')^*pu_n'dx
\]
\[
=u_m^*pu_n'\big|_a^b-\int_a^bu_m^*(pu_n')'dx
\]
\[
=u_m^*pu_n'\big|_a^b+\int_a^bu_m^*\lambda_nwu_ndx
\]
\[
=u_m^*pu_n'\big|_a^b+\lambda_n\br{u_m}{u_n}=\lambda_n\delta_{mn}
\]
which means $u_m',u_n'$ are orthogonal, as long as the boundary condition $u_m^*pu_n'\big|_a^b=0$ is satisfied. \\(Or equivalently $(u_m^*)'pu_n\big|_a^b=0$, because we have $\big[u_m^*pu_n'-(u_m^*)'pu_n \big]_a^b=0$ from the boundary conditions making  $u_m,u_n$ orthogonal.)

\paragraph{8.2.9}
Assume linear dependence, so $\varphi_n=\sum_{i=1}^{n-1}a_i\varphi_i$, then
\[
A\varphi_n=\lambda_n\varphi_n=\sum_{i=1}^{n-1}\lambda_na_i\varphi_i
\]
and also
\[
A\varphi_n=A(\sum_{i=1}^{n-1}a_i\varphi_i)=\sum_{i=1}^{n-1}a_i\lambda_i\varphi_i
\]
so
\[
\sum_{i=1}^{n-1}a_i(\lambda_n-\lambda_i)\varphi_i=0
\]
Note that $\lambda_n-\lambda_1\neq0$, so the equation implies $\varphi_1,\cdots,\varphi_{n-1}$ are linearly dependent. Therefore, the linear dependence between $\varphi_1,\cdots,\varphi_n$ implies the linear dependence between $\varphi_1,\cdots,\varphi_{n-1}$, and by repeating the process, we will find $\varphi_1,\varphi_2$ being linearly dependent, which is impossible because it implies $\lambda_1=\lambda_2$ ($\lambda_2\varphi_2=A\varphi_2=Ak\varphi_1=\lambda_1k\varphi_1=\lambda_1\varphi_2$). So $\varphi_1,\cdots,\varphi_n$ must be linearly independent.

\paragraph{8.2.10}
(a)
Using Eq 8.15, the ODE will be self-adjoint if multiplied by
\[
\frac{1}{1-x^2}e^{\int\frac{-(2\alpha
+1)x}{1-x^2}dx}=\frac{1}{1-x^2}e^{(\alpha+\frac{1}{2})\ln(1-x^2)}=(1-x^2)^{\alpha-\frac{1}{2}}
\]
so the ODE becomes
\[
\left\{(1-x^2)^{\alpha+\frac{1}{2}}\frac{d^2}{dx^2}-(2\alpha+1)x(1-x^2)^{\alpha-\frac{1}{2}}\frac{d}{dx}+n(n+2\alpha)(1-x^2)^{\alpha-\frac{1}{2}} \right\}C_n^{(\alpha)}(x)=0
\]
which is self-adjoint because
\[
\frac{d}{dx}(1-x^2)^{\alpha+\frac{1}{2}}=-(2\alpha+1)x(1-x^2)^{\alpha-\frac{1}{2}}
\]

(b)
The boundary conditions will be satisfied if we choose the interval to be $[-1,1]$\,:
\[
(1-x^2)^{\alpha+\frac{1}{2}}\big[v^*u'-(v^*)'u \big]_{-1}^1=0
\]
so the eigenfunctions of different eigenvalues will be orthogonal if the inner product is defined as
\[
\br{C_m}{C_n}=\int_{-1}^1C_m^*C_n(1-x^2)^{\alpha-\frac{1}{2}}\,dx
\]

\section*{8.3 ODE Eigenvalue Problems}

\paragraph{8.3.1}
Let $y=\sum_{j=0}^\infty a_jx^{s+j}$ and substitute:
\[
(1-x^2)\sum_{j=0}^\infty a_j(s+j)(s+j-1)x^{s+j-2}-2x\sum_{j=0}^\infty a_j(s+j)x^{s+j-1}+n(n+1)\sum_{j=0}^\infty a_j x^{s+j}=0
\]
The coefficients of each order must be zero, so
\begin{alignat*}{2}
    & x^{s-2}:\qquad && a_0s(s-1)=0\\
    & x^{s-1}:\qquad && a_1(s+1)s=0\\
    & x^{s+j}:\qquad && a_{j+2}(s+j+2)(s+j+1)-a_j(s+j)(s+j-1)-2a_j(s+j)+n(n+1)a_j=0\\
    & && a_{j+2}=\frac{(s+j)(s+j+1)-n(n+1)}{(s+j+1)(s+j+2)}a_j
\end{alignat*}

(a)
$a_0\neq0$, so $s(s-1)=0$.
\medskip

(b)
Let $s=0$ and $a_1=0$ (so $a_3,a_5,\cdots$ vanish), then
\[
a_{j+2}=\frac{j(j+1)-n(n+1)}{(j+1)(j+2)}a_j=\frac{(j-n)(j+n+1)}{(j+1)(j+2)}a_j
\]
\[
y_{even}=\sum_{j\; even}a_jx^j=a_0\left[1-\frac{n(n+1)}{2!}x^2+\frac{(n-2)n(n+1)(n+3)}{4!}x^4-\cdots \right]
\]

(c)
Let $s=1$, then $a_1(s+1)s=0$ implies $a_1=0$, and
\[
a_{j+2}=\frac{(j+1)(j+2)-n(n+1)}{(j+2)(j+3)}a_j=\frac{(j+1-n)(j+2+n)}{(j+2)(j+3)}a_j
\]
\[
y_{odd}=\sum_{j\;even}a_jx^{1+j}=a_0\left[x-\frac{(n-1)(n+2)}{3!}x^3+\frac{(n-3)(n-1)(n+2)(n+4)}{5!}x^5-\cdots \right]
\]

(d)
For $y_{even}$, let $u_k=a_{2k}$, so
\[
u_{k+1}=\frac{2k(2k+1)-n(n+1)}{(2k+1)(2k+2)}u_k
\]
then the series at $x=\pm 1$ becomes
\[
y_{even}=\sum_{j\;even}a_jx^j=\sum_{k=0}^\infty u_k(x^2)^k=\sum_{k=0}^\infty u_k
\]
and
\[
\frac{u_k}{u_{k+1}}=\frac{(2k+1)(2k+2)}{2k(2k+1)-n(n+1)}=1+\frac{1}{k}+\frac{B(k)}{k^2}
\]
where $B(k)$ is bounded for large $k$, so by Gauss' test the series diverge.
\medskip

Similarly, for $y_{odd}$, let $u_k=a_{2k}$, so
\[
u_{k+1}=\frac{(2k+1)(2k+2)-n(n+1)}{(2k+2)(2k+3)}u_k
\]
then the series at $x=\pm 1$ becomes
\[
y_{odd}=\sum_{j\;even}a_jx^{1+j}=\sum_{k=0}^\infty xu_k(x^2)^k=\pm\sum_{k=0}^\infty u_k
\]
and
\[
\frac{u_k}{u_{k+1}}=\frac{(2k+2)(2k+3)}{(2k+1)(2k+2)-n(n+1)}=1+\frac{1}{k}+\frac{B(k)}{k^2}
\]
where $B(k)$ is bounded for large $k$, so by Gauss' test the series diverge.
\medskip

(e)
From the recurrence relations of $y_{even}$ and $y_{odd}$, if $n$ is a non-negative even integer, then $y_{even}$ will terminate at $a_nx^n$; if $n$ is a non-negative odd integer, then $y_{odd}$ will terminate at $a_{n-1}x^n$. So the series are converted into finite polynomials.

\paragraph{8.3.2}
When multiplied by $e^{-x^2}$, the equation becomes
\[
e^{-x^2}y''-2xe^{-x^2}y'+2\alpha e^{-x^2}y=0
\]
so
\[
\frac{d}{dx}\big[e^{-x^2}\big]=-2xe^{-x^2}
\]
and
\[
e^{-x^2}\big[v^*u'-(v^*)'u \big]_{-\infty}^\infty=0
\]
which means the ODE is self-adjoint (Hermitian).

\paragraph{8.3.3}
Let $y=\sum_{j=0}^\infty a_jx^{s+j}$ and substitute:
\[
\sum_{j=0}^\infty a_j(s+j)(s+j-1)x^{s+j-2}-2x\sum_{j=0}^\infty a_j(s+j)x^{s+j-1}+2\alpha\sum_{j=0}^\infty a_j x^{s+j}=0
\]
The coefficients of each order must be zero, so
\begin{alignat*}{2}
    & x^{s-2}:\qquad && a_0s(s-1)=0\\
    & x^{s-1}:\qquad && a_1(s+1)s=0\\
    & x^{s+j}:\qquad && a_{j+2}(s+j+2)(s+j+1)-2a_j(s+j)+2\alpha a_j=0 \\
    & && a_{j+2}=a_j\frac{2(s+j-\alpha)}{(s+j+1)(s+j+2)}
\end{alignat*}

(a)
$s=0$:
\[
a_{j+2}=a_j\frac{2(j-\alpha)}{(j+1)(j+2)}
\]
\[
y_{even}=\sum_{j\;even}a_jx^j=a_0\left[1+\frac{2(-\alpha)}{2!}x^2+\frac{2^2(-\alpha)(2-\alpha)}{4!}x^4+\cdots \right]
\]

$s=1$:
\[
a_{j+2}=a_j\frac{2(j+1-\alpha)}{(j+2)(j+3)}
\]
\[
y_{odd}=\sum_{j\;even}a_jx^{1+j}=a_0\left[x+\frac{2(1-\alpha)}{3!}x^3+\frac{2^2(1-\alpha)(3-\alpha)}{5!}x^5+\cdots \right]
\]

(b)
For $y_{even}$, let $u_k=a_{2k}$, then
\[
u_{k+1}=u_k\frac{2(2k-\alpha)}{(2k+1)(2k+2)}
\]
\[
\lim_{k\to\infty}\frac{a_{2k+2}x^{2k+2}}{a_{2k}x^{2k}}=\lim_{k\to\infty}\frac{u_{k+1}}{u_k}x^2=\lim_{k\to\infty}\frac{4x^2k-2x^2\alpha}{4k^2+6k+2}=\lim_{k\to\infty}\frac{x^2}{k}=0
\]
so by ratio test the series converge.
\medskip

Similarly, for $y_{odd}$, let $u_k=a_{2k}$, then
\[
u_{k+1}=u_k\frac{2(2k+1-\alpha)}{(2k+2)(2k+3)}
\]
\[
\lim_{k\to\infty}\frac{a_{2k+2}x^{2k+3}}{a_{2k}x^{2k+1}}=\lim_{k\to\infty}\frac{u_{k+1}}{u_k}x^2=\lim_{k\to\infty}\frac{4x^2k+2x^2(1-\alpha)}{4k^2+10k+6}=\lim_{k\to\infty}\frac{x^2}{k}=0
\]
so by ratio test the series converge.
\medskip

$e^{x^2}=\sum_{k=0}^\infty\frac{x^{2k}}{k!}$, so the ratio of seccessive terms is
\[
\lim_{k\to\infty}\frac{x^{2(k+1)}}{(k+1)!}\frac{k!}{x^{2k}}=\lim_{k\to\infty}\frac{x^2}{k+1}=\lim_{k\to\infty}\frac{x^2}{k}
\]
which is the same as the ratios of seccessive terms of $y_{even}$ and $y_{odd}$.
\medskip

(c)
From the recurrence relations of $y_{even}$ and $y_{odd}$, if $\alpha$ is a non-negative even integer, then $y_{even}$ will terminate at $a_{\alpha}x^{\alpha}$; if $n$ is a non-negative odd integer, then $y_{odd}$ will terminate at $a_{\alpha-1}x^{\alpha}$. So the series are converted into finite polynomials.

\paragraph{8.3.4}
Let $L_n(x)=\sum_{j=0}^\infty a_jx^{s+j}$ and substitute:
\[
x\sum_{j=0}^\infty a_j(s+j)(s+j-1)x^{s+j-2}+(1-x)\sum_{j=0}^\infty a_j(s+j)x^{s+j-1}+n\sum_{j=0}^\infty a_jx^{s+j}=0
\]
The coefficients of each order must be zero, so
\begin{alignat*}{3}
    & x^{s-1}:\qquad && a_0s(s-1)+a_0s=a_0s^2=0\qquad && s=0\\
    & x^{s+j}:\qquad && a_{j+1}(j+1)j+a_{j+1}(j+1)-a_jj+na_j=0\qquad\qquad && a_{j+1}=a_j\frac{j-n}{(j+1)^2}
\end{alignat*}
so
\[
y=\sum_{j=0}^\infty a_jx^j=a_0\left[1+\frac{(-n)}{1^2}x+\frac{(-n)(1-n)}{1^2\cdot2^2}x^2+\cdots \right]
\]

From the recurrence relation of $y$, if $n$ is a non-negative integer, then $y$ will terminate at $a_{n}x^{n}$, and the series will be converted into a finite polynomial.

\paragraph{8.3.5}
Let $T_n=\sum_{j=0}^\infty a_jx^{s+j}$ and substitute:
\[
(1-x^2)\sum_{j=0}^\infty a_j(s+j)(s+j-1)x^{s+j-2}-x\sum_{j=0}^\infty a_j(s+j)x^{s+j-1}+n^2\sum_{j=0}^\infty a_jx^{s+j}=0
\]

The coefficients of each order must be zero, so
\begin{alignat*}{2}
    & x^{s-2}:\qquad && a_0s(s-1)=0\\
    & x^{s-1}:\qquad && a_1(s+1)s=0\\
    & x^{s+j}:\qquad && a_{j+2}(s+j+2)(s+j+1)-a_j(s+j)(s+j-1)-a_j(s+j)+n^2a_j=0\\
    & && a_{j+2}=a_j\frac{(s+j-n)(s+j+n)}{(s+j+1)(s+j+2)}
\end{alignat*}

For $s=0$, let $a_1=0$, then
\[
a_{j+2}=a_j\frac{(j-n)(j+n)}{(j+1)(j+2)}
\]
\[
y_{even}=\sum_{j\;even}a_jx^j=a_0\left[1+\frac{(-n)n}{2!}x^2+\frac{(2-n)(-n)n(2+n)}{4!}x^4+\cdots \right]
\]

For $s=1$, $a_1=0$, and
\[
a_{j+2}=a_j\frac{(j+1-n)(j+1+n)}{(j+2)(j+3)}
\]
\[
y_{odd}=\sum_{j\;even}a_jx^{1+j}=a_0\left[x+\frac{(1-n)(1+n)}{3!}x^3+\frac{(3-n)(1-n)(1+n)(3+n)}{5!}x^5+\cdots \right]
\]
\medskip

To test the convergence at $x=\pm1$, let $u_k=a_{2k}$:

$y_{even}:$
\[
u_{k+1}=u_k\frac{(2k-n)(2k+n)}{(2k+1)(2k+2)}
\]
\[
y_{even}=\sum_{j\;even}a_jx^j=\sum_{k=0}^\infty u_k(x^2)^k=\sum_{k=0}^\infty u_k
\]
\[
\frac{u_k}{u_{k+1}}=\frac{4k^2+6k+2}{4k^2-n^2}=1+\frac{3}{2k}+\frac{B(k)}{k^2}
\]
so $y_{even}$ converges at $x=\pm1$ by Gauss' test.
\medskip

$y_{odd}:$
\[
u_{k+1}=u_k\frac{(2k+1-n)(2k+1+n)}{(2k+2)(2k+3)}
\]
\[
y_{odd}=\sum_{j\;even}a_jx^{1+j}=\sum_{k=0}^\infty xu_k(x^2)^k=\pm\sum_{k=0}^\infty u_k
\]
\[
\frac{u_k}{u_{k+1}}=\frac{4k^2+10k+6}{4k^2+4k+1-n^2}=1+\frac{3}{2k}+\frac{B(k)}{k^2}
\]
so $y_{odd}$ converges at $x=\pm1$ by Gauss' test.

\paragraph{8.3.6}
Let $U_n=\sum_{j=0}^\infty a_jx^{s+j}$ and substitute:
\[
(1-x^2)\sum_{j=0}^\infty a_j(s+j)(s+j-1)x^{s+j-2}-3x\sum_{j=0}^\infty a_j(s+j)x^{s+j-1}+n(n+2)\sum_{j=0}^\infty a_jx^{s+j}=0
\]
The coefficients of each order must be zero, so
\begin{alignat*}{2}
    & x^{s-2}:\qquad && a_0s(s-1)=0\\
    & x^{s-1}:\qquad && a_1(s+1)s=0\\
    & x^{s+j}:\qquad && a_{j+2}(s+j+2)(s+j+1)-a_j(s+j)(s+j-1)-3a_j(s+j)+n(n+2)a_j=0\\
    & && a_{j+2}=a_j\frac{(s+j)(s+j+2)-n(n+2)}{(s+j+1)(s+j+2)}=a_j\frac{(s+j-n)(s+j+n+2)}{(s+j+1)(s+j+2)}
\end{alignat*}
Choose $s=1$, then $a_1=0$, and
\[
y_{odd}=\sum_{j\;even}a_jx^{1+j}=a_0\left[x+\frac{(1-n)(3+n)}{3!}x^3+\frac{(3-n)(1-n)(3+n)(5+n)}{5!}x^5+\cdots \right]
\]

From the recurrence relation, if $n$ is a positive odd integer, then $y_{odd}$ will terminate at $a_{n-1}x^{n}$, and the series will be converted into a finite polynomial.

\section*{8.4 Variation Method}

\paragraph{8.4.1}
(a)
\[
\br{\varphi}{\varphi}=\int_0^\infty4\alpha^3x^2e^{-2\alpha x}dx=4\alpha^3\left[2\frac{e^{-2\alpha x}}{(-2\alpha)^3} \right]_0^\infty=1
\]

(b)
\[
\langle x^{-1}\rangle=\int_0^\infty 4\alpha^3xe^{-2\alpha x}dx=4\alpha^3\left[-\frac{e^{-2\alpha x}}{(-2\alpha)^2} \right]_0^\infty=\alpha
\]

(c)
\[
\langle\frac{d^2}{dx^2}\rangle=\int_0^\infty4\alpha^3xe^{-\alpha x}\frac{d^2}{dx^2}(xe^{-\alpha x})dx
\]
\[
=4\alpha^5\int_0^\infty x^2e^{-2\alpha x}dx-8\alpha^4\int_0^\infty xe^{-2\alpha x}dx
\]
\[
=4\alpha^5\left[2\frac{e^{-2\alpha x}}{(-2\alpha)^3} \right]_0^\infty-8\alpha^4\left[-\frac{e^{-2\alpha x}}{(-2\alpha)^2} \right]_0^\infty
\]
\[
=\alpha^2-2\alpha^2=-\alpha^2
\]

(d)
\[
\left\langle\varphi\left|-\frac{1}{2}\frac{d^2}{dx^2}-\frac{1}{x} \right|\varphi \right\rangle=\frac{\alpha^2}{2}-\alpha
\]
\[
\frac{d}{d\alpha}\left[\frac{\alpha^2}{2}-\alpha\right]=\alpha-1=0
\]
so
\[
\alpha=1
\]
and the minimum value of the expectation value is
\[
\left[\frac{\alpha^2}{2}-\alpha\right]_{\alpha=1}=-\frac{1}{2}
\]

\end{document}

Mathematical Methods for Physicists/Chapter 08/main.tex


%%%
% This advanced example of a B+ tree is supposed to help creating/modifying B+
% trees using the btreevis package. It covers all possibilities of extending and
% shrinking a B+ tree. Hence, it is a good way to learn and understand what are
% the necessary steps to create and modify B+ trees, i.e. which macros/styles
% have to be used/modified.
%
% All sections and subsections provide a header describing what has to be done
% and why. Each (sub-)section contains exactly a single tikzpicture containing
% inline comments to describe single parts of the header description.
%
% The (sub-)sections are described in terms of the (sub-)section before. So, if
% a change is described, it is a change with respect to the (sub-)section before.
%%%

\documentclass{article}

\usepackage{hyperref}
\usepackage[german]{babel}

% Use btreevis package.
\usepackage{btreevis}

\begin{document}
  \tableofcontents
  \clearpage

  %%%
  % Create an intially empty B+ tree with one node containing 3 key cells and
  % 4 pointer cells.
  %%%
  \section{Initial B$^+$ tree}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 1                 % No scaling necessary.
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate (empty) content of (tree) level 0 (root level).
    \CreateBTreeNode{0}{1}{{}}{\levelZeroNodeOne}

    % Generate B+ tree with a single node (no content).
    \node[BTreeNodeDefault] {\levelZeroNodeOne};

    % As there is just a single node by now, no nodes need to be connected.
  \end{tikzpicture}
  \end{center}

  %%%
  % This section describes all possibilities of extending a B+ tree:
  %   - Add values to an existing node when a node is not yet full.
  %   - Add values to an existing node when a node is already full.
  %   - Add a new level to the B+ tree and connect the new nodes/leaves.
  %   - Add a new node to an existing level and connect the new node.
  %%%
  \section{Extending the B$^+$ tree}

  %%%
  % Values 3 and 9 are added to the existing (empty) node.
  % Hence, the node is neither full before nor after the inserts.
  %
  % This is probably the easiest thing to do: we simply add the values 3 and 9
  % to the comma-separated list of values (which is empty by now) as third
  % argument of the \CreateBTreeNode macro. The third values is treated as empty
  % and thus the cell will also have no content in it.
  %%%
  \subsection{Insert 3 and 9}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 1                 % No scaling necessary.
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate content of (tree) level 0 (root level).
    % Here we add 3 and 9 to the comma-separated list, i.e. {3, 9}.
    \CreateBTreeNode{0}{1}{{3, 9}}{\levelZeroNodeOne}

    % Generate B+ tree with a single node.
    % No change here because we still have only a single node.
    \node[BTreeNodeDefault] {\levelZeroNodeOne};

    % As there is still just a single node by now, no nodes need to be connected.
  \end{tikzpicture}
  \end{center}

  %%%
  % Value 10 is added to the existing node containing two values by now.
  % The node is full afterwards.
  %
  % As the workflow is the same, this should be as easy to understand as the
  % last step: we again add the value 10 to the comma-separated list of values.
  %%%
  \subsection{Insert 10}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 1                 % No scaling necessary.
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate content of (tree) level 0 (root level).
    % Here we add 10 to the comma-separated list, i.e. {3, 9, 10}.
    \CreateBTreeNode{0}{1}{{3, 9, 10}}{\levelZeroNodeOne}

    % Generate B+ tree with a single node.
    % No change here because we still have only a single node.
    \node[BTreeNodeDefault] {\levelZeroNodeOne};

    % As there is still just a single node by now, no nodes need to be connected.
  \end{tikzpicture}
  \end{center}

  %%%
  % Values 1 and 2 are added to the existing node which is already full. Because
  % the node is already full we need to split the node into two and add another
  % level to the tree.
  %
  % Several things have to be done:
  %   - Add two new calls of the \CreateBTreeNode macro to generate a total of
  %     three node contents: one root node and its two child nodes.
  %   - When generating the tree, we need two new 'child' clauses to utilize the
  %     tree environment of TikZ to position the nodes properly. We use the newly
  %     generated contents as node contents.
  %   - As we have two tree levels, the \ConnectBTreeNodes and the
  %     \ConnectBTreeLeaves macros have to be used to connect the nodes in a
  %     proper way. Hence, we introduce one call for each of these two macros.
  %   - Because of the two tree levels it is also recommended to add a style for
  %     the new level of the tree.
  %%%
  \subsection{Insert 1 and 2}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 1,                % No scaling necessary.
    level 1/.style = {        % Level 1 tree style recommended.
      sibling distance = 8em,
      level distance = 6em
    }
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate content of (tree) level 0 (root level).
    % Here we just have a single value (9) in the comma-separated list because
    % we only have two subsequent nodes.
    \CreateBTreeNode{0}{1}{{9}}{\levelZeroNodeOne}

    % Generate content of (tree) level 1.
    % We add two new calls of the \CreateBTreeNode macro to generate the contents
    % of the subsequent nodes. One node contains three values, i.e. the comma-
    % separated list is {1, 2, 3}, and the second node contains two values, i.e.
    % {9, 10}.
    % We also have to provide the correct level number (1) as first argument of
    % both calls as well as the correct node number for each call as second
    % argument, i.e. 1 and 2 respectively.
    % As last argument we need to specify two new variables in which the
    % respective node content is stored.
    \CreateBTreeNode{1}{1}{{1, 2, 3}}{\levelOneNodeOne}
    \CreateBTreeNode{1}{2}{{9, 10}}{\levelOneNodeTwo}

    % Generate B+ tree with one root and two child nodes.
    % Here we add two 'child' clauses generating two new tree nodes. Because
    % these nodes are on the subsequent tree level (level number 1), we use the
    % two contents generated for this level as node contents.
    \node[BTreeNodeDefault] {\levelZeroNodeOne}
    child { node[BTreeNodeDefault] {\levelOneNodeOne} }
    child { node[BTreeNodeDefault] {\levelOneNodeTwo} };

    % Because the tree now consists of three nodes and two levels, we need to
    % use the \ConnectBTreeNodes macro to connect all the nodes vertically.
    % We connect from level 0 (first argument) node 1 (second argument) to
    % level 1 (third argument). On level 1 we have 2 nodes to connect (fourth
    % argument) and the node to start with on level 1 has number 1 (fifth
    % argument).
    \ConnectBTreeNodes{0}{1}{1}{2}{1}

    % Because the tree now consists of more than one leaf node, we need to
    % use the \ConnectBTreeLeaves macro to connect all the leaves horizontally.
    % We connect all leaf nodes of level 1 (first argument) and there are 2 leaf
    % nodes to connect. Remember: the \ConnectBTreeLeaves macro always starts
    % connecting from node number 1 of the supplied level, so no node to start
    % with has to be defined.
    \ConnectBTreeLeaves{1}{2}
  \end{tikzpicture}
  \end{center}

  %%%
  % Values 6 and 4 are added to the first node of the B+ tree. Hence, this node
  % is overfilled and has to be split into two nodes. So another node must be
  % added to the existing leaf level of the tree.
  %
  % To accomplish this, the following steps have to be done:
  %   - The root node has to be modified. Because we add another node on the
  %     subsequent level, the root node needs to hold another value, i.e. 3.
  %   - Obviously, one new call to the \CreateBTreeNode is necessary to generate
  %     the content of the new leaf node. Thus, also a new variable to hold this
  %     content has to be declared. Furthermore, the node is located between the
  %     two existing leaf nodes. Because of the consecutive numbering of the
  %     nodes, we also have to provide the correct node numbers for the new and
  %     the last leaf node!
  %   - A new child has to be added to the tree containing the newly generated
  %     node content.
  %   - The \ConnectBTreeNodes and \ConnectBTreeLeaves calls have to be adjusted
  %     according to the new number of leaf nodes.
  %%%
  \subsection{Insert 6 and 4}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 1,                % No scaling necessary.
    level 1/.style = {        % Level 1 tree style recommended.
      sibling distance = 8em,
      level distance = 6em
    }
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate content of (tree) level 0 (root level).
    % Here we have to add a value (3) to the comma-separated list.
    \CreateBTreeNode{0}{1}{{3, 9}}{\levelZeroNodeOne}

    % Generate content of (tree) level 1.
    % We add one new call of the \CreateBTreeNode macro to generate the content
    % one additional leaf node. Because of the splitting, the new node is located
    % between the two already existing leaves. Hence, we also have to adjust the
    % node numbers of this level: the previously node 2 now has node number 3 and
    % the new leaf node gets node number 2. Also a new variable is introduced and
    % the variables are used according to the node numbering.
    % Summary:
    %   - Node 1 holds values 1 and 2.
    %   - Node 2 holds values 3, 4 and 6.
    %   - Node 3 holds values 9 and 10.
    \CreateBTreeNode{1}{1}{{1, 2}}{\levelOneNodeOne}
    \CreateBTreeNode{1}{2}{{3, 4, 6}}{\levelOneNodeTwo}
    \CreateBTreeNode{1}{3}{{9, 10}}{\levelOneNodeThree}

    % Generate B+ tree with one root and three child nodes.
    % Here we add another 'child' clauses generating one new tree node. As before
    % we use the previously generated node contents.
    \node[BTreeNodeDefault] {\levelZeroNodeOne}
    child { node[BTreeNodeDefault] {\levelOneNodeOne} }
    child { node[BTreeNodeDefault] {\levelOneNodeTwo} }
    child { node[BTreeNodeDefault] {\levelOneNodeThree} };

    % Because the root node now has three child nodes, we need to modify the
    % the \ConnectBTreeNodes call accordingly.
    % We connect from level 0 (first argument) node 1 (second argument) to
    % level 1 (third argument). On level 1 we now have 3 nodes to connect (fourth
    % argument) and the node to start with on level 1 has number 1 (fifth
    % argument).
    \ConnectBTreeNodes{0}{1}{1}{3}{1}

    % Because the tree now consists of one more leaf node, we also need to
    % use the \ConnectBTreeLeaves macro accordingly.
    % We connect all leaf nodes of level 1 (first argument) and now there are 3
    % of those to connect.
    \ConnectBTreeLeaves{1}{3}
  \end{tikzpicture}
  \end{center}

  %%%
  % Values 5 and 7 are added to the second node of the B+ tree. Hence, this node
  % is overfilled and has to be split into two nodes. So another node must be
  % added to the existing leaf level of the tree.
  %
  % To accomplish this, the following steps have to be done:
  %   - The root node has to be modified. Because we add another node on the
  %     subsequent level, the root node needs to hold another value, i.e. 5.
  %   - Once again, a new call to the \CreateBTreeNode is necessary to generate
  %     the content of the new leaf node. Thus, also a new variable to hold this
  %     content has to be declared. Furthermore, the node is located between the
  %     second and the third existing leaf nodes. Because of the consecutive
  %     numbering of the nodes, we also have to adjust the node numbers for the
  %     new and all following leaf nodes.
  %   - A new child has to be added to the tree containing the newly generated
  %     node content.
  %   - The \ConnectBTreeNodes and \ConnectBTreeLeaves calls have to adjusted
  %     according to the new number of leaf nodes.
  %   - The tikzpicture options are changed as well: the sibling distance of
  %     level 1 is reduced to 7em and the level distance is increased to 8em.
  %     This is not obligatory but playing around with the sibling and level
  %     distances often helps to make the B+ tree look more beautiful (e.g. the
  %     nodes do not overlap or the orientation of the arrows is better).
  %%%
  \subsection{Insert 5 and 7}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 1,                % No scaling necessary.
    level 1/.style = {        % Level 1 tree style recommended.
      sibling distance = 7em, % Smaller distance betweens siblings.
      level distance = 8em    % Larger distance between levels.
    }
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate content of (tree) level 0 (root level).
    % Here we have to add a value (5) to the comma-separated list.
    \CreateBTreeNode{0}{1}{{3, 5, 9}}{\levelZeroNodeOne}

    % Generate content of (tree) level 1.
    % We add one new call of the \CreateBTreeNode macro to generate the content
    % one additional leaf node. Because of the splitting, the new node is located
    % between the second and the third existing leaves. Hence, we also have to
    % adjust the node numbers of this level: the previously node 3 now has node
    % number 4 and the new leaf node gets node number 3. Node number 2 keeps its
    % number. Also a new variable is introduced and the variables are used
    % according to the node numbering.
    % Summary:
    %   - Node 1 holds values 1 and 2.
    %   - Node 2 holds values 3 and 4.
    %   - Node 3 holds values 5, 6 and 7.
    %   - Node 4 holds values 9 and 10.
    \CreateBTreeNode{1}{1}{{1, 2}}{\levelOneNodeOne}
    \CreateBTreeNode{1}{2}{{3, 4}}{\levelOneNodeTwo}
    \CreateBTreeNode{1}{3}{{5, 6, 7}}{\levelOneNodeThree}
    \CreateBTreeNode{1}{4}{{9, 10}}{\levelOneNodeFour}

    % Generate B+ tree with one root and four child nodes.
    % Here we add another 'child' clauses generating one new tree node. As before
    % we use the previously generated node contents.
    \node[BTreeNodeDefault] {\levelZeroNodeOne}
    child { node[BTreeNodeDefault] {\levelOneNodeOne} }
    child { node[BTreeNodeDefault] {\levelOneNodeTwo} }
    child { node[BTreeNodeDefault] {\levelOneNodeThree} }
    child { node[BTreeNodeDefault] {\levelOneNodeFour} };

    % Because the root node now has four child nodes, we need to modify the
    % the \ConnectBTreeNodes call accordingly.
    % We connect from level 0 (first argument) node 1 (second argument) to
    % level 1 (third argument). On level 1 we now have 4 nodes to connect (fourth
    % argument) and the node to start with on level 1 has number 1 (fifth
    % argument).
    \ConnectBTreeNodes{0}{1}{1}{4}{1}

    % Because the tree now consists of one more leaf node, we also need to
    % use the \ConnectBTreeLeaves macro accordingly.
    % We connect all leaf nodes of level 1 (first argument) and now there are 4
    % of those to connect.
    \ConnectBTreeLeaves{1}{4}
  \end{tikzpicture}
  \end{center}

  %%%
  % Value 8 is added to the third leaf node. This node is overfilled and is split
  % into two nodes. Afterwards, the leaf level of the tree contains of five nodes
  % but the root node only has four pointers. Thus, an additional level has to be
  % added to the tree. The tree afterwards consists of
  %   - one root node holding one value, i.e. {5}.
  %   - two nodes on level 1 holding values {3} and {7, 9}, respectively.
  %   - five leaf nodes on level 2 holding their respective values.
  %
  % This is one of the hardest modifications of an existing B+ tree. The
  % following steps are necessary:
  %   - The root node has to be modified. Because we add another level, the root
  %     node now holds the smallest value of its right subtree, i.e. 5.
  %   - The level of the existing leaf nodes has to be changed to 2 and also
  %     the variable names should be changed accordingly. Although the renaming
  %     is not obligatory as long as the contents are used correctly afterwards,
  %     it is still recommended to keep it traceable and avoid errors.
  %   - Two new (inner) nodes have to be generated on level 1. Remember: these
  %     have to be numbered consecutively, i.e. {1}{1} and {1}{2} as the first
  %     two arguments, respectively.
  %   - One new leaf nodes has to be generated on level 2, holding the values 7
  %     and 8. This node is generated between the nodes previously numbered 3 and
  %     4. Hence, node number 3 keeps its number, the newly generated node gets
  %     number 4 and the previously content numbered 4 is now node number 5.
  %   - The new level has to be added to the tree environment as well.
  %   - The existing \ConnectBTreeNodes call has to be modified because the root
  %     node now only has two child nodes. Furthermore, two new calls of
  %     \CreateBTreeNodes are necessary to draw the connections between two nodes
  %     of level 1 and the 5 leaf nodes of level 2.
  %   - The \ConnectBTreeLeaves call has to be modified according to the new
  %     level of the leaf nodes and the increased number of leaves.
  %   - The tikzpicture options are changed as well:
  %       - The sibling distance of level 1 is increased to 18em. This is
  %         recommended because of the new level. The sibling distance has to
  %         be increased almost every time when adding a new level.
  %       - The level distance of level 1 is decreased to 6em. This is just a
  %         minor adjustment.
  %       - A new style for level 2 is introduced.
  %       - The whole tikzpicture is scaled down to 0.7 now because the tree got
  %         higher and wider.
  %       - A new style is introduced to scale the nodes too. This is necessary
  %         because nodes have to be scaled in TikZ separately. So, we just use
  %         the BTreeNodeDefault style and add a scale clause for the nodes
  %         afterwards.
  %     This is not obligatory but playing around with the sibling and level
  %     distances often helps to make the B+ tree look more beautiful (e.g. the
  %     nodes do not overlap or the orientation of the arrows is better).
  %%%
  \subsection{Insert 8}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 0.7,              % Scaling to 0.7 necessary.
    level 1/.style = {        % Level 1 tree style recommended.
      sibling distance = 18em,% Larger distance betweens siblings.
      level distance = 6em    % Smaller distance between levels.
    },
    level 2/.style = {        % Level 2 tree style recommended.
      sibling distance = 7em, % Just like the style used for level 1 previously.
      level distance = 6em
    },
    BTreeNodeScaled/.style = {% New B+ tree node style.
      BTreeNodeDefault,       % Uses the predefined B+ tree node style.
      nodes = { scale = 0.7 } % Scales all nodes to 0.7.
    }
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate content of (tree) level 0 (root level).
    % Because a new level is added, the root has to hold the smallest value of
    % its right subtree, i.e. 5.
    \CreateBTreeNode{0}{1}{{5}}{\levelZeroNodeOne}

    % Generate content of (tree) level 1.
    % Here we generate the new level of the B+ tree consisting of two nodes.
    % Because we push down the leaf level by 1, the new level has level number 1.
    % Numbering is done consecutively, as always, starting with node number 1.
    % The names of the variables are chosen as before to avoid any confusion.
    % Summary:
    %   - Node 1 holds values 3.
    %   - Node 2 holds values 7 and 9.
    \CreateBTreeNode{1}{1}{{3}}{\levelOneNodeOne}
    \CreateBTreeNode{1}{2}{{7, 9}}{\levelOneNodeTwo}

    % Generate content of (tree) level 2.
    % We add one new call of the \CreateBTreeNode macro to generate the content
    % one additional leaf node. Because of the splitting, the new node is located
    % between the third and the fourth existing leaves. Hence, we also have to
    % adjust the node numbers of this level: the previously node 4 now has node
    % number 5 and the new leaf node gets node number 4. Node number 3 keeps its
    % number. Also a new variable is introduced and the variables are used
    % according to the node numbering.
    % Because a new level is added, the leaves are now located at level number 2.
    % This is changed in the first argument for all leaf nodes accordingly.
    % Also the names of the variables are changed accordingly to avoid confusion.
    % Summary:
    %   - Node 1 holds values 1 and 2.
    %   - Node 2 holds values 3 and 4.
    %   - Node 3 holds values 5 and 6.
    %   - Node 4 holds values 7 and 8.
    %   - Node 5 holds values 9 and 10.
    \CreateBTreeNode{2}{1}{{1, 2}}{\levelTwoNodeOne}
    \CreateBTreeNode{2}{2}{{3, 4}}{\levelTwoNodeTwo}
    \CreateBTreeNode{2}{3}{{5, 6}}{\levelTwoNodeThree}
    \CreateBTreeNode{2}{4}{{7, 8}}{\levelTwoNodeFour}
    \CreateBTreeNode{2}{5}{{9, 10}}{\levelTwoNodeFive}

    % Generate B+ tree with one root, two inner nodes and five leaf nodes.
    % Here we add the level according to the new structure of the B+ tree.
    \node[BTreeNodeScaled] {\levelZeroNodeOne}
    child {
      node[BTreeNodeScaled] {\levelOneNodeOne}
      child { node[BTreeNodeScaled] {\levelTwoNodeOne} }
      child { node[BTreeNodeScaled] {\levelTwoNodeTwo} }
    }
    child {
      node[BTreeNodeScaled] {\levelOneNodeTwo}
      child { node[BTreeNodeScaled] {\levelTwoNodeThree} }
      child { node[BTreeNodeScaled] {\levelTwoNodeFour} }
      child { node[BTreeNodeScaled] {\levelTwoNodeFive} }
    };

    % Connect nodes level 0 -> level 1.
    % Because the root now only has two child nodes, we just change the fourth
    % argument accordingly.
    \ConnectBTreeNodes{0}{1}{1}{2}{1}
    % Connect nodes level 1 node 1 -> level 2 nodes 1 and 2.
    % Because we added a new level, we also need to add additional calls to the
    % \ConnectBTreeNodes macro.
    % This call is used to connect the first node of level 1 with its two child
    % nodes of level 2, starting from node number 1 of level 2. So, the nodes
    % 1 and 2 of level 1 are child nodes of node 1 of level 1.
    \ConnectBTreeNodes{1}{1}{2}{2}{1}
    % Connect nodes level 1 node 2 -> level 2 nodes 3, 4 and 5.
    % This call is used to connect the second node of level 1 with its three
    % child nodes of level 2, starting from node number 3 of level 2. So, the
    % nodes 3, 4 and 5 of level 2 are child nodes of node 2 of level 1.
    \ConnectBTreeNodes{1}{2}{2}{3}{3}

    % Because the leaf nodes are now located at level 2 and there is one more
    % leaf node, we need to adjust the \ConnectBTreeLeaves call.
    % We connect all leaf nodes of level 2 (first argument) and now there are 5
    % of those to connect.
    \ConnectBTreeLeaves{2}{5}
  \end{tikzpicture}
  \end{center}

  %%%
  % This section describes all possibilities of shrinking a B+ tree:
  %   - Delete a value in a leaf node, delete corresponding value in inner node
  %     accordingly and connect nodes/leaves
  %   - Change a value in a node/leaf and connect nodes/leaves
  %   - Delete a whole level of the B+ tree and connect nodes/leaves accordingly
  %%%
  \section{Shrinking the B$^+$ tree}

  %%%
  % Value 7 is removed from the B+ tree, specifically from leaf number 4. After
  % removing 7 from leaf number 4, this leaf has an insufficient number of keys.
  % Hence, it is merged with its left sibling, leaf number 3, which contains the
  % keys 5, 6 and 8 after the merge. Also the parent node has to be updated,
  % because the parent node has two child nodes now (instead of three). Thus, one
  % key has to be removed, i.e. 7.
  %
  % These are the necessary steps:
  %   - One of the existing \CreateBTreeNode calls has to be removed, preferably
  %     the one of node number 5 because we only have four leaf nodes afterwards.
  %   - The values of node number 3 need to be changed. In essence, value 8 has
  %     to be added to the comma-separated list supplied as third argument.
  %   - Because we removed one \CreateBTreeNode call, we have to remove one child
  %     from the tree as well.
  %   - The last call of the \ConnectBTreeNodes macro has to be updated. Now
  %     there are only two instead of three child nodes.
  %   - The \ConnectBTreeLeaves call has to be modified. Only four leaves need to
  %     be connected (instead of formerly five).
  %   - The tikzpicture options are not altered (not obligatory). However, the
  %     sibling/level distances could be adjusted here if desired (e.g. to reduce
  %     the horizontal distance between the leaves).
  %%%
  \subsection{Delete 7}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 0.7,              % Scaling to 0.7.
    level 1/.style = {        % Level 1 tree style recommended.
      sibling distance = 18em,% No changes.
      level distance = 6em
    },
    level 2/.style = {        % Level 2 tree style recommended.
      sibling distance = 7em, % No changes.
      level distance = 6em
    },
    BTreeNodeScaled/.style = {% No changes.
      BTreeNodeDefault,
      nodes = { scale = 0.7 }
    }
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate content of (tree) level 0 (root level).
    % No modifications to the root node.
    \CreateBTreeNode{0}{1}{{5}}{\levelZeroNodeOne}

    % Generate content of (tree) level 1.
    % On level 1 we just have to alter the values of the second node. We remove
    % value 7, so node number 2 of level 1 just contains a single value, i.e. 9.
    \CreateBTreeNode{1}{1}{{3}}{\levelOneNodeOne}
    \CreateBTreeNode{1}{2}{{9}}{\levelOneNodeTwo}

    % Generate content of (tree) level 2.
    % We remove one call of the \CreateBTreeNode macro (the last one), so only
    % four leaf nodes are generated on level 2. The node numbering is straight
    % forward from 1 to 4.
    % To be consistent, we also use the variable names corresponding to the
    % respective number of each node.
    % Summary:
    %   - Node 1 holds values 1 and 2.
    %   - Node 2 holds values 3 and 4.
    %   - Node 3 holds values 5, 6 and 8.
    %   - Node 4 holds values 9 and 10.
    \CreateBTreeNode{2}{1}{{1, 2}}{\levelTwoNodeOne}
    \CreateBTreeNode{2}{2}{{3, 4}}{\levelTwoNodeTwo}
    \CreateBTreeNode{2}{3}{{5, 6, 8}}{\levelTwoNodeThree}
    \CreateBTreeNode{2}{4}{{9, 10}}{\levelTwoNodeFour}

    % Generate B+ tree with one root, two inner nodes and four leaves.
    % Here we remove one node (\levelTwoNodeFive) from the right subtree.
    \node[BTreeNodeScaled] {\levelZeroNodeOne}
    child {
      node[BTreeNodeScaled] {\levelOneNodeOne}
      child { node[BTreeNodeScaled] {\levelTwoNodeOne} }
      child { node[BTreeNodeScaled] {\levelTwoNodeTwo} }
    }
    child {
      node[BTreeNodeScaled] {\levelOneNodeTwo}
      child { node[BTreeNodeScaled] {\levelTwoNodeThree} }
      child { node[BTreeNodeScaled] {\levelTwoNodeFour} }
    };

    % Connect nodes level 0 -> level 1.
    % No changes, the root has still two child nodes.
    \ConnectBTreeNodes{0}{1}{1}{2}{1}
    % Connect nodes level 1 node 1 -> level 2 nodes 1 and 2.
    % No changes, the left subtree does not change.
    \ConnectBTreeNodes{1}{1}{2}{2}{1}
    % Connect nodes level 1 node 2 -> level 2 nodes 3 and 4.
    % Here the fourth parameter needs to be changed to 2 because we removed one
    % leaf node from the right subtree and thus have one child node less to
    % connect.
    \ConnectBTreeNodes{1}{2}{2}{2}{3}

    % Here we need to change the last argument because of the altered number of
    % leaf nodes (four instead of formerly 5).
    % We connect all leaf nodes of level 2 and now there are 4 of those to
    % connect.
    \ConnectBTreeLeaves{2}{4}
  \end{tikzpicture}
  \end{center}

  %%%
  % Value 10 is removed from the B+ tree, specifically from leaf number 4. After
  % removing 10 from leaf number 4, this leaf has an insufficient number of keys.
  % Hence, it is merged with its left sibling, leaf number 3. Because after this
  % merge node number 3 would contain one key too much, the node must be split.
  % Hence, we can keep the two existing nodes and just alter their values
  % accordingly. Node number 3 holds the two smaller values, i.e. 5 and 6, and
  % node number 4 holds the two greater values, i.e. 8 and 9.
  % Because of the B+ tree characteristics, the content of the parent node also
  % needs to be changed. The right pointer of a key in the parent node has to
  % hold the smallest value of the subtree the pointer points to. In this case
  % this is 8.
  %
  % The following steps need to be done:
  %   - Remove value 10 from the content of the last leaf node
  %     (\levelTwoNodeFour).
  %   - Insert value 8 into the content of the last leaf node (\levelTwoNodeFour)
  %     in front of value 9.
  %   - The value of the parent node has to be changed to 8 (formerly 9).
  %   - The \ConnectBTreeNodes and \ConnectBTreeLeaves calls need not to be
  %     changed because the number of nodes does not change, only their
  %     values.
  %   - As before the tikzpicture options are not altered (not obligatory).
  %%%
  \subsection{Delete 10}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 0.7,              % Scaling to 0.7.
    level 1/.style = {        % Level 1 tree style recommended.
      sibling distance = 18em,% No changes.
      level distance = 6em
    },
    level 2/.style = {        % Level 2 tree style recommended.
      sibling distance = 7em, % No changes.
      level distance = 6em
    },
    BTreeNodeScaled/.style = {% No changes.
      BTreeNodeDefault,
      nodes = { scale = 0.7 }
    }
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate content of (tree) level 0 (root level).
    % No modifications to the root node.
    \CreateBTreeNode{0}{1}{{5}}{\levelZeroNodeOne}

    % Generate content of (tree) level 1.
    % On level 1 we just have to alter the value of the second node. We replace
    % value 9 with value 8 (to comply with the B+ tree characteristics).
    \CreateBTreeNode{1}{1}{{3}}{\levelOneNodeOne}
    \CreateBTreeNode{1}{2}{{8}}{\levelOneNodeTwo}

    % Generate content of (tree) level 2.
    % We just alter the comma-separated value lists of the last two calls to
    % {5, 6} and {8, 9}, respectively.
    % Summary:
    %   - Node 1 holds values 1 and 2.
    %   - Node 2 holds values 3 and 4.
    %   - Node 3 holds values 5 and 6.
    %   - Node 4 holds values 8 and 9.
    \CreateBTreeNode{2}{1}{{1, 2}}{\levelTwoNodeOne}
    \CreateBTreeNode{2}{2}{{3, 4}}{\levelTwoNodeTwo}
    \CreateBTreeNode{2}{3}{{5, 6}}{\levelTwoNodeThree}
    \CreateBTreeNode{2}{4}{{8, 9}}{\levelTwoNodeFour}

    % Generate B+ tree with one root, two inner nodes and four leaves.
    % No changes necessary because we just altered the contents of the nodes,
    % neither their location nor their numbering.
    \node[BTreeNodeScaled] {\levelZeroNodeOne}
    child {
      node[BTreeNodeScaled] {\levelOneNodeOne}
      child { node[BTreeNodeScaled] {\levelTwoNodeOne} }
      child { node[BTreeNodeScaled] {\levelTwoNodeTwo} }
    }
    child {
      node[BTreeNodeScaled] {\levelOneNodeTwo}
      child { node[BTreeNodeScaled] {\levelTwoNodeThree} }
      child { node[BTreeNodeScaled] {\levelTwoNodeFour} }
    };

    % Connect nodes level 0 -> level 1.
    % No changes, the root has still two child nodes.
    \ConnectBTreeNodes{0}{1}{1}{2}{1}
    % Connect nodes level 1 node 1 -> level 2 nodes 1 and 2.
    % No changes, the left subtree does not change.
    \ConnectBTreeNodes{1}{1}{2}{2}{1}
    % Connect nodes level 1 node 2 -> level 2 nodes 3 and 4.
    % No changes, the right subtree does not change as well.
    \ConnectBTreeNodes{1}{2}{2}{2}{3}

    % No changes as well because the leaf node level and the number of leaf nodes
    % do not change.
    \ConnectBTreeLeaves{2}{4}
  \end{tikzpicture}
  \end{center}

  %%%
  % Value 6 is removed from the B+ tree, specifically from leaf number 3. Thus,
  % this leaf consists of an insufficient number of keys and is merged with its
  % right sibling (because no left sibling exists). After this merge, the parent
  % of the resulting node would just have a single child node, which is not
  % B+ tree compliant. Hence, we need to remove the whole mid level (level 1) of
  % the tree because three leaf nodes are covered by a single root node with two
  % keys and three pointers. So, the resulting B+ tree consists of:
  %   - A root node holding the values 3 and 5 (smallest value of the respective
  %     right subtree).
  %   - Three leaf nodes holding the values {1, 2}, {3, 4} and {5, 8, 9},
  %     respectively.
  %
  % This is one of the hardest modifications of an existing B+ tree. The
  % following steps are necessary:
  %   - The values of the root node need to be changed. The comma-separated list
  %     is {3, 5} afterwards.
  %   - The calls of \CreateBTreeNode for level 2 can be removed.
  %   - One call of \CreateBTreeNode needs to be added for level 1. Previously,
  %     level 1 one consisted of two nodes, now it consists of three nodes. The
  %     numbering of the nodes has to be correct (1 - 3) and the variable names
  %     are chosen according to the level and the node number, e.g. for node 2 of
  %     level 1, the variable is named \levelOneNodeTwo.
  %   - When generating the tree, all clauses generating level 2 are removed and
  %     a clause to generate a third node on level 1 is added. The content of the
  %     nodes is assigned accordingly.
  %   - Only the first call of \ConnectBTreeNodes has to be kept, the other two
  %     subsequent calls are removed. The kept call needs to be changed because
  %     we now have three instead of two nodes on level 1.
  %   - The \ConnectBTreeLeaves call has to be altered too. The level of the leaf
  %     nodes has changed (now 1, formerly it was 2) and the number of leaves has
  %     changed (now 3 instead of previously 4).
  %   - The tikzpicture options are shortened. The style for level 2 of the tree
  %     is removed (not used anymore). Also the sibling and level distance of
  %     level 1 is changed, both to 8em. Last but not least, the scaling is
  %     reset/removed - the global tikzpicture scaling was reset to 1 and the
  %     BTreeNodeScaled style was removed because node scaling is needed.
  %%%
  \subsection{Delete 6}
  \begin{center}
  \begin{tikzpicture}[
    BTreeDefault,             % Use default B+ tree style.
    scale = 1,                % No scaling necessary.
    level 1/.style = {        % Level 1 tree style recommended.
      sibling distance = 8em, % Smaller distance betweens siblings.
      level distance = 8em    % Larger distance between levels.
    },
  ]
    % Set number of pointers per node (this should be done always upfront).
    \SetNoOfPoinersPerNode{4}

    % Generate content of (tree) level 0 (root level).
    % Here we just need to change to the comma-separated list to contain 3 and 5.
    \CreateBTreeNode{0}{1}{{3, 5}}{\levelZeroNodeOne}

    % Generate content of (tree) level 1.
    % On level 1 we now have all the unaltered leaf nodes as well as the altered
    % leaf node holding the values 5, 8 and 9. The node numbers are chosen
    % consecutively as required and the variable names are chosen accordingly.
    \CreateBTreeNode{1}{1}{{1, 2}}{\levelOneNodeOne}
    \CreateBTreeNode{1}{2}{{3, 4}}{\levelOneNodeTwo}
    \CreateBTreeNode{1}{3}{{5, 8, 9}}{\levelOneNodeThree}

    % Generate content of (tree) level 2.
    % Removed because the tree has only two levels after the deletion of 6.

    % Generate B+ tree with one root, two inner nodes and four leaves.
    % We removed all clauses generating level 2 and added a clause to add another
    % child to the root node (holding the value 5, 8 and 9).
    \node[BTreeNodeDefault] {\levelZeroNodeOne}
    child { node[BTreeNodeDefault] {\levelOneNodeOne} }
    child { node[BTreeNodeDefault] {\levelOneNodeTwo} }
    child { node[BTreeNodeDefault] {\levelOneNodeThree} };

    % Connect nodes level 0 -> level 1.
    % We changed only the fourth argument, i.e. 3, because the root now has three
    % instead of two child nodes.
    \ConnectBTreeNodes{0}{1}{1}{3}{1}

    % Connect nodes level 1 -> level 2.
    % Removed because the three has only two levels after the deletion of 6.

    % We changed both arguments. The first one because the leaf nodes were
    % relocated from level 2 to level 1 and the second argument because the
    % number of leaves changed from 4 to 3.
    \ConnectBTreeLeaves{1}{3}
  \end{tikzpicture}
  \end{center}
\end{document}


\documentclass[12pt]{article}

\usepackage{amsthm}

% collectivised from: https://www.overleaf.com/learn/latex/Theorems_and_proofs#Theorem_styles
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
%

\begin{document}

\begin{remark}
    This statement is true, I guess.
\end{remark}

\begin{definition}[Fibration]
    A fibration is a mapping between two topological spaces that has the homotopy lifting property for every space $X$.
\end{definition}

\begin{lemma}
    Given two line segments whose lengths are $a$ and $b$ respectively there
    is a real number $r$ such that $b=ra$.
\end{lemma}

\begin{proof}
    To prove it by contradiction try and assume that the statement is false,
    proceed from there and at some point you will arrive to a contradiction.
\end{proof}

\newpage
\section{Super vertex coloring}

\begin{definition}[Super vertex coloring]
    Let $G$ be an undirected graph.\\ $c: V(G) \rightarrow \{1, 2, ... , k\}$ is a super vertex coloring iff:
    $$\forall v_1, v_2 \in V(G), c(v_1) = c(v_2) \Rightarrow v_1 \notin N(v_2), \forall u \in N(v_1), v_2\notin N(u)$$
    We say that $G$ is $n$-super colorable if we can find a super vertex coloring using $n$ colors.
\end{definition}

%\subsection{Using a $K_n$ as a tool}
Let $K_n$ be a complete graph. We can clearly find a super vertex coloring by assigning a different color to each vertex. Also by [1] (lemma 2), We
can find an edge coloring using $n$ colors (respectively $n-1$) if $n$ is odd (respectively even).

\begin{theorem}
    If $G$ admitt a super vertex coloring using $n$ colors, then we can find and $n$ or $n-1$ coloring of it's edges.
\end{theorem}

\begin{proof}
The idea is to use the $K_n$ graph as a tool to decide which color to assign to each edge. \\
Let $G$ be a $n$-super colorable graph. Call $c_g$ such a coloration. Let $K_n$ and denote by $(k_i)$ it's vertices. As stated earlier,
we can find a $n$ (or $n-1$) edge coloration of it. We shall call this edge coloration $e_k$.  \\
Then, assign to the $k_i$ a different number in $\{1,... , n\}$. Call $c_k$ such a coloration. \\
Let $v_i v_j$ be an edge of $G$. Find $k_1, k_2$ the vertices of $K_n$ such that $c_g(v_i) = c_k(k_1)$ and $c_g(v_j) = c_k(k_2)$ assign to $v_iv_j$ the color
$e_k(k_1k_2)$. \\
Now let's prove by contradiction that such a coloring of the edges is proper. Assume the existence of $v_1, v_2, v_3$ such that $v_1v_2, v_2v_3 \in E(G)$ are assigned to the same color.
Let $k_1, k_2, k_3$ such that $c_g(v_i) = c_k(k_i)$. As $e_k$ is a proper edge coloring, if $e_k(k_1k_2) = e_k(k_2k_3)$, then $k_1=k_3$. Thus, it would mean that
$c_g(v_1) = c_g(v_3)$, ie $c_g$ is not a super vertex coloring of $G$.
\end{proof}

\section{Special graphs}

\subsection{Trees}

\begin{lemma}
    Let $G$ be a tree with maximum degree $\Delta$. Then $G$ is $\Delta + 1$ super colorable.
\end{lemma}

\begin{proof}
    The proof is done by induction on $|E(G)|$.\\
    When $|E(G)| = 0$, $\Delta = 0$ and a super coloration is simply assigning the same color to each vertex.\\
    Let $G$ be a graph with $\Delta$ maximum degree. Find $v$ such that $d(v)=1$, call $v'$ it's only neighbour.
    As per the induction property $G-v$ admitts a $\Delta +1$ super vertex coloring. As the degree of $v'$ in $G-v$ is at most $\Delta -1$, it means it
    lacks at least a color among the color of $v'$ and it's neighbours. Choose it for $v$.
\end{proof}

\subsection{Interval graphs}

\begin{lemma}
    Let $G$ be an interval intersection graph with maximum degree $\Delta$ . Then $G$ is $\Delta+1$ super colorable.
\end{lemma}

\begin{proof}
    The proof is done by induction on the number of intervals.\\
    The result is trivial with one interval. \\ \\
    Let $G$ an interval graph. Call $I_i$ it's intervals and $v_i$ it's associated vertices.
    We can find an ordering of it's intervals. $I_1, I_2, ...$ such that $\forall i, r_i < r_{i+1}$.
    Consider $G-v_1$. By the induction property, it admitts a $\Delta(G-I_1)+1$ super vertex coloration. \\
    If $\Delta(G) > \Delta(G-v_1)$, then just assign to $v_1$ the newly available color.\\ \\
    Suppose $d_G(v_1) = k-1 < \Delta(G)$. The neighbours of $v_1$ are $v_2, ... , v_k$. Observe that each two of the neighbours of $v_1$ are neighbours in G:
    Indeed, they share at least $r_1$ as a common point. \\
    Moreover, we can state that $\forall i, j \in \{2, ... k\}, i<j \Rightarrow N(i) \subset N(j)$:\\
    Let $i, j$ such that $v_i, v_j$ and $v_1$ are neighbours. Let $v^*$ an neighbour of $v_i$, such as $v^* \notin N(v_1)$
    \begin{itemize}
        \item As $v_i$ and $v^*$ are neighbours, $l^* < r_i$; so $l^* < r_j$ by construction.
        \item As $v^*$ and $v_1$ are not neighbours, $r_1<l^*$
        \item As $v_j$ and $v_1$ are neighbours, $l_j<r_1$
    \end{itemize}
    Thus, $l_j< l^* < r_j$; so $I^*$ and $I_j$ share a common point in $l^*$. \\
    So each neighbour of $I_1$ is also a neighbour of $I_k$. As $d_{G-v_1}(v_k)$ is at most $\Delta(G)-1$; we deduce that a least one color has to be missing
    among the neighbours of $v_k$ (including itself); choose this color for $v_1$.
\end{proof}

\section{References}
[1] V.A. Bojarshinov, Edge and total coloring of interval graphs, Disctrete Applied Mathematics 114 (2001) 23-28

\end{document}


\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm]{geometry}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{times}
\usepackage[bottom]{footmisc}
\usepackage{listings}
\usepackage{bm}
\usepackage{amsmath}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{tikz-qtree}

\titleformat{\subsubsection}[runin]{}{}{}{}[]

\title{\textbf{Advanced Machine Learning -- Homework 3}}
\author{Anna Berger, Ashwin Sadananda Bhat (AML 25)}

\setlength{\parindent}{0pt}

\usepackage{booktabs}

\begin{document}
\maketitle

 \section*{Exercise 1}
 To investigate the effect of dimensionality reduction and PCA we apply the Bayesian approach to the predict whether a person has breast cancer or not. There are two possible classes: benign (labelled as 2) and malicious (labelled as 4). In the assignment we refer to them as B and M respectively.

  From the data we can estimate the prior distributions of these classes by counting the number of B's and M's and normalising them by the total number of people: $$ priors \approx (0.65, 0.35) $$

 Hereafter we define the error as the ratio of misclassified objects.

 \subsection*{Part a}

 \begin{enumerate}
	 \item \textbf{Univariate classifiers}
	\begin{enumerate}
		\item \textbf {x2 (Clump Thickness) only} \\
		In this case, the feature is the second column of the dataset which represents clump thickness.
		First, we estimate the mean and the variance of this feature for each class:
		$$\bar{x}_{2B} \approx 2.936, \quad var(x_{2B}) \approx 2.739, $$
		$$\bar{x}_{2M} \approx 7.133, \quad var(x_{2M}) \approx 6.215.$$

		Then we fit the Gaussians using these estimations and apply the Bayes rule to classify objects.
		The statistics for this classifier can be seen from the Table \ref{tab:results-x2}:

		\begin{table}[H]
			\centering
				\begin{tabular}{lrr}
					\toprule
					 & \textbf{Train} & \textbf{Validation}  \\ \midrule
					Error & 0.137 & 0.146 \\
					Precision (malicious) & 0.907 &0.868 \\
					Recall (malicious) & 0.678 & 0.6875 \\
					\bottomrule
				\end{tabular}
			\caption{Univariate classifier (feature x2).}
			\label{tab:results-x2}
		\end{table}

		The confusion matrices for train and validation sets are shown in the Figures \ref{fig:conf_train_x2.png} and \ref{fig:conf_val_x2.png}.

		\begin{figure}[H]\centering
				\begin{minipage}{0.49\textwidth}
					\includegraphics[width=\linewidth]{figures/conf_train_x2.png}
					\caption{Feature x2, train}\label{fig:conf_train_x2.png}
				\end{minipage}
				\begin{minipage}{0.49\textwidth}
 				\includegraphics[width=\linewidth]{figures/conf_val_x2.png}
				\caption{Feature x2, val}\label{fig:conf_val_x2.png}
			\end{minipage}
		\end{figure}

	\item \textbf {First principal component} \\
	We perform SVD on the covariance matrix for the total dataset and obtain eigenvalues (diagonal matrix $s$) and eigenvectors for it (columns of matrix $U$). The first column of matrix $U$ is the first principal component which covers 68,7\% of the variance of the dataset and looks as follows:
	$$ [-0.3059, -0.4085, -0.3859, -0.3280 , -0.2293, -0.4522, -0.2830 , -0.3581, -0.1329]^\tau $$

	Then, we project all the datapoints on the obtained vector.

	After that, we estimate the mean and the variance of projected dataset:
	$$\bar{x}_{pca1B} \approx -4.718, \quad var(x_{pca1B}) \approx 3.566, $$
	$$\bar{x}_{pca1M} \approx -17.729, \quad var(x_{pca1M}) \approx 19.710.$$

	Then we fit the Gaussians using these estimations and apply the Bayes rule to classify objects.
	The statistics for this classifier can be seen from the Table \ref{tab:results-pca-1}:

	\begin{table}[H]
		\centering
		\begin{tabular}{lrr}
			\toprule
			& \textbf{Train} & \textbf{Validation}  \\ \midrule
			Error & 0.037 & 0.014 \\
			Precision (malicious) & 0.932 & 0.969 \\
			Recall (malicious) & 0.965 & 0.989 \\
			\bottomrule
		\end{tabular}
		\caption{Univariate classifier (first principal component).}
		\label{tab:results-pca-1}
	\end{table}

	The confusion matrices for train and validation sets are shown in the Figures \ref{fig:conf_train_pca_1.png} and \ref{fig:conf_val_pca_1.png}.

	\begin{figure}[H]\centering
		\begin{minipage}{0.49\textwidth}
			\includegraphics[width=\linewidth]{figures/conf_train_pca_1.png}
			\caption{The first principal component, train set}\label{fig:conf_train_pca_1.png}
		\end{minipage}
		\begin{minipage}{0.49\textwidth}
		\includegraphics[width=\linewidth]{figures/conf_val_pca_1.png}
		\caption{The first principal component, val set}\label{fig:conf_val_pca_1.png}
		\end{minipage}
	\end{figure}

	\end{enumerate}

	\item \textbf{Bivariate classifiers}
	\begin{enumerate}
		\item \textbf {x2 and x7 (Clump Thickness and Bare Nuclei)} \\
		In this case, the features are the second and the seventh columns of the dataset which represent clump thickness and bare nuclei.

		First, we estimate the mean and the covariance of this feature for each class:
		\[
		\bar{x}_{27B} \approx (2.936,  1.365), \quad
		\Sigma_{27B} \approx
		\begin{bmatrix}
		2.739 & 0.220   \\
		0.220 & 1.470   \\
		\end{bmatrix}.
		\]

		\[
		\bar{x}_{27M} \approx (7.133,  7.706), \quad
		\Sigma_{27M} \approx
		\begin{bmatrix}
		6.215 & 0.082   \\
		0.082 & 9.082   \\
		\end{bmatrix}.
		\]

		Then we fit the Gaussians using these estimations and apply the Bayes rule to classify objects.
		The statistics for this classifier can be seen from the Table \ref{tab:results-x2-x7}:

		\begin{table}[H]
			\centering
			\begin{tabular}{lrr}
				\toprule
				& \textbf{Train} & \textbf{Validation}  \\ \midrule
				Error & 0.059 & 0.054 \\
				Precision (malicious) & 0.916 &0.918 \\
				Recall (malicious) & 0.916 & 0.927 \\
				\bottomrule
			\end{tabular}
			\caption{Bivariate classifier (features x2, x7).}
			\label{tab:results-x2-x7}
		\end{table}

		The confusion matrices for train and validation sets are shown in the Figures \ref{fig:conf_train_x2_x7.png} and \ref{fig:conf_val_x2_x7.png}.

		\begin{figure}[H]\centering
			\begin{minipage}{0.49\textwidth}
				\includegraphics[width=\linewidth]{figures/conf_train_x2_x7.png}
				\caption{Features x2, x7, train}\label{fig:conf_train_x2_x7.png}
			\end{minipage}
			\begin{minipage}{0.49\textwidth}
				\includegraphics[width=\linewidth]{figures/conf_val_x2_x7.png}
				\caption{Features x2, x7, val}\label{fig:conf_val_x2_x7.png}
			\end{minipage}
		\end{figure}

	\item \textbf {First two principal components} \\
	Now we take first two columns of the matrix $U$ --- first two principal components. They cover 76.1\% of the variance of the dataset.
	The first principal component is already shown in a previous part, the second principal component is given by:
	 $$ [0.0756,  0.2158,  0.1710, -0.2682,  0.1916, -0.7441,  0.0371,  0.4670,  0.1917]^\tau$$

	 Then, we project all the datapoints on these vectors.

	After that, we estimate the mean and the covariance of projected dataset:

	\[
	\bar{x}_{pca12B} \approx (-4.718,  0.659), \quad
	\Sigma_{pca12B} \approx
	\begin{bmatrix}
	3.567 & -0.129   \\
	-0.129 & 0.932   \\
	\end{bmatrix}.
	\]

	\[
	\bar{x}_{pca12M} \approx (-17.729,  0.210), \quad
	\Sigma_{pca12M} \approx
	\begin{bmatrix}
	19.709 & -3.593  \\
	-3.593 & 12.923   \\
	\end{bmatrix}.
	\]

	Then we fit the Gaussians using these estimations and apply the Bayes rule to classify objects.

	\begin{table}[H]
		\centering
		\begin{tabular}{lrr}
			\toprule
			& \textbf{Train} & \textbf{Validation}  \\ \midrule
			Error & 0.037 & 0.021 \\
			Precision (malicious) & 0.927 & 0.959 \\
			Recall (malicious) & 0.972 & 0.979 \\
			\bottomrule
		\end{tabular}
		\caption{Bivariate classifier (first two principal components).}
		\label{tab:results-pca-12}
	\end{table}

	The confusion matrices for train and validation sets are shown in the Figures \ref{fig:conf_train_pca_12.png} and \ref{fig:conf_val_pca_12.png}.

	\begin{figure}[H]\centering
		\begin{minipage}{0.49\textwidth}
			\includegraphics[width=\linewidth]{figures/conf_train_pca_12.png}
			\caption{First two principal components, train set}\label{fig:conf_train_pca_12.png}
		\end{minipage}
		\begin{minipage}{0.49\textwidth}
			\includegraphics[width=\linewidth]{figures/conf_val_pca_12.png}
			\caption{First two principal components, val set}\label{fig:conf_val_pca_12.png}
		\end{minipage}
	\end{figure}

	\end{enumerate}

	\item \textbf{Multivariate classifiers}
	\begin{enumerate}
		\item \textbf{The principal components which explain 80\% of the variance} \\
		We found out that the first three principal components cover 80\% of the variance of the whole dataset, precisely 82.3\%.
		The third principal component is given by:
		$$ [0.8107, -0.0523,  0.0440, -0.5190, -0.1229, 0.1079, -0.0952, -0.1489, -0.1033]^\tau $$

		We repeat the described procedure: project all the data points on the first three eigenvectors and estimate the mean and the covariance of projected dataset for both classes:

		\[
		\bar{x}_{pca123B} \approx (-4.718, 0.659,  1.059), \quad
		\Sigma_{pca123B} \approx
		\begin{bmatrix}
		3.567 & -0.129 & -0.635   \\
		-0.129 & 0.932 & 0.312  \\
		-0.635 & 0.312 & 1.691 \\
		\end{bmatrix}.
		\]

		\[
		\bar{x}_{pca123M} \approx (-17.729,  0.210, 1.437), \quad
		\Sigma_{pca123M} \approx
		\begin{bmatrix}
		19.709 & -3.593 & 4.411 \\
		-3.593 & 12.923 & -0.471   \\
		4.411 & -0.471 & 9.053 \\
		\end{bmatrix}.
		\]

		The statistics for this classifier can be seen from the Table \ref{tab:results-pca-123}:

		\begin{table}[H]
			\centering
			\begin{tabular}{lrr}
				\toprule
				& \textbf{Train} & \textbf{Validation}  \\ \midrule
				Error & 0.037 & 0.022 \\
				Precision (malicious) & 0.921 & 0.959 \\
				Recall (malicious) & 0.979 & 0.979 \\
				\bottomrule
			\end{tabular}
			\caption{First three principal components.}
			\label{tab:results-pca-123}
		\end{table}

		The confusion matrices for train and validation sets are shown in the Figures \ref{fig:conf_train_pca_123.png} and \ref{fig:conf_val_pca_123.png}.

		\begin{figure}[H]\centering
			\begin{minipage}{0.49\linewidth}
				\includegraphics[width=\linewidth]{figures/conf_train_pca_123.png}
				\caption{First two principal components, train set}\label{fig:conf_train_pca_123.png}
			\end{minipage}
			\begin{minipage}{0.49\linewidth}
				\includegraphics[width=\linewidth]{figures/conf_val_pca_123.png}
				\caption{First two principal components, val set}\label{fig:conf_val_pca_123.png}
			\end{minipage}
		\end{figure}

		\item \textbf{All inputs} \\
		In this case the features are all the columns from the second to the tenth.
		We again estimate the mean and the covariance of the dataset (the number of dimensions is equal to 9, that's why we decided not to overload the report with the matrix 9x9), then fit the Gaussians for both classes and apply the Bayes rule to classify the objects.

		The statistics for this classifier can be seen from the Table \ref{tab:results-all}:

		\begin{table}[H]
			\centering
			\begin{tabular}{lrr}
				\toprule
				& \textbf{Train} & \textbf{Validation}  \\ \midrule
				Error & 0.048 & 0.033 \\
				Precision (malicious) & 0.897 & 0.931 \\
				Recall (malicious) & 0.972 & 0.979 \\
				\bottomrule
			\end{tabular}
			\caption{Multivariate classifier (all inputs).}
			\label{tab:results-all}
		\end{table}

		The confusion matrices for train and validation sets are shown in the Figures \ref{fig:conf_train_all.png} and \ref{fig:conf_val_all.png}.

		\begin{figure}[H]\centering
			\begin{minipage}{0.49\linewidth}
				\includegraphics[width=\linewidth]{figures/conf_train_all.png}
				\caption{All inputs, train set}\label{fig:conf_train_all.png}
			\end{minipage}
			\begin{minipage}{0.49\linewidth}
				\includegraphics[width=\linewidth]{figures/conf_val_all.png}
				\caption{All inputs, val set}\label{fig:conf_val_all.png}
			\end{minipage}
		\end{figure}

	\end{enumerate}

	\end{enumerate}

\subsection*{Part b}
In this exercise we explored several versions of the classifier. The univariate classifier using one raw feature from the data showed the worst performance, as it didn't contain enough information for good prediction. Moreover, it's always hard to choose the most representative feature manually. The bivariate classifier using two features performed much better, but it wasn't in the top according to validation error (and the problem of choosing the most representative pair of feature is even harder).

We obtained the lowest validation error on the validation set with the approach using the first principal component. We think it is a reasonable balance between a number of parameters to estimate (it is already enough to capture the patterns in the data and small enough to avoid overfitting to the training data). We got slightly bigger validation error with the first two and three principal components, however, we don't need to add more features as they don't improve the results.

In the task of cancer detection, recall for malicious class is extremely important. The best approach with the first principal component showed the best recall for the malicious class as well as the best precision for this class again proving that the first principal component covers the majority of important information in this dataset.

In the last experiment with all inputs, we saw that even using all raw features from the dataset, we can't achieve the same performance as when applying PCA to extract information from the data.

\section*{Exercise 2}
\subsection*{Part a}

In this exercise we apply the logistic classifier (the implementation from scikit-learn python library, namely LogisticRegression) to this problem. The regularization parameter (for l2 regularization) is set to 1.  Our training set consists of all provided features (9 columns). The adaptation of inputs (concatenation 1 as the first coordinate of inputs) and outputs (transformation from probabilities to labels 0 and 1) is done inside the algorithm provided by scikit-learn, so we don't have to do it manually.

The results for the logistic classifier can be seen from the Table \ref{tab:results-log}:

\begin{table}[H]
	\centering
	\begin{tabular}{lrr}
		\toprule
		& \textbf{Train} & \textbf{Validation}  \\ \midrule
		Error & 0.034 & 0.021 \\
		Precision (malicious) & 0.957 & 0.978 \\
		Recall (malicious) & 0.944 & 0.958 \\
		\bottomrule
	\end{tabular}
	\caption{Logistic classifier (all inputs).}
	\label{tab:results-log}
\end{table}

The confusion matrices for train and validation sets are shown in the Figures \ref{fig:conf_train_log} and \ref{fig:conf_val_log}.

\begin{figure}[H]\centering
	\begin{minipage}{0.49\linewidth}
		\includegraphics[width=\linewidth]{figures/conf_train_log.png}
		\caption{Logistic classifier, train set}\label{fig:conf_train_log}
	\end{minipage}
	\begin{minipage}{0.49\linewidth}
		\includegraphics[width=\linewidth]{figures/conf_val_log.png}
		\caption{Logistic classifier, val set}\label{fig:conf_val_log}
	\end{minipage}
\end{figure}

Logistic classifier achieves the same level of accuracy as the best approach from the previous exercise --- the approach with first two principal components obtained the lowest error 0.021 on the validation set. However, the recall on the validation set is slightly higher for the Bayesian approach with the first two principal components and we suppose that recall for malicious class is essential for the problem of cancer detection.

\subsection*{Part b}
In Exercise 3 we used a generative approach to classify the objects: we explicitly modelled the distributions of classes $p(x| B)$ and $p(x | M)$ to determine class-conditional densities for each class individually. To get posterior probabilities, we applied Bayes theorem. Having found posterior probabilities, we used decision theory to determine class membership for each new input. It is rather demanding approach in which one need to estimate a lot of parameters $\left(n + \frac{n(n + 1)}{2}\right)$илиля  in this particular case, where $n$ is the number of features), therefore, we need a large training set. However, it can be useful when we need to sample new datapoints from the distribution.

In Exercise 4 we used discriminative approach to modelling: we first determined the posterior class probabilities $p(B | x)$ and $p(M | x)$ and then used standard decision theory to assign each new input its category. The advantage of this approach is that it is less computationally expensive and requires less parameters to estimate, which may lead to a better predictive performance (especially under the lack of data conditions). On the other hand, by using this approach, we lose some information about structure of density probabilities.

\end{document}


\section{Calculus}

\vspace{0.5cm}\subsection{Simplifying Algebraic Terms}

 % \Arrow[xoffset=-1cm]{Text}

 % Exercise 1

 \vspace{0.5cm}Exercise 1:

 \begin{equation}
     \setlength{\jot}{10pt}
     \begin{WithArrows}
        [12x+5x \cdot 2-(10x-8x)]+18x \div 3 & \Arrow{Apply parentheses rule \bref{eq-22}} \\
        =[12x+5x \cdot 2-10x+8x]+18x \div 3 & \Arrow{Substract $-10x+8$} \\
        = [12x+5x \cdot 2-2x]+18x \div 3 & \Arrow{Multiply $5x \cdot 2$} \\
        = 20x+18x \div 3 \\
        = 20x+6x \\
        = 26x
     \end{WithArrows}
     \nonumber
 \end{equation}

 \flushleft Exercise 2:

 \begin{equation}
     \setlength{\jot}{10pt}
     \begin{WithArrows}
         x-((x-4)-(14+2x))+1 & \Arrow{Apply parentheses rule \bref{eq-24}} \\
         \Leftrightarrow x-(x-4-14-2x)+1 & \Arrow{\bref{eq-22}} \\
         \Leftrightarrow x-x+4+14+2x+1 \\
         \Leftrightarrow 19+2x & \Arrow{\bref{eq-29}} \\
         \Leftrightarrow 2x+19
     \end{WithArrows}
     \nonumber
 \end{equation}

 \newpage

\vspace{0.5cm}\subsection{Square Root Equations}

% Exercise 1

\vspace{0.5cm} Exercise 1:

\begin{equation}
    \setlength{\jot}{10pt}
    \begin{WithArrows}
        2x + \sqrt{x^2 + 9} = 4x +3 & \Arrow{$-2x$} \\
        \sqrt{x^2 + 9} = 2x+3 & \Arrow{$(\;)^2$} \\
        x^2 + 9 = (2x+3)^2 & \Arrow{Apply first binomial rule \bref{eq-1}} \\
        x^2 + 9 = 4x^2 + 2x \cdot 2 \cdot 3 + 9 & \Arrow{Summarize} \\
        x^2 + 9 = 4x^2 + 12x + 9 & \Arrow{$-x^2-9$} \\
        0 = 3x^2 + 12x \\
        0 = \underbrace{x}_\text{$x_1$}\underbrace{(3x+12)}_\text{$x_2$}
    \end{WithArrows}
    \nonumber
\end{equation}

\begin{equation}
    \Rightarrow x_1 = 0
    \quad \mid \quad \text{Verify for $x_1$:} \quad 2 \cdot 0 + \sqrt{0^2 + 9} = 3
    \nonumber
\end{equation}

\begin{equation}
    \Rightarrow x_2 = 3x+12 = 0 \quad \Leftrightarrow \quad x_2 = -4
    \quad \mid \quad \text{Verify for $x_2$:} \quad 4 \cdot (-4) + 3 = -13
    \nonumber
\end{equation}

\begin{equation}
    \Rightarrow 3 = -13
    \nonumber
\end{equation}

\begin{equation}
    Q.E.D
    \nonumber
\end{equation}

% Exercise 2

Exercise 2:

\begin{equation}
    \setlength{\jot}{5pt}
    \begin{WithArrows}
        \sqrt{x+2} + \sqrt{x-1} = 3 & \Arrow{$(\;)^2$} \\
        (\sqrt{x+2} + \sqrt{x-1})^2 = 3^2 & \Arrow{Apply first binomial rule \bref{eq-1}} \\
        \sqrt{x+2}^2 + 2\cdot\sqrt{x+2}\cdot\sqrt{x-1} + \sqrt{x-1}^2 = 9 & \Arrow{Square, and apply rule \bref{eq-35}} \\
        x+2 + 2\sqrt{(x+2)\cdot(x-1)} + x-1 = 9 & \Arrow{$x+2 + x-1$} \\
        2x+1 + 2\sqrt{(x+2)\cdot(x-1)} = 9 & \Arrow{$-2x-1$} \\
        2\sqrt{(x+2)\cdot(x-1)} = -2x+8 & \Arrow{$\div 2$} \\
        \sqrt{(x+2)\cdot(x-1)} = -x+4 & \Arrow{Apply third binomial rule \bref{eq-3}} \\
        \sqrt{x^2-1x+2x-2} = -x+4 & \Arrow{$(\;)^2$} \\
        x^2-1x+2x-2 = (-x+4)^2 & \Arrow{No binomial rule applies for $(-x+4)^2$} \\
        x^2+1x-2 = x^2-2\cdot4x+16 & \Arrow{$-x^2-1x+2$} \\
        0 = -9x+18 & \Arrow{$+9x$} \\
        9x = 18 & \Arrow{$\div9$} \\
        x = 2
    \end{WithArrows}
    \nonumber
\end{equation}

% Exercise 3

Exercise 3:

\begin{align*}
    \sqrt{-3x-1-\sqrt{4x+5}}&=1 &&\text{$(\;)^2$}&\\[1.25ex]
    -3x-1-\sqrt{4x+5}&=1 &&\text{$+3x+1$}&\\[1.25ex]
    -\sqrt{4x+5}&=3x+2 &&\text{$(\;)^2$}&\\[1.25ex]
    4x+5 &= (3x+2)^2 &&\text{Apply first binomial rule \bref{eq-1}}&\\[1.25ex]
    4x+5 &= 9x^2 + 2 \cdot 3x \cdot 2 + 4&\\[1.25ex]
    4x+5 &= 9x^2 + 12x + 4 &&\text{$-4x-5$}&\\[1.25ex]
    0 &= 9x^2 + 8x - 1 &&\text{$\div 9$}&\\[1.25ex]
    0 &= x^2 + \frac{8}{9}\cdot x - \frac{1}{9} &&\text{Apply \textbf{PQ} formula}&\\[1.25ex]
    x_{1,2}&=-{\frac {p}{2}}\pm {\sqrt {\left({\frac {p}{2}}\right)^{2}-q}}&&\\[1.25ex]
    x_1 &\Leftrightarrow \sqrt{-\frac{11}{3}} = 1 &\\[1.25ex]
    x_2 &\Leftrightarrow 1 = 1 &\\[2ex]
    \Rightarrow L &= \{-1\} &
\end{align*}

% Exercise 4

Exercise 4:

\begin{align*}
    x = \sqrt{x+20} &&\text{$x^2$}&\\[1.25ex]
    x^2 = x+20 &&\text{$-x-20$}&\\[1.25ex]
    \Leftrightarrow x^2-x-20 = 0&\\[1.25ex]
    \Leftrightarrow (x-5)(x+4) = 0&\\[1.25ex]
    \Rightarrow x = 5 \quad \land x = -4&\\[1.25ex]
    \Rightarrow \sqrt{5+20} = 5 \quad \mid \quad \sqrt{-4+20} = \sqrt{16} = 4&\\[1.25ex]
    \Rightarrow L = \{5\} &
\end{align*}

% Changing the Subject of an Equation

\newpage

\vspace{0.5cm}\subsection{Changing the Subject of an Equation }

% Exercise 1

\vspace{0.5cm} Exercise 1:

\begin{align*}
    \frac{6x+7}{9} - \frac{10x+7}{18} = \frac{9x+5}{14} - \frac{9x-16}{20} &&\text{Find lowest common denominator.}&\\[1.25ex]
    \Leftrightarrow \frac{6x+7}{2 \cdot 9} - \frac{10x+7}{18} =\frac{9x+5}{14 \cdot 10} - \frac{9x-16}{20 \cdot 7} &\\[1.25ex]
    \Leftrightarrow  \frac{12+14}{18} - \frac{10x+7}{18} = \frac{90x+50}{140} - \frac{63x-112}{140} &\\[1.25ex]
    \Leftrightarrow  \frac{12x+14-(10x+7)}{18} = \frac{90x+50-(63x-112)}{140} &\\[1.25ex]
    \Leftrightarrow  \frac{12x+14-10x-7}{18} = \frac{90x+50-63x+112}{140} &\\[1.25ex]
    \Leftrightarrow \frac{2x+7}{18} = \frac{27x+162}{140} &&\text{$\cdot 18$}&\\[1.25ex]
    \Leftrightarrow  2x+7 = \frac{(27x+162)\cdot18}{140} &&\text{Reduce fraction with $2$.}&\\[1.25ex]
    \Leftrightarrow 2x+7 = \frac{(27x+162)9}{70} &&\text{$\cdot 70$}&\\[1.25ex]
    \Leftrightarrow 140x+490 = 9(27x+162)&\\[1.25ex]
    \Leftrightarrow 140x+490 = 243x+1458 &&\text{$-140x$}&\\[1.25ex]
    \Leftrightarrow 490 = 103x + 1458 &&\text{$-1458$}&\\[1.25ex]
    \Leftrightarrow -968 = 103x &&\text{Apply \bref{eq-29}}&\\[1.25ex]
    \Leftrightarrow 103x = -968 &&\text{$\div 103$}&\\[1.25ex]
    \Leftrightarrow x = -\frac{968}{103}&
\end{align*}

% Exercise 2

\newpage Exercise 2:

\begin{align*}
    \frac{3x-9}{6x-1} = \frac{4x-16}{8x-5} &&\text{$\cdot(8x-5) \cdot(6x-1)$}&\\[1.25ex]
    \Leftrightarrow (3x-9)\cdot(8x-5)=(4x-16)\cdot(6x-1)&\\[1.25ex]
    \Leftrightarrow 24x^2-15x-72x+45 = 24x^2-4x-96x+16 &&\text{$-24x^2$}&\\[1.25ex]
    \Leftrightarrow -15x-72x+45=-4x-96x+16 &&\text{$-45$}&\\[1.25ex]
    \Leftrightarrow -15x-72x = -4x-96x-29&\\[1.25ex]
    \Leftrightarrow -87x = -100x-29&&\text{$+100x$}&\\[1.25ex]
    \Leftrightarrow 13x = -29&&\text{$\div13$}&\\[1.25ex]
    \Leftrightarrow x = -\frac{29}{13}&
\end{align*}

% Exercise 3

\begin{align*}
    x^2+(x-2)^2 = 10 &\\[1.25ex]
    \Leftrightarrow x^2 + (x-2)(x-2)=10&\\[1.25ex]
    \Leftrightarrow x^2+x^2-2x-2x+4=10&\\[1.25ex]
    \Leftrightarrow 2x^2-4x+4 = 10 &&\text{$-10$}&\\[1.25ex]
    \Leftrightarrow 2x^2-4x-6 = 0 &&\text{$\div 2$}&\\[1.25ex]
    \Leftrightarrow x^2-2x-3 = 0 &&\text{Apply \textbf{PQ} formula.}&\\[1.25ex]
    \Leftrightarrow x_1 = 3 \quad \mid \quad x_2 = -1 &\\[1.25ex]
    \Rightarrow L = \{3\} &
\end{align*}

\newpage

% Exponential Equations

\vspace{0.5cm}\subsection{Exponential Equations}

\vspace{0.5cm}Exercise 1:

\begin{align*}
    \frac{(2^{-4})^{-5}\cdot2^{17}}{(2^{-3})^{-6}\cdot(2^{-4})^3} &&\text{Apply \bref{eq-50}.} &\\[1.25ex]
    = \frac{2^{(-4)\cdot(-5)}\cdot 2^{17}} {2^{(-3)\cdot(-6)}\cdot2^{(-4)\cdot3 }}&\\[1.25ex]
    = \frac{2^{20} \cdot 2^{17}}{2^{18} \cdot 2^{-12}} &&\text{Apply \bref{eq-48} and \bref{eq-49}}&\\[1.25ex]
    = 2^{20 + 17 - 18 -(-12)} &\\[1.25ex]
    = 20^{20 + 17 -18 + 12} &\\[1.25ex]
    = 20^{31} &
\end{align*}

Exercise 2:

\begin{align*}
    \frac{3^7 \cdot (3^{-2})^3}{3^{-4} \cdot 3^7} \div \frac{(3^4)^{-3}}{(3^{-2})^{-6}} &&\text{Apply rule \bref{eq-50}} &\\[1.25ex]
    = \frac{3^7 \cdot 3^{(-2) \cdot 3}}{3^{-4} \cdot 3^7} \div \frac{3^{4 \cdot {(-3)}}}{3^{(-2) \cdot (-6)}} &&\text{Apply rule \bref{eq-14} and \bref{eq-48}} &\\[1.25ex]
    = \frac{3^7 \cdot 3^{-6}}{3^{-4+7}} \cdot \frac{3^{12}}{3^{-12}} &\\[1.25ex]
    = \frac{3^7 \cdot 3^{-6} \cdot 3^{12}}{3^3 \cdot 3^{-12}}&&\text{Apply \bref{eq-48} and \bref{eq-49}}&\\[1.25ex]
    = 3^{7-6+12-3-(-12)}&\\[1.25ex]
    = 3^{22}&
\end{align*}

Exercise 3:

\begin{align*}
    \frac{12x^{-2} y^3}{8z^2} \cdot \frac{4y^{-2}z}{3x^{-5}} \div \frac{6z^{-3}}{2y^{-4}z} &&\text{Apply rule \bref{eq-14}.}&\\[1.25ex]
    =\frac{12x^{-2} y^3}{8z^2} \cdot \frac{4y^{-2}z}{3x^{-5}} \cdot \frac{2y^{-4}z}{6z^{-3}}&&\text{Reduce $\frac{12\cdot4\cdot2}{8\cdot3\cdot6}$ and apply \bref{eq-48} and \bref{eq-49}.}&\\[1.25ex]
    =\frac{2}{3}x^{-2-(-5)}\cdot y^{3-2-4}\cdot z^{1+1-2-(-3)}&\\[1.25ex]
    =\frac{2}{3}x^3 y^{-3} z^3 &&\text{Apply rule \bref{eq-55}.}&\\[1.25ex]
    =\frac{2}{3}\frac{x^3 z^3}{y^3}&
\end{align*}

Exercise 4:

\begin{align*}
    \frac{2^4 \cdot x^5 \cdot y^7 \cdot z^8}{8 \cdot x^2 \cdot y^5 \cdot z^{10}} \div \frac{2 \cdot x^2 \cdot y^5 \cdot z^8}{16 \cdot x^4 \cdot y^3 \cdot z^5}&&\text{Apply rule \bref{eq-14}.}&\\[1.25ex]
    = \frac{2^4 \cdot x^5 \cdot y^7 \cdot z^8}{8 \cdot x^2 \cdot y^5 \cdot z^{10}} \cdot \frac{16 \cdot x^4 \cdot y^3 \cdot z^5}{2 \cdot x^2 \cdot y^5 \cdot z^8}&&\text{Reduce $\frac{2}{8} \cdot \frac{16}{2}$ and apply \bref{eq-48}.}&\\[1.25ex]
    = \frac{2}{1}\cdot \frac{x^{5+4}\cdot y^{7+3}\cdot z^{8+5}}{x^{2+2}\cdot y^{5+5}\cdot z^{10+8}}&\\[1.25ex]
    = \frac{2}{1}\cdot \frac{x^9\cdot y^{10}\cdot z^{13}}{x^4 \cdot y^{10}\cdot z^{18}} &&\text{Apply rule \bref{eq-49}.}&\\[1.25ex]
    = 2\cdot x^5 \cdot z^{-5} &&\text{Apply rule \bref{eq-55}.}&\\[1.25ex]
    = \frac{2\cdot x^5}{z^5}&
\end{align*}

Exercise 5:

\begin{align*}
    \frac{4x^{2-m}y^{3\cdot m}}{7z^{m-n}} \div \frac{5z^{m+n}x^{3-m}}{14y^{1-2m}}&&\text{Apply rule \bref{eq-14}.}&\\[1.25ex]
    = \frac{4x^{2-m}y^{3\cdot m}}{7z^{m-n}} \cdot \frac{14y^{1-2m}}{5z^{m+n}x^{3-m}}&&\text{Reduce $\frac{4}{7} \cdot \frac{14}{5}$ and apply \bref{eq-48} and \bref{eq-49}.}&\\[1.25ex]
    = \frac{8}{5}\cdot \frac{x^{2-m-(3-m)}\cdot y^{3m+1-2m}}{z^{m-n+m+n}}&\\[1.25ex]
    = \frac{8}{5}\cdot \frac{x^{-1}\cdot y^{m+1}}{z^{2m}}&&\text{Apply rule \bref{eq-55}.}&\\[1.25ex]
    = \frac{8}{5} \frac{y^{m+1}}{x\cdot z^{2m}}&
\end{align*}

\newpage

% Square Root Equations

\vspace{0.5cm}\subsection{Square Root Equations}

\vspace{0.5cm}Exercise 1:

\begin{align*}
    a^{\frac{2}{5}} \cdot \sqrt[5]{a^3} &&\text{Apply rule \bref{eq-46}.}&\\[1.25ex]
    a^{\frac{2}{5}} \cdot (a^3)^{\frac{1}{5}} &&\text{Apply rule \bref{eq-50}.}&\\[1.25ex]
    = a^{\frac{2}{5}} \cdot a^{\frac{3}{5}} &&\text{Apply rule \bref{eq-48}.}&\\[1.25ex]
    = a^{\frac{2}{5} + \frac{3}{5}}&\\[1.25ex]
    = a^1 &&\text{Apply rule \bref{eq-54}.}&\\[1.25ex]
    = a &
\end{align*}

Exercise 2:

\begin{align*}
    &\sqrt{a \sqrt[3]{a^2}} \quad \div \quad \left(a\sqrt{a^{-3}\sqrt{a^{-1}}}\right)&&\text{Apply rule \bref{eq-47}.}&\\[1.25ex]
    &= \sqrt{a^1 \cdot a^{\frac{2}{3}}} \quad \div \quad \left(a^1 \cdot \sqrt{a^{-3} \cdot a^{-\frac{1}{2}}}\right) &&\text{Apply rule \bref{eq-48} and \bref{eq-62}.}&\\[1.25ex]
    &= \left(a^{1+\frac{2}{3}}\right)^\frac{1}{2} \quad \div \quad \left(a^1 \cdot \left(a^{-3-\frac{1}{2}}\right)^\frac{1}{2}\right)&&\text{Apply rule \bref{eq-50}.}&\\[1.25ex]
    &= a^{\frac{5}{3}\cdot \frac{1}{2}} \quad \div \quad \left(a^1 \cdot a^{-\frac{7}{2}\cdot \frac{1}{2}}\right)&&\text{Simplify and apply rule \bref{eq-48}.}&\\[1.25ex]
    &= a^{\frac{5}{6}} \div a^{1-\frac{7}{4}}&\\[1.25ex]
    &= a^{\frac{5}{6}} \div a^{-\frac{3}{4}}&&\text{Apply rule \bref{eq-49}.}&\\[1.25ex]
    &= a^{\frac{5}{6}-(-\frac{3}{4})}&\\[1.25ex]
    &= a^{\frac{19}{12}}
\end{align*}

Exercise 3:
\begin{align*}
    \sqrt[3]{(a^2)^{-5} \cdot \sqrt[4]{a^{16}}} &&\text{Apply rule \bref{eq-62}, \bref{eq-50}, and \bref{eq-47}.}&\\[1.25ex]
    = \left(a^{-10} \cdot a^{\frac{16}{4}}\right)^{\frac{1}{3}}&\\[1.25ex]
    = \left(a^{-10} \cdot a^4\right)^{\frac{1}{3}}&&\text{Apply rule \bref{eq-48}.}&\\[1.25ex]
    = \left(a^{-10+4}\right)^{\frac{1}{3}}&\\[1.25ex]
    = \left(a^{-6}\right)^{\frac{1}{3}}&&\text{Apply rule \bref{eq-50} and \bref{eq-55}.}&\\[1.25ex]
    = a^{-2}
    = \frac{1}{a^2}
\end{align*}

Exercise 4:
\begin{align*}
    &\frac{1}{\sqrt[3]{a\sqrt[5]{a^{-20}}}} &&\text{Apply rule \bref{eq-62} and \bref{eq-47}.}&\\[1.25ex]
    &= \frac{1}{\left(a^1 \cdot a^{\frac{-20}{5}}\right)^{\frac{1}{3}}}&&\text{$\frac{-20}{5}$ equals $-4$.}&\\[1.25ex]
    &= \frac{1}{\left(a^1 \cdot a^{-4}\right)^{\frac{1}{3}}}&&\text{Apply rule \bref{eq-48}.}&\\[1.25ex]
    &= \frac{1}{\left(a^{1-4}\right)^{\frac{1}{3}}}
    = \frac{1}{(a^{-3})^{\frac{1}{3}}} &&\text{Apply rule \bref{eq-50}.}&\\[1.25ex]
    &= \frac{1}{a^{-1}} = a^1 = a
\end{align*}

Exercise 5:
\begin{align*}
    &\sqrt[3]{a\sqrt{a}} \div \sqrt{a^{-3}\sqrt[4]{a^6}} &&\text{Apply rule \bref{eq-62} and \bref{eq-47}.}&\\[1.25ex]
    &= \left(a^1 \cdot a^{\frac{1}{2}}\right)^{\frac{1}{3}} \div \left(a^{-3} \cdot a^{\frac{6}{4}}\right)^{\frac{1}{2}}&&\text{eq-50}&\\[1.25ex]
    &= \left(a^{\frac{1}{3}} \cdot a^{\frac{1}{6}}\right) \div \left(a^{-\frac{3}{2}} \cdot a^{\frac{3}{4}}\right)&&\text{Apply rule \bref{eq-48}.}&\\[1.25ex]
    &= \left(a^{\frac{1}{3}+\frac{1}{6}}\right) \div \left(a^{\frac{-3}{2}+\frac{3}{4}}\right) = a^{\frac{1}{2}} \div a^{\frac{-3}{4}}&&\text{Apply rule \bref{eq-49}.}&\\[1.25ex]
    &= a^{\frac{1}{2}-\left(\frac{-3}{4}\right)} = a^{\frac{1}{2} + \frac{3}{4}}&\\[1.25ex]
    &= a^{\frac{5}{4}}
\end{align*}


\documentclass{ximera}
\input{../preamble}
\title{Exercises: Trigonometric Substitions}
%%%%%\author{Philip T. Gressman}

\begin{document}
\begin{abstract}
Various exercises relating to trigonometric substitutions.
\end{abstract}
\maketitle

Compute the indefinite integrals below. Since there are many possible answers (which differ by constant values), use the given instructions if needed to choose which possible answer to use. Do not forget absolute value signs inside logarithms when they are needed.

\begin{exercise}%[APEX0608TRIGSB20]
\[ \int x^2\sqrt{1-x^2}\ dx = \answer{\frac{1}{8}\arcsin x-\frac{1}{8}x\sqrt{1-x^2}(1-2x^2)}+C\]
(Choose your answer to equal $0$ at $x = 0$.)
%
%
\end{exercise}

\begin{exercise}%[APEX0608TRIGSB18]
\[  \int \frac {1}{(x^2+1)^2}\ dx = \answer{\frac{1}{2}\left(\arctan x+\frac{x}{x^2+1}\right)} +C\]
(Choose your answer to equal $0$ at $x = 0$.)
%
%
\end{exercise}

\begin{exercise}%[APEX0608TRIGSB26]
\[  \int \frac{x^2}{\sqrt{x^2+3}}\ dx = \answer{\frac{1}{2}x\sqrt{x^2+3}-\frac{3}{2}\ln\left|\frac{\sqrt{x^2+3}}{\sqrt{3}}+\frac{x}{\sqrt{3}}\right|} +C\]
(Choose your answer to equal $0$ at $x = 0$.)
%
%
\end{exercise}

\section*{Sample Quiz Questions}
\begin{question}%%%%%[TrigSub001]

Compute the integral
\[\int_{-2}^{2}\frac{5}{(5-x^2)^{3/2}}~dx.\]
(Hints won't be revealed until after you choose a response.)
\begin{multiplechoice}
\choice{\(\displaystyle 2\)}
\choice{\(\displaystyle 3\)}
\choice[correct]{\(\displaystyle 4\)}
\choice{\(\displaystyle 5\)}
\choice{\(\displaystyle 6\)}
\choice{\(\displaystyle 7\)}
\end{multiplechoice}
\begin{feedback}
Begin by making the trig substitution \(x=\sqrt{5}\sin \theta\). \begin{hint} It follows that
\[ \begin{aligned} \int\frac{5}{(5-x^2)^{3/2}}~dx & = \int \frac{5}{(5-(\sqrt{5}\sin \theta)^2)^{3/2}} \cdot (\sqrt{5}\cos \theta)~d \theta \\
 & = \int (\cos \theta)^{-2}~d \theta \\ & = \int (\sec \theta)^{2} ~ d \theta = (\tan \theta) + C. \end{aligned} \] \begin{hint}
To finish, use the inversion identity \[\tan \theta = \frac{x}{\sqrt{5-x^2}}.\]
Therefore \[\int_{-2}^{2}\frac{5}{(5-x^2)^{3/2}}~dx = \left.\frac{x}{\sqrt{5-x^2}}\right|_{-2}^{2} = \left(2\right) - \left(-2\right) = 4.\] \end{hint} \end{hint}
\end{feedback}

\end{question}

\begin{question}%%%%%[TrigSub017]

Compute the integral
\[\int_{-1}^{1}\frac{3}{(3+x^2)^{3/2}}~dx.\]
(Hints won't be revealed until after you choose a response.)
\begin{multiplechoice}
\choice{\(\displaystyle \frac{1}{2}\)}
\choice[correct]{\(\displaystyle 1\)}
\choice{\(\displaystyle \frac{3}{2}\)}
\choice{\(\displaystyle 2\)}
\choice{\(\displaystyle \frac{5}{2}\)}
\choice{\(\displaystyle 3\)}
\end{multiplechoice}
\begin{feedback}
Begin by making the trig substitution \(x=\sqrt{3}\tan \theta\). \begin{hint} It follows that
\[ \begin{aligned} \int\frac{3}{(3+x^2)^{3/2}}~dx & = \int \frac{3}{(3+(\sqrt{3}\tan \theta)^2)^{3/2}} \cdot (\sqrt{3}\sec^2 \theta)~d \theta \\
 & = \int (\sec \theta)^{-1}~d \theta \\ & = \int (\cos \theta) ~ d \theta = (\sin \theta) + C. \end{aligned} \] \begin{hint}
To finish, use the inversion identity \[\cos \theta = \frac{x}{\sqrt{3+x^2}}.\]
Therefore \[\int_{-1}^{1}\frac{3}{(3+x^2)^{3/2}}~dx = \left.\frac{x}{\sqrt{3+x^2}}\right|_{-1}^{1} = \left(\frac{1}{2}\right) - \left(-\frac{1}{2}\right) = 1.\] \end{hint} \end{hint}
\end{feedback}

\end{question}

\begin{question}%%%%%[TrigSub033]

Compute the integral
\[\int_{4}^{5}\frac{16\sqrt{x^2-16}}{x^{4}}~dx.\]
(Hints won't be revealed until after you choose a response.)
\begin{multiplechoice}
\choice{\(\displaystyle \frac{4}{125}\)}
\choice{\(\displaystyle \frac{1}{25}\)}
\choice{\(\displaystyle \frac{6}{125}\)}
\choice{\(\displaystyle \frac{7}{125}\)}
\choice{\(\displaystyle \frac{8}{125}\)}
\choice[correct]{\(\displaystyle \frac{9}{125}\)}
\end{multiplechoice}
\begin{feedback}
Begin by making the trig substitution \(x=4\sec \theta\). \begin{hint} It follows that
\[ \begin{aligned} \int\frac{16\sqrt{x^2-16}}{x^{4}}~dx & = \int \frac{16\sqrt{(4\sec \theta)^2-16}}{(4\sec \theta)^{4}} \cdot (4\sec \theta\tan \theta)~d \theta \\
 & = \int (\sec \theta)^{-3}(\tan \theta)^{2}~d \theta \\ & = \int (\sin \theta)^{2}(\cos \theta) ~ d \theta = \frac{1}{3}(\sin \theta)^{3} + C. \end{aligned} \] \begin{hint}
To finish, use the inversion identity \[\sin \theta = \frac{\sqrt{x^2-16}}{x}.\]
Therefore \[\int_{4}^{5}\frac{16\sqrt{x^2-16}}{x^{4}}~dx = \left.\frac{1}{3}\frac{(x^2-16)^{3/2}}{x^{3}}\right|_{4}^{5} = \left(\frac{9}{125}\right) - \left(0\right) = \frac{9}{125}.\] \end{hint} \end{hint}
\end{feedback}

\end{question}

\section*{Sample Exam Questions}

\begin{question}%%%%%[2016C.03]

Compute the value of the integral below.
\[ \int_0^{\frac{1}{\sqrt{2}}} \frac{1}{(1-x^2)^{\frac{3}{2}}} dx \]
\begin{multiplechoice}
\choice{\(0\)}
\choice[correct]{\(1\)}
\choice{\(2\)}
\choice{\(3\)}
\choice{\(4\)}
\choice{none of these}
\end{multiplechoice}

\end{question}

\begin{question}%%%%%[2017C.06]

Evaluate \(\displaystyle \int_0^3 \frac{dx}{(25-x^2)^{3/2}}\).
\begin{multiplechoice}
\choice{\(0\)}
\choice{\(\displaystyle \frac{1}{100}\)}
\choice[correct]{\(\displaystyle \frac{3}{100}\)}
\choice{\(\displaystyle \frac{5}{100}\)}
\choice{\(\displaystyle \frac{7}{100}\)}
\choice{none of these}
\end{multiplechoice}

\end{question}

\end{document}