%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Clustering}
\label{chap:cluster}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Evaluating Performance}
\label{cluster:eval}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Davies-Bouldin Index}
\label{cluster:eval:davies_bouldin}
% TODO

\begin{equation} \label{eq:davies_bouldin}
\text{DB} = \frac{1}{m} \sum_{i=1}^{m} \max_{i \neq j} \left(\frac{\sigma_{i} + \sigma_{j}}{\abs{\vb{c}_{i} - \vb{c}_{j}}}\right)
\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Adjusted Rand Index}
\label{cluster:eval:adjusted_rand_index}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Shannon Index}
\label{cluster:eval:shannon_index}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Silhouette Coefficient}
\label{cluster:eval:silhouette}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{\texorpdfstring{$k$}{k}-Means}
\label{cluster:kMean}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Choosing \texorpdfstring{$k$}{k}: Elbow Method}
\label{cluster:kMean:elbow}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Metrics}
\label{cluster:kMean:metrics}
% TODO

\subsubsection{Cartesian Radius}
\label{cluster:kMean:metrics:cartesian}
% TODO

% \begin{equation}\label{eq:cartesian}
% \end{equation}

\subsubsection{Cosine Simularity}
\label{cluster:kMean:metrics:cos}
% TODO

% \begin{equation}\label{eq:cos}
% \end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Expectation Maximization (EM)}
\label{cluster:EM}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Gaussian Mixture Model (GMM)}
\label{cluster:EM:GMM}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Louvain Method}
\label{cluster:louvain}

When working with a graph, \ie network, based dataset
we can use the Louvain\footnote{Named for the location of the author's university in Louvain-la-Neuve, Belgium.} method \cite{louvain}
to detect related clusters, \ie communities,
of nodes by optimizing the graph's modularity\footnote{Today the Louvain method can refer to the greedy optimization algorithm on its own,
with the modularity $Q$ being one possible objective function}.
The modularity $Q$ of a graph $G$ with a given set of clusters $C$
is a measure of the graph's degree of clustering;
being the fraction of edges within the clusters
minus the expected fraction if the edges were randomly distributed.
In short, we can think of $Q$ as a measure of
the density of interior to exterior edges of the clusters.
$Q$ ranges from \num{-0.5} for relatively uncluttered graphs
to \num{1} for fully clustered graphs.
We can compute the modularity $Q$ of $G$ as:

\begin{equation} \label{eq:unsupervised:louvain:modularity}
Q\left(G\right) = \frac{1}{2 W_{G}} \sum_{ij \in G} \bigg(w_{ij} - \gamma \frac{W_{i} W_{j}}{2 W_{G}}\bigg) \delta\left(c_{i},\,c_{j}\right)
\end{equation}

\noindent where\footnote{Note $w_{ij}=1$ for an unweighted graph, and $2 W_{G} = \sum_{ij \in G} w_{ij}$ accounts for double counting edges.}
$w_{ij}$ is the edge weight between nodes $i$ and $j$,
$W_{i}$ is the sum of edge weights of node $i$,
$W_{G}$ is the total edge weight of the graph,
$c_{i} \in C$ is the cluster of node $i$,
and $0 < \gamma$ is a resolution hyperparameter.

The Louvain method constructs $C$ by greedily maximizing $Q$ in an iterative two phase process as shown in \cref{fig:louvain}.
In the first phase, we define each node $n_{i} \in G$ to be its own cluster $c_{i}$.
We then merge each $c_{i}$ with the neighboring $c_{j}$, $0 < w_{ij}$, which maximizes $\Delta Q$.
If $\max\left(\Delta Q\right) = 0$ we leave $c_{i}$ unmerged.
After all clusters have been merged and $Q$ is at a local maximum we enter the second phase.
Here a new graph $G'$ is constructed by making each cluster $c_{i}$ into a node $n'_{i} \in G'$.
The old weights of $G$ are summed to become the new weights $w'_{ij}$,
with intra-cluster weights becoming self-loops $w'_{ii}$ in $G'$.
We return to the first phase and repeat until $Q$ has been maximized.

\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{figures/ml/louvain_algo}
\caption{
Illustration of the two iterative phases of the Louvain method \cite{leiden}.
}
\label{fig:louvain}
\end{figure}

The resolution parameter $\gamma$ controls the number and size of clusters, $\gamma =1$ by default.
The location of $\gamma$ depends on the text and implementation,
but here $1 < \gamma$ ($\gamma < 1$) favors more (fewer) clusters with fewer (more) constituent nodes.
The \texttt{python-louvain}
\href{https://python-louvain.readthedocs.io/en/latest/}{package} \cite{python-louvain}
implements the Louvain method for \texttt{networkx} \cite{networkx}
\href{https://networkx.org/}{based graphs}.
Community detection in large networks is an important problem for social networks and other use cases,
making this an active area of research.
For example, one proposed improvement to the Louvain method is the Leiden algorithm \cite{leiden}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Correlation Clustering}
\label{cluster:correlation}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Affinity Clustering}
\label{cluster:affinity}
% TODO

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Support Vector Clustering}
\label{cluster:SVC}
% TODO


%!TEX root =  ../main.tex

\mychapters{Logarithms}{logs}{\chapdir/pics/Lunar_eclipse}

It may surprise you to learn that most phenomena in the world are exponential in nature.
Year over year, the growth of populations and galactic superclusters is a percentage of
their sizes the year before.  This means the independent variable is in the exponent.

A foolish kind once promised a sage whatever he wanted, and the sage asked for
a number of grains of wheat per square on a chessboard: 2 on the first, 4 on the second,
8 on the third, etc.  How many were on the 64th tile?  Would he have been better off
asking for 100,000 grains of rice per square?

\newpage
\chapterminitoc

%									7 - 1
\newpage
\invisiblesection{Triangle of Power}
\marginlessinput{\chapdir/0701p}
\newpage
\input{\chapdir/0701}
\newpage
\input{\chapdir/0701x}

%									7 - 2
\newpage
\invisiblesection{Exponential}
\marginlessinput{\chapdir/0702p}
\newpage
\input{\chapdir/0702}
\newpage
\subsection{Exercises}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{\chapdir/0702xA.pdf}}
\newpage
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{\chapdir/0702xB.pdf}}
\newpage
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{\chapdir/0702xC.pdf}}
\newpage
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{\chapdir/0702xD.pdf}}

%									7 - 3
\newpage
\invisiblesection{Properties of Logs}
\marginlessinput{\chapdir/0703p}
\newpage
\input{ch07/0703}
\newpage
\input{\chapdir/0703x}
\includegraphics[scale=0.5]{ch07/0703xA.png}
\includegraphics[scale=0.5]{ch07/0703xB.png}

%									7 - 4
\newpage
\invisiblesection{Log Equations}
\marginlessinput{\chapdir/0704p}
\newpage
\input{ch07/0704}
\newpage
\subsection{Exercises}
In kuta

%									7 - 5
\newpage
\invisiblesection{Logistic Curves}
\subsection{Problems}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{ch07/0705p.pdf}}
\newpage
\input{ch07/0705}
\newpage
\subsection{Exercises}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{ch07/0705xA.pdf}}
\newpage
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{ch07/0705xB.pdf}}
\newpage
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{ch07/0705xC.pdf}}

%									7 - 6
\newpage
\section{Review}
\subsection{Chapter Review}
\input{ch07/0706}
\subsection{Chapter Test}


\chapter{Chances to Discover Circumbinary Object}
\label{Chapter3}

Chances to discover a circumbinary substellar body depend primarily on three factors:
\begin{itemize}[noitemsep]
\item the precision and number of the minima which can be achieved;
\item the semi-amplitude of the LITE caused by the body;
\item the intrinsic variability of the binary causing noise in minima timings.
\end{itemize}
%(i) the precision and number of the minima which can be achieved;
%(ii) the semi-amplitude of the LITE caused by the body;
%(iii) the intrinsic variability of the binary causing noise in minima timings.

\section{Precision of the Minimum Time}
The precision of the minimum time $\Delta$t (for a triangular shape of the minimum) can be determined from equation (see, e.g., \cite{sybilski2010})

\begin{equation}\label{eq:dt}
\Delta t = \dfrac{D \sigma}{2d\sqrt{N}}
\end{equation}
where $\sigma$ is the brightness uncertainty (in magnitudes) of a single observational point, $D$ is the duration of the minimum, $d$ is the depth (in magnitudes) and $N$ is the number of observational points during the eclipse.
The above relation shows that the precision of the minimum time increases with the number of data points taken in the minimum and their precision. The shape of the minimum also affects the precision of the timing -- deep and narrow minima provide the best precision.

In Table \ref{tb:lite_dt} calculated precision for 60 cm telescope of selected as example EB is presented, where $V$ is the out-of-eclipse brightness of the binary, $M_{1,2}$ -- masses of the component, $D$ -- duration of the primary eclipse, $d_{I}, d_{II}$ are the depths of primary and secondary minima, respectively, $\Delta T$ is the amplitude of the LITE for 1 Jupiter mass planet orbiting the binary on a 10 years orbit,
$\Delta t$ -- theoretically achievable primary minimum precision for a 60 cm telescope.
On Fig.\ref{fig:4_depend} vertical black dash line is corresponding to the mean value of $\Delta t$ calculated for target list from \cite{Pribula2012},~ $\overline{\Delta t} = 2.8$ ~seconds.

\section{Amplitude of LITE Effect}
In case when an unseen third component revolves an EB, the residuals with respect to a linear (or quadratic) ephemeris will show
a wavelike behaviour in the O-C diagram because of the LITE.

The O-C curve (due only to the inner binary) can be described by a linear (constant period) or quadratic
ephemeris (linear period variation) and if a third body is orbiting the inner binary adding the LITE effect, the times
of the minima can be computed from equation (\ref{eq:P_lin_OC_sin}) from Chapter \ref{Chapter_oc}.
%(a quadratic ephemeris added to the theoretical LITE given by formula (2) and (3) of \cite{irwin1959}).

%\begin{equation}\label{eq:4_minima}
%T_{min} = JD_{0}+P \times E + Q \times E^2 + \dfrac{a_{12}\sin i}{c}   \left[  \dfrac{1-e^2}{1+e \cos\nu}   \sin(\nu + \omega)  + e \sin \omega  \right]
%\end{equation}

%where $a_{12} \sin i$ is the projected semi-major axis (inclination cannot be derived from the LITE alone), $e$ is the eccentricity,
%$\omega$ is the longitude of the periastron, $\nu$ is the true anomaly of the EB orbit around the common center of the mass of
%the whole system, $JD_{0} + P \times E + Q \times E^2$ is the quadratic ephemeris of the minima of the EB and $c$ is the velocity
%of light. The parameter $Q$ is the coefficient of the quadratic term and gives the rate of the orbital period change of the EB.

\begin{table}[!t]
 \centering
% \small
 \caption{Expected LITE amplitude for Jupiter-mass companion on 15-years orbit and theoretical precision for 60 cm telescope \citep{Pribula2012}.}
 \label{tb:lite_dt}
 \vspace*{1ex}
 \scalebox{1.0}{
 \begin{tabular}{c||c|c|c|c|c|c|c|c}\small
%   Star        &  V   & $M_{1}[M_{\odot}]$ & $M_{2}[M_{\odot}]$ &  $d_{1}[mag]$ & $d_{2}[mag]$ & $D[days]$ & $\Delta ~T[s]$ & $\Delta ~t[s]$ \\
   Star             &  V   & $M_{1}$       & $M_{2}$       &  $d_{I}$ & $d_{II}$ & $D$    & $\Delta T$ & $\Delta t$ \\
                    &  mag & $[M_{\odot}]$ & $[M_{\odot}]$ &  [mag]   & [mag]    & [days] & [s]         & [s] \\
\hline
DV Psc              & 10.6  & 0.49 & 0.51  &  0.32 & 0.15 & 0.062  & 4.5            & 1.1    \\
BX Tri              & 13.4  & 0.51 & 0.26  &  0.33 & 0.27 & 0.072  & 5.4            & 4.2     \\
V470 Cam            & 14.7  & 0.48 & 0.13  &  1.00 & 0.20 & 0.015  & 6.3            & 1.2     \\
GSC 19411746        & 12.9  & 0.56 & 0.65  &  0.90 & 0.40 & 0.453  & 5.1            & 6.1      \\
NY Vir              & 13.3  & 0.50 & 0.15  &  0.90 & 0.15 & 0.012  & 6.0            & 0.6   \\
NSVS 02502726       & 14.0  & 0.71 & 0.35  &  0.50 & 0.35 & 0.084  & 4.3            & 3.9    \\
NSVS 06507557       & 13.4  & 0.66 & 0.28  &  0.70 & 0.23 & 0.062  & 4.7            & 1.8    \\
MR Del              & 11.0  & 0.69 & 0.63  &  0.33 & 0.17 & 0.073  & 3.7            & 1.4      \\
\hline
 \end{tabular}}
\end{table}

The full amplitude of the expected LITE changes caused by another body orbiting a binary on the edge-on (i $\sim$ 90\degree ) circular orbit (e $\sim$ 0\degree) is:

\begin{equation}\label{eq:dT}
\Delta T = \dfrac{2M_{3}G^{1/3}}{c} \left[    \dfrac{P_{3}}{ 2 \pi \left( M_{1}+M_{2} \right) }   \right]^{2/3}
\end{equation}
where $M_{1} , M_{2} , M_{3}$ are the masses of the components, $G$ is the gravitational constant, $c$ is the speed of light,
and $P_{3}$ is the orbital period of the third (sub-stellar) component. Equation (\ref{eq:dT}) shows that the semi-amplitude of the LITE
changes is proportional to the mass of the third component and nearly proportional to its orbital period \citep{Pribula2012}.
Amplitude of LITE effect depends on value of inclination $i$, so if it is less then $90\degree$, $\Delta T$ is decreasing too.
Calculated value of $\Delta T$ for some binary systems is presented in Table \ref{tb:lite_dt}.

Full amplitude of LITE effect from period of $3^{rd}$ body dependence is presented graphically on Fig.\ref{fig:4_depend}. %, \ref{fig:4_depend2}.

\begin{figure}[!ht]
\vspace{0cm}
\centerline{\includegraphics[width=0.8\textwidth,angle=0] {M3_dep_P_1.png}}
\centerline{\includegraphics[width=0.8\textwidth,angle=0] {M3_dep_P_3.png}}
\caption{Amplitude of the expected LITE effect $\Delta T$ as the dependence of period of $3^{rd}$ body $P_{3}$. Different masses of third body $M_{3}$ in Jupiter masses is presented by different colours. Vertical dash line is a mean value of theoretical precision of minima $\Delta t$.
Two graphs for different system components ($M_{1}, M_{2}$).}
\label{fig:4_depend}
\end{figure}

%\begin{figure}[!ht]
%\vspace{0cm}
%\centerline{\includegraphics[width=0.8\textwidth,angle=0] {M3_dep_P_3.png}}
%\caption{Amplitude of the expected LITE effect $\Delta T$ as the dependence of period of third body $P_{3}$.  Different masses of third body $M_{3}$ in Jupiter masses is presented by different colours. Vertical dash line is a mean value of theoretical precision of minima $\Delta t$.}
%\label{fig:4_depend2}
%\end{figure}

As can be seen from graphs, minimum amplitude from LITE that can be registered by ~$\sim$ half meter telescope corresponds to one Jupiter mass body or force us to observe binary system on very long time intervals (>15 year). Otherwise, in case of Kepler EB catalogue we have magnitude precision $10^{-6}$, larger diameter, brightness uncertainty $\sigma$ and sometimes more points on minima, that can decrease value of theoretical minima precision $\Delta t$ and allow us to define exoplanets or brown dwarfs in eclipsing binary systems with masses of third body less then one Jupiter mass.

\section{Building O-C Diagrams from Kepler Data}
Kepler satellite provides us with unprecedented accuracy of photometric data.
Such a huge database of EBs observed with high precision and monitored continuously over a period of several years
encouraged several teams to look for a periodic modulation of data, indicative of multiple systems.
For example, \cite{gies2012} presented 41 suspected triples, while \cite{conroy2014} listed 236
potential triples. Moreover, \cite{Rappaport2013} presented 39 dynamically interesting systems, where
the third-body periods are short enough (if compared with the binary period) that some interaction between the orbits is
expected or even observed (e.g., changing of the inclination).
On the other hand, most of the triples listed in \cite{conroy2014} have periods of the order of hundreds or even thousands
of days, so long periods were usually only estimated (due to limited coverage of the Kepler data) or were influenced by
large errors \citep{Zasche2015}.

For this reason, we decided to perform a similar analysis to detect circumbinary objects for other systems, but based on a
larger data set if available, and taking into account different phenomena that distort EBs light curve.

In order to define the time of minima from available light curve in Kepler EB catalogue, special python script was written.
This algorithm reads Kepler input catalog ID (KIC), period and initial epoch of binary system from Kepler EB catalogue. According to obtained KIC, we check if ~short or long cadence data, or both of them, are available, and start to process this light data.

In order to find the exact time of minima different methods can be used, most popular of them are described in Chapter \ref{Chapter_minima_det}. In this preliminary analysis we use fitting with Lorentz function (see equation \ref{eq:lorentz}) because it is simple method with good accuracy. In dissertation thesis we plan to compare mentioned methods and the best one will be used. Using Lorentz function we do not fit whole light curve, only the minimum part, for primary minimum we use only data with phase in range $-0.25 < \varphi < 0.25$.

Also, we can cut upper part of LC, for example taking into account only 70\%~-~90\% of LC amplitude, such approach increase fit precision. This is demonstrated on Fig.\ref{fig:ind_min_fit},\ref{fig:ind_min_fit2}. The only warning, in such approach, is to get enough data points because, as we know, precision of minima also depends on number of used points.
\begin{figure}[!t]
\vspace{0cm}
\begin{tabular}{ll}
\includegraphics[width=.49\textwidth,angle=0] {lor/54988_9437025_08.png}
&
\includegraphics[width=.49\textwidth,angle=0] {lor/54988_9445532_1.png}
\end{tabular}
\caption{Individual minima fit (dashed line) of KIC 4681152 primary minima. Same minima fitted on two figures. Left: 80\% of amplitude Right: 100\% of amplitude}
\label{fig:ind_min_fit}
\end{figure}
\begin{figure}[!t]
\vspace{0cm}
\begin{tabular}{ll}
\includegraphics[width=.49\textwidth,angle=0] {lor/2/85_56164_3332913.png}
&
\includegraphics[width=.49\textwidth,angle=0] {lor/2/100_56164_3332725.png}
\end{tabular}
\caption{Individual minima fit (dashed line) of KIC 12553806 primary minima. Same minima fitted on two figures. Left: 85\% of amplitude Right: 100\% of amplitude}
\label{fig:ind_min_fit2}
\end{figure}

On the final stage, new ephemeris is computed and O-C diagram is formed from obtained times of minima. Some of these O-C diagrams are presented on Fig.\ref{fig:oc}. Having precessed, in such way, all binary systems in Kepler EB catalogue we have highlighted, in a first approximation, 169 systems with possible circumbinary objects or other physical phenomenons that are appearing on O-C diagrams. Some of these binary systems are highlighted for sure, and in many cases good detected systems are marked as multiple previously in works of ~\cite{gies2012, Rappaport2013, conroy2014}. There is also lot of candidates which will be studied more accurately with considering of other factors influence.
\begin{figure}[!th]
  \begin{subfigure}[b]{0.5\linewidth}
    \centering
    \includegraphics[width=0.95\linewidth]{oc/oc_8719897.png}
    \caption{O-C diagram of KIC 8719897.}
    \label{fig:oc:a}
    \vspace{4ex}
  \end{subfigure}%%
  \begin{subfigure}[b]{0.5\linewidth}
    \centering
    \includegraphics[width=0.95\linewidth]{oc/oc_9912977.png}
    \caption{O-C diagram of KIC 9912977.}
    \label{fig:oc:b}
    \vspace{4ex}
  \end{subfigure}
  \begin{subfigure}[b]{0.5\linewidth}
    \centering
    \includegraphics[width=0.95\linewidth]{oc/oc_8043961.png}
    \caption{O-C diagram of KIC 8043961.}
    \label{fig:oc:c}
  \end{subfigure}%%
  \begin{subfigure}[b]{0.5\linewidth}
    \centering
    \includegraphics[width=0.95\linewidth]{oc/oc_10226388.png}
    \caption{O-C diagram of KIC 10226388.}
    \label{fig:oc:d}
  \end{subfigure}
  \caption{Illustration of few obtained O-C diagram with possible presence of 3rd body}
  \label{fig:oc}
\end{figure}


\section{WordEx: Extensions to Word}
[Warren D. Smith (wds@research.NJ.NEC.COM) provided the
analysis and the module.]

It has often struck me as outrageous that most higher level
languages do not allow you to access the fundamental machine-language
primitives for add-with-carry, subtract-with-borrow, shift-with-carry,
multiply-to-get-a-double-length-product, and
double-length-divide-with-remainder. In addition,
I think syntactic sugar should be added to m3 for:
\begin{description}
\item[SWAP(x,y)] Swapping 2 words.
\item[SQUARE(x)] Squaring a number.
\end{description}

These are necessary for writing a bignum package or a linear congruential
random number generator.

Also, it annoys me that more hardware does not provide the (cray)
machine language primitives (very useful for SETs as boolean vectors as words!)
\begin{description}
\item[PopCount(x)] Returns number of 1s in binary representation of x
\item[FindLeastSignifBit(x)]  Returns index of the least significant
bit of x that is a 1
\item[FindMostSignifBit(x)]  Returns index of the  most significant
bit of x (often can be done thru conversion to floating
point in normalized form, by the way)
\end{description}

But even if you ARE on such hardware, you can't get at the primitives
in your high-level language. Very annoying again. I claim there is a vicious
cycle here: hardware designers observe that compiled code has no PopCount()
calls so they omit it from their next processor design, and software
designers see no reason to provide it since it is not in the hardware!
How silly - in fact these are very useful.

So MY SUGGESTION is that these functions be added to modula-3 as an
enhancement to the "Word" library, in such a way that the compiler
will compile them into the appropriate machine language instructions!!

View this as a selling point of modula-3 - the language that actually
helps you to use your machine rather than preventing you!!

However, as a stopgap measure, I provide a software
implementation, which the compiler could resort to until such
point as the compiler writers provide code-generation support.

[See module for implementations.]


\section*{Hashing summary - Ada Nzulumike}

Introduction:
\\
- Definition of hash functions

Universal Hashing:
\\
- Universal and c-universal (definitions, applications)
\\
- Multiply-mod-prime (definition)
\\
- Multiply-shift (definition, advantages)

Strong universality:
\\
- Strongly universal and strongly c-universal (definitions, applications)
\\
- Multiply-mod-prime (definition)
\\
- Multiply-shift (definition)


\documentclass[main.tex]{subfiles}
\begin{document}

\section*{Exercise 4.1}

The detector frame is \emph{locally flat}:
we choose coordinates so that \(g_{\mu \nu } (x_0 ) = \eta_{\mu \nu }\) and \(\Gamma^{\mu }_{\nu \rho } (x_0) = 0\).

This is a \emph{non-relativistic} frame.
The corrections around a point will be of the order (distance to that point) squared.

By making all the approximations we get
%
\begin{align}
\dv[2]{\xi^{i}}{\tau } = \xi^{\lambda } \partial_{\lambda } \Gamma^{i}_{00} \qty(\dv{x^{0}}{\tau })^2 = 0
\,.
\end{align}

The Riemann tensor is \emph{invariant} under gauge transformations in linearized GR.

In the TT gauge we have
%
\begin{align}
R_{i0j0} = - \frac{1}{2 c^2} \ddot{h}_{ij}
\,,
\end{align}
%
so
%
\begin{align}
\ddot{\xi}^{i} - \frac{\ddot{h}_{ij}}{2} \xi_{j} = 0
\,,
\end{align}
%
which is very similar to a Newtonian force, with
%
\begin{align}
F_{i} = m \ddot{\xi}_{i} = \frac{m}{2} \ddot{h}_{j} \xi_{j}
\,.
\end{align}

\end{document}


\documentclass[10pt]{article}
\usepackage{graphicx}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amssymb}

\title{Writing of Mathematics}
\author{Atreya Choudhury}

\begin{document}

\maketitle

\section{Introduction}
\textbf{The Problem:}\\
\textit{A dart is thrown at a unit square. The probability of hitting a point closer to the centre than to any of the edges equals}

\begin{equation*}
  \frac{4\sqrt{2}-5}{3}
\end{equation*}

We assume \textit{uniform} distribution. Therefore, we can say that the probability of landing the dart on two regions of equal area is equal. To find the probability, we must first find the region where the landing of the dart is acceptable. Then the required probability is the ratio of the areas of target region and the dart board.

\section{The Target}
To define the boundary of the region, we consider those points which are at equal distance from the centre of the board and a particular edge. We observe that boundaries are defined by portions of parabolas.

Figure 1 shows the upper right quarter of the board. The red dashed line represents the $1\times1$ board. We set up a co-ordinate system centred at (0,0) co-inciding with the centre of the board. The boundaries of the dart-board are:

\begin{align*}
y &= \frac{1}{2}\\
y &= -\frac{1}{2}\\
x &= \frac{1}{2}\\
x &= -\frac{1}{2}
\end{align*}
\newpage
\begin{figure}[H]
\centering
\includegraphics[width = 8cm]{fig1.png}
\caption{Upper Right Quarter of Diagrammatic Representation}
\end{figure}

To calculate the area of the target, we will first find the area of the region enclosed between the orange dotted parabola and the orange dotted side. Then, we can multiply it by 4 (owing to symmetry of the figure) and then add it to the area of the square PQRS.\\

Using the definition of parabolas, the equation of the orange dotted parabola is:

\begin{equation}
\begin{split}
& \therefore \sqrt{{x}^2+{y}^2} = \frac{1}{2} - x\\
&\implies {x}^2+{y}^2 = \frac{1}{4} - x + {x}^2\\
&\implies {y}^2 = \frac{1}{4} - x
\end{split}
\end{equation}
\newpage
To find the co-ordinate of P, we find the intersection of the above parabola with $y = x$.

\begin{equation*}
\begin{split}
& \therefore {x}^2 = \frac{1}{4} - x\\
&\implies {x}^2 + x + \frac{1}{4} = \frac{1}{2}\\
&\implies \left({x + \frac{1}{2}}\right)^2 = \frac{1}{2}\\
&\implies x = - \frac{1}{2} \pm \frac{1}{\sqrt{2}}
\end{split}
\end{equation*}
\\Since, P is in the first quadrant, the co-ordinates of P are $\left(-\frac{1}{2}+\frac{1}{\sqrt{2}}, -\frac{1}{2}+\frac{1}{\sqrt{2}}\right)$
Therefore, the line through P and Q is given by
\begin{equation}
x = - \frac{1}{2} + \frac{1}{\sqrt{2}}
\end{equation}

\section{Area of the Target}
The area enclosed by the orange dotted region is given by:
\begin{equation}
\begin{split}
&2 \times \int_{- \frac{1}{2} + \frac{1}{\sqrt{2}}}^{\frac{1}{4}} \sqrt{\frac{1}{4} - x} \,dx\\
&= 2 \times \Biggl| \frac{-\left({\frac{1}{4} - x}\right)^\frac{3}{2}}{\frac{3}{2}}\Biggr|_{- \frac{1}{2} + \frac{1}{\sqrt{2}}}^{\frac{1}{4}}\\
&= \frac{4}{3} \times \left( \frac{1}{4} - \left(- \frac{1}{2} + \frac{1}{\sqrt{2}}\right) \right)^\frac{3}{2}\\
&= \frac{4}{3} \times \left(\frac{3-2\sqrt{2}}{4}\right)^\frac{3}{2}\\
&= \frac{5\sqrt{2} - 7}{6}\\
\end{split}
\end{equation}

Therefore, the area of the Target Region:

\begin{equation}
\begin{split}
&= \text{Area of PQRS} + 4 \times \text{Area obtained in (3)}\\
&= {(\sqrt{2} - 1)}^2 + 4 \times \left(\frac{5\sqrt{2} - 7}{6}\right)\\
&= \frac{4\sqrt{2} - 5}{3}
\end{split}
\end{equation}
\newpage
\section{Answer and a Small Computation}
The required probability is given by the ratio of the area of the target region obtained in (4) to the area of the dart board which is a unit square.\\

Hence, the probability of landing the dart closer to the centre than any edge is $$\frac{4\sqrt{2} - 5}{3}$$\\
which is what we had to prove.\\

I also tried to approximately verify our results by writing a program that generates random co-ordinates, checks if they are in the target region, and calculates the probability accordingly. It generates N such random co-ordinates where N is supplied by the user.\\

\begin{table}[H]
  \centering
  {\renewcommand{\arraystretch}{1.5}
  \renewcommand{\tabcolsep}{0.2cm}
  \begin{tabular}{c|p{1.5 cm}|p{2 cm}|p{3 cm}|p{3 cm}}
    Sl & N & Average Probability & Average Percentage Deviation from the Actual Value & Standard Deviation of Probability from 50 experiments\\
    \hline
    1 & 1,000 & 0.2226 & 5.26587892 & 0.094414\\
    2 & 10,000 & 0.219936 & 1.61945974 & 0.029048\\
    3 & 100,000 & 0.219013 & 0.50371302 & 0.009274\\
    4 & 1,000,000 & 0.218903 & 0.1291184 & 0.0025\\
  \end{tabular}}
  \caption{Probabilities for Experiments with N tries}
  \label{}
\end{table}

\end{document}


\documentclass[12pt,a4]{article}

\usepackage{graphicx,amsmath,amssymb,amsthm, boxedminipage, bm}
\usepackage{float}
\usepackage[body={14.64cm, 24.62cm}, centering, dvipdfm]{geometry}
\usepackage{enumerate}

\newtheorem{theorem}{Theorem}%[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}

\newcommand{\scalar}[2]{\ensuremath{\langle #1, #2\rangle}}
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
\newcommand{\ceil}[1]{\left\lceil #1 \right\rceil}
\newcommand{\norm}[1]{\|#1\|}
\newcommand{\pfrac}[2]{\left(\frac{#1}{#2}\right)}
\newcommand{\nth}[1]{#1^{\textsuperscript{th}}}

\newcommand{\N}{\mathbb{N}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\F}{\mathbb{F}}

\newcounter{exercise}

\newcommand{\exercise}{\addtocounter{exercise}{1}\noindent\textbf{Exercise \arabic{section}.\arabic{exercise}. }}

\date{2015-12-06}
\author{Dumb Ways to Die}
\title{Algorithms and Complexity\\
	Homework Assignment 06
}

\begin{document}
\maketitle
\setcounter{section}{5}
\section{Deterministic Streaming Algorithms}

\exercise{}

\input{cty-6.1.tex}

\subsection{Second and Fourth Moment}

\exercise{}

\begin{enumerate}
	\item \input{ksy-6.2.1.tex}
	\item \input{yrz-6.2.2.tex}
	\item \input{sxy-6.2.3.tex}
\end{enumerate}

\exercise{}

\begin{enumerate}
	\item \input{cty-6.3.1.tex}
	\item \input{sxy-6.3.2.tex}
\end{enumerate}

\end{document}


\chapter{Pedagogical comments and references}
\label{ch:refs}
Here are some higher-level comments on the way specific topics were presented,
as well as pointers to further reading.

\section{Basic algebra and topology}
\subsection{Linear algebra and multivariable calculus}
Following the comments in \Cref{sec:basis_evil},
I dislike most presentations of linear algebra and multivariable calculus
since they miss the two key ideas, namely:
\begin{itemize}
	\ii In linear algebra, we study \emph{linear maps} between spaces.
	\ii In calculus, we \emph{approximate functions at points by linear functions}.
\end{itemize}
Thus, I believe linear algebra should
\emph{always} be taught before multivariable calculus.
In particular, I do not recommend most linear algebra or
multivariable calculus books.

For linear algebra, I've heard that \cite{ref:axler} follows this approach,
hence the appropriate name ``Linear Algebra Done Right''.
I followed with heavy modifications the proceedings of Math 55a,
see \cite{ref:55a}.

For multivariable calculus and differential geometry,
I found the notes \cite{ref:manifolds} to be unusually well-written.
I referred to it frequently while I was enrolled in Math 55b \cite{ref:55b}.

\subsection{General topology}
My personal view on spaces is that every space I ever work with
is either metrizable or is the Zariski topology.

I adopted the approach of \cite{ref:pugh}, using metric topology first.
I find that metric spaces are far more intuitive, and are a much better
way to get a picture of what open / closed / compact etc.\ sets look like.
This is the approach history took;
general topology grew out of metric topology.

I personally dislike starting any general topology class
by defining what a general topological space is,
because it doesn't communicate a good picture of open and closed sets
to draw pictures of.

\subsection{Groups and commutative algebra}
I teach groups before commutative rings but might convert later.
Rings have better examples, don't have the confusion of multiplicative
notation for additive groups, and modding out by ideals is more intuitive.

There's a specific thing I have a qualm with in group theory:
the way that the concept of a normal subgroup is introduced.
Only \cite{ref:gowers} does something similar to what I do.
Most other people simply \emph{define} a normal subgroup $N$
as one with $gNg\inv$ and then proceed to define modding out,
without taking the time to explain where this definition comes from.
I remember distinctly this concept as the first time in learning math
where I didn't understand what was going on.
Only in hindsight do I see where this definition came from;
I tried hard to make sure my own presentation didn't have this issue.

I deliberately don't include a chapter on just commutative algebra;
other than the chapter on rings and ideals.
The reason is that I always found it easier to learn
commutative algebra theorems on the fly,
in the context of something like algebraic number theory or algebraic geometry.
For example, I finally understand why radicals and the Nullstellensatz were important
when I saw how they were used in algebraic geometry.
Before then, I never understood why I cared about them.

\subsection{Calculus}
I do real analysis by using metric and general topology
as the main ingredient, since I think it's the most useful
later on and the most enlightening.
In some senses, I am still following \cite{ref:pugh}.

\section{Second-year topics}
\subsection{Measure theory and probability}
The main inspiration for these lectures is
Vadim Gorin's 18.175 at MIT;
\cite{ref:gorin} has really nice lecture notes taken by Tony Zhang.
I go into a bit more details of the measure theory,
and (for now) less into the probability.
But I think probability is a great way to motivate measure theory anyways,
and conversely, it's the right setting in to which state things like
the central limit theorem.

I also found \cite{ref:lebesgue} quite helpful,
as another possible reference.

\subsection{Complex analysis}
I picked the approach of presenting the Cauchy-Goursat theorem as given
(rather than proving a weaker version by Stokes' theorem, or whatever),
and then deriving the key result that holomorphic functions are analytic
from it.
I think this most closely mirrors the ``real-life'' use of complex
analysis, i.e.\ the computation of contour integrals.

The main reference for this chapter was \cite{ref:dartmouth}, which I recommend.

\subsection{Category theory}
I enthusiastically recommend \cite{ref:msci},
from which my chapters are based,
and which contains much more than I had time to cover.

You might try reading chapters {2-4} in reverse order though:
I found that limits were much more intuitive than adjoints.
But your mileage may vary.

The category theory will make more sense as you learn
more examples of structures: it will help to have read,
say, the chapters on groups, rings, and modules.

\subsection{Quantum algorithms}
The exposition given here is based off a full semester
at MIT taught by Seth Lloyd, in 18.435J \cite{ref:18-435}.
It is written in a far more mathematical perspective.

I only deal with finite-dimensional Hilbert spaces,
because that is all that is needed for Shor's algorithm,
which is the point of this chapter.
This is not an exposition intended for someone who wishes to seriously
study quantum mechanics (though it might be a reasonable first read):
the main purpose is to give students a little appreciation for
what this ``Shor's algorithm'' that everyone keeps talking about is.

\subsection{Representation theory}
I staunchly support teaching the representation of algebras first,
and then specializing to the case of groups by looking at $k[G]$.
The primary influence for the chapters here is \cite{ref:etingof},
and you might think of what I have here as just some selections
from the first four chapters of this source.

\subsection{Set theory}
Set theory is far off the beaten path.
The notes I have written are based off the class
I took at Harvard College, Math 145a \cite{ref:145a}.

My general impression is that the way I present set theory
(trying to remain intuitive and informal in a logical minefield)
is not standard. Possible other reference: \cite{ref:miquel}.

\section{Advanced topics}
\subsection{Algebraic topology}
I cover the fundamental group $\pi_1$ first, because I think the subject is more
intuitive this way. A possible reference in this topic is \cite{ref:munkres}.
Only later do I do the much more involved homology groups.
The famous standard reference for algebraic topology is \cite{ref:hatcher},
which is what almost everyone uses these days.
But I also found \cite{ref:maxim752} to be very helpful,
particularly in the part about cohomology rings.

I don't actually do very much algebraic topology.
In particular, I think the main reason to learn algebraic topology
is to see the construction of the homology and cohomology groups
from the chain complex, and watch the long exact sequence in action.
The concept of a (co)chain complex comes up often in other contexts as well,
like the cohomology of sheaves or Galois cohomology.
Algebraic topology is by far the most natural one.

I use category theory extensively, being a category-lover.

\subsection{Algebraic number theory}
I learned from \cite{ref:oggier_NT},
using \cite{ref:lenstra_chebotarev}
for the part about the Chebotarev density theorem.

When possible I try to keep the algebraic number theory chapter close at
heart to an ``olympiad spirit''.
Factoring in rings like $\ZZ[i]$ and $\ZZ[\sqrt{-5}]$
is very much an olympiad-flavored topic at heart:
one is led naturally to the idea of factoring in general rings of integers,
around which the presentation is built.
As a reward for the entire buildup, the exposition finishes
with the application of the Chebotarev density theorem to IMO 2003, Problem 6.

\subsection{Algebraic geometry}
My preferred introduction to algebraic geometry is \cite{ref:gathmann}
for a first read and \cite{ref:vakil} for the serious version.
Both sets of lecture notes are essentially self-contained.

I would like to confess now that I know relatively little algebraic geometry,
and in my personal opinion the parts on algebraic geometry
are the weakest part of the Napkin.
This is reflected in my work here:
in the entire set of notes I only barely finish defining a scheme,
the first central definition of the subject.

Nonetheless, I will foolishly still make some remarks about my own studies.
I think there are three main approaches to beginning the study of schemes:
\begin{itemize}
	\ii Only looking at affine and projective varieties,
	as part of an ``introductory'' class,
	typically an undergraduate course.
	\ii Studying affine and projective varieties closely
	and using them as the motivating example of a \emph{scheme},
	and then developing algebraic geometry from there.
	\ii Jumping straight into the definition of a scheme,
	as in the well-respected and challenging \cite{ref:vakil}.
\end{itemize}
I have gone with the second approach,
I think that if you don't know what a scheme is,
then you haven't learned algebraic geometry.
But on the other hand I think the definition of a scheme is
difficult to digest without having a good handle first on varieties.

These opinions are based on my personal experience of having
tried to learn the subject through all
three approaches over a period of a year.
Your mileage may vary.

I made the decision to, at least for the second part,
focus mostly on \emph{affine} schemes.
These already generalize varieties in several ways,
and I think the jump is too much if one starts
then gluing schemes together.
I would rather that the student first feel like
they really understand how an affine scheme works,
before going on into the world where they now have a general scheme $X$
which is locally affine (but probably not itself affine).
The entire chapter dedicated to a gazillion examples
of affine schemes is a hint of this.

\section{Topics not in Napkin}
\subsection{Analytic number theory}
I never had time to write up notes in Napkin for these.
If you're interested though, I recommend \cite{ref:analytic_NT}.
They are highly accessible and delightful to read.
The only real prerequisites are a good handle on Cauchy's residue formula.


\subsection{Precedences}\label{ssec:prec}

These are the current precedence levels for standard and UTP predicates,
determined by the following \emph{choices}%
\footnote{These are not laws,
just conventions we feel are most useful
for the kinds of things we usually write.}%
\RLEQNS{
   P \refinedby Q \implies R &=& P \refinedby (Q \implies R) & \refinedby_1
\\ P \equiv Q \implies R  &=& P \equiv (Q \implies R) & \equiv_1
\\ P \implies Q \cond R S &=& P \implies (Q \cond R S) & \implies_2
\\ P \cond Q R \seq S     &=& P \cond Q (R \seq D)     & \cond\!_3
\\ P \seq Q \lor R        &=& P \seq (Q \lor R)        & \seq_4
\\ P \lor Q \land R       &=& P \lor (Q \land R)       & \lor_5, \ndc_5
\\ P \land c * Q          &=& P \land (c * Q)          & \land_6
\\ \lnot c * P            &=& (\lnot c) * P            & *_7
\\ \lnot e = f            &=& \lnot(e=f)               & \lnot_8
\\ e = f[e/x]             &=& e = (f[e/x])             & =_9, [/]_{10}
}