\chapter{Introduction}
\label{chapter:Introduction}

\section{Types of machine learning}
\begin{equation}\nonumber
\begin{cases}
\text{Supervised Learning} \begin{cases} \text{Classification} \\ \text{Regression} \end{cases}\\
\text{Unsupervised Learning} \begin{cases} \text{Discovering clusters} \\ \text{Discovering latent factors} \\ \text{Discovering graph structure} \\ \text{Matrix completion} \end{cases}\\
\text{Reinforcement Learning}
\end{cases}
\end{equation}
In the \textbf{predictive} or \textbf{supervised learning} approach,the goal is to learn a \textbf{mapping} from \textbf{inputs} $\mathbf{x}$ to \textbf{outputs} $y$,given a labeled set of input-output paris $D=\{(\mathbf{x_i},y_i)\}_{i=1}{N}$.Here $D$ is called the \textbf{training set},and N is the number of training examples.
In the simplest setting,each training input $\mathbf{x_i}$ is a D-dimensional vector of numbers,representing,say,the height and weight of a person,which are called \textbf{features,attributes,or covariates}.

\section{Supervised learning}
  Similarly the form of the output or \textbf{response variable} can in principle be anything,but most methods assume that $y_i$ is \textbf{categorical or nominal} variable from some finite set,$y_i \in \{1,...,C\}$.When $y_i$ is categorical,the problem is known as \textbf{classification or pattern recognition},and when real-valued,known as \textbf{regression}.
\subsection{Classification}
  Here the goal is to learn a mapping from inputs $x$ to outputs $y$,where $y \in \{1,...,C\}$,with $C$ being the number of classes.If $C=2$,this is called \textbf{binary classification};if $C>2$,this is called \textbf{multiclass classification}.if the class labels are not mutually exclusive,we call it \textbf{multi-label classification},but this is best viewed as predicting multiple related binary class labels(a so-called \textbf{multiple output model}).
  One way to formalize the problem is as \textbf{function approximation}:assume $y=f(\mathbf{x})$ for some unknown function $f$,and the goal of learning is to estimate the function $f$ given a labeled training set,and then to make predictions(estimate) using $\hat{y} =\hat{f}(\mathbf{x})$.Our main goal is to make predictions on novel inputs,meaning ones that we have not seen before(\textbf{generalization}.
\subsubsection{Probabilistic predictions}
We denote the probability distribution over possible labels,given the input vector $\vec{x}$ and training set $\mathcal{D}$ by $p(y|\vec{x},\mathcal{D})$.
Given a probabilistic output,we can always compute out "best guess" as to the "true label" using
\begin{equation}
\hat{y} = \hat{f}(\mathbf{x}) = \arg\max\limits_{c=1}^{C} p(y=c|\mathbf{x},D)
\end{equation}
This corresponds to the most probable class label,and is called the \textbf{mode} of distribution $p(y|\vec{x},\mathcal{D})$;it is also known as a \textbf{MAP estimate}(MAP stands for\textbf{maximum a posteriori}).
\subsubsection{Applications}
\subsection{Regression}

\section{Unsupervised learning}
  \textbf{Descriptive or unsupervised learning} approach is sometimes called \textbf{knowledge discovery}.We will formalize out task as one of \textbf{density estimation},that is we want to build models of the form $p(\mathbf{x_i|\theta})$,instead of $p(y_i|\mathbf{x_i,\theta})$.
\subsection{Discovering clusters}
Let $z_i \in \{1,...,K\}$ represent the cluster to which data point $i$ is assigned.($z_i$ is an exmaple of \textbf{hidden or latent} variable).
\subsection{Discovering latent factors}
Although the data may appear high dimensional,there may only be a small number of degrees of variability,corresponding to \textbf{latent factors}.The most common approach to dimensionality reduction is called \textbf{principal components analysis or PCA}.
\subsection{Discovering graph structure}
\subsection{Matrix completion}
\subsubsection{Image inpainting}
\subsubsection{Collaborative filtering}
\subsubsection{Market basket analysis}

\section{Three elements of a machine learning model}

\textbf{Model = Representation + Evaluation + Optimization}\footnote{Domingos, P. A few useful things to know about machine learning. Commun. ACM. 55(10):78–87 (2012).}

\subsection{Representation}
In supervised learning, a model must be represented as a conditional probability distribution $P(y|\vec{x})$(usually we call it classifier) or a decision function $f(x)$. The set of classifiers(or decision functions) is called the hypothesis space of the model. Choosing a representation for a model is tantamount to choosing the hypothesis space that it can possibly learn.

\subsection{Evaluation}
In the hypothesis space, an evaluation function (also called objective function or risk function) is needed to distinguish good classifiers(or decision functions) from bad ones.

\subsubsection{Loss function and risk function}
\label{sec:Loss-function-and-risk-function}

\begin{definition}
In order to measure how well a function fits the training data, a \textbf{loss function} $L:Y \times Y \rightarrow R \geq 0$ is defined. For training example $(x_i,y_i)$, the loss of predicting the value $\widehat{y}$ is $L(y_i,\widehat{y})$.
\end{definition}

The following is some common loss functions:
\begin{enumerate}
\item 0-1 loss function \\ $L(Y,f(X))=\mathbb{I}(Y,f(X))=\begin{cases} 1, & Y=f(X) \\ 0, & Y \neq f(X) \end{cases}$
\item Quadratic(squared) loss function $L(Y,f(X))=\frac{1}{2}\left(Y-f(X)\right)^2$
\item Absolute loss function $L(Y,f(X))=\abs{Y-f(X)}$
\item Exponential loss function $L(Y,f(X)=exp(-\hat{y_i}f(\mathbf{x_i}))$
\item Logarithmic loss function \\ $L(Y,P(Y|X))=-\log{P(Y|X)}$
\end{enumerate}

\begin{tabular}{l*{3}{c}r}
Name & Loss & Derivative & $f^*$ & Algorithm                                                                                \\
\hline
Squared error & $\frac{1}{2}(y_i-f(\mathbf{x_i}))^2$ & $y_i - f(\mathbf{x_i})$ & $\mathbb{E}[y|\mathbf{x_i}]$ & L2Boosting \\
Absolute error & $|y_i-f(\mathbf{x_i})|$ & $sgn(y_i-f(\mathbf{x_i}))$ & $median(y|\mathbf{x_i})$ & Gradient boosting \\
Exponential loss & $exp(-\hat{y_i}f(\mathbf{x_i}))$ & $-\hat{y_i}exp(-\hat{y_i}f(\mathbf{x_i}))$ & $\frac{1}{2}log\frac{\pi_i}{1-\pi_i}$ & AdaBoost \\
Logloss & $log(1+e^{-\hat{y_i}f_i})$ & $y_i-\pi_i$ & $\frac{1}{2}log\frac{\pi_i}{1-\pi_i•}$ & LogitBoost \\
\hline
\end{tabular}

\begin{definition}
The risk of function $f$ is defined as the expected loss of $f$:
\begin{equation}\label{eqn:expected-loss}
R_{\mathrm{exp}}(f)=E\left[L\left(Y,f(X)\right)\right]=\int L\left(y,f(x)\right)P(x,y)\mathrm{d}x\mathrm{d}y
\end{equation}
which is also called expected loss or \textbf{risk function}.
\end{definition}

\begin{definition}
The risk function $R_{\mathrm{exp}}(f)$ can be estimated from the training data as
\begin{equation}
R_{\mathrm{emp}}(f)=\dfrac{1}{N}\sum\limits_{i=1}^{N} L\left(y_i,f(x_i)\right)
\end{equation}
which is also called empirical loss or \textbf{empirical risk}.
\end{definition}

You can define your own loss function, but if you're a novice, you're probably better off using one from the literature. There are conditions that loss functions should meet\footnote{\url{http://t.cn/zTrDxLO}}:
\begin{enumerate}
\item They should approximate the actual loss you're trying to minimize. As was said in the other answer, the standard loss functions for classification is zero-one-loss (misclassification rate) and the ones used for training classifiers are approximations of that loss.
\item The loss function should work with your intended optimization algorithm. That's why zero-one-loss is not used directly: it doesn't work with gradient-based optimization methods since it doesn't have a well-defined gradient (or even a subgradient, like the hinge loss for SVMs has).

The main algorithm that optimizes the zero-one-loss directly is the old perceptron algorithm(chapter \S \ref{chap:Perceptron}).
\end{enumerate}

\subsubsection{ERM and SRM}
\begin{definition}
ERM(Empirical risk minimization)
\begin{equation}
\min\limits _{f \in \mathcal{F}} R_{\mathrm{emp}}(f)=\min\limits _{f \in \mathcal{F}} \dfrac{1}{N}\sum\limits_{i=1}^{N} L\left(y_i,f(x_i)\right)
\end{equation}
\end{definition}

\begin{definition}
Structural risk
\begin{equation}
R_{\mathrm{smp}}(f)=\dfrac{1}{N}\sum\limits_{i=1}^{N} L\left(y_i,f(x_i)\right) +\lambda J(f)
\end{equation}
\end{definition}

\begin{definition}
SRM(Structural risk minimization)
\begin{equation}
\min\limits _{f \in \mathcal{F}} R_{\mathrm{srm}}(f)=\min\limits _{f \in \mathcal{F}} \dfrac{1}{N}\sum\limits_{i=1}^{N} L\left(y_i,f(x_i)\right) +\lambda J(f)
\end{equation}
\end{definition}

\subsection{Optimization}
Finally, we need a \textbf{training algorithm}(also called \textbf{learning algorithm}) to search among the classifiers in the the hypothesis space for the highest-scoring one. The choice of optimization technique is key to the \textbf{efficiency} of the model.

\section{Model Selection}
If data is plentiful,then on approach to avoid over-fitting is to use some of the some of the available data to train a range of models,or a given model with a range of values for its complexity parameters,and then to compare them on independent data,sometimes called a \textbf{Validation set},and select the one having the best predictive performance.If the model design is iterated many times using a limited size data set,then some over-fitting to the validation data can occur and so it may be necessary to keep aside a third \textbf{test set} on which the performance of the selected model is finally evaluated.

\subsubsection{Cross validation}
\label{sec:Cross-validation}
\begin{definition}
	\textbf{Cross validation}, sometimes called \emph{rotation estimation}, is a \emph{model validation} technique for assessing how the results of a statistical analysis will generalize to an independent data set\footnote{\url{http://en.wikipedia.org/wiki/Cross-validation_(statistics)}}.
\end{definition}

Common types of cross-validation:
\begin{enumerate}
	\item K-fold cross-validation. In k-fold cross-validation, the original sample is randomly partitioned into k equal size subsamples. Of the k subsamples, a single subsample is retained as the validation data for testing the model, and the remaining k − 1 subsamples are used as training data.
	\item 2-fold cross-validation. Also, called simple cross-validation or holdout method. This is the simplest variation of k-fold cross-validation, k=2.
	\item Leave-one-out cross-validation(\emph{LOOCV}). k=M, the number of original samples.
\end{enumerate}
In many applications,however,the supply of data for training and testing will be limited.We wish to use as much of available data as possible for both training and validation set.One solution to this dilemma is to use \textbf{cross-validations}.One round of cross-validation involves partitioning a sample of data into complementary subsets, performing the analysis on one subset (called the training set), and validating the analysis on the other subset (called the validation set or testing set). To reduce variability, multiple rounds of cross-validation are performed using different partitions, and the validation results are averaged over the rounds.

\section{The Curse of Dimensionality}
The common theme that arise when analyzing and organizing data in \textbf{high-dimensional spaces} is that when the \textbf{demensionality increases},the \textbf{volume of the space} increases so fast (\textbf{grows exponentially with the dimensionality}) that the available data become sparse.

\begin{figure}
	\includegraphics[ ]{figures/prml/Figure1.21a.jpg}
	\includegraphics[ ]{figures/prml/Figure1.21b.jpg}
	\includegraphics[ ]{figures/prml/Figure1.21c.jpg}
	\caption{Illustration of the curse of dimensionality:the number of regions of a regular grid grows exponentially with the dimensionality $D$ of the space.}
\end{figure}
The volume of a sphere of radius $r$ in $D$ dimensions must scale as $r^D$,and so we write
\begin{align}
V_D(r) = K_D r^D
\end{align}
The fraction of the volume of the sphere that lies between radius $r=1-\epsilon$ and $r=1$
\begin{align}
\dfrac{V_D(1)-V_D(1-\epsilon)}{V_D(1)}=1-(1-\epsilon)^D
\end{align}
for large $D$ this fraction tends to $1$ even for small values of $\epsilon$.Thus most of the volume of a sphere is concentrated in a thin shell near the surface!

\section{Decision Theory}
Probability theory provides us with a consistent mathematical framework for quantifying and manipulating uncertainty.And when combined with probability theory,decision theory allows us to make optimal decisions in situations involving uncertainty such as those encountered in pattern recognition.

Suppose we have an input vector x together with a corresponding vector t of target variables, and our goal is to predict t given a new value for x. For regression problems, t will comprise continuous variables, whereas for classification problems t will represent class labels. The joint probability distribution p(x, t) provides a complete summary of the uncertainty associated with these variables. Determination of p(x, t) from a set of training data is an example of \textbf{inference} and is typically a very difficult problem.

The \textbf{decision} step, is the subject of decision theory to tell us how to make optimal decisions given the appropriate probabilities. We shall see that the decision stage is generally very simple, even trivial, once we have solved the inference problem.

Consider,for a classification problem,in which case,the input are vectors  $\vec{x}$ and we denote the class $i$ by $\mathcal{C}_k$.Using Bayes' theorem,these probabilities can be expressed in the form
\begin{equation}
p(\mathcal{C}_k|\vec{x}) = \dfrac{p(\vec{x}|\mathcal{C}_k)p(\mathcal{C}_k)}{p(\vec{x})}
\end{equation}
Note that any of the quantities appearing in Bayes' theorem can be obtained from the joint distribution $p(\vec{x},\mathcal{C}_k)$ by either \textbf{marginalizing} or \textbf{conditioning} with respect to the appropriate variables.We can now interpret $p(\mathcal{C}_k)$ as the prior probability for the class $\mathcal{C}_k$,and the $p(\mathcal{C}_k|\vec{x})$ as the corresponding posterior probability,$p(\vec{x}|\mathcal{C}_k)$ is the likelihood function.If our aim it to minimize the chance of assigning $\vec{x}$ to the wrong class,then intuitively we would choose the class having the higher posterior probability.
\subsection{Minimizing the misclassification rate}
\subsection{Minimizing the expected loss}
\subsection{The reject option}
\subsection{Inference and decision}
We have broken the classification problem down into two separate stages,the \textbf{inference stage} in which we use training data to learn to \textbf{model} for $p(\mathcal{C}_k|\vec{x})$,and the subsequent \textbf{decision stage} in which we use these posterior probabilities to make optimal class assignments.An alternative  possibility would be to solve both problems together and simply learn a function that maps input $\vec{x}$ directly into decisions.Such a function is called a \textbf{discriminant function}.

In fact,we can identify three distinct approaches to solving decision problems,given, in decreasing order of complexity,by
\begin{enumerate} %[label=(\alph*)]
	\item First solve the inference problem of determining the class-conditional densities
	$p(x|\mathcal{C}_k)$ for each class $\mathcal{C}_k$ individually. Also separately infer the prior class probabilities $p(\mathcal{C}_k)$. Then use $Bayes’$ theorem in the form
	\begin{equation}
	p(\mathcal{C}_k|\vec{x}) = \dfrac{p(x|\mathcal{C}_k)p(\mathcal{C}_k)}{p(\vec{x})}
	\end{equation}
	to find the posterior class probabilities $p(\mathcal{C}_k|\vec{x})$. As usual, the denominator in $Bayes’$ theorem can be found in terms of the quantities appearing in the
	numerator, because
	\begin{equation}
	p(\vec{x}) = \sum_k{p(\vec{x}|\mathcal{C}_k)p(\mathcal{C}_k)}
	\end{equation}
	Equivalently, we can model the joint distribution $p(x, \mathcal{C}_k)$ directly and then
	normalize to obtain the posterior probabilities. Having found the posterior
	probabilities, we use decision theory to determine class membership for each new input x.Approaches that explicitly or implicitly model the \textbf{distribution of inputs as well as outputs} are known as \textbf{Generative models},because by sampling from them it is possible to generate synthetic data points in the input space.
	\item First solve the inference problem of determining the posterior class probabilities $p(\mathcal{C}_k|\vec{x})$,and then subsequently use decision theory to assign each new $\vec{x}$ to one of the classes.Approaches that model the posterior probabilities are called \textbf{discriminative models}
	\item Find a function $f(\vec{x})$,called a discriminant function,which maps each input $\vec{x}$ directly into a class label.For instance,in the case of two-case problems,$f(\cdot)$ might be binary valued and such that $f=0$ represents class $\mathcal{C}_1$ and so on.
\end{enumerate}
Now consider the relative merits of there three alternatives.Approach (a) is the
most demanding because it involves finding the joint distribution over both x and
Ck. For many applications, x will have high dimensionality, and consequently we
may need a large training set in order to be able to determine the class-conditional
densities to reasonable accuracy. Note that the class \textbf{priors} $p(\mathcal{C_k})$ can often be estimated simply from the \textbf{fractions of the training set data points in each of the classes}. One advantage of approach (a), however, is that it also allows the marginal density of data p(x) to be determined from (1.83). This can be useful for detecting new data
points that have low probability under the model and for which the predictions may
be of low accuracy, which is known as \textbf{outlier detection or novelty detection} (Bishop,
1994; Tarassenko, 1995).

However, if we only wish to make classification decisions, then it can be wasteful
of computational resources, and excessively demanding of data, to find the joint
distribution p(x, Ck) when in fact we only really need the posterior probabilities
p(Ck|x), which can be obtained directly through approach (b). Indeed, the class conditional
densities may contain a lot of structure that has little effect on the posterior
probabilities, as illustrated in Figure 1.27. There has been much interest in
exploring the relative merits of generative and discriminative approaches to machine
learning, and in finding ways to combine them (Jebara, 2004; Lasserre et al., 2006).
An even simpler approach is (c) in which we use the training data to find a
discriminant function f(x) that maps each x directly onto a class label, thereby
combining the inference and decision stages into a single learning problem. In the
example of Figure 1.27, this would correspond to finding the value of x shown by
the vertical green line, because this is the decision boundary giving the minimum
probability of misclassification.

Reasons for wanting to compute the posterior probabilities include:
\begin{itemize}
	\item \textbf{Minimize risk.}
	\item \textbf{Reject option.}
	\item \textbf{Compensating for class priors.}
	\item \textbf{Combining models.} For complex applications,we may wish to break the problem into a number of smaller subproblems each of which can be tackled by a separate module.As long as each of 	the two models gives posterior probabilities for the classes, we can combine 	the outputs systematically using the rules of probability. One simple way to 	do this is to assume that, for each class separately, the distributions of inputs are independent,so that
	\begin{equation}
	p(\vec{x_I},\vec{x_B}|\mathcal{C}_k)  = p(\vec{x_I}|\mathcal{C}_k)p(\vec{x_B}|\mathcal{C}_k)
	\end{equation}
	This is an example of \textbf{conditional independence} property.The posterior probability,given both data(from different modules) ,is then given by
	\begin{align}
	p(\mathcal{C}_k|\vec{x_I},\vec{x_B}) &\propto p(\vec{x_I},\vec{x_B}|\mathcal{C}_k)p(\mathcal{C}_k) \\
	&\propto p(\vec{x_I}|\mathcal{C}_k)p(\vec{x_B}|\mathcal{C}_k)p(\mathcal{C}_k) \\
	&\propto \dfrac{p(\mathcal{C}_k|\vec{x_I})p(\mathcal{C}_k|\vec{x_B})}{p(\mathcal{C}_k)}
	\end{align}
\end{itemize}

\section{Information theory}
Consider a discrete random variable x and we ask how much information is received when we observe a specific value for this variable.Our measure of information content will therefore depend on the probability distribution $p(x)$,and we therefore look for a quantity $h(x)$ that is monotonic function of the probability $p(x)$ and that expresses the information content.The form of $h(\cdot)$ can be found by noting that if we have two events $x$ and $y$ that are unrelated,then the information gain from observing both of them should be the sum of the information gained from each of them separately,so that $h(x,y) = h(x)+ h(y)$.Two unrelated events will be statistically independent and so $p(x,y) = p(x)p(y)$.From these two relationships,it is easily shown that $h(x)$ must be given by the logarithm of $p(x)$ and so we have
\begin{equation}\label{eqn:information content}
h(x) = -\log_2p(x)
\end{equation}
where the negative sign ensures that information is positive or zero.Note that low probability events x correspond to high information content.The choice of basis for the logarithm is arbitrary.

Now suppose that a sender wishes to transmit the value of a random variable to a receiver.The average amount of information that they transmit in the process is obtained by taking the expectation of \ref{eqn:information content}  with respect to the distribution $p(x)$ and is given by
\begin{equation}
H[x] = -\sum\limits_{x}p(x)\log_2 p(x)
\end{equation}
This important quantity is called the \textbf{entropy} of the random variable x.

The \textbf{noiseless coding theorem} (Shannon,1948) states that the entropy is a lower bound on the number of bits needed to transmit the state of a random variable.

For example ,we can represente the states $x={a, b, c, d, e, f, g, h}$ using, for instance, the following set of code strings: 0, 10, 110, 1110, 111100, 111101, 111110, 111111.
The average length of the code that has to be transmitted is then
\begin{equation}
\text{average code length} = \dfrac{1}{2} \times 1 + \dfrac{1}{4} \times 2+\dfrac{1}{8} \times 3 + \dfrac{1}{16} \times 4 + 4\times \dfrac{1}{64}\times 6 = 2 \text{ bits}
\end{equation}
Now,we switch to the use of natural logarithm in defining entropy.And entropy can be understood in an alternative view of \textbf{multiplicity}.
The continuous form of the entropy is given by
\begin{equation}
\lim\limits_{\Delta\rightarrow 0}\{\sum\limits_{i}p(x_i)\Delta \ln p(x_i) \} = -\int p(x)\ln p(x)dx
\end{equation}
where the quantity on the right-side is called the \textbf{differential entropy}.

For a density defined over multiple continuous variables,denoted collectively by the vector $\vec{x}$,the differential entropy is given by
\begin{equation}
H[x] = -\int p(\vec{x})lnp(\vec{x})d\vec{x}
\end{equation}

In the case of discrete distributions,we see that the maximum entropy configuration correspondes to an equal distribution of probabilities across the possible states of variable.Now consider the maximum entropy configuration for a continuous variable.It will be necessary to constrain the first and second moments of $p(x)$ as well as preserving the normalization constraint.Therefore we need to maximize the differential entropy $H[x] = -\int p(\vec{x}) \ln p(\vec{x})d\vec{x}$ with three constraints
\begin{align}
\int_{-\infty}^{\infty}p(x)dx &= 1 \\
\int_{-\infty}^{\infty}xp(x)dx &= \mu \\
\int_{-\infty}^{\infty}(x-\mu)^2p(x)dx &= \sigma^2.
\end{align}
The constrained maximization can be performed using Lagrange multipliers so that we maximize the following functional with respect to $p(x)$
\begin{equation}
-\int_{-\infty}^{\infty}p(x)\ln p(x)dx + \lambda_1(\int_{-\infty}^{\infty}p(x)dx-1) + \lambda_2(\int_{-\infty}^{\infty}xp(x)dx-\mu) + \lambda_3(\int_{-\infty}^{\infty}(x-\mu)^2p(x)dx - \sigma^2)
\end{equation}
Using the calculus of variations,we set the derivative of this functional to zero giving
\begin{equation}
p(x) = exp\{-1+\lambda_1+\lambda_2 x+\lambda_3 (x-\mu)^2\}
\end{equation}
The Lagrange multipliers can be found by back substitution of this result into the three constraint equations,leading finally to the result
\begin{equation}
p(x) = \dfrac{1}{(2\pi \sigma^2)^(1/2)}exp\{-\dfrac{(x-\mu)^2}{2\sigma ^2}\}
\end{equation}
and so the distribution that maximizes the differential entropy is the Gaussian.

If we evaluate the differential entropy of the Gaussian,we obtain
\begin{equation}
H[x] = \dfrac{1}{2}\{1+\ln (2\pi \sigma^2)\}
\end{equation}
Thus we see again that the entropy increases as the distribution becomes broader,i.e.,as $\sigma^2$ increases.

Suppose we have joint distribution $p(\vec{x},\vec{y})$ from which we draw pairs of values of $\vec{x}$ and $\vec{y}$.If a value of $\vec{x}$ is already known,then the additional information needed to specify the corresponding value of $\vec{y}$ is given by $-\ln p(\vec{y}|\vec{x})$,thus the average additional information needed can be written as
\begin{equation}
H[\vec{y}|\vec{x}] = -\iint p(\vec{y},\vec{x})\ln p(\vec{y}|\vec{x})d\vec{y}d\vec{x}
\end{equation}
which is called the \textbf{conditional entropy} of $\vec{y}$ given $\vec{x}$.Using the product rule,the conditional entropy satisfies the relation
\begin{equation}
H[\vec{x},\vec{y}] = H[\vec{y}|\vec{x}] + H[\vec{x}]
\end{equation}
where $H[\vec{x},\vec{y}]$ is the differential entropy of $p(\vec{x},\vec{y})$ and $H[\vec{x}]$ is the differential entropy of the marginal distribution $p(\vec{x})$.
\begin{proof}
	\begin{align}
	H[\vec{x},\vec{y}] - H[\vec{y}|\vec{x}] &=  -\iint p(\vec{y},\vec{x}) \ln p(\vec{y},\vec{x})d\vec{y}d\vec{x} + \iint p(\vec{y},\vec{x})\ln p(\vec{y}|\vec{x})d\vec{y}d\vec{x} \\
	& = \iint p(\vec{y},\vec{x}) \ln \dfrac{p(\vec{y}|\vec{x})}{p(\vec{y},\vec{x})} \\
	& = \iint p(\vec{y},\vec{x}) \ln \dfrac{1}{p(\vec{x})}d\vec{y}d\vec{x} \\
	& = -\iint p(\vec{y},\vec{x}) \ln {p(\vec{x})}d\vec{y}d\vec{x} \\
	& = -\iint p(\vec{x}) \ln {p(\vec{x})}d\vec{x} \\
	& = H[\vec{x}]
	\end{align}
\end{proof}

\subsection{Relative entropy and mutual information}
Consider some unknown distribution $p(\vec{x})$,and suppose that we have modelled this using an approximating distribution $q\vec{x})$.Then the average \textbf{additional} amount of information(in nats) required to specify the value of $\vec{x}$ as a result of using $q(\vec{x})$ instead of the true distribution is given by
\begin{align}
KL(q\parallel p) &= -\int p(\vec{x})\ln q(\vec{x}) d\vec{x} - (- \int p(\vec{x}) \ln p(\vec{x})d\vec{x}) \\
& = -\int p(\vec{x})\ln \{\dfrac{q\vec{x}}{p\vec{x}}\}d\vec{x}
\end{align}
This is known as the \textbf{relative  entropy} or \textbf{Kullback-Leibler divergence},or \textbf{KL divergence} (Kullback and Leibler,1951),between the distributions $p(\vec{x})$ and $q(\vec{x})$.Note that it is not a symmetrical quantity.
Now introduce the  concept of \textbf{convex} functions .A function $f(x)$ is said to be convex if it has the property that every chord lies on or above the function, as shown in Figure 1.31. Any value of x in the interval from x = a to x = b can be written in the form λa + (1 − λ)b where $0 \leq λ \leq 1$. The corresponding point on the chord is given by λf(a) + (1 − λ)f(b),and the corresponding value of the function is f(λa + (1 − λ)b).Convexity then implies
\begin{equation}
f(\lambda a + (1-\lambda)b) \leq \lambda f(a) + (1-\lambda) f(b)
\end{equation}
This is equivalent to the requirement that the second derivative of the function be everywhere positive. A function is called strictly convex if the equality is satisfied only for $λ\lambda = 0$ and $λ = 1$. If a function has the opposite property, namely that every chord lies on or below the function, it is called concave, with a corresponding definition for strictly concave. If a function $f(x)$ is convex, then $−f(x)$ will be concave.

Using the technique of \textbf{proof by induction},we can show that a convex function $f(x)$ satisfies
\begin{equation}\label{ineqn:Jensen's inequality}
f(\sum_{i=1}^{M}\lambda_i x_i) \leq \sum_{i=1}^{M}\lambda_i f(x_i)
\end{equation}
where $\lambda_i \geq 0$ and $\sum_{i}\lambda_i = 1$,for any set of points $\{x_i\}$,this is known as \textbf{Jensen's inequality}.If we interpret the $\lambda_i$ as the probability distribution over a discrete variable $x$ taking the values $\{x_i\}$,then \ref{ineqn:Jensen's inequality} can be written
\begin{equation}
f(\mathbb{E}[x]) \leq \mathbb{E}[f(x)]
\end{equation}
where $\mathbb{E}(\cdot)$ denotes the expectation.For continuous variables,Jensen's inequality takes the form
\begin{equation}
f(\int \vec{x}p(\vec{x})) \leq \int f(\vec{x})p(\vec{x})d\vec{x}
\end{equation}
We can apply Jensen's inequality to the KL-divergence to give
\begin{equation}
KL(p\parallel q) = -\int p(\vec{x}) \ln\{\dfrac{q(\vec{x})}{p(\vec{x})}\}d\vec{x} \geq -\ln \int q(\vec{x})d\vec{x} = 0
\end{equation}
where we have used the fact that $-\ln x$ is a convex function,together with the normalization condition $\int q(\vec{x})d\vec{x} = 1$.
\begin{theorem}[log sum inequality]
	Let $a_1,...,a_n$ and $b_1,...,b_n$ be nonnegative numbers.Denote the sum of all $a_i$ by $a$ and sum of all $b_i$ by $b$.The log sum inequality states that
	\begin{align}
	\sum_{i=1}^n a_i\log\frac{a_i}{b_i}\geq a\log\frac{a}{b},
	\end{align}
\end{theorem}
\begin{proof}
	Setting $f(x) = x\log x$,we have
		\begin{align}
		\sum_{i=1}^n a_i\log\frac{a_i}{b_i} & {} = \sum_{i=1}^n b_i f\left(\frac{a_i}{b_i}\right)
		= b\sum_{i=1}^n \frac{b_i}{b} f\left(\frac{a_i}{b_i}\right) \\
		& {} \geq b f\left(\sum_{i=1}^n \frac{b_i}{b}\frac{a_i}{b_i}\right) = b f\left(\frac{1}{b}\sum_{i=1}^n a_i\right)
		= b f\left(\frac{a}{b}\right) \\
		& {} = a\log\frac{a}{b},
		\end{align}
where the inequality follows Jensen's inequality\ref{ineqn:Jensen's inequality} since $f$ is convex.
So we have
\begin{align}
D_{\mathrm{KL}}(P\|Q) \equiv \sum_{i=1}^n p_i \log_2 \frac{p_i}{q_i} \geq 1\log\frac{1}{1} = 0.
\end{align}
\end{proof}

Suppose we try to approximate this distribution using some parametric distribution $q(\vec{x}|\vec{\theta})$.Then the expectation of KL-divergence with respect to $p(\vec{x})$ can be approximated by a finite sum over these training points,so that
\begin{equation}
KL(p\parallel q) \simeq \sum_{n=1}^{N}\{-\ln q(\vec{x_n}|\vec{\theta}) + \ln p(\vec{x_n})\}
\end{equation}
The second term on the right-hand side is independent of $\theta$,and the first term is the negative log likelihood function for $\theta$ under the distribution $q(\vec{x}|\vec{\theta})$ evaluated using the training set.Thus \textbf{minimizing this KL-divergence is equivalent to maximizing the likelihood function}.

If ,for a joint distribution,the variables $\vec{x}$ and $\vec{y}$ are not independent,we can gain some idea of whether they are 'close' to being independent by considering the KL-divergence between the joint distribution and the product of the marginals,given by
\begin{align}
I[\vec{x},\vec{y}] &\equiv KL(p(\vec{x},\vec{y}\parallel p(\vec{x})p(\vec{y})) \\
& = -\iint p(\vec{x},\vec{y})\ln (\dfrac{p(\vec{x})p(\vec{y})}{p(\vec{x},\vec{y})})d\vec{x}d\vec{y}
\end{align}
which is called the \textbf{mutual information} between the variables $\vec{x}$ and $\vec{y}$.From the property of the KL-divergence,we see that $I(\vec{x},\vec{y}) \geq 0$ with equality if,and only if $\vec{x}$ and $\vec{y}$ are independent.Using the sum and product rules of probability,we see the relationship to conditional entropy through
\begin{equation}
I[\vec{x},\vec{y}] = H[\vec{x}] - H[\vec{x}|\vec{y}] = H[\vec{y}] - H[\vec{y}|\vec{x}]
\end{equation}
Thus we can view the mutual information as the reduction in the uncertainty about $\vec{x}$ by virtue of being told the value of $\vec{y}$ (or vice versa).

\section{Some basic concepts}

\subsection{Parametric vs non-parametric models}

\subsection{A simple non-parametric classifier: K-nearest neighbours}

\subsubsection{Representation}
\begin{equation}
y=f(\vec{x})=\arg\min_{c}{\sum\limits_{\vec{x}_i \in N_k(\vec{x})} \mathbb{I}(y_i=c)}
\end{equation}
where $N_k(\vec{x})$ is the set of k points that are closest to point $\vec{x}$.

Usually use \textbf{k-d tree} to accelerate the process of finding k nearest points.

\subsubsection{Evaluation}
No training is needed.

\subsubsection{Optimization}
No training is needed.

\subsection{Overfitting}

\subsection{Model selection}
When we have a variety of models of different complexity (e.g., linear or logistic regression models with different degree polynomials, or KNN classifiers with different values ofK), how should we pick the right one? A natural approach is to compute the \textbf{misclassification rate} on the training set for each method.


\documentclass[10pt]{article}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{tabularx}

\newcommand\tmpset[2]{
  \begingroup
  #1
  #2
  \endgroup
}

\newcommand\autoscaletable[3][0pt]{
  \tmpset{\setlength\tabcolsep{#1}}{
    \noindent
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} #2}
      #3
    \end{tabular*}}
}

\begin{document}

\section{Megolm group ratchet}\label{megolm-group-ratchet}

An AES-based cryptographic ratchet intended for group communications.

\subsection{Background}\label{background}

The Megolm ratchet is intended for encrypted messaging applications
where there may be a large number of recipients of each message, thus
precluding the use of peer-to-peer encryption systems such as
\href{https://gitlab.matrix.org/matrix-org/olm/blob/master/docs/olm.md}{Olm}.

It also allows a recipient to decrypt received messages multiple times.
For instance, in client/server applications, a copy of the ciphertext
can be stored on the (untrusted) server, while the client need only
store the session keys.

\subsection{Overview}\label{overview}

Each participant in a conversation uses their own outbound session for
encrypting messages. A session consists of a ratchet and an
\href{http://ed25519.cr.yp.to/}{Ed25519} keypair.

Secrecy is provided by the ratchet, which can be wound forwards but not
backwards, and is used to derive a distinct message key for each
message.

Authenticity is provided via Ed25519 signatures.

The value of the ratchet, and the public part of the Ed25519 key, are
shared with other participants in the conversation via secure
peer-to-peer channels. Provided that peer-to-peer channel provides
authenticity of the messages to the participants and deniability of the
messages to third parties, the Megolm session will inherit those
properties.

\subsection{The Megolm ratchet
algorithm}\label{the-megolm-ratchet-algorithm}

The Megolm ratchet \(R_i\) consists of four parts, \(R_{i,j}\) for
\(j \in {0,1,2,3}\). The length of each part depends on the hash
function in use (256 bits for this version of Megolm).

The ratchet is initialised with cryptographically-secure random data,
and advanced as follows:

$\begin{aligned}
R_{i,0} &=
  \begin{cases}
  H_0\left(R_{2^{24}(n-1),0}\right) &\text{if }\exists n | i = 2^{24}n\\
  R_{i-1,0} &\text{otherwise}
  \end{cases}\\
R_{i,1} &=
  \begin{cases}
  H_1\left(R_{2^{24}(n-1),0}\right) &\text{if }\exists n | i = 2^{24}n\\
  H_1\left(R_{2^{16}(m-1),1}\right) &\text{if }\exists m | i = 2^{16}m\\
  R_{i-1,1} &\text{otherwise}
  \end{cases}\\
R_{i,2} &=
  \begin{cases}
  H_2\left(R_{2^{24}(n-1),0}\right) &\text{if }\exists n | i = 2^{24}n\\
  H_2\left(R_{2^{16}(m-1),1}\right) &\text{if }\exists m | i = 2^{16}m\\
  H_2\left(R_{2^8(p-1),2}\right) &\text{if }\exists p | i = 2^8p\\
  R_{i-1,2} &\text{otherwise}
  \end{cases}\\
R_{i,3} &=
  \begin{cases}
  H_3\left(R_{2^{24}(n-1),0}\right) &\text{if }\exists n | i = 2^{24}n\\
  H_3\left(R_{2^{16}(m-1),1}\right) &\text{if }\exists m | i = 2^{16}m\\
  H_3\left(R_{2^8(p-1),2}\right) &\text{if }\exists p | i = 2^8p\\
  H_3\left(R_{i-1,3}\right) &\text{otherwise}
  \end{cases}
\end{aligned}$

where \(H_0\), \(H_1\), \(H_2\), and \(H_3\) are different hash
functions. In summary: every \(2^8\) iterations, \(R_{i,3}\) is reseeded
from \(R_{i,2}\). Every \(2^{16}\) iterations, \(R_{i,2}\) and
\(R_{i,3}\) are reseeded from \(R_{i,1}\). Every \(2^{24}\)
iterations, \(R_{i,1}\), \(R_{i,2}\) and \(R_{i,3}\) are reseeded
from \(R_{i,0}\).

The complete ratchet value, \(R_{i}\), is hashed to generate the keys
used to encrypt each message. This scheme allows the ratchet to be
advanced an arbitrary amount forwards while needing at most 1020 hash
computations. A client can decrypt chat history onwards from the
earliest value of the ratchet it is aware of, but cannot decrypt history
from before that point without reversing the hash function.

This allows a participant to share its ability to decrypt chat history
with another from a point in the conversation onwards by giving a copy
of the ratchet at that point in the conversation.

\subsection{The Megolm protocol}\label{the-megolm-protocol}

\subsubsection{Session setup}\label{session-setup}

Each participant in a conversation generates their own Megolm session. A
session consists of three parts:

\begin{itemize}
\item
  a 32 bit counter, \(i\).
\item
  an \href{http://ed25519.cr.yp.to/}{Ed25519} keypair, \(K\).
\item
  a ratchet, \(R_i\), which consists of four 256-bit values, \(R_{i,j}\)
  for \(j \in {0,1,2,3}\).
\end{itemize}

The counter \(i\) is initialised to \(0\). A new Ed25519 keypair is
generated for \(K\). The ratchet is simply initialised with 1024 bits of
cryptographically-secure random data.

A single participant may use multiple sessions over the lifetime of a
conversation. The public part of \(K\) is used as an identifier to
discriminate between sessions.

\subsubsection{Sharing session data}\label{sharing-session-data}

To allow other participants in the conversation to decrypt messages, the
session data is formatted as described in
\ref{session-sharing-format}{Session-sharing format}. It
is then shared with other participants in the conversation via a secure
peer-to-peer channel (such as that provided by
\href{https://gitlab.matrix.org/matrix-org/olm/blob/master/docs/olm.md}{Olm}).

When the session data is received from other participants, the recipient
first checks that the signature matches the public key. They then store
their own copy of the counter, ratchet, and public key.

\subsubsection{Message encryption}\label{message-encryption}

This version of Megolm uses
\href{http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf}{AES-256}
in
\href{http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf}{CBC}
mode with \href{https://tools.ietf.org/html/rfc2315}{PKCS\#7} padding
and \href{https://tools.ietf.org/html/rfc2104}{HMAC-SHA-256} (truncated
to 64 bits). The 256 bit AES key, 256 bit HMAC key, and 128 bit AES IV
are derived from the megolm ratchet \(R_i\):

$\begin{aligned}
 \mathit{AES\_KEY}_{i}\;\parallel\;\mathit{HMAC\_KEY}_{i}\;\parallel\;\mathit{AES\_IV}_{i}
    &= \operatorname{HKDF}\left(0,\,R_{i},\text{"MEGOLM\_KEYS"},\,80\right) \\
\end{aligned}$

where \(\parallel\) represents string splitting, and
\(\operatorname{HKDF}\left(\mathit{salt},\,\mathit{IKM},\,\mathit{info},\,L\right)\)
refers to the \href{https://tools.ietf.org/html/rfc5869}{HMAC-based key
derivation function} using using
\href{https://tools.ietf.org/html/rfc6234}{SHA-256} as the hash function
(\href{https://tools.ietf.org/html/rfc5869}{HKDF-SHA-256}) with a salt
value of \(\mathit{salt}\), input key material of \(\mathit{IKM}\),
context string \(\mathit{info}\), and output keying material length of
\(L\) bytes.

The plain-text is encrypted with AES-256, using the key
\(\mathit{AES\_KEY}_{i}\) and the IV \(\mathit{AES\_IV}_{i}\) to give
the cipher-text, \(X_{i}\).

The ratchet index \(i\), and the cipher-text \(X_{i}\), are then packed
into a message as described in
\ref{message-format}{Message format}. Then the entire
message (including the version bytes and all payload bytes) are passed
through HMAC-SHA-256. The first 8 bytes of the MAC are appended to the
message.

Finally, the authenticated message is signed using the Ed25519 keypair;
the 64 byte signature is appended to the message.

The complete signed message, together with the public part of \(K\)
(acting as a session identifier), can then be sent over an insecure
channel. The message can then be authenticated and decrypted only by
recipients who have received the session data.

\subsubsection{Advancing the ratchet}\label{advancing-the-ratchet}

After each message is encrypted, the ratchet is advanced. This is done
as described in \ref{the-megolm-ratchet-algorithm}{The
Megolm ratchet algorithm}, using the following definitions:

$\begin{aligned}
    H_0(A) &\equiv \operatorname{HMAC}(A,\text{``\char`\\x00"}) \\
    H_1(A) &\equiv \operatorname{HMAC}(A,\text{``\char`\\x01"}) \\
    H_2(A) &\equiv \operatorname{HMAC}(A,\text{``\char`\\x02"}) \\
    H_3(A) &\equiv \operatorname{HMAC}(A,\text{``\char`\\x03"}) \\
\end{aligned}$

where \(\operatorname{HMAC}(A, T)\) is the HMAC-SHA-256 of \texttt{T},
using \texttt{A} as the key.

For outbound sessions, the updated ratchet and counter are stored in the
session.

In order to maintain the ability to decrypt conversation history,
inbound sessions should store a copy of their earliest known ratchet
value (unless they explicitly want to drop the ability to decrypt that
history - see \ref{partial-forward-secrecy}{Partial
Forward Secrecy}). They may also choose to cache calculated ratchet
values, but the decision of which ratchet states to cache is left to the
application.

\subsection{Data exchange formats}\label{data-exchange-formats}

\subsubsection{Session-sharing format}\label{session-sharing-format}

The Megolm key-sharing format is as follows:

\begin{verbatim}
+---+----+--------+--------+--------+--------+------+-----------+
| V | i  | R(i,0) | R(i,1) | R(i,2) | R(i,3) | Kpub | Signature |
+---+----+--------+--------+--------+--------+------+-----------+
0   1    5        37       69      101      133    165         229   bytes
\end{verbatim}

The version byte, \texttt{V}, is \texttt{"\textbackslash{}x02"}.

This is followed by the ratchet index, \(i\), which is encoded as a
big-endian 32-bit integer; the ratchet values \(R_{i,j}\); and the
public part of the Ed25519 keypair \(K\).

The data is then signed using the Ed25519 keypair, and the 64-byte
signature is appended.

\subsubsection{Message format}\label{message-format}

Megolm messages consist of a one byte version, followed by a variable
length payload, a fixed length message authentication code, and a fixed
length signature.

\begin{verbatim}
+---+------------------------------------+-----------+------------------+
| V | Payload Bytes                      | MAC Bytes | Signature Bytes  |
+---+------------------------------------+-----------+------------------+
0   1                                    N          N+8                N+72   bytes
\end{verbatim}

The version byte, \texttt{V}, is \texttt{"\textbackslash{}x03"}.

The payload uses a format based on the
\href{https://developers.google.com/protocol-buffers/docs/encoding}{Protocol
Buffers encoding}. It consists of the following key-value pairs:

\autoscaletable{c c c c}{\textbf{Name} & \textbf{Tag} & \textbf{Type} & \textbf{Meaning} \\ Message-Index & 0x08 & Integer & The index of the ratchet, $i$ \\
Cipher-Text & 0x12 & String & The cipher-text, $X_i$, of the message \\}

Within the payload, integers are encoded using a variable length
encoding. Each integer is encoded as a sequence of bytes with the high
bit set followed by a byte with the high bit clear. The seven low bits
of each byte store the bits of the integer. The least significant bits
are stored in the first byte.

Strings are encoded as a variable-length integer followed by the string
itself.

Each key-value pair is encoded as a variable-length integer giving the
tag, followed by a string or variable-length integer giving the value.

The payload is followed by the MAC. The length of the MAC is determined
by the authenticated encryption algorithm being used (8 bytes in this
version of the protocol). The MAC protects all of the bytes preceding
the MAC.

The length of the signature is determined by the signing algorithm being
used (64 bytes in this version of the protocol). The signature covers
all of the bytes preceding the signature.

\subsection{Limitations}\label{limitations}

\subsubsection{Message Replays}\label{message-replays}

A message can be decrypted successfully multiple times. This means that
an attacker can re-send a copy of an old message, and the recipient will
treat it as a new message.

To mitigate this it is recommended that applications track the ratchet
indices they have received and that they reject messages with a ratchet
index that they have already decrypted.

\subsubsection{Lack of Transcript
Consistency}\label{lack-of-transcript-consistency}

In a group conversation, there is no guarantee that all recipients have
received the same messages. For example, if Alice is in a conversation
with Bob and Charlie, she could send different messages to Bob and
Charlie, or could send some messages to Bob but not Charlie, or vice
versa.

Solving this is, in general, a hard problem, particularly in a protocol
which does not guarantee in-order message delivery. For now it remains
the subject of future research.

\subsubsection{Lack of Backward
Secrecy}\label{lack-of-backward-secrecy}

\href{https://intensecrypto.org/public/lec_08_hash_functions_part2.html\#sec-forward-and-backward-secrecy}{Backward
secrecy} (also called `future secrecy' or `post-compromise security') is
the property that if current private keys are compromised, an attacker
cannot decrypt future messages in a given session. In other words, when
looking \textbf{backwards} in time at a compromise which has already
happened, \textbf{current} messages are still secret.

By itself, Megolm does not possess this property: once the key to a
Megolm session is compromised, the attacker can decrypt any message that
was encrypted using a key derived from the compromised or subsequent
ratchet values.

In order to mitigate this, the application should ensure that Megolm
sessions are not used indefinitely. Instead it should periodically start
a new session, with new keys shared over a secure channel.

\subsubsection{Partial Forward Secrecy}\label{partial-forward-secrecy}

\href{https://intensecrypto.org/public/lec_08_hash_functions_part2.html\#sec-forward-and-backward-secrecy}{Forward
secrecy} (also called `perfect forward secrecy') is the property that if
the current private keys are compromised, an attacker cannot decrypt
\emph{past} messages in a given session. In other words, when looking
\textbf{forwards} in time towards a potential future compromise,
\textbf{current} messages will be secret.

In Megolm, each recipient maintains a record of the ratchet value which
allows them to decrypt any messages sent in the session after the
corresponding point in the conversation. If this value is compromised,
an attacker can similarly decrypt past messages which were encrypted by
a key derived from the compromised or subsequent ratchet values. This
gives `partial' forward secrecy.

To mitigate this issue, the application should offer the user the option
to discard historical conversations, by winding forward any stored
ratchet values, or discarding sessions altogether.

\subsubsection{Dependency on secure channel for key
exchange}\label{dependency-on-secure-channel-for-key-exchange}

The design of the Megolm ratchet relies on the availability of a secure
peer-to-peer channel for the exchange of session keys. Any
vulnerabilities in the underlying channel are likely to be amplified
when applied to Megolm session setup.

For example, if the peer-to-peer channel is vulnerable to an unknown
key-share attack, the entire Megolm session become similarly vulnerable.
For example: Alice starts a group chat with Eve, and shares the session
keys with Eve. Eve uses the unknown key-share attack to forward the
session keys to Bob, who believes Alice is starting the session with
him. Eve then forwards messages from the Megolm session to Bob, who
again believes they are coming from Alice. Provided the peer-to-peer
channel is not vulnerable to this attack, Bob will realise that the
key-sharing message was forwarded by Eve, and can treat the Megolm
session as a forgery.

A second example: if the peer-to-peer channel is vulnerable to a replay
attack, this can be extended to entire Megolm sessions.

\subsection{License}\label{license}

The Megolm specification (this document) is licensed under the Apache
License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.

\end{document}


\documentclass{article}
\usepackage{a4wide}
\usepackage{amsmath}

\usepackage{igor_macros}

%%No paragraph break on emty lines
\catcode10=10   \catcode13=10

\def\dint#1#2{\int_{#1}^{#2}}

\def\tower3#1#2#3{\overset{#3}{\underset{#2}{#1}}}

\def\braced#1{\left\lbrace{#1}\right\rbrace}

\title {Some relations for a and b operators}
\author {Igor Bukanov}
\date { 2004-1-27 }

\begin{document}

\begin{abstract}
Should be written
\end{abstract}

\section{Should be named 1}

In the following I will assume that $a$ and $b$ are operators with the following commutator:

\eqnl{main-commutator}{
[a, b] = 1
}

or assuming that $[a, b]$ is represented as $ab - ba$

\eqnl{main-commutator-m}{
ab - ba = 1
}

Typically $a$ corresponds to anyhilation operator and $b$ denotes creation operator so $b = a^+$, but I would not assume such relation in the following.
\p

I define operator $N$ as a product:
\eqnl{N-definition}{
N = ba
}
which typicaly denotes number-of-particles operator.

\p

Any polynomial $P(a, b)$ over a and b can always be represented in the following form:
\eqnl{canonical-ab}{
P(a, b) = \sum_{i} A(i, f_i(N)).
}

Here sum is carried over some set of integers including negative numbers and zero and by definition
\alignDo{
A(i, f_i(N)) = f_i(N)a^i, i > 0
\\
A(i, f_i(N)) = b^{-i}f_i(N), i < 0
\\
A(0, f_0(N)) = f_0(N), i = 0,
}
where $f_i(N)$ is a polynomial over $N$.

\p

The proof follows from \rf{main-commutator} by induction over number of $a$ and $b$ in an arbitrary P(a, b) term as such term can always be rearanged as $N^ia^k$ or $b^lN^j$ plus terms with smaller number of $a$ and $b$.

\p

My goal is to give presentation in the form \rf{canonical-ab} for the product $A(i, f_i(N)) A(j, f_j(N))$ which would give a rule for multiplying $P(a,b)$ polynomials.

\p First I prove that for any $i >= 0$
\eqnl{abi-and-N}{
\splitDo{
 a^i N & = (N + i) a^i, \\
 N b^i & = b^i (N + i)
}
}

When $i = 0$, the relation follows trivialy. Now consider induction over $i$ when $i \ge 0$:
\eqn{
\splitDo{
a^{i+1} N
& = a{a^i} N = a (N + i)a^i \; \text{(induction hypothesis)} \\
& = (aN + ia)a^i \equiv (aba + ia)a^i = ((ba + 1)a +ia)a^i
    \; \text{(using \rf{main-commutator-m})} \\
& \equiv ((N + 1)a +ia)a^i  = (Na + a + ia) a^i = (N + 1 + i) aa^i \\
& = (N + i + 1) a^{i+1}.
}}

Similarly in the $b$ case I obtain:
\eqn{
\splitDo{
Nb^{i+1}
& = Nb^ib = b^i(N + i)b \; \text{(induction hypothesis)} \\
& = b^i(Nb + ib) \equiv b^i(bab + ib) = b^ib(ab + i)
\\ &= b^{i+1}(ba + i + 1)\; \text{(using \rf{main-commutator-m})}
\equiv b^{i+1}(N + i + 1).
}}

\p
Using \rf{abi-and-N} as a base case for another induction, it allows to prove that
\eqnl{aib-and-Nk}{
\splitDo{
a^i N^k & = (N + i)^k a^i, \\
N^k b ^i  & = b^i (N + i)^k
}
}
for any $i \ge 0$, $k >= 0$. Indeed:
\eqn{
\splitDo{
a^i N^{k+1}
& = a^iN^kN = (N + i)^k a^iN \text{(induction hypothesis)} \\
& = (N + i)^k (N + i) a^i = (N + i)^{k + 1} a^i.
}}
and similarly for $b$.

From \rf{aib-and-Nk} it follows that
\eqnl{aib-and-fN}{
\splitDo{
a^i f(N) & = f(N + i) a^i, \\
f(N)b^i  & = b^i f(N + i), \\
f(N) a^i & = a^i f(N - i), \\
b^if(N) & =  f(N - i) b^i
}}
where f(N) is some polynomial over N:
\eqn{
f(N) = \sum_{k=0}^{k_{max}} n_kN^k
}
so
\eqn{
\splitDo{
a^i f(N) & = \sum_{k=0}^{k_{max}} n_k a^i N^k
= \sum_{k=0}^{k_{max}} n_k (N+i)^k a^i = f(N+i) a^i,
\\
f(N) b^i  & = \sum_{k=0}^{k_{max}} n_k N^k b^i
= \sum_{k=0}^{k_{max}} n_k b^i (N+i)^k  = b^i f(N+i).
}
}

The last 2 lines in \rf{aib-and-Nk} follows trivially from the relabeling $f(N - i)$ as $\tilde{f}(N)$ and using the first 2 lines line for $\tilde{f}(N)$.

\p

I will also need the expression for $b^ia^i$, $a^ib^i$, $i > 0$ as a polynomial of $N$:
\eqnl{ak-bk}{
\splitDo{
b^ia^i & = \prod_{k=0}^{i - 1} (N - k), \\
a^ib^i & = \prod_{k=1}^{i} (N + k)
}
}
which can also be symbolically written as
\eqn{
b^ia^i = \frac{N!}{(N-i)!}, \quad a^ib^i = \frac{(N+i)!}{N!}
}
or more explicitly
\eqn{
\splitDo{
b^ia^i & = N(N - 1)...(N - (i - 2))(N - (i - 1)),
\\
a^ib^i & = (N + 1)(N + 2)...(N + i - 1)(N + i).
}}

\p
As in the previous cases to prove \rf{ak-bk} I use induction over $i$. The base case of $i=1$ is trivial:
\eqn{
ba \equiv N = \prod_{k=0}^{0} (N - k),
\quad ab = ba + 1 \equiv N + 1 = \prod_{k=1}^{1} (N + k)
}

For the induction step I have using \rf{aib-and-fN}:
\eqn{
\splitDo{
b^{i+1}a^{i+1} & = bb^ia^ia = b \left(\prod_{k=0}^{i - 1} (N - k)\right) a \;
 \text{(induction hypothesis)}
\\ & = ba \left(\prod_{k=0}^{i - 1} (N - 1 - k)\right) \; \text{(using \rf{aib-and-fN})}
 \equiv N \left(\prod_{k=0}^{i - 1} (N - 1 - k)\right)
\\ & = N \left(\prod_{k=1}^{i} (N - k)\right)
    =  \prod_{k=0}^{i} (N - k)
}
}
and for the $ab$ case:
\eqn{
\splitDo{
a^{i+1}b^{i+1} & = aa^ib^ib = a \left(  \prod_{k=1}^{i} (N + k)  \right) b  \;
 \text{(induction hypothesis)}
\\ & = \left(\prod_{k=1}^{i} (N + 1 + k) \right) ab
= \left(\prod_{k=1}^{i} (N + 1 + k) \right) (N + 1)
\\&
= \left(\prod_{k=2}^{i + 1} (N + k) \right) (N + 1)
= \prod_{k=1}^{i + 1} (N + k).
}
}

\p
The relations \rf{aib-and-fN} and \rf{ak-bk} allows to calculate $A(i, f(N))A(j, g(N))$. First I consider simple cases when $i$ and $j$ has the same sign. Indeed:
\eqnl{AA-same-sign}{\splitDo{
A(i, f(N))A(j, g(N))&, i \ge 0, j \ge 0
\\ & \equiv f(N)a^if_j(N)a^j
 =  f(N)g(N + i)a^ia^j = f(N)g(N + i) a^{i+j}
\\ &
= A(i+j, f(N)g(N+i)),
\\
A(i, f(N))A(j, g(N)) &, i \le 0, j \le 0
\\ &
 \equiv b^{-i} f(N) b^{-j} g(N)
 = b^{-i} b^{-j}  f(N - j) g(N) = b^{-(i + j)} f(N - j) g(N)
\\ &
= A(i+j, f(N -j)g(N)).
}}

No I calculate $A(i, f(N))A(j, g(N))$ when $i \ge 0$, $j \le 0$ which I split into 2 subcases:
\eqnl{AA-posnegpos}{\splitDo{
A(i, f(N)) & A(j, g(N)), i \ge 0, j \le 0, i + j \ge 0
\\ &
\equiv f(N) a^i b^{-j} g(N)
 = f(N) a^{i+j} a^{-j} b^{-j} g(N)
 = f(N) a^{i+j} \frac{(N - j)!}{N!} g(N)
\\ &
 = f(N) \frac{(N - j + i + j)!}{(N +i + j)!} a^{i+j} g(N)
 = f(N) \frac{(N + i)!}{(N + i + j)!} g(N + i+j) a^{i+j}
\\ &
= A\left(i + j, f(N) g(N + i + j) \frac{(N + i)!}{(N + i + j)!} \right),
}}

\eqnl{AA-posnegneg}{\splitDo{
A(i, f(N)) & A(j, g(N)), i \ge 0, j \le 0, i + j \le 0
\\ &
\equiv f(N) a^i b^{-j} g(N)
 = f(N) a^i b^i b^{-(i + j)} g(N)
 = f(N) \frac{(N + i)!}{N!} b^{-(i + j)} g(N)
\\ &
 = f(N) b^{-(i + j)}  \frac{(N + i - (i + j))!}{(N - (i + j))!} g(N)
 = b^{-(i + j)}  f(N - j - i)  \frac{(N - j)!}{(N - j - i)!} g(N)
\\ &
= A\left(i + j, f(N - j - i) g(N) \frac{(N - j)!}{(N - j - i)!} \right).
}}

The treatment of the last case when $i \le 0$, $j \ge 0$ follows the same pattern of 2 subcases:
\eqnl{AA-negpospos}{\splitDo{
A(i, f(N)) & A(j, g(N)), i \le 0, j \ge 0, i + j \ge 0
\\ &
\equiv b^{-i}f(N) g(N)a^{j}
 = f(N-(-i)) g(N-(-i)) b^{-i}a^j
\\ &
 = f(N+i) g(N + i) b^{-i}a^{-i}a^{j+i}
 = f(N+i) g(N + i) \frac{N!}{(N - (-i))!}a^{j+i}
\\&
= A\left(i + j, f(N+i) g(N + i) \frac{N!}{(N + i)!} \right),
}}

\eqnl{AA-negposneg}{\splitDo{
A(i, f(N)) & A(j, g(N)), i \le 0, j \ge 0, i + j \le 0
\\ &
\equiv b^{-i}f(N) g(N)a^{j}
 b^{-i}a^{j}f(N - j) g(N - j)
\\ &
 b^{-i-j}b^{j}a^{j}f(N - j) g(N - j)
 = b^{-(i + j)}\frac{N!}{(N - j)!}f(N - j) g(N - j)
\\&
= A\left(i + j, f(N - j) g(N - j)\frac{N!}{(N - j)!} \right).
}}

Combing \rf{AA-same-sign}, \rf{AA-posnegpos}, \rf{AA-posnegneg}, \rf{AA-negpospos}, \rf{AA-negposneg} gives
\eqnl{AA-product}{
A(i, f(N)) A(j, g(N)) = A(i + j, \Pi(i, j, f(N), g(N)))
}

where by defintion:
\eqnl{Pi-def}{
\splitDo{
\Pi(i, j, f(N), g(N)), &i \ge 0, j \ge 0
    = f(N)g(N + i),
\\
\Pi(i, j, f(N), g(N)), &i \le 0, j \le 0
    = f(N - j)g(N),
\\
\Pi(i, j, f(N), g(N)), & i \ge 0, j \le 0, i + j \ge 0
    = f(N) g(N + i + j) \frac{(N + i)!}{(N + i + j)!},
\\
\Pi(i, j, f(N), g(N)), & i \ge 0, j \le 0, i + j \le 0
    = f(N - j - i) g(N) \frac{(N - j)!}{(N - j - i)!},
\\
\Pi(i, j, f(N), g(N)), & i \le 0, j \ge 0, i + j \ge 0
 = f(N+i) g(N + i) \frac{N!}{(N + i)!}
\\
\Pi(i, j, f(N), g(N)), & i \le 0, j \ge 0, i + j \le 0
    = f(N - j) g(N - j)\frac{N!}{(N - j)!}.
}}

Replacing symbolic factorial-like expressions with explicit products leads gives:
\eqnl{Pi-def-explicit}{
\splitDo{
\Pi(i, j, f(N), g(N)), &i \ge 0, j \ge 0
    = f(N)g(N + i),
\\
\Pi(i, j, f(N), g(N)), &i \le 0, j \le 0
    = f(N - j)g(N),
\\
\Pi(i, j, f(N), g(N)), & i \ge 0, j \le 0, i + j \ge 0
    = f(N) g(N + i + j) \prod_{k = i + j + 1}^{i} (N + k)
\\
\Pi(i, j, f(N), g(N)), & i \ge 0, j \le 0, i + j \le 0
    = f(N - j - i) g(N) \prod_{k = -j - i + 1}^{-j} (N + k)
\\
\Pi(i, j, f(N), g(N)), & i \le 0, j \ge 0, i + j \ge 0
 = f(N+i) g(N + i) \prod_{k = i + 1}^{0} (N + k)
\\
\Pi(i, j, f(N), g(N)), & i \le 0, j \ge 0, i + j \le 0
    = f(N - j) g(N - j) \prod_{k = -j + 1}^{0} (N + k).
}}

In the last expressions it is assummed that empty product means 1 to cover properly cases with $i = 0$, $j = 0$.

\end{document}


% !TEX root = index.tex

\section{Sheaves}
\epigraph{Out of nothing I've created a strange new universe.}{Bolyai (MC Tagline)}

Why do the cohomologies compute the ``number of holes in a space''? This question is difficult to answer as for general spaces we cannot even answer the question ``what does it mean to have an $n$ dimensional hole''. Instead, we can see that for simple spaces like graphs, surfaces, $n$-dimensional spheres, cohomologies indeed compute the $n$ dimensional holes in the space. And so, for spaces that we cannot visualize well, we simply adapt Cech cohomology as an algebraic substitute for the number of holes in a space.

\begin{figure}[H]
	\begin{tabular}{|l|l|l|l|l|}
		\hline
		$X$ & $\dim \check H^0(X)$ & $\dim \check H^1(X)$ & Other non-zero cohomologies\\\hline
		Any contractible Space & 1 & 0 & 0 \\
		$d$ points & d & 0 & 0\\
		$S^1$ & 1 & 1 & 0 \\
		$S^1 \vee S^1$ & 1 & 2 & 0 \\
		$S^1 \sqcup S^1$ & 2 & 2 & 0 \\
		Connected Graph $G$ & 1 & number of cycles & 0 \\
		 $ \R^2 \setminus \{(0,0), (1,0), \dots, (k,0) \}$  & 1 & k+1 & 0 \\
		 $ S^2 $ minus a point & 1 & 0 & 0 \\
		 $ S^2 $ minus 2 points & 1 & 1 & 0 \\
		 $ S^2 $ & 1 & 0 & $\dim \check H^2(X)=1$  \\
		 $ S^1 \times S^1 $ & 1 & 2 & $\dim \check H^2(X)=1$  \\
		 Klein Bottle & 1 & 2 & $\dim \check H^2(X)=1$  \\
		 Projective Space & 1 & 1 & $\dim \check H^2(X)=1$  \\
		 $g$ holed surface & 1 & 2g & $\dim \check H^2(X)=1$  \\
		 $S^n$ & 1 & 0 & $\dim \check H^n(S^n)=1$  \\\hline
	\end{tabular}
	\caption{Which of the above spaces are not homeomorphic to each other?}
\end{figure}

We were able to compute cohomology groups using just locally constant functions. It's natural to ask whether one can compute deeper properties of spaces (not just holes) using more complicated functions. And indeed this is the case; the most general setting in which Cech cohomologies can be computed is that of a sheaf and different sheaves allow us to understand different aspects of spaces\\

\noindent	\textbf{Note: } I'm including this section for the sake of completeness. Knowing what a sheaf is does not help you with anything else. Knowing lots of other maths helps you understand sheaves better. \\

In this section, $X$ will always stand for a topological space.

\begin{definition}
	A \textbf{presheaf} $\P$ on a space $X$ valued in vector spaces, is a pair $(\P, \mor)$ where:
	\begin{enumerate}
		\item $\P$ is an assignment
		\begin{align*}
			 U \mapsto \P(U)
		\end{align*}
		which assigns a vector space $\P(U)$ for each open subset $ U \subseteq X$.
		\item $\mor$ is a collection of linear transformations
		\begin{align*}
			\mor_{V \rightarrow U}:\P(V) \rightarrow \P(U)
		\end{align*}
		for each pair of inclusions $U \subseteq V$ where $U, V$ are open subsets of $X$. We want the maps $\mor_{V \rightarrow U}$ to satisfy the following conditions:
		      \begin{itemize}
			      \item For each open subset $ U $, $ \mor_{U \rightarrow U}$ is the identity map.
			      \item For each inclusion of open subsets $ U \subseteq V \subseteq W$
						\begin{align*}
							\mor_{V\rightarrow U} \circ \mor_{W \rightarrow V} = \mor_{W \rightarrow U}
							&&
							\xymatrix{
				      \P(W) \ar@/_1pc/_{\mor_{V \rightarrow U} \circ \mor_{W \rightarrow V}= \mor_{W \rightarrow U}}[rrrr] \ar^{\mor_{W \rightarrow V}}[rr] && \P(V) \ar^{ \mor_{V\rightarrow U}}[rr] && \P(U)
				      }
						\end{align*}
		      \end{itemize}
	\end{enumerate}
\end{definition}

Recall that $\L(U)$ is the space of continuous maps $U \rightarrow \F$ and for $U \subseteq V$ the morphism $\res_{V \rightarrow U}$ is the restriction of functions $f \mapsto f|_{U}$. $\L$ is called the \textbf{constant sheaf} on $X$.
\begin{ques}
	Show that $(\L, \res)$ defines a presheaf over $X$ valued in $\F$-vector spaces.
\end{ques}
There is nothing special about $\F$. We can replace $\F$ with any space and get the corresponding presheaf.
\begin{definition}
	\label{def:presheaf_Y}
	For a topological space $Y$ let $\L_Y(X)$ denote the space of continuous maps $X \rightarrow Y$ (this is just a set and not a vector space) and for $U \subseteq V$ the morphism $\res_{V \rightarrow U}$ is the restriction of functions $f \mapsto f|_{U}$.
\end{definition}
\begin{ques}
	Show that $(\L_Y, \res)$ defines a presheaf over $X$ valued in sets.
\end{ques}
Finally, we can let the target vary with each point and get the most general notion of a function.
\begin{definition}
	Given a map $\phi:Z \rightarrow X$ a \textbf{section} of $\phi$ over a subset $U \subseteq X$ is a map $s: U \rightarrow Z$ satisfying $\phi \circ s(u) = u$ for all $u \in U$.
	\begin{align*}
		\xymatrix{
			& Z \ar^\phi[d] \\
			U \ar@{^{(}->}[r] \ar^s[ru] & X
		}
	\end{align*}
	Let $\L_\phi(U)$ denote the set of sections of $\phi$ over $U$  and for $U \subseteq V$ the morphism $\res_{V \rightarrow U}$ is the restriction of sections $f \mapsto f|_{U}$.
\end{definition}

\begin{ques}
	\begin{enumerate}
		\item Show that $(\L_\phi, \res)$ is a presheaf over $X$.
		\item Find a $\phi$ such that $\L_\phi = \L_Y$ where $\L_Y$ is as defined in \ref{def:presheaf_Y}.
		\item Describe the presheaf $\L_\phi$ when $\phi: Z \rightarrow X$ is an injection.
		\item Describe the presheaf $\L_\phi$ when $\phi: Z \rightarrow X$ is a surjection.
	\end{enumerate}
\end{ques}

\begin{ques}
	Define $(\mathcal{Q}, \mor)$ as
	\begin{align*}
		\mathcal{Q}(U) &= \R\\
		\mor_{V \rightarrow U} &= \mbox{ multiplication by }1 \mbox{ for any } U \subseteq V
	\end{align*}
	\begin{enumerate}
		\item Show that this is  presheaf.
		\item If we instead have $\mor_{V \rightarrow U} = $ multiplication by 0, is it a presheaf?
		\item If we instead have $\mor_{V \rightarrow U} = $ multiplication by 0 if $V \neq U$, multiplication by 1 if $V = U$, is it a presheaf?
	\end{enumerate}
\end{ques}

\begin{ques}
	Let $X = \R^1$. Define
	\begin{align*}
		\mathcal{B}(U) = \{ f : U \rightarrow \R \mbox{ continuous such that } |f(x)| < M \mbox{ for some $M \in \R$ and every } x \in U \}
	\end{align*}
	and the $\res_{V \rightarrow U} $ is the restriction of functions. Is $(\mathcal{B},\res)$ a presheaf?
\end{ques}

\begin{ques}
	Let $p$ be a point in $X$. Define
	\begin{align*}
		\mathcal{S}(U) = \begin{cases}
			 \R	& \mbox{ if } p \in U \\
			 0 & \mbox{ otherwise}
		\end{cases}
	\end{align*}
	Define $\mor$ such that $(S,\mor)$ becomes a presheaf. This is the \textbf{skyscraper sheaf} over $p$.
\end{ques}

\begin{definition}
	For a presheaf $\P$ the elements of $\P(U)$ are called the \textbf{sections} of $\P$ over $U$.
\end{definition}
\begin{definition}
	A \textbf{sheaf} on $ X$ is a presheaf $ \P$ that further satisfies the following conditions. Let $V$ be an open subset of $X$. Let $ \U = \{U_i\}_{i \in \aleph}$ (here we do not require $\aleph$ to be finite) be a cover of $ V$.
	\begin{enumerate}
		\item \textit{(Identity axiom)} If a section $s \in \P(V)$ is such that $ \mor_{U \rightarrow U_i}(s) = 0$ for all $ U_i$ then $ s = 0$.
		\item \textit{(Gluing axiom)} If there exists a collection of sections $ s_i \in \P(U_i)$ such that for all $ i,j \in I$ the intersections are compatible $$ \mor_{U_i \rightarrow U_i \cap U_j} (s_i) = \mor_{U_j \rightarrow U_i \cap U_j} (s_j)$$ then there exists a section $ s \in \P(V)$ such that $$ s_i = \mor_{V \rightarrow U_i} (s) $$
	\end{enumerate}
\end{definition}
These two axioms ensure that sections of sheaves behave like functions. The identity axiom is saying that if two functions agree on all the points then they must be the same functions. The gluing axiom allows us to create piece-wise functions.
% The identity axiom is a uniqueness axiom. It ensures that there if two sections look the same when restricted to small sets, then the two sets should have been the same to begin with.
%
% The gluing axiom is a constructive axiom. It is saying that you can glue sections on small open subsets to get a section on a large open subset as long as the sections on the smaller sets agree on intersections.

\begin{ques}
	Determine which of the presheaves defined in the previous problems are also sheaves.
\end{ques}
\begin{remark}
	Every sheaf (defined below) is of the type $\L_\phi$ for some $\phi$. The space $Z$ is called the \'etal\'e space of $\L_\phi$. This is not true for presheaves which can get weird.
\end{remark}

The difference between presheaves and sheaves is that, thanks to the gluing axiom, sheaves are determined by the sections on smaller and smaller subsets.
\begin{ques}
	Let $X = \{-1 , 1\}$. Let $\P$ be presheaf on $X$ valued in vector spaces.
	\begin{enumerate}
		\item If $\P$ is a sheaf find $\P(X)$ in terms of $\P(\{-1\})$ and $\P(\{1\})$.
		\item If $\P$ is just a presheaf what is the relationship between $\P(X)$, $\P(\{-1\})$ and $\P(\{1\})$?
	\end{enumerate}
\end{ques}

The Cech cohomology for sheaves is a direct generalization of the one we defined for $\L$.
\begin{definition}
	If $\U$ is a cover of $X$ and $\P$ is a sheaf on $X$ valued in vector spaces over $\F$ then the \textbf{Cech complex} of $\P$ on $\U = \{ U_i \}_{i \in \aleph}$ is defined as :\\ the spaces are
	  	\begin{align*}
	  		\P^k := \prod_{I \subseteq \aleph, \: |I| = k+1} \P(U_I)
	  	\end{align*}
	and the differential maps $d^k$ are constructed from the maps $\mor_{U_I \rightarrow U_J}$ with $J \subseteq \aleph, |J| = k+2$.

		The \textbf{Cech cohomology} of the sheaf $\P$ on the cover $\U$, denoted $H^*(\U, \P)$ is defined as the cohomology of this cochain complex.
\end{definition}
\begin{remark}
	The first major difference is that the indexing set $\aleph$ is no longer required to be finite. There are no finiteness conditions on the sets $\P(U)$ either so we need to replace direct sums with direct products.

	The second major difference is that for general sheaves it is no longer true that all good covers give the same cohomologies and so we need to keep track of the cover.
\end{remark}

We've only explored the cohomology of one simple sheaf, the constant sheaf.
It is hard to describe what cohomologies compute for general sheaves. Sheaves provide the language for describing complicated structures in algebra and almost every important algebraic invariant is a cohomology of some sheaf.


\section{Pilot Automaton}

\subsection{Parts of a Pilot Automaton}
\begin{figure}[H]
    \centering
    \begin{tikzpicture}
        \draw (0,0) -- (2,0) -- (2,2) -- (0,2) -- (0,0);
        \draw (0,1.33) -- (2,1.33);
        \draw (0.1,1.66) node[anchor=west] {$1_S\qquad \dashv$};
        \draw (0.1,1) node[anchor=west] {$0_A\qquad \dashv$};
        \draw (0.1,0.33) node[anchor=west] {$0_B\qquad a\dashv$};

        \draw[dotted] (0.4,1) ellipse (0.4 and 1.1);
        \draw (0.4,0) node[anchor=north] {kernel};
        \draw[dotted] (1.6,1) ellipse (0.4 and 1.1);
        \draw (1.6,2.1) node[anchor=south] {lookaheads};

        \draw [decorate,decoration={brace,amplitude=3},xshift=-4pt,yshift=0pt]
        (0,1.33) -- (0,2) node [black,midway,xshift=-0.6cm]
        {base};
        \draw [decorate,decoration={brace,amplitude=3},xshift=-4pt,yshift=0pt]
        (0,0) -- (0,1.33) node [black,midway,xshift=-0.8cm]
        {closure};
    \end{tikzpicture}
\end{figure}

\subsection{Closure Function}
Let $C$ be a set of candidates:

\begin{algorithm*}[H]
    \caption{Closure Function}
    \SetAlgoLined
    $K = C$\;
    \Do{nothing changes}{
        \begin{alignat*}{2}
            K = K \cup \{ &\langle 0_B,b \rangle | \exists \langle q,a \rangle \in K \land \\
            & \exists\text{ arc } q\xrightarrow{B} r \text{ in } M \land b \in Ini(L(r).a) \}
        \end{alignat*}
    }
    $closure(C) = K$
\end{algorithm*}

In words:
\begin{itemize}
    \item For each candidate add new candidates with $0_B$ as the kernel.
    \item The lookaheads are $Ini(L(r).a)$, i.e. the characters that can follow $r$, including those due to the nullableness of $r$.
\end{itemize}

\subsection{Construction of the automaton}
Construct the m-states $R = \{I_0, I_1, \ldots\}$ and the state-transition function $\theta$.

\begin{algorithm*}[H]
    \caption{Construction of the automaton}
    \SetAlgoLined
    $R' = \{I_0\}$\;
    \Do{$R \ne R'$}{
        $R = R'$\;
        \For{$I\in R$ and $X\in \Sigma \cup V$}{
            $I' = Closure(\theta(I,X))$\;
            \If{$I' \ne \emptyset$}{
                add arc $I \xrightarrow{X} I'$ to $\theta$\;
                \If{$I'\notin R$}{
                    add $I'$ to $R'$\;
                }
            }
        }
    }
\end{algorithm*}

\newpage

In words:
\begin{itemize}
    \item Start from the initial m-state built from the closure of the initial state of the axiom.
    \item For each m-state add an arc for the exiting transitions to a new m-state considering all the candidates.
    \item Compute and add the closure to the new m-state.
    \item Add the m-state to the automaton \textbf{if not already present}.
\end{itemize}

\textbf{Note}: shift moves do not change the lookaheads, only closures do.


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{October 29, 2014}
\maketitle
if $\liminf x_n=L$ then there exists $\{x_{n_k}\}$ such that $\lim x_{n_k}=L$

$l=\liminf x_n=\lim(inf\{\underbrace{x_{n_1},x_{n_2},x_{n_3},\dots}_{c_n}\}$

why not just let $c_n$ be the subseuence? because $c_n$ may not be equal to any of the $x_k$ in the sequence

$c_n=\inf\{x_{n_1},x_{n_2},\dots\}$ give $\varepsilon=2^{-n}$ there exists $x_{n_k}\in\{x_{n_1},x_{n+1},x_{n+2},\dots\}$ such that $\left\lvert c_n-x_{n_k}\right\rvert<2^{-n}$ by def of infinum

we has a sequence $\{c_n\}$ given $\varepsilon>0$ there exists $N$ such that $\left\lvert c_n-L\right\rvert<\varepsilon$ if $n\ge N$. we approximate each $c_n$ by some $x_{n_k}$ from the oricinal sequence sutch that ....

\section*{convergence test for series}
first we talk about series with positive terms $\sum\limits_{k=1}^\infty{a_k}$, $s_n=\sum\limits_{k=1}^n{a_k}$. So if $s_n$ is bounded about then the series is convergent. and if not, it is divergent.

geometric series $\sum\limits_{n=0}^\infty{r^n}$ is convergent if $\left\lvert r\right\rvert<1$. $s_n=\sum\limits_{k=0}n{r^k}=1+r+r^2+\dots+r^n, rs_n=r+r^2+r^3+\dots, sn-rSn=1-r^{n+1}$

$s_n=\frac{1-r^{n+1}}{1-r}\to\frac{1}{1-r}$

\section*{comparison test}
if $\forall n, |a_n|\le b_n$
\begin{itemize}
\item
  if $\sum\limits_{n=1}^\infty{b_n}$ is convergent then $\sum\limits_{n=1}^\infty{a_n}$ is convergent,
  \item
  if $\sum\limits{a_n}$ is divergent, so is $\sum\limits{b_n}$.
\end{itemize}
\section*{3.2.b}
show that if $\left(|a_n|\right)_{n=1}^\infty$ is summable then so is $\left(a_n\right)_{n=1}^\infty$.
\begin{align*}
  \sum\limits_{k=n+1}^m{|a_k|}&<\varepsilon\text{ for all }N\le n\le m \text{ because is is summable}\\
  \left\lvert\sum\limits_{k=n+1}^m{a_k}\right\rvert&\le\sum\limits_{k=n+1}^m{|a_k|}<\varepsilon
\end{align*}
so then $\sum\limits{a_k}$ is also cauchy and summable

\section*{cauchy-schwartz inequality}
$\sum\limits_{k=1}^n{a_kb_k}\le \left(\sum\limits_{k=1}^n{a_k^2}\right)^{1/2}\left(\sum\limits_{k=1}^n{b_k^2}\right)^{1/2}$

\section*{3.2.f}

\section*{leibniz test for alternating series}
if $\{a_n\}$ is a monotone decreasing sequence of positive terms with the $\lim a_n=0$ then $\sum\limits_{n=1}^\infty{(-1)^na_n}$ is convergent

\section*{note!} a sequence my have the property $\lim |a_n-a_{n+!}|=0$ but not be cauchy
\section*{3.2.h}
Show that if $\sum\limits_{n=1}^\infty{a_n}$ and $\sum\limits_{n=1}^\infty{b_n}$ are series with $b_n\ge 0$ such that $\limsup\limits_{n\to\infty}<\infty$ and $\sum\limits_{n=1}^\infty{b_n}<\infty$, then the series $\sum\limits_{n=1}^\infty{a_n}$ converges.

\begin{align*}
  \left\lvert\left(\sup\limits_{k\ge n}\frac{|a_k|}{b_k}\right)-L\right\rvert<\varepsilon\\
  \left(\sup\limits_{k\ge n}\frac{|a_k|}{b_k}\right)<L+\varepsilon\\
  \frac{|a_k|}{b_k}<L\varepsilon\\
  |a_k|<(L+\varepsilon) b_k\\
\end{align*}
\section*{3.2.j}
$\liminf\frac{a_n+1}{a_n}\le\liminf{a_n^{\frac{1}{n}}}\le\limsup a_n^{\frac{1}{n}}\le \limsup\frac{a_n+1}{a_n}$.
\subsection*{step 1}
if $x\ge r$ for all $r>b$ then $x$ is a lower bound for the set $\{r\in \mathbb{R}:r>b\}$, $x\le\inf\{r\in\mathbb{R}:r>b\}=b$

we will show that if $\limsup \frac{a_n}{b_n}<r$ then $\limsup a_n^{\frac{1}{n}}\le r$ and then apply step one.

let $r>\limsup \frac{a_{n+1}}{a_n}$ then $\exists N$ such that $r>\frac{a_{n+!}}{a_n}\forall n\ge N$
\begin{align*}
  a_{N+1}<ra_N\\
  a_{N+2}<ra_{N+1}\le r^2a_{N}\\
  a_{N+K}<r^{k}a_N\\
  a_{N+k}^{\frac{1}{N+k}}<(r^ka_N)^{\frac{1}{N+k}}
\end{align*}
\section*{quiz from 10/1/2014}
$L_k\to L$ then $\{x_n\}$ such that $\forall k, \exists$ a subsequence of $\{x_n\}$ converging to $L_k$. prove that $\{x_n\}$ has a subsequence converging to $L$.

given $\varepsilon>0\exists N_0$ such that $\left\lvert L_k-L\right\rvert<\varepsilon$ if $k\ge N_0$

$\left\lvert x_{N_k}-L\right\rvert\le\left\lvert x_{N_k}-L_k\right\rvert+\left\lvert L_k-L\right\rvert<2\varepsilon$

\section*{example}
let $A,B\subseteq \mathbb{R}$, prove that $\sup A\le\inf B$, if $\forall a\in A, b\in B, a\le b$

\section*{3.3.5}
any rearrangement of an absolutely convergent series converges tothe same limit
\subsubsection*{proof}
let $\sum\limits{a_n}=L<\infty$. We know $\sum\limits{|a_n|}$ is convergent (not necessarily to $L$). by th cauchy riterion for series $\forall\varepsilon>0\exists N$ such that $\left(\sum\limits_{n=N+1}^\infty{|a_n|}\right)<\varepsilon$

$\pi:\mathbb{N}\to\mathbb{N}$ is bijective, the rearranged series is $\sum\limits_{n=1}^{\infty}{a_{\pi(n)}}$ and $\{a_1\dots a_N\}\subseteq\{a_{\pi(1)1}\dots a_{\pi(M)}\}$

\section*{3.3.7 rearrangement theorem}
let $\sum\limits{a_n}=L<\infty$ and define $b_n=(a_n\ge 0)?a_n:0$ and $c_n=(a_n<0)?a_n:0$

consider the series $\sum\limits{b_n}$ and $\sum\limits{|c_n|}$
\subsection*{case 1}
both convergent

$\sum\limits{|a_n|}=\sum\limits{b_n}+\sum\limits{|c_n|}$ which is convergent, which contradicts the fact that $a_n$ is conditionally convergent
\subsection*{case 2}
one convergent, one divergent

assume $\sum\limits{|c_n|}=A<\infty$ and $\sum\limits{b_n}$ is divergent to $+\infty$

given any $R\in\mathbb{N}$ big, $\exists N$ such that $\sum\limits_{n=1}^N{b_n}>R+A$, then we pick $M$ big enough so that $\{b_1,\dots,b_N\}\subseteq\{a_1,a_2,\dots,a_M\}$ and $\sum\limits_{n=1}^M{a_n}\ge\sum\limits_{n=1}^N{b_n}-\sum\limits{|c_n|}>R$ so $\sum\limits{a_n}$ is divergent, which  is a contradiction.
\subsection*{case 3}
both divergent

\section*{chapter 4}
$\mathbb{R}^n=\{(x_1,x_2,\dots,x_n),x_i\in\mathbb{R}\}$, vector space (or point in $n$-space).

with the coordinate wise sum and the product by real numbers (scalars).
\begin{align*}
  (x_1,\dots x_n)+(y_1,\dots,y_n)&=(x_1+y_1,\dots,x_n+y_n)\\
  \lambda(x_1,\dots,x_n)&=(\lambda x_1,\dots,\lambda x_n)\\
  x^{\to}&=(x_1,\dots,x_n)=x
  \intertext{euclidean norm}
  ||x||=\sqrt{x_1^2+\dots+ x_n^2}\\
  \intertext{distance from x to y}
  ||x-y||
\end{align*}
\subsection*{cauchy-schwarz}
$\left\lvert\sum\limits_{i=1}^n{a_jb_j}\right\rvert\le\left(\sum\limits_{i=1}^n{a_j^2}\right)^{1/2}\left(\sum\limits_{i=1}^n{b_j^2}\right)^{1/2}$

$|a\cdot b|\le||a||||b||$
\subsubsection*{dot product}
$a\cdot b=\sum\limits{a_ib_i}$
\subsection*{triangle inequality}
\begin{align*}
  ||x+y||\le||x|||+||y||
\end{align*}
\subsubsection*{proof}
\begin{align*}
  ||x+y||^2&=\sum\limits{(x_i+y_i)^2}\\
  &=(x+y)\cdot(x+y)\\
  &=x\cdot x+2x\cdot y+y\cdot y\\
  &=||x||^2+2x\cdot y+||y||^2\\
  &\le ||x||^2+2||x||||y||+||y||^2\\
  =(||x||+||y||)^2
\end{align*}

\subsection*{standard orthogonal base of $\mathbb{R}^n$}
\begin{align*}
  e_1&=<1,0,\dots,0>\\
  e_2&=<0,1,\dots,0>\\
  &\vdots\\
  e_n&=<0.0,\dots,1>
\end{align*}

\section*{4.2 convergence in $\mathbb{R}^n$}
definition:
a sequence $\{x^i\}$ of parts in $\mathbb{R}^n$ converge to $c\in \mathbb{R}^n$ if $\forall\varepsilon>0 \exists N=N(\varepsilon)\in\mathbb{N}$, such that $||x^i-c||<\epsilon$ if $i\ge N$ we say $\lim x^i=c$.

\subsection*{4.2.2 lemma}
$\lim  x^i=a$ if and only if $\lim ||x^i-a||=0$.

\subsection*{4.2.3 lemma}
$\lim x^i=a$ if and only if $\forall j=1,\dots,n, \lim x_j^i=a_j$
\section*{october 15}
\section*{lemma 4.2.3****know this}
a sequence $\{x^i\}$ of points $\mathbb{R}^n$ converges to $a\in \mathbb{R}^n$ if and only if for each coordinate $\lim x_j^i=a_j$

\section*{thm 4.2.5}
every cauchy sequence of points in $\mathbb{R}^n$ converges to a point in $\mathbb{R}^n$.
\subsection*{def}
a sequence $\{x^i\}$ of points in $\mathbb{R}^n$ is cauchy if $\forall\varepsilon>0\exists N\in \mathbb{N}$ such that $||x^i-x^j||<\varepsilon$ for all $i,j\ge N$
\subsubsection*{proof}
we have a cauchy sequence. given $\varepsilon>0, \exists N$, $||x^i-x^j||<\varepsilon$ if $i,j\ge N$

$|x_k^i-x_k^j|\le||x^i-x^j||=\sqrt{(x_1^i-x_1^j)^2+(x_2^i-x_2^j)^2+\dots+(x_n^i-x_n^j)^2}$

so each of the coordinates for the sequence is cauchy ($\{x_k^i\}$ is cauchy). So it converges to some $a_k\in\mathbb{R}$ and $a=(a_1,a_2,\dots,a_n)$ and so b lemma 4.2.3 $||x^i-a||\to 0$

\section*{4.2.6}
read, useful for next weeks hw

\section*{4.3 open, closed sets in $\mathbb{R}^n$}
def: let $A\subseteq\mathbb{R}^n$. we say that $x$ is a limit point of $A$ if there exists  a sequence $\{a_k\}$ with $a^{k}\in A$ such that the limit of the sequence is $x$.

def: a set $A\subseteq\mathbb{R}^n$ is closed if it contains all of it's limit points.

\subsubsection*{example}
is $[0,1]$ closed? and is $(0,1]$ not closed?

0 is a limit point because $0=\lim \frac{1}{n}$ an $\frac{1}{n}\in(0,1]$.

consider $[a,b]$. $\{x_n\}\subseteq[a,b]$. $a\le x_n\le b, \forall n=1,2,3,\dots$

assume $\lim x_n$ exists, call it $x$. we will show $a\le x\le b$.  then assume not and show wlog $x>b$.

take $\varepsilon=\frac{x-b}{2}$. then $\exists N$ such that $|x_N-x|<\epsilon$. $x-x_N<\frac{x-b}{2}$ and $b<\frac{x}{2}+\frac{b}{2}<x_n$ and so we have a contradiction

\subsection*{special cases}
$\emptyset$ is closed. $[a,+\infty)$ and $(-\infty,a]$ are closed.

finite sets of $\mathbb{R}^n$ are closed.
\subsubsection*{proof}
let $A=\{a_1,\dots,a_M\}$. considera sequence $\{x_j\}$ such that $x_j\in A,\forall j\in \mathbb{N}$. at least one of the points appears $\infty$ many times. if $\lim x_j$ exists then at some point the sequence is a single repeating point, which is the limit, which is in $A$.

\section*{proposition 4.3.3}
the finite union of closed sets is closed, arbitrary  intersections of closed sets are closed.

\subsubsection*{proof}
let $A,B$ be closed, we need to check that $A\cup B$ is closed, then by induction, if $A_1,\dots,A_N$ is closed then $\bigcup_{i=1}^NA_i$ is closed.

pick a sequence $\{x_j\}$ of points in $A\cup B$. converging to some $x\in \mathbb{R}^n$. We need to show that $x\in A\cup B$

$x_j\in A\cup B\Rightarrow x_j\in A$ or $x_j\in B$. We have infinitely many points and so either $A$ or $B$ contains infinitely many of the points. but since the sequence has a limit $\exists N$ such that $x_j\in A\forall j\ge N$

infinitely many of the points are in one of the sets, but since the sequence has a limit, passing to a subsequence oif necessary, we get that all points in the sequence are eventually in one of the seats, hence the limit is in that set because the set is closed $\Rightarrow x\in A\cup B$

and for the second part:
let $\{A_i\}$ be a collection of closed sets. let $\{x_n\}$ be a sequence such that $x_n\in\bigcap_{i\in I}A_i$ and $\lim x_n=x$. we need to show $x\in \cap A_i$ since $x_n\in A_i\forall i$ and $A_i$ is closed $\lim x_n=x\in A_i\forall i$

\subsubsection*{example}
a countable union of closed sets may not be closed. $A_n=[\frac{1}{n},1]\quad \bigcup_{n=1}^\infty[\frac{1}{n},1]=(0,1]$

\subsubsection*{def}
let $A\subseteq\mathbb{R}^n$. The closure of $A$, $\bar{A}$ is the set containing all the limit points of $A$. $\bar{A}$ is the smallest closed set that contains $A$.

\subsubsection*{def}
a set $U\subseteq \mathbb{R}^n$ is open if $\forall x\in U\exists B(x,\varepsilon)\subset U$. $B(x,\varepsilon)=\{y\in \mathbb{R}^2:||y-x||<\varepsilon\}$

\subsubsection*{proposition}
a set is open iff $A^C$ is closed.

\section*{october 20}
$\overline{\mathbb{Q}}=\mathbb{R}$ and $\mathbb{Q}^\circ=\emptyset$

$\overline{\mathbb{R}-\mathbb{Q}}=\mathbb{R}$ and $(\mathbb{R}-\mathbb{Q})^\circ$

define: a set $A\subseteq\mathbb{R}^n$ is dense if $\overline{A}=\mathbb{R}^n$.

A set $A\subseteq B$ is dense in $B$ if $B\subseteq\overline A$

\subsection*{4.3M}
Let $A$ be dense in $\mathbb{R}^n$ and let $U$ be an open set

a) we need to show that $U\subseteq \overline{A\cap U}$. Pick $x\in U$ to show that $x\in \overline{A\cap U}$. we have to find a sequence $a^i\in A\cap U$ such that $\lim a^i=x$.

since $A$ is dense in $\mathbb{R}^n$ and $x\in U\in\mathbb{R}^n\exists\{b^i\}\subseteq A$ such that $\lim b^i=x$

since $x\in U$ and U s open there is a ball ($B(x,r),r>0$) in U and $b^i\in B(x,r)$ so $||x-b^i||<r$. the sequence $\{b^i\}$ is in $A\cap U$ and converges to $x\in U$ hence $A\cap U$ is dense in U.

\subsubsection*{more notes}
$\overline{C}$ is closure

$C^\circ$ is interior

$C=\{(x,y):y=x^2\}\quad \overline{C}=C\quad C^\circ=\emptyset$

$S=\{(x,y):y=\sin\frac{1}{x}\}\quad \overline{S}=S\cup\{(0,a):a\in[-1,1]\}\quad S^\circ=\emptyset$

\subsection*{cantor set}
start with $C_0=[0,1], C_1=[0,\frac{1}{3}]\cup[\frac{2}{3},1]\dots$ and continue on removing the middle thirds.
$\mathcal{C}=\bigcap_{n=1}^\infty C_n$ and by the nested intervals theorem $\mathcal{C}\ne\emptyset$. this is actually  an uncountable set.

what are we removing? $C_0=\frac{1}{3}, C_1=\frac{2}{9}, C_n=\frac{2^{n-1}}{3^(n)}$

length of the removed part is $\sum\limits_{n=1}^\infty{\frac{2^{n-1}}{3^{n}}}=\frac{1}{3}\sum\limits_{n=1}^\infty{\left(\frac{2}{3}\right)^{n-1}}=1$ so $\mathcal{C}$ has length 0.

if we look at the sets $C_0,C_2,C_2$ in base 3 then $x\in[0,1]=\sum\limits_{i=1}^\infty{\frac{a_i}{3^i}},a_i\in\{0,1,2\}$.

in step n we are removing from $[0,1]$ all the points whose base 3 expansion has a 1 in the $n$th position.

so $\mathcal{C}=\{x\in[0,1]\text{ st $x$'s base 3 expansion does not contain 1}\}$. $F:\mathcal{C}\to[0,1]$ we map all the twos to ones. $x=0.2->0.1=y$. this is a surjection. so cardinality of $\mathcal{C}$ is greater than or equal to $[0,1]$ which is the continuum (cardinality of the real numbers. but $\mathcal{C}\subseteq[0,1]$ so they have the same cardinality.

assume $(a,b)\subseteq\mathcal{C}$ then $(a,b)\subseteq C_n$. Every interval has lenght $3^{-n}$ and so we can find an $N$ such that $|a-b|>3^{-N}$.

\subsection*{defintions}
def: a set $A\subseteq\mathbb{R}^n$ is compact if every sequence $\{a^k\}$ of elements of $A$ has a convergent subsequence $\{a^{k_n}\}$ and $\lim a^k=a\in A$ any closed and bounded set in $\mathbb{R}^n$ is compact by bolzano-weierstrass

\section*{october 27}
\section*{chap 5 functions}
\subsection*{def}
The limit of the function $f$ as $\vec{x}\in S$ approaches $\vec{a}\in \mathbb{R}^n$ is $\vec{v}\in \mathbb{R}^m$ if $\forall \varepsilon>0\exists r>0$ such that $||f(\vec{x})-\vec{v}||<\varepsilon$ whenever $||\vec{x}-\vec{a}||<r$
\subsection*{def}
$f$ is continuous at $\vec{a}$ if $\forall \varepsilon>0\exists r>0$ such that $||f(\vec{x})-f(\vec{a})||<\varepsilon$ whenever $||\vec{x}-\vec{a}||<r$.
\subsection*{example}
prove that $\lim\limits_{x\to 2} x^2=4$. using the definition of limit of a function.

given $\varepsilon>0$ we have to find $r$ depending on $\varepsilon$ such that if $|x-2|<r$ then $|x^2-4|<\varepsilon$.

since $x$ is approaching 2 then $|x-2|$ will eventually be less than 1. $1\le x\le 3$. $3\le x+2\le 5$
\begin{align*}
  |x^2-4|=|x-2||x+2|<r\cdot 5=\varepsilon
\end{align*}
now take $r=\frac{\varepsilon}{5}$ we get $|x^2-4|<\varepsilon$. so given $\epsilon>0$, take$r=\frac{\epsilon}{5}$ and this guaranteesthat if$|x-2|<r$ then $|x^2-4|<\varepsilon$
\subsection*{5.1.C}
let $f(x)=\begin{cases}x-2n&\text{if }2n\le x\le 2n+1\\2n+2-x&\text{if }2n+1\le x\le 2n+2\end{cases}$

take $2n<a<2n+1$. Then $|f(x)-f(a)|=|x-2n(a-2n)|=|x-a|$. take $r=\varepsilon$ if $|x-a|<r$ then $|f(x)-f(a)|<\varepsilon$. Similar with $a\in (2n+1,2n+2)$.

now $a=2n$. Then $|f(x)-f(a)|=\begin{cases}x-2n-0&\text{if }x>a\\|2n-x-0|&\text{if }x<a\end{cases}$ assuming $|x-a|<1$. In eiher case $|f(x)-f(a)|=|x-2n|=|x-a|$ again, take $r=\varepsilon$.
\subsection*{defintion}
a function is Lipschitz if $\exists C>0$ such that $||f(x)-f(y)||\le C||x-y||\forall x,y\in S$

by definition $||x-y||<\frac{\varepsilon}{C}$ then$||f(x)-f(y)||<\varepsilon$. so it is continuous, and $r=\frac{\varepsilon}{C}$ for every point so it is ``uniformly'' continuous because $r$ does not depend on $x,y$.

$\lim\limits_{x\to b} x^2=b^2$ is continuous but r depends on both $\varepsilon$ and $b$ so $x^2$ is not uniformly continuous, but it is continuous.

let $f:\mathbb{R}\to\mathbb{R}$ be such that $|f'(x)|\le A \forall x\in \mathbb{R}$ then $f$ is Lipschitz, therefore uniformly continuous.

\subsubsection*{proof}
mean value theorem
$|f(x)-f(y)|=|f'(\varsigma)|x-y|<A|x-y|$. $x<y\therefore\varsigma\in(x,y)$.

\subsection*{5.1.k}
find a bounded continuous function on $\mathbb{R}$ that is not lipschitz. note $x^2$ is not bounded.

$f(x)=\sin \frac{1}{x}$ on $(0,+\infty)$

$y=\arctan x$

\subsection*{example}
if $f:\mathbb{R}^n\to\mathbb{R}^m$ is liner then it is Lipschitz.

let $A$ be the matrix of $f$.
$A=\left[\begin{array}{ccc}a_{11}&\hdots&a_{1n}\\\vdots&&\vdots\\a_{m1}&\hdots&a_{mn}\end{array}\right]$

$f(\vec{x})=A\vec{x}=\left(\sum\limits_{j=1}^n{a_{1j}x_j},\dots,\sum\limits_{j=1}^n{a_{mj}x_j}\right)$

\begin{align*}
  ||f(x)-f(y)||\le C||x-y||\\
  ||F(x)-f(y)||=||f(x-y)||=\sqrt{\sum\limits_{k=1}^m{\sum\limits_{j=1}^n{a_{kj}(x_j-y_j)}}}\le\text{cauchy schwartz}
\end{align*}

\section*{october 29}
$f:S\to \mathbb{R}^m$ where $s\subseteq \mathbb{R}^n$

lipschitz means that $\exists C>0$ such  that $\forall x,y\in S,||f(x)-f(y)||_{\mathbb{R}^m}\le C||x-y||_{\mathbb{R}^n}$

uniformally continuous means that $\forall \varepsilon>0\exists r>0:||f(x)-f(y)||<\varepsilon$ whenever $||x-y||<r$ where $r(\varepsilon)$

continuous means that $\forall \varepsilon>0\exists r>0:||f(x)-f(y)||<\varepsilon$ whenever $||x-y||<r$ where $r(\varepsilon,y)$

continuous at $\vec{a}\in S$ means that $\forall \varepsilon>0\exists r>0:||f(x)-f(\vec{a})||<\varepsilon$ whenever $||x-y||<r$ where $r(\varepsilon,\vec{a})$

\subsection*{exercise 5.1.B}
prove the $f$ is continous at $0$.

find $r>0$ st $|f(x)-1|<10^{-6}$ if $|x|<r$

$f(x)=\begin{cases}\frac{x}{\sin x},&x\in[-\frac{\pi}{2},\frac{\pi}{2}]-\{0\}\\1,&x=0\end{cases}$

$\forall\varepsilon>0$ we need to find $r>0$ st if $|x-0|<r$ then $|\frac{x}{\sin x}-1|<\varepsilon$

$\frac{\sin x}{2}\le \frac{1}{2}r^2\theta=\frac{x}{2}\le \frac{\tan x}{2}$

$1\le \frac{x}{\sin x}\le \frac{1}{\cos x}$

$|\frac{x}{\sin x}-1|\le |\frac{1}{\cos x}-1|=\left\lvert\frac{1-\cos x}{\cos x}\right\rvert$

$\cos x=\sqrt{1-\sin^2 x}\ge \sqrt{1-x^2\ge 1-x^2}$ if $1-x^2\in [0,1)$

we did see that $x^2$ is a continuous function.

$\frac{x^2}{1-x^2}<10^{-6}\to x^2<1-^{-6}(1-x^2)\to x^2(1+10^{-6})<10^{-6}\to x<10^{-6}/(1+10^{-6}$

\subsection*{section 5.2 discontinuities}
survey of types of discontinuities.

\subsubsection*{def of right limit}
the right limit of $f(x)$ as $x$ approaches $a$ is $b$ if $\forall \varepsilon>0\exists r>0 (r=r(\varepsilon,a))$ such that if $a+r>x>a$ then $|f(x)-b|<\varepsilon$

if a function $f$ has different values for it's left and right limit, then we say it has a jump disconinuouity at $a$.

prototype of jump discontinuouities is the heavyside function.
\begin{align*}
  H(x)=
  \begin{cases}
    0,&x<0\\
    1,&x>0
  \end{cases}
\end{align*}

example:
\begin{align*}
  f(x)=
  \begin{cases}
    0&x<0\\
    1+x&x>0
  \end{cases}
\end{align*}
and $f-H$ is continuous

a removeable discontinuity happens when $\lim_{x\to a^+}f(x)=\lim_{x\to a^-}f(x)$ but $f(x)\ne \lim_{x\to a^+}f(x)$. we can fix the discontinuity by redefining $f(a)=\lim_{x\to a}f(x)$

a function is piecewise continuous if on any  bounded interval, $f$ has a finite number of jump discontinuouities

$f(x)=\lfloor x\rfloor$ is piecewise continuous because if we pick bounds, then we limit the number of discontinuities.

if $\lim_{x\to a^\pm}=\pm\infty$ then we have a discontinuity (vertical asymptote) with no way to fix

$\sin \frac{1}{x}$ has not limit at 0. there isn't even a reasonable way to define the limit. no name for this kind of disconitnuity.

\begin{align*}
  \lim_{(x,y)\to(0,0)} \frac{x^2}{x^2+y^22}&=\lim_{x\to 0}\frac{x^2}{x^2+m^2x^2}=\frac{1}{1+m^2}
\end{align*}

  let $A\subseteq \mathbb{R}^n$

  define the characteristic function of the set $A$.
  $1_A(x)=\begin{cases}1&x\in A\\0& x\not\in A\end{cases}$

  how discontinuous this is depends on the set $A$.

  example $A=(0,1)$ is piecewise continuous with only two jump discontinuouities.

  but if $A=\mathbb{Q}$? yuck.

\subsubsection*{example}
\[f(x)=\begin{cases}0&x\not\in \mathbb{Q}\\\frac{1}{q}&x=\frac{p}{q}\end{cases}\]
where $\gcd(p,q)=1$ and $q>0$. f is continuous on $\mathbb{R}\setminus \mathbb{Q}$ and discontinuous on $\mathbb{Q}$.  if $a\in \mathbb{R}, \lim_{x\to a}f(x)=0$. let $\varepsilon>0$. let $M>|a|, M\in \mathbb{N}$. let $N\in \mathbb{N}, \frac{1}{N}>\varepsilon$.

$\{\frac{p}{q}:1\le q\le N,-Mq\le p\le Mq\}\setminus \{a\}$. set $S$ is finite and so closed. $a\in S^C$ is open. There exists an interval  $(a-\varsigma,a+\varsigma)\subseteq S^C\cap[-M,M]$

if $x\in S^C\cap[-M,M]$ either $x$ is irrational $(f(x)=0$ or $x$ is rational but $x=\frac{p}{q},q>N$, $f(x)=\frac{1}{q}<\frac{1}{N}<\varepsilon$, hence $\lim f(x)=0$
\end{document}


\documentclass[../../../../main]{subfiles}

\begin{document}

\paragraph{Accord.NET}

Accord NET is a framework for machine learning, mathematical statistics, basic scientific computing and computer vision entirely made with {\Csharp}. It includes classification algorithms (\ac{SVM}, decision trees, neural networks, deep learning and etc.), regression algorithms (linear regression, polynomial regression, logarithmic regression, logistic regression and etc.), clustering algorithms (K-Means, Mean-Shift, Gaussian Mixture Models and etc.), algorithms for distribution analyses.

In general, Accord.NET was created to extend features of the AForge.NET created by Andrew Kirillov for the .NET Framework in 2006. However in 2012 Andrew announced the end of support for the AForge.NET thus Accord.NET absorbed most of the original AForge.NET code into its code-base and continued to develop and support the code under Accord.NET name.

\begin{figure} [!ht]
  \centering
    \lstset{style=sharpc}
        \begin{lstlisting}
            double[,] A =
            {
                {1, 2, 3},
                {6, 2, 0},
                {0, 0, 1}
            };

            // Singular value decomposition
            var svd = new SingularValueDecomposition(A);
            var U = svd.LeftSingularVectors;
            var S = svd.Diagonal;
            var V = svd.RightSingularVectors;

            // Eigenvalue decomposition
            var eig = new EigenvalueDecomposition(A);
            var V = eig.Eigenvectors;
            var D = eig.DiagonalMatrix;

            // LU decomposition
            var lu = new LuDecomposition(A);
            var L = lu.LowerTriangularFactor;
            var U = lu.UpperTriangularFactor;
        \end{lstlisting}
  \caption{Accord.NET decomposition samples.}
  \label{accordnetdecompose}
\end{figure}

As can be seen from the figure \ref{accordnetdecompose} Accord.NET includes a huge amount of different mathematical extensions for the standard .NET value types thus having a single .NET matrix a value decomposition can be done in 1 line of code. This library has such type of helpers for the enormous amount of mathematical operations.

\end{document}


\chapter{Small-step semantics}
\[
  \begin{prooftree}[center=false]
    \infer0[\textsc{IntE}/\textsc{BoolE}]{v \longrightarrow v}
  \end{prooftree}
  \qquad
  \begin{prooftree}[center=false]
    \infer0[\textsc{Lambda}]{e \longrightarrow \mathbold{\lambda} x : \tau \ldotp e'}
  \end{prooftree}
\]
\[
  \begin{prooftree}
    \hypo{e_1 \longrightarrow e'_1}
    \infer1[\textsc{PairA1}]{\langle e_1,e_2 \rangle \longrightarrow \langle e'_1,e_2 \rangle}
  \end{prooftree}
  \qquad
  \begin{prooftree}
    \hypo{e_2 \longrightarrow e'_2}
    \infer1[\textsc{PairA2}]{\langle e_1,e_2 \rangle \longrightarrow \langle e_1,e'_2 \rangle}
  \end{prooftree}
\]
\[
  \begin{prooftree}
    \hypo{e_1 \longrightarrow e'_1}
    \infer1[\textsc{AppF}]{e_1\,e_2 \longrightarrow e'_1\,e_2}
  \end{prooftree}
  \quad
  \begin{prooftree}
    \hypo{e_2 \longrightarrow e'_2}
    \infer1[\textsc{AppV}]{(\mathbold{\lambda}x : \tau \ldotp e_1)\,e_2 \longrightarrow (\mathbold{\lambda}x : \tau \ldotp e_1)\,e'_2}
  \end{prooftree}
\]
\[
  \begin{prooftree}
    \hypo{e[\sfrac{v}{x}] \longrightarrow v'}
    \infer1[\textsc{App}]{(\mathbold{\lambda}x : \tau \ldotp e)\,v \longrightarrow v'}
  \end{prooftree}
  \quad
  \begin{prooftree}
    \hypo{e \longrightarrow e'}
    \infer1[\textsc{FixF}]{\text{\textbf{fix }} e \longrightarrow \text{\textbf{fix }} e'}
  \end{prooftree}
  \quad
  \begin{prooftree}
    \hypo{e[\sfrac{\text{\textbf{fix }} (\mathbold{\lambda}x : \tau \ldotp e)}{x}] \rightarrow e'}
    \infer1[\textsc{FixV}]{\text{\textbf{fix }} (\mathbold{\lambda}x : \tau \ldotp e) \rightarrow e'}
  \end{prooftree}
\]
\[
  \begin{prooftree}
    \hypo{c \longrightarrow c'}
    \infer1[\textsc{CondC}]{\text{\textbf{if} } c \text{ \textbf{then} } e_1 \text{ \textbf{else} } e_2 \longrightarrow \text{\textbf{if} } c' \text{ \textbf{then} } e_1 \text{ \textbf{else} } e_2}
  \end{prooftree}
\]
\begin{prooftree*}
  \hypo{e_1 \longrightarrow e'_1}
  \infer1[\textsc{CondA1}]{\text{\textbf{if} } v \text{ \textbf{then} } e_1 \text{ \textbf{else} } e_2 \longrightarrow \text{\textbf{if} } v \text{ \textbf{then} } e'_1 \text{ \textbf{else} } e_2}
\end{prooftree*}
\begin{prooftree*}
  \hypo{e_2 \longrightarrow e'_2}
  \infer1[\textsc{CondA2}]{\text{\textbf{if} } v \text{ \textbf{then} } e_1 \text{ \textbf{else} } e_2 \longrightarrow {\text{\textbf{if} } v \text{ \textbf{then} } e_1 \text{ \textbf{else} } e'_2}}
\end{prooftree*}
\[
  \begin{prooftree}
    \hypo{v \longrightarrow \text{True}}
    \infer1[\textsc{CondTrue}]{\text{\textbf{if} } v \text{ \textbf{then} } e_1 \text{ \textbf{else} } e_2 \longrightarrow e_1}
  \end{prooftree}
  \quad
  \begin{prooftree}
    \hypo{v \longrightarrow \text{False}}
    \infer1[\textsc{CondFalse}]{\text{\textbf{if} } v \text{ \textbf{then} } e_1 \text{ \textbf{else} } e_2 \longrightarrow e_2}
  \end{prooftree}
\]
\[
  \begin{prooftree}
    \hypo{e_1 \longrightarrow e'_1}
    \infer1[\textsc{PrimBinOpA1}]{e_1 \text{ \textbf{binop} } e_2 \longrightarrow e'_1 \text{ \textbf{binop} } e_2}
  \end{prooftree}
\]
\[
  \begin{prooftree}
    \hypo{e_2 \longrightarrow e'_2}
    \infer1[\textsc{PrimBinOpA1}]{e_1 \text{ \textbf{binop} } e_2 \longrightarrow e_1 \text{ \textbf{binop} } e'_2}
  \end{prooftree}
\]
\[
  \begin{prooftree}
    \infer0[\textsc{PrimBinOp}]{v_1 \text { \textbf{binop} } v_2 \longrightarrow v}
  \end{prooftree}
  \quad
  \begin{prooftree}
    \hypo{e \longrightarrow e'}
    \infer1[\textsc{PrimOpA}]{\text{\textbf{op} } e \longrightarrow \text{\textbf{op} } e'}
  \end{prooftree}
  \quad
  \begin{prooftree}
    \infer0[\textsc{PrimOp}]{\text{\textbf{op} } v \longrightarrow v'}
  \end{prooftree}
\]