% !TEX root = ../main.tex

In this chapter, we sketch some adaptations of the set reconciliation algorithm to related problems. \Cref{general-partitions} considers more general partitioning strategies than one-dimensional ranges. \Cref{maps} presents how to reconcile key-value mappings. \Cref{set-mirror} shows an asymmetric variant of the protocol, mirroring the contents of a set or map held at a primary node to a replica node. \Cref{authenticated} demonstrates how our data structures for fingerprint computations can also serve as simple authenticated data structures.

\section{Higher-Dimensional Ranges}
\label{general-partitions}

The set reconciliation algorithm recursively partitions the item sets of both nodes by splitting the sets into successive ranges. But for the correctness of the algorithm, the exact mechanism by which partitions are chosen is irrelevant. All that is necessary is that in each communication round, when receiving a mismatching fingerprint for some non-empty $S \subseteq U$, the node chooses a partition $\disjointunion{S_0}{\disjointunion{S_1}{\disjointunion{\ldots}{S_k}}} = S$ of $S$, and then communicates to the other node the choice of the partition and how its items are distributed among the individual sets.

Partitioning into successive ranges over a linearly ordered set has some nice properties: It can be applied to virtually any set since one can always arbitrarily define a linear order. The choice of the partition and the way the items are distributed among the sets can be encoded and transmitted efficiently. And finally, when receiving an arbitrarily chosen partition into successive ranges, a node can always efficiently compute the items it holds within that partition as well as the fingerprint over these items.

As long as nodes always want to synchronize the complete sets they hold, this is completely sufficient. But more elaborate partitioning strategies can become attractive if nodes might wish to only synchronize certain subsets. The partitioning mechanism effectively dictates which such subsets can be described, taking on the role of a query language. A natural next step is to look for more powerful partitioning mechanisms that still admit efficient fingerprint computation.

We now give one such partitioning scheme by generalizing the one-dimensional ranges of the original presentation of the algorithm to $k$-dimensional ranges. Let $U$ be a finite set of items, and let $\preceq_0, \preceq_1, \ldots, \preceq_{k-1}$ be linear orders over $U$. A \defined{$k$-dimensional range} is a $k$-tuple $((x_0, y_0), (x_1, y_1), \ldots, (x_{k-1}, y_{k-1}))$ with $x_i \preceq_i y_i$. Given some $S \subseteq U$, the items from $S$ in this range are all items $v \in S$ such that $x_i \preceq_i v \preceq_i y_i$ for all $0 \leq i < k$. Note that for $k = 1$ this is equivalent to the ranges used in previous chapters. The reconciliation protocol needs to be adapted so that messages include the $k$-dimensional range boundaries, but otherwise no changes are required.

Fingerprints can be computed efficiently by storing the set as a (balanced) $k$-d tree~\cite{bentley1975multidimensional}. As $k$-d trees are binary trees, the labels from \cref{fingerprints} can be used without any modification. Fingerprint computation still works by traversing the tree, alternating between the dimensions just as in e.g. a $k$-d tree item lookup. For $k = 1$, this yields exactly the algorithms of \cref{fingerprints}.

Generalized partitioning schemes, including $k$-dimensional ranges, can not only be applied to the regular set reconciliation protocol, but also to all modifications discussed in the further sections.

\section{Map Reconciliation}
\label{maps}

A key-value mapping, i.e. a partial function $\partialfun{\m}{K}{V}$ with a finite domain from some set of keys $K$ to a set of values $V$, can be reconciled by reconciling the set $\set{(k, v) \mid \text{$k \in \domain(\m)$ and $v = \m(k)$}}$. After this reconciliation, a node may have obtained two pairs $(k, v), (k, v')$ if the two nodes mapped the same key $k$ to distinct values $v, v'$, so the resulting set would not correspond to an updated map. In those cases, both nodes compute the single new image of $k$ as $\f(v, v')$, where $\fun{\f}{V \times V}{V}$ is some function known to all participating nodes.

Particularly interesting are cases where $\f$ can be computed via another interactive protocol. If for example $V$ consists of the fingerprints of finite subsets of some universe $U$, and $\f(v, v')$ is defined to be the fingerprint of the union of the two sets whose fingerprints are $v$ and $v'$, then the two nodes can run a set reconciliation session to efficiently obtain the union. Viewed more abstractly, when reconciling a map, the values can be reconciled via arbitrary nested protocol invocations.

\section{Set and Map Mirroring}
\label{set-mirror}

We based the presentation of our synchronization approach on set reconciliation because it is a symmetric problem where both nodes use identical algorithms to compute identical types of messages. A related, asymmetric problem is that of a \defined{replica} node setting its locally stored set to that of a \defined{primary} node, utilizing similarity between the two initial sets to minimize the communication complexity. The approach of recursively exchanging fingerprints for subsets of decreasing size can be modified to solve this \defined{set mirroring} problem.

The primary node can run exactly the same protocol as that for such reconciliation. The replica node uses a slightly modified version. Whenever it receives a range item set, it adds the received items to its local set as usual, but then it deletes all item it holds within that range which were not part of the received range item set. Whenever the replica node sends a range item set, it sends an empty one.

The complexity analysis is identical to that of the set reconciliation protocol, the correctness argument is analogous: ranges with equal fingerprints are already correctly mirrored if no fingerprint collisions occurred, exchanging range item sets correctly mirrors all items within that range, and large ranges with non-equal fingerprints can be handled recursively because mirroring the partitions of a set results in mirroring the whole set.

Just as for reconciliation, maps can be mirrored by interpreting them as sets of key-value pairs. Mirroring maps has some interesting use cases, for example filesystems can be regarded as maps from paths to strings. The efficient creation of backups then becomes the problem of mirroring such a map onto a backup server that may already hold a similar, older backup. An equivalent problem is that of efficiently distributing source code updates from a server to clients which may hold old versions of the source code.

\section{Authenticated Data Structures}
\label{authenticated}

Authenticated data structures solve the problem of outsourcing data structure membership queries processing to untrusted replicas rather than processing all queries at the original trusted data source. The trusted source publishes a short digest to a client. The client can then send a query to a replica, which answers with the result and a small certificate which together with the digest proves that the answer is indeed correct. For more details on this three-party model and pointers to the rich literature on the topic, we refer to~\cite{martel2004general}.

Merkle trees form a simple authenticated set. The root label is the digest, and the certificate for an affirmative membership query consists of the labels of the children of the vertices on the path from the root to the item in question. These labels can be used to recompute the root label, proving that the item is part of the original tree. Fabricating a sequence of labels to fake inclusion of an item amounts to breaking the hash function. Non-membership queries can be authenticated by providing certificates for tree membership of items stored in adjacent leaves such that one is less than and one is greater than the item in question.

Our examination of randomized data structures was driven by the need for Merkle-like properties, so it is not very surprising that they can also be used as authenticated data structures. Indeed~\cite{naor2000certificate} mentions treaps as an alternative to regular Merkle trees. Monoidal labels based on Cayley hash functions remove the need for a specific tree shape to be maintained. Skip lists as authenticated data structures have been studied in~\cite{goodrich2000efficient}, but they require the hash function to be commutative. Our construction removes this assumption.


\chapter{Expectation values}

\section*{3.1. Flip until heads}
\addcontentsline{toc}{section}{3.1. Flip until heads}
In Example 2 on page 136, we found that if you flip a coin until you get a Heads, the
expectation value of the total number of coins is
\begin{equation*}\tag{3.89}
    \frac{1}{2} \cdot 1 + \frac{1}{4} \cdot 2 +
    \frac{1}{8} \cdot 3 + \frac{1}{16} \cdot 4 + \frac{1}{32} \cdot 5 \ldots
\end{equation*}

We claimed that this sum equals 2. Demonstrate this by writing the sum as a
geometric series starting with 1/2, plus another geometric series starting
with 1/4, and so on. You can use the fact that the sum of a geometric series
with first term $a$ and ratio $r$ is $a/(1-r)$.

\vspace{1em}

\begin{proof}
    It can be easily seen that the general term of the sum is $\frac{n}{2^n}$, so
    \[
        S_n = \frac{1}{2} \cdot 1 + \frac{1}{4} \cdot 2 + \frac{1}{8} \cdot 3 + \frac{1}{16} \cdot 4 +
        \frac{1}{32} \cdot 5 + \ldots + \frac{1}{2^n} \cdot n
        = \sum_{k = 1}^{n} \frac{n}{2^n}
    \]

    We rewrite the sum and observe the suggested pattern:
    \begin{align*}
        \frac{1}{2} + \frac{2}{4} + \frac{3}{8} + \ldots + \frac{n}{2^n}
        &= \bigg(\frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \ldots + \frac{1}{2^n}\bigg)
            + \bigg(\frac{1}{4} + \frac{1}{8} + \ldots + \frac{1}{2^n}\bigg) + \ldots
            + \bigg(\frac{1}{2^{n - 1}} + \frac{1}{2^n}\bigg) + \frac{1}{2^n} \\
        &= \sum_{k = 1}^{n}\bigg(\frac{1}{2}\bigg)^k + \sum_{k = 2}^{n}\bigg(\frac{1}{2}\bigg)^k + \ldots
            + \sum_{k = n - 1}^{n}\bigg(\frac{1}{2}\bigg)^k + \sum_{k = n}^{n}\bigg(\frac{1}{2}\bigg)^k
    \end{align*}

    By observing the fact that the sums are actually geometric series with the ratio $r = \frac{1}{2}$
    and the first term $a = \frac{1}{2^k}$, we obtain:
    \[
        \sum_{k = p}^{n} \bigg(\frac{1}{2}\bigg)^k = \frac{\big(\frac{1}{2}\big)^p}{1 - \frac{1}{2}}
        = \bigg(\frac{1}{2}\bigg)^{p - 1}
    \]

    Therefore, by rewriting the sum using the last expression and then applying the geometric
    series result again, we get our desired result:
    \[
        S = \bigg(\frac{1}{2}\bigg)^0 + \bigg(\frac{1}{2}\bigg)^1 + \ldots + \bigg(\frac{1}{2}\bigg)^{n - 1}
        = \sum_{k = 0}^{n - 1} \bigg(\frac{1}{2}\bigg)^k
        = \frac{1}{1 - \frac{1}{2}} = 2
    \]
\end{proof}

\section*{3.2. HT waiting time}
\addcontentsline{toc}{section}{3.2. HT waiting time}
We know from Example 2 on page 136 that the expected number of flips required to obtain a Heads is 2.
What is the expected number of flips required to obtain a Heads and a Tails in succession (in that order)?

\vspace{1em}

\begin{proof}
    Since the first flip in the succession has to be Heads, we flip the coin until we obtain a Heads.
    It is known that the expected number of flips for that to happen is 2. Now, we need to obtain a
    Tails. Since Heads and Tails are equally likely in a fair coin flip, the expected number of flips
    needed to obtain Tails is also 2. Therefore, the expected number of flips needed to obtain a
    Heads and Tails succession (in this order) is $2 + 2 = 4$.
\end{proof}

\section*{3.3. Sum of dependent variables}
\addcontentsline{toc}{section}{3.3. Sum of dependent variables}
Consider the example on page 137, but now let $X$ and $Y$ be dependent in the following
manner: If $Y = 1$, then it is always the case that $X = 1$. If  $Y = 2$, then it is always the
case that $X = 2$. If $Y = 3$, then there are equal chances of $X$ being 1 or 2. If we assume that
$Y$ takes on the values 1, 2, and 3 with equal probabilities of 1/3, then you can quickly show
that $X$ takes on the values 1 and 2 with equal probabilities of 1/2. So we have reproduced
the probabilities in the original example. Show (by explicitly calculating the probabilities of
the various outcomes) that in the present scenario where $X$ and $Y$ are dependent, the relation
$E(X + Y) = E(X) + E(Y)$ still holds.

\vspace{1em}

\begin{proof}
    Since we know that the $X$ takes on the values 1, 2 with equal probabiliy, we can easily find that:
     \[
         E(X) = p(X = 1) \cdot 1 + p(X = 2) \cdot 2 = \frac{1}{2} + \frac{1}{2} \cdot 2 =\frac{3}{2}
    \]

    We do the same for $Y$ to obtain:
    \[
        E(Y) = p(Y = 1) \cdot 1 + p(Y = 2) \cdot 2 + p(Y = 3) \cdot 3
        = \frac{1}{3} + \frac{2}{3} + \frac{3}{3} = 2
    \]

    Therefore, it is straightforward that:
    \[
        E(X) + E(Y) = \frac{3}{2} + 2 = \frac{7}{4}
    \]

    We continue by computing $E(X + Y)$. We'll do that by analyzing the obtained cases from the perspective
    of  $Y$.
    \begin{enumerate}[(1)]
        \item We know that there is a  $\frac{1}{3}$ probability that $Y = 1$ and that if $Y = 1$, then $X = 1$.
            As a result, there is a $\frac{1}{3}$ probability that $Y = 1 \text{ and } X = 1$.

        \item Analogously, we find that there is a $\frac{1}{3}$ probability that $Y = 2$ and $X = 2$.

        \item For $Y = 3$, $X$ takes on the values $1, 2$ with equal probabilities of $\frac{1}{2}$. Hence,
            ($Y = 3$ and $X = 1$) and ($Y = 3$ and $X = 2$) are equally likely with a probability
            of $\frac{1}{6}$.
    \end{enumerate}

    By looking at the described cases, we obtain the outcomes of $X + Y$ and their probabilities:
    \begin{enumerate}[(i)]
        \item $\frac{1}{3}$ probability that $X + Y = 2$, for ($X = 1$ and $Y = 1$)

        \item $\frac{1}{3} + \frac{1}{6} = \frac{1}{2}$ probability that $X + Y = 4$, for ($Y = 2$ and $X = 2$)
    and ($Y = 3$ and  $X = 1$)

    \item $\frac{1}{6}$ probability that $X + Y = 5$, for ($Y = 3$ a and $X = 2$)
    \end{enumerate}

    Finally, we compute the expectation of the sum and prove the linearity of expectation:
    \begin{align*}
        E(X + Y) =& P(X + Y = 2) \cdot 2 + P(X + Y = 4) \cdot 4 + P(X + Y = 5) \cdot 5 \\
        =& \frac{1}{3} \cdot 2 + \frac{1}{2} \cdot 4 + \frac{1}{6} \cdot 5 = \frac{7}{4} = E(X) + E(Y)
    \end{align*}
\end{proof}

\section*{3.4. Playing "unfair" games}
\addcontentsline{toc}{section}{3.4. Playing "unfair" games}
\begin{enumerate}[(a)]
    \item Assume that later on in life, things work out so that you have more than enough money
        in your retirement savings to take care of your needs and beyond, and that you truly
        don't have a need for any more money. Someone offers you the chance to play a one-time
        game where you have a 3/4 chance of doubling your money, and a 1/4 chance of losing
        it all. If you initially have $N$ dollars, what is the expectation value of your
        resulting amount of money if you play the game? Would you want to play it?

    \item Assume that you are stranded somewhere, and that you have only \$10 for a \$20 bus
        ticket. Someone offers you the chance to play a one-time game where you have a 1/4
        chance of doubling your money, and a 3/4 change of losing it all. What is the expectation
        value of your resulting amount of money if you play the game? Would you want to play it?
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item Since there is a 3/4 chance of doubling the money and a 1/4 chance of losing it all,
            the expectation value of the resulting money if playing the game is:
            \[
                E(X) = \frac{3}{4} \cdot 2N + \frac{1}{4} \cdot 0 = \frac{3N}{2}
            \]

            Even if the expected return looks favorable, I would not play the game in the given context.
            If I don't have a need for more money, a potential of doubling the money is dwarfed by the
            devastating result of losing it all, so the 1/4 probability of losing the money doesn't
            make the game appealing enough.

        \item The expected value of the resulting amount of money if playing the second game is given
            by:
            \[
                E(Y) = \frac{3}{4} \cdot \$0 + \frac{1}{4} \cdot \$20 = \$5
            \]

            Here, even if the expected return doesn't look favorable, I would play the game. The price
            is small enough that it would be worth losing the money for a $\frac{1}{4}$ chance of being
            able to get the bus ticket and get home.
    \end{enumerate}
\end{proof}

\section*{3.5. Simpson's paradox}
\addcontentsline{toc}{section}{3.5. Simpson's paradox}
During the baseball season in a particular year, player A has a higher batting average than player B.
In the following year, A again has a higher average than B. But to your great surprise when you
calculate the batting averages over the combined span of the two years, you find that A's average is
$\emph{lower}$ than B's! Explain, by giving a concrete example, how this is possible.

\vspace{1em}

\begin{proof}
    The Simpson's paradox is a phenomenon in which a trend appears in several different groups of data
    but disappears when these groups are combined. Let's consider the same setup as in the description of
    the problem. Suppose that the batting averages in the first year are 5/10 for player A and 15/35 for
    player B, respectively 10/20 for player A and 20/30 for player B in the second year. We can easily
    see that if we take years individually, the averages of player A are higher than averages of player B.
    However, if we combine the data of the two years, we get that the overall batting average
    of player A will be lower than the overall average of player B:
    \[
        \frac{5 + 10}{10 + 20} = \frac{1}{2} < \frac{7}{13} = \frac{15 + 20}{35 + 30}
    \]
\end{proof}

\section*{3.6. Variance of a product}
\addcontentsline{toc}{section}{3.6. Variance of a product}
Let $X$ and $Y$ each be the result of independent (and fair) coin flips where we assign the value
1 to Heads and 0 to Tails. Show that Var($XY$) is not equal to Var($X$)Var($Y$).

\vspace{1em}

\begin{proof}
    Since we know that $X$ takes on the values $1, 2$ with equal probability, we easily compute the
    variance of $X$:
    \[
        \text{Var}(X) = E[(X - \mu_x)^2] = E\bigg[\bigg(X - \frac{1}{2}\bigg)^2\bigg]
        = \frac{1}{2}\bigg(0 - \frac{1}{2}\bigg)^2  + \frac{1}{2}\bigg(1 - \frac{1}{2}\bigg)^2
        = \frac{1}{2} + \frac{1}{2}
        = \frac{1}{4}
    \]

    Analogously, we get the same result for Var($X$), so:
    \[
        \text{Var}(X)\text{Var}(Y) = \frac{1}{4} \cdot \frac{1}{4} = \frac{1}{16}
    \]

    X and Y can be chosen in 4 ways, 3 give $XY = 0$ and one gives $XY = 1$, so $\mu_{XY} = \frac{1}{4}$.
    Since all pairings are equally likely, we have that $P(XY = 0) = \frac{3}{4}$ and
    $P(XY = 1) = \frac{1}{4}$. Now, the variance of the product is given by:
    \[
        \text{Var}(XY) = E[(XY - \mu_{XY})^2] = E\bigg[\bigg(XY - \frac{1}{4}\bigg)^2\bigg]
        = \frac{3}{4} \bigg(0 - \frac{1}{4}\bigg)^2 + \frac{1}{4} \bigg(1 - \frac{1}{4}\bigg)^2
        = \frac{3}{64} + \frac{9}{64}
        = \frac{3}{16}
    \]

    In conclusion, we proved that in this setup Var($XY$) $\neq$ Var($X$)Var($Y$).
\end{proof}

\section*{3.7. Variances}
\addcontentsline{toc}{section}{3.7. Variances}
For each of the three examples near the beginning of Section 3.2., show that the alternative
$E(X^2) - \mu^2$ form of the variance given in Eq. (3.34) leads to the same results we obtained
in the examples.

\begin{proof}
    \hfill
    \begin{itemize}
        \item \textbf{Example 1 (Die roll):} The expectation value of the six equally likely outcomes
            of a dire roll is $\mu = \frac{21}{6}$, therefore $\mu^2 = \frac{441}{36}$. The expected value
            of $X^2$ is:
            \[
                E(X^2) = \frac{1}{6}(1 + 4 + 9 + 16 + 25 + 36) = \frac{91}{6}
            \]

            Hence, the variance result is the same as using the standard formula in (3.20):
            \[
                \text{Var}(X) = E(X^2) - \mu_X^2 = \frac{91}{6} - \frac{441}{36} = \frac{105}{36} \approx 2.92
            \]

        \item \textbf{Example 2 (Coin flip):} Consider a coin flip where we assign the value 1 to Heads
            and 0 to Tails. The expectation value of these two equally likely outcomes is $\mu = \frac{1}{2}$,
            so $\mu^2 = \frac{1}{4}$. The expected value of $X^2$ is:
            \[
                E(X^2) = \frac{1}{2} (0 + 1) = \frac{1}{2}
            \]

            As a result, the variance is the same as using the standard variance form in (3.21):
            \[
                \text{Var}(X) = E(X^2) - \mu^2 = \frac{1}{4}
            \]

        \item \textbf{Example 3 (Biased coin):} Consider a biased coins, where the probability of getting
            Heads is $p$ and the probability of getting Tails is $1 - p \equiv q$. If we again
            assign the value 1 to Heads and 0 to Tails, then the expectation value is
            $\mu = p \cdot 1 + (1 - p) \cdot 0 = p$, so $\mu^2 = p^2$. The expected value
            of $X^2$ is:
             \[
                 E(X^2) = p \cdot 1 + q \cdot 0 = p
            \]

            Once again, the variance is the same as in (3.22):
            \[
                \text{Var}(X) = E(X^2) - \mu^2 = p - p^2 = p(1 - p) = pq
            \]
    \end{itemize}
\end{proof}

\section*{3.8. Random walk}
\addcontentsline{toc}{section}{3.8. Random walk}
Consider the following one-dimensional random walk. A person starts at the origin and
then takes $n$ successive steps. Each step is equally likely to be to the right or to the
left. All steps have the same length.
\begin{enumerate}[(a)]
    \item What is the probability that the person is located back at the
        origin after the $n$th step?

    \item After $n$ steps, what is the standard deviation of the person's position
        relative to the origin? (Assume that the length of each step is, say, one
        foot).
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item We see from the beginning that a person can end up in the origin only
            if he made the same number of steps in both directions. Therefore, it's
            impossible to end up in the origin if $n$ is odd, so:
            \[
                P(O | n = \text{odd}) = 0
            \]

            If $n$ is even, we
            count the favorable cases by considering the sequence of performed steps
            and seeing in how many ways can the left steps be placed in the sequence,
            the right steps taking the remaining positions. So, the number
            of ways in which the person ends up in the origin for an even $n$ is:
             \[
                 \binom{n}{\frac{n}{2}} = \frac{n!}{\big(\frac{n}{2}\big)!\big(\frac{n}{2}\big)!}
            \]

            The number of possible step sequences is obviously $2^n$, giving us the
            probability that is located back at the origin after the $n$th step:
            \[
                P(O | n = \text{even}) = \frac{n!}{2^n\big(\frac{n}{2}\big)!\big(\frac{n}{2}\big)!}
            \]

            By using the Law of Total Probability:
            \[
                P(O) = P(O | n = \text{even})P(n = \text{even}) + P(O | n = \text{odd})P(n = \text{odd})
                = \frac{n!}{2^{n+1}\big(\frac{n}{2}\big)!\big(\frac{n}{2}\big)!}
            \]

        \item Let $X$ be the distance from the origin after n steps, where steps are represented
            by the random variables $X_i$ which take on the values $-1$ and $1$ and 2 equally likely. Then,
            \[
                X = \sum_{i = 1}^{n} X_i
            \]

            We compute the expectation of $X^2$:
            \[
                E[X^2] = E\bigg[\bigg(\sum_{i = 1}^n X_i\bigg)^2\bigg]
                = E\bigg[\bigg(\sum_{i = 1}^n {X_i}^2 + \sum_{j = 1}^n\sum_{k = j+1}^n X_jX_k\bigg)\bigg]
            \]

            Since $X_i$ takes on -1 and 1, then $X_i^2 = 1$, so $\displaystyle \sum_{i = 1}^n {X_i}^2 = n$.
            Using this and the linearity of expectation, our expression becomes:
            \[
                E[X^2] = E[n] + E\bigg[\sum_{j = 1}^n\sum_{k = j+1}^n X_jX_k\bigg]
                = n + \sum_{j = 1}^n\sum_{k = j+1}^n E[X_jX_k]
            \]

            The events $X_i$ and $X_j$ of choosing a step are independent for $i \neq j$. From
            this and the fact that the expected value of $X_i$ is 0, we get:
             \[
                 E[x^2]= n + \sum_{j = 1}^n\sum_{k = j+1}^n E[X_j]E[X_k] = n
            \]

            The mean is now given by:
            \[
            \mu = \frac{1}{n}\sum_{i = -n}^n i = 0
            \]

            Finally, the standard deviation is:
            \[
                \sigma = \sqrt{E(X^2) - \mu^2} = \sqrt{n}
            \]
    \end{enumerate}
\end{proof}

\section*{3.9. Expected product, without replacement}
\addcontentsline{toc}{section}{3.9. Expected product, without replacement}
Consider a set of $N$ given numbers, $a_1, a_2, \ldots a_N$. Let the mean of these $N$ numbers
be $\mu$, and let the standard deviation be $\sigma$. Draw two numbers $X_1$ and $X_2$
randomly $\emph{without replacement}$. Show that the expectation value of their
product is
\begin{equation*}\tag{3.90}
    E[X_1X_2] = \mu^2 - \frac{\sigma^2}{N - 1}
\end{equation*}

$\emph{Hint}$: All of the $a_ia_j$ possibilities (with $i \neq j$) are equally likely.

\vspace{1em}

\begin{proof}
    There are $\binom{N}{2} = \frac{N(N - 1)}{2}$ ways of choosing $X_1$ and $X_2$, all of
    them being equally likely, so:
    \[
        E[X_1X_2] = \frac{2}{N(N - 1)} \sum_{i = 1}^n \sum_{j = i + 1}^n a_ia_j
    \]

    Seeing that
    \[
        \bigg(\sum_{i = 1}^n a_i\bigg)^2 = \sum_{i = 1}^n {a_i}^2 + 2\sum_{i = 1}^n \sum_{j = i + 1}^n a_ia_j
    \]

    , the expression of the expectation becomes:
    \[
        E[X_1X_2] = \frac{1}{N(N - 1)} \bigg[\bigg(\sum_{i = 1}^n a_i\bigg)^2 - \sum_{i = 1}^n {a_i}^2\bigg]
    \]

    From the formula of the mean we notice that
    \begin{equation*}\tag{3.9.1}
        N\mu = \sum_{i = 1}^n a_i
    \end{equation*}

    , so then
    \begin{align*}
        E[X_1X_2] = \frac{1}{N(N - 1)} \bigg(N^2\mu^2 - \sum_{i = 1}^n {a_i}^2\bigg)
        =& \frac{N\mu^2}{N - 1} - \frac{1}{N(N - 1)}\sum_{i = 1}^n {a_i}^2 \\
        =& \mu^2 - \frac{1}{N(N - 1)}\bigg(\sum_{i = 1}^n {a_i}^2 - N\mu^2\bigg) \\
    \end{align*}

    By rewriting the expression of the variance and using (3.9.1), we obtain:
    \begin{align*}
        \frac{\sigma^2}{N - 1} = \frac{1}{N(N - 1)}\sum_{i = 1}^n (a_i - \mu)^2
        =& \frac{1}{N(N - 1)} \bigg(\sum_{i = 1}^n {a_i}^2 - 2\mu \sum_{i = 1}^n a_i + N\mu^2\bigg) \\
        =& \frac{1}{N(N - 1)} \bigg(\sum_{i = 1}^n {a_i}^2 - 2N\mu^2 + N\mu^2\bigg) \\
        =& \frac{1}{N(N - 1)} \bigg(\sum_{i = 1}^n {a_i}^2 - N\mu^2\bigg) \\
    \end{align*}

    In conclusion, by substituting the last expression in the expectation's form, we see
    that
    \begin{equation*}\tag{3.90}
        E[X_1X_2] = \mu^2 - \frac{\sigma^2}{N - 1}
    \end{equation*}
\end{proof}

\section*{3.10. Standard deviation of the mean, without replacement}
\addcontentsline{toc}{section}{3.10. Standard deviation of the mean, without replacement}
Consider a set of $N$ given numbers, $a_1, a_2, \ldots, a_N$. Let the mean of these
$N$ numbers be $\mu$ and let the standard deviation be $\sigma$. Draw a sample
of $n$ numbers $X_i$, randomly $\emph{without replacement}$, and calculate
their sample mean. Show that the variance of the sample mean is given by
\begin{equation*}\tag{3.91}
    E\bigg[\bigg(\frac{1}{n}\sum_{i = 1}^n X_i - \mu\bigg)^2\bigg]
    = \frac{\sigma^2}{n}\bigg(1 - \frac{n-1}{N-1}\bigg)
\end{equation*}

\vspace{1em}

\begin{proof}
    We start by expanding the square in the expression:

    \begin{align*}
        E\bigg[\bigg(\frac{1}{n}\sum_{i = 1}^n X_i - \mu\bigg)^2\bigg]
        =& E\bigg[\frac{1}{n^2}\bigg(\sum_{i = 1}^n X_i\bigg)^2
                              - \frac{2\mu}{n}\sum_{i = 1}^n X_i + \mu^2\bigg] \\
        =& E\bigg[\frac{1}{n^2}\sum_{i = 1}^{n} {X_i}^2 + \frac{2}{n^2}\sum_{i = 1}^n\sum_{j = i + 1}^n X_iX_j
                              - \frac{2\mu}{n}\sum_{i = 1}^n X_i + \mu^2\bigg] \\
    \end{align*}

    By using the linearity of expectation, the expression becomes:
    \[
        E\bigg[\bigg(\frac{1}{n}\sum_{i = 1}^n X_i - \mu\bigg)^2\bigg] =
        \frac{1}{n^2}\sum_{i = 1}^nE[{X_i}^2] + \frac{2}{n^2}\sum_{i = 1}^n\sum_{j = i + 1}^n E[X_iX_j]
        - \frac{2\mu}{n} \sum_{i = 1}^n E[X_i] + \mu^2
    \]

    We assume that the $n$ numbers $X_i$ are equally likely to be extracted, so
    we denote $X$ such that for all $1 \leq i \leq n$,
    \begin{align*}
        E[X_i] &= E[X] = \mu \\
        E[{X_i}^2] &= E[X^2] = \mu^2 + \sigma^2
    \end{align*}
    $X_iX_j$ are also distributed the same. Using (3.90), we denote $X_aX_b$ so that
    for all $1 \leq i \leq j \leq n$,
    \[
        E[X_iX_j] = E[X_aX_b] = \mu^2 - \frac{\sigma^2}{N - 1}
    \]

    By using the proposed substitutions, our expression becomes:
    \begin{align*}
        E\bigg[\bigg(\frac{1}{n}\sum_{i = 1}^n X_i - \mu\bigg)^2\bigg]
        =& \frac{1}{n^2}\sum_{i = 1}^nE[{X}^2] + \frac{2}{n^2}\sum_{i = 1}^n\sum_{j = i + 1}^n E[X_aX_b]
            - \frac{2\mu}{n} \sum_{i = 1}^n E[X] + \mu^2 \\
        =& \frac{1}{n}\bigg[\mu^2 + \sigma^2 + (n - 1)
            \bigg(\mu^2 - \frac{\sigma^2}{N - 1}\bigg)\bigg] - \mu^2 \\
        =& \mu^2 \bigg(\frac{1}{n} + \frac{n-1}{n} - 1\bigg) +
            \sigma^2\bigg(\frac{1}{n} - \frac{n-1}{n(N - 1)}\bigg)
    \end{align*}

    The coefficient of $\mu^2$ is 0, so we obtain the desired result:
    \begin{equation*}\tag{3.91}
        E\bigg[\bigg(\frac{1}{n}\sum_{i = 1}^n X_i - \mu\bigg)^2\bigg]
        = \frac{\sigma^2}{n}\bigg(1 - \frac{n-1}{N-1}\bigg)
    \end{equation*}
\end{proof}

\section*{3.11. Biased sample standard deviation}
\addcontentsline{toc}{section}{3.11. Biased sample standard deviation}
We mentioned on page 163 that the sample standard deviation $s$ is a $\emph{biased}$
estimator of the distribution standard deviation $\sigma$. The basic reason for this
is that  the square root operation is nonlinear, which means that the square
root of the average of a set of numbers isn't equal to the average of their
square roots. For example, the average of 1.1 and 0.9 is 1, but the average of
$\sqrt{1.1}$ and  $\sqrt{0.9}$ isn't 1. It is smaller than 1. Let's give a general
proof that  $E[s] \leq \sigma$ (unlike  $E[s^2] = \sigma$).

If we calculate the sample variances for a large number $N$ of sets of $n$ numbers,
then the $E[s^2] = \sigma^2$ equality in Eq. (3.74) tells us that in the $N \to \infty$
limit, we have
\begin{equation*}\tag{3.92}
    \frac{s_1^2 + s_2^2 + \ldots + s_N^2}{N} = \sigma^2
\end{equation*}

Our goal is to show that
\begin{equation*}\tag{3.93}
    \frac{s_1 + s_2 + \ldots + s_N}{N} \leq \sigma
\end{equation*}
in the $N \to \infty$ limit. To demonstrate this, square both sides of Eq. (3.93)
and make copious use of the arithmetic-geometric-mean inequality, $\sqrt{ab} \leq (a+b)/2$.

\vspace{1em}

\begin{proof}
    Let us define the series $(a_N)_{N \geq 1}, (b_N)_{N \geq 1} \subset \mathbb{N}$, with

    \vspace{1em}
    \begin{minipage}{0.5\textwidth}
        \[
            a_N = \frac{s_1 + s_2 + \ldots + s_N}{N}
        \]
    \end{minipage}
    \begin{minipage}{0.5\textwidth}
        \[
            b_N = \sqrt{\frac{s_1^2 + s_2^2 + \ldots + s_N^2}{N}}
        \]
    \end{minipage}
    \vspace{1em}

    We'll prove that $a_N \leq b_N$, for all $N \in \mathbb{N}$. The starting point is
    the inequality
    \[
        \sum_{i = 1}^N \sum_{j = i + 1}^N (s_i - s_j)^2 \geq 0
    \]
    which is true, since a sum of squares is always nonnegative. By expanding
    the sum, we get that
    \[
        (N - 1)\sum_{i = 1}^{N}s_i^2 - \sum_{i = 1}^N \sum_{j = i + 1}^N 2s_is_j \geq 0
    \]
    After moving the second term in the right-hand side of the inequality and then
    adding $\displaystyle \sum_{i = 1}^{N} s_i^2$ to both sides, the expression becomes:
    \[
        N\sum_{i = 1}^N s_i^2 \geq \sum_{i = 1}^N s_i^2 + \sum_{i = 1}^N \sum_{j = i + 1}^N 2s_is_j
    \]

    The member on the right is the expansion of the squared sum of $s_i$'s, so
    \[
        N\sum_{i = 1}^N s_i^2 \geq \bigg(\sum_{i = 1}^{N} s_i\bigg)^2
    \]

    We divide both sides by $N^2 > 0$ and. Then,
    \[
        \frac{1}{N}\sum_{i = 1}^N s_i^2 \geq \bigg(\frac{1}{N}\sum_{i = 1}^{N} s_i\bigg)^2
    \]

    The next step is applying the squared root operation on both sides of the expression.
    Since the squared root function is increasing, the inequality is preserved:
    \[
        \bigg(\frac{1}{N}\sum_{i = 1}^N s_i^2\bigg)^{\frac{1}{2}} \geq \frac{1}{N}\sum_{i = 1}^{N} s_i
    \]

    We expand the sum and see that we find $a_N$ and $b_N$ :
    \[
        \sqrt{\frac{s_1^2 + s_2^2 + \ldots s_N^2}{N}} = b_N \geq a_N = \frac{s_1 + s_2 + \ldots + s_N}{N}
    \]

    Therefore, we proved that $a_N \leq b_N$, for all $N \in \mathbb{N}$.

    \vspace{1em}

    Now, we know that:
    \[
        a_N \leq b_N, \forall N \in \mathbb{N} \implies \lim_{N \to \infty} a_N \leq \lim_{N \to \infty} b_N
    \]

    By substituting the actual values of $a_N$ and $b_N$, we get:
    \[
        \lim_{N \to \infty} \frac{s_1 + s_2 + \ldots + s_N}{N}
        \leq \lim_{N \to \infty} \sqrt{\frac{s_1^2 + s_2^2 + \ldots + s_N^2}{N}}
    \]

    By using the continuity of the square root and then substituting with (3.92) in the
    right-hand side member, we obtain the desired result:
    \begin{equation*}\tag{3.93}
        \lim_{N \to \infty} \frac{s_1 + s_2 + \ldots + s_N}{N} \leq \sigma
    \end{equation*}
\end{proof}

\section*{3.13. Sample variance for two dice rolls}
\addcontentsline{toc}{section}{3.13. Sample variance for two dice rolls}
\begin{enumerate}[(a)]
    \item We know from the first example in Section 3.2 that the variance of a
        single die roll is $\sigma^2 = 2.92$. If you use Eq. (3.73) to
        calculate the sample variance  $s^2$ for $n = 2$ dice rolls,
        the expected value of $s^2$ should be $\sigma^2 = 2.92$,
        according to Eq. (3.74). By considering the 36 equally
        likely pairs of dice in Table 1.5, verify that this is indeed the case.

    \item Using the information you generated from Table 1.5, calculate Var($s^2$).
        Then show that the result agrees with the expression of Var($s^2$) in
        Eq. (3.94), with $n = 2$.
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill

    \begin{enumerate}[(a)]
        \item By using (3.74) for $n = 2$, our sample variance is:
             \[
                 s^2 = \frac{1}{n - 1}\sum_{i = 1}^n (x_i - \overline{x})^2
                 = (x_1 - \overline{x})^2 + (x_2 - \overline{x})^2
            \]

        Using the fact that $\overline{x} = \frac{1}{2}(x_1 + x_2)$, we
        can easily prove that
        \[
            s^2 = \frac{(x_1 - x_2)^2}{2}
        \]

        Now, we analyze each one of the 36 possible dice roll pairs and analyze their sample variances.
        We have 6 cases:
        \begin{enumerate}[(1)]
            \item $x_1$ and $x_2$ are equal. There are 6 such cases, with $s^2 = 0$.

            \item The difference between $x_1$ and $x_2$ is 1. There are $5 \cdot 2 = 10$
                such roll pairs, with $s^2 = \frac{1}{2}$

            \item The difference between $x_1$ and $x_2$ is 2. There are $4 \cdot 2 = 8$
                such roll pairs, with $s^2 = 2$

            \item The difference between $x_1$ and $x_2$ is 3. There are $3 \cdot 2 = 6$
                such roll pairs, with $s^2 = \frac{9}{2}$.

            \item The difference between $x_1$ and $x_2$ is 4. There are $2 \cdot 2 = 4$
                such roll pairs, with $s^2 = 8$.

            \item The difference between $x_1$ and $x_2$ is 5. There are $1 \cdot 2 = 2$
                such roll pairs, with $s^2 = \frac{25}{2}$.
        \end{enumerate}

        Therefore, the expected value of the sample variance $s^2$ for $n = 2$ is:
        \[
            E[s^2] = \bigg(\frac{6}{36} \cdot 0\bigg) + \bigg(\frac{10}{36} \cdot \frac{1}{2}\bigg)
                  + \bigg(\frac{8}{36} \cdot 2\bigg) + \bigg(\frac{6}{36} \cdot \frac{9}{2}\bigg)
                  + \bigg(\frac{4}{36} \cdot 8\bigg) + \bigg(\frac{2}{36} \cdot \frac{25}{2}\bigg)
                  = \frac{88}{36} \approx 2.92
        \]
        which matches the expected result.

    \vspace{1em}

    \item The variance of the sample variance is given by:
        \begin{align*}
            \text{Var}(s^2) = E[(s^2 - 2.92)^2]
               &= \bigg[\frac{6}{36} \cdot (0 - 2.92)^2\bigg]
                + \bigg[\frac{10}{36} \cdot (0.5 - 2.92)^2\bigg]
                + \bigg[\frac{8}{36} \cdot (2 - 2.92)^2\bigg] \\
               &+ \bigg[\frac{6}{36} \cdot (4.5 - 2.92)^2\bigg]
                + \bigg[\frac{4}{36} \cdot (8 - 2.92)^2\bigg]
                + \bigg[\frac{2}{36} \cdot (12.5 - 2.92)^2\bigg] \\
               &\approx 11.62
        \end{align*}

        The fourth-order mean $\mu_4$ is
        \begin{align*}
            \mu_4 = E[(X - \mu)^4]
            &= \frac{1}{6}\big[(1 - 3.5)^4 + (2 - 3.5)^4 + (3 - 3.5)^4
                + (4 - 3.5)^4 + (5 - 3.5)^4 + (6 - 3.5)^4] \\
            &\approx 14.73
        \end{align*}

        Eq. (3.94) is given by
        \begin{equation*}\tag{3.94}
            \text{Var}(s^2) = \frac{1}{n}\bigg[\mu_4 - \sigma^2\bigg(\frac{n-3}{n-1}\bigg)\bigg]
        \end{equation*}
        so by plugging the numbers, we see that:
        \[
            \text{Var}(s^2) = \frac{1}{2}(14.73 + {2.92}^2) = 11.62
        \]
        which matches the expected result.
    \end{enumerate}
\end{proof}t


\section{Edge homomorphisms, transgression}
Recall the Serre spectral sequence for a fibration $F\to E\to B$ has $E^2$-page
given by
$$
E^2_{s,t} = H_s(B;H_t(F)) \Rightarrow H_{s+t}(E).
$$
If $B$ is path-connected, $\widetilde{H}_t(F) = 0$ for $t<q$,
$\widetilde{H}_s(B) = 0$ for $s<p$, and $\pi_1(B)$ acts trivially on
$H_\ast(F)$, we showed that there is a long exact sequence (the Serre exact
sequence)
\begin{equation}\label{serre-exact}
    H_{p+q-1}(F)\xrightarrow{\bullet} H_{p+q-1}(E)\to H_{p+q-1}(B)\to
    H_{p+q-2}(F)\to\cdots
\end{equation}
Let us attempt to describe the arrow marked by $\bullet$. %If $t>q$, we know

Let $(E^r_{p,q},d^r)$ be any spectral sequence such that $E^r_{p,q} = 0$ if
$p<0$ or $q<0$; such a spectral sequence is called a \emph{first quadrant}
spectral sequence. The Serre spectral sequence is a first quadrant spectral
sequence. In a first quadrant spectral sequence, the $d^2$-differential
$d^2:E^2_{0,t}\to E^2_{-2,t+1}$ is zero, since $E^2_{s,t}$ vanishes for $s<0$.
This means that $H_t(F) = H_0(B;H_t(F)) = E^2_{0,t}$ surjects onto $E^3_{0,t}$.
Arguing similarly, this surjects onto $E^4_{0,t}$. Eventually, we find that
$E^{r}_{0,t} \simeq E^{t+2}_{0,t}$ for $r\geq t+2$.
In particular,
$$E^{t+2}_{0,t} \simeq E^\infty_{0,t} \simeq \gr_0 H_t(E) \simeq F_0 H_t(E),$$
which sits inside $H_t(E)$. The composite
$$E^2_{0,t} = H_t(F) \to E^3_{0,t}\to \cdots\to E^{t+2}_{0,t} \subseteq F_0
H_t(E)\to H_t(E)$$
is precisely the map $\bullet$! Such a map is known as an \emph{edge
homomorphism}.

The map $F\to E$ is the inclusion of the fiber; it induces a map $H_t(F)\to
H_t(E)$ on homology. We claim that this agrees with $\bullet$.
%We almost saw this in the construction of a sseq for a filtered complex.
Recall that $F_0H_t(E)$ is defined to be $\img(H_t(F_0 E) \to H_t(E))$. In the
construction of the Serre spectral sequence, we declared that $F_0 E$ is
exactly the preimage of the zero skeleton. Since $B$ is simply connected, we
find that $F_0 E$ is exactly the fiber $F$.

To conclude the proof of the claim, consider the following diagram:
\begin{equation*}
    \xymatrix{
	F\ar[r]\ar[d] & F\ar[d]\\
	F\ar[r]\ar[d] & E\ar[d]\\
	\ast\ar@{^(->}[r] & B
    }
\end{equation*}
The naturality of the Serre spectral sequence implies that there is an induced
map of spectral sequences. Tracing through the symbols, we find that this
observation proves our claim.

The long exact sequence \eqref{serre-exact} also contains a map $H_s(E)\to
H_s(B)$. The group $F_s H_s(E) = H_s(E)$ maps onto $\gr_s H_s(E) \simeq
E^\infty_{s,0}$. If $F$ is connected, then $H_s(B) = H_s(B;H_0(F)) =
E^2_{s,0}$. Again, the $d^2$-differential $d^2:E^2_{s+2,-1}\to E^2_{s,0}$ is
trivial (since the source is zero). Since $E^3 = \ker d^2$, we have an
injection $E^3_{s,0} \to E^2_{s,0}$. Repeating the same argument, we get
injections
$$E^\infty_{s,0} = E^{s+1}_{s,0}\to \cdots\to E^2_{s,0}\to E^2_{s,0} =
H_s(B).$$
Composing with the map $H_s(E)\to E^\infty_{s,0}$ gives the desired map $H_s(E)
\to H_s(B)$ in the Serre exact sequence. This composite is also known as an
edge homomorphism.

As above, this edge homomorphism is the map induced by $E\to B$. This can be
proved by looking at the induced map of spectral sequences coming from the
following map of fiber sequences:
\begin{equation*}
    \xymatrix{
	F\ar[r]\ar[d] & \ast\ar[d]\\
	E\ar[r]\ar[d] & B\ar[d]\\
	B\ar[r] & B
    }
\end{equation*}

The topologically mysterious map is the boundary map $\partial:H_{p+q-1}(B)\to
H_{p+q-2}(F)$. Such a map is called a \emph{transgression}. Again, let
$(E^r_{s,t},d^r)$ be a first quadrant spectral sequence. In our case,
$E^2_{n,0} = H_n(B)$, at least $F$ is connected. As above, we have injections
$$i:E^n_{n,0} \to \cdots\to E^3_{n,0} \to E^2_{n,0} = H_n(B).$$
Similarly, we have surjections
$$s:E^2_{0,n-1}\to E^3_{0,n-1}\to \cdots\to E^n_{0,n-1}.$$
There is a differential $d^n:E^n_{n,0}\to E^n_{0,n-1}$. The transgression is
defined as the \emph{linear relation} (not a function!) $E^2_{n,0}\to
E^2_{0,n-1}$ given by
$$x\mapsto i^{-1} d^n s^{-1}(x).$$
However, the reader should check that in our case, the transgression is indeed
a well-defined function.

Topologically, what is the origin of the transgression? There is a map
$H_n(E,F)\xrightarrow{\pi_\ast} H_n(B,\ast)$, as well as a boundary map
$\partial : H_n(E,F) \to H_{n-1}(F)$. We claim that:
$$\img \pi_\ast = \img(E^n_{n,0}\to H_n(B) = E^2_{n,0}),\quad
\partial\ker\pi_\ast = \ker(H_{n-1}(F) = E^2_{0,n-1} \to E^n_{0,n-1}).$$
\begin{proof}[Proof sketch]
    Let $x\in H_n(B)$. Represent it by a cycle $c\in Z_n(B)$. Lift it to a
    chain in the total space $E$. In general, this chain will not be a cycle
    (consider the Hopf fibration). The differentials record this boundary; let
    us recall the geometric construction of the differential. Saying that the
    class $x$ survives to the $E^n$-page is the same as saying that we can find
    a lift to a chain $\sigma$ in $E$, with $d\sigma\in S_{n-1}(F)$. Then
    $d^n(x)$ is represented by the class $[dc]\in H_{n-1}(F)$. This is
    precisely the trangression.

    Informally, we lift something from $H_n(B)$ to $S_n(E)$; this is
    well-defined up to something in $F$. In particular, we get an element in
    $H_n(E,F)$. We send it, via $\partial$, to an element of $H_{n-1}(F)$ ---
    and this is precisely the transgression.
\end{proof}
\subsection{An example}
We would like to compare the Serre exact sequence \eqref{serre-exact} with the
homotopy exact sequence:
$$\ast\to \pi_{p+q-1}(F)\to \pi_{p+q-1}(E)\to \pi_{p+q-1}(B)\xar{\partial}
\pi_{p+q-2}(F)\to \cdots$$
There are Hurewicz maps $\pi_{p+q-1}(X)\to H_{p+q-1}(X)$. We claim that there
is a map of exact sequences between these two long exact sequences.
\begin{equation*}
    \xymatrix{
	H_{p+q-1}(E) \ar[r]^{\pi_\ast} & H_{p+q-1}(B)\ar[r]_\partial &
	H_{p+q-2}(F)\ar[r] & \cdots\\
	\pi_{p+q-1}(E)\ar[r]_{\pi_\ast}\ar[u]_{h} &
	\pi_{p+q-1}(B)\ar[u]^h\ar[r] & \pi_{p+q-2}(F)\ar[r]\ar[u]^h &
	\cdots\\
    }
\end{equation*}
The leftmost square commutes by naturality of Hurewicz. The commutativity of
the righmost square is not immediately obvious. For this, let us draw in the
explicit maps in the above diagram:
\begin{equation*}
    \xymatrix{
	& & H_{p+q-1}(E,F)\ar[dl]\ar[dr] & &\\
	H_{p+q-1}(E) \ar[r]^{\pi_\ast} & H_{p+q-1}(B)\ar[rr]_\partial & &
	H_{p+q-2}(F)\ar[r] & \cdots\\
	\pi_{p+q-1}(E)\ar[r]_{\pi_\ast}\ar[dr]\ar[u]_{h} &
	\pi_{p+q-1}(B)\ar[u]^h\ar[rr] & & \pi_{p+q-2}(F)\ar[r]\ar[u]^h &
	\cdots\\
	& \pi_{p+q-1}(E,F)\ar[uuur]\ar[urr]\ar[u]^\cong_{s} & &
    }
\end{equation*}
The map marked $s$ is an isomorphism (and provides the long arrow in the above
diagram, which makes the square commute), since
$$
\pi_n(E,F) = \pi_{n-1}(\mathrm{hofib}(F\to E)) = \pi_{n-1}(\Omega B) =
\pi_n(B).
$$
Let us now specialize to the case of the fibration
$$\Omega X\to PX\to X.$$
Assume that $X$ is connected, and $\ast \in X$ is a chosen basepoint. Let
$p\geq 2$, and suppose that $\widetilde{H}_s(X) = 0$ for $s<p$. Arguing as in
\S \ref{loops-sn}, we learn that the Serre spectral sequence we know that the
homology of $\Omega X$ begins in dimension $p-1$ since $PX\simeq \ast$, so $q =
p-1$. Likewise, if we knew $\widetilde{H}_n(\Omega X) = 0$ for $n<p-1$, then
the same argument shows that $\widetilde{H}_n(X) = 0$ for $n<p$.
\subsection*{A surprise gust: the Hurewicz theorem}
The discussion above gives a proof of the Hurewicz theorem; this argument is
due to Serre.
\begin{theorem}[Hurewicz, Serre's proof]
    Let $p\geq 1$. Suppose $X$ is a pointed space with $\pi_i(X) = 0$ for
    $i<p$. Then $\widetilde{H}_i(X) = 0$ for $i<p$ and $\pi_p(X)^{ab}\to
    H_p(X)$ is an isomorphism.
\end{theorem}
\begin{proof}
    Let us assume the case $p=1$. This is classical: it is Poincar\'{e}'s
    theorem. We will only use this result when $X$ is a loop space, in which
    case the fundamental group is already abelian.

    Let us prove this by induction, using the loop space fibration. By
    assumption, $\pi_i(\Omega X) = 0$ for $i<p-1$. By our inductive hypothesis,
    $\widetilde{H}_i(\Omega X) = 0$ for $i<p-1$, and $\pi_{p-1}(\Omega X)
    \xrightarrow{\simeq} H_{p-1}(\Omega X)$. By our discussion above, we learn
    that $\widetilde{H}_i(X) = 0$ for $i<p$. The Hurewicz map
    $\pi_p(X)\xrightarrow{h}H_p(X)$ fits into a commutative diagram:
    \begin{equation*}
	\xymatrix{
	    \pi_{p-1}(\Omega X)\ar[r]^\simeq & H_{p-1}(\Omega X)\\
	    \pi_p(X)\ar[u]^\simeq \ar[r]_h &
	    H_p(X)\ar[u]^{\simeq}_{\text{transgression}}
	    }
    \end{equation*}
    It follows from the Serre exact sequence that the transgression is an
    isomorphism.
\end{proof}
%This proof has an enormous advantage, since you can make modifications that modify all primes except for a single prime, or get rational information.
%In other words, it's amenable to localizations.
%On Monday we'll talk about Serre classes and get information about homotopy groups way beyond conductivity of the space, if you do it right.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CS671: Machine Learning
% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>
% Creative Commons Attribution-ShareAlike 4.0 International License
% More info: https://github.com/ghorbanzade/beacon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{Question 2}

Let $f : \mathbb{R}^2 \rightarrow \mathbb{R}$ be the function given in Equation \ref{eq21}.

\begin{equation}
f(x) = x_1^2 + 4x_2^2
\label{eq21}
\end{equation}

Let $S$ be the set of feasible solutions defined by the restrictions

\begin{equation}
\begin{aligned}
5x_1 + 8x_2 - 41 &\leqslant 0,\\
x_1 &\geqslant 0,\\
x_2 &\geqslant 0.\\
\end{aligned}
\label{eq22}
\end{equation}

Using Fritz John theorem determine the point of minimum for $f$.

\subsection*{Solution}

Figure \ref{fig21} depicts the feasible region $S$ for function $f: \mathbb{R}^2 \rightarrow \mathbb{R}$.

\begin{figure}[H]\centering
\begin{tikzpicture}
    \draw [thick] (1.708,0) coordinate (a_1) -- (0,2.733) coordinate (a_2);
    \path [fill=gray!20] (0,0) -- (a_2) to
        (a_1) -- (0,0);
    \draw [<->,thick] (0,3) node (yaxis) [above] {$y$} |- (3,0) node (xaxis) [right] {$x$};
    \fill[black] (a_1) circle (2pt) node[above right] {$(0, 5.125)$};
    \fill[black] (a_2) circle (2pt) node[right] {$(8.2, 0)$};
    \node at (0.5,1) {$S$};
\end{tikzpicture}
\caption{Feasible region $S$ defined by restrictions given in Eq. \ref{eq22}}\label{fig21}
\end{figure}

We define $g_i$ for $i \in \{1,2,3\}$ as follows.

\begin{equation}
\begin{aligned}
g_1(\mathbf{x}) &= 5x_1 + 8x_2 - 41\\
g_2(\mathbf{x}) &= x_1\\
g_3(\mathbf{x}) &= x_2\\
\end{aligned}
\label{eq23}
\end{equation}

Using Eq. \ref{eq21} and \ref{eq23}, $(\nabla f)_x$ and $(\nabla g_i)$ can be obtained as follows.

\begin{equation}
\begin{aligned}
(\nabla f)'_\mathbf{x} &= \begin{pmatrix} 2x_1 & 8x_2\end{pmatrix} \\
(\nabla g_1)'_\mathbf{x} &= \begin{pmatrix} 5 & 8\end{pmatrix} \\
(\nabla g_2)'_\mathbf{x} &= \begin{pmatrix} 1 & 0\end{pmatrix} \\
(\nabla g_3)'_\mathbf{x} &= \begin{pmatrix} 0 & 1\end{pmatrix} \\
\end{aligned}
\label{eq24}
\end{equation}

We claim $\mathbf{x} = (0,0)$ is an optimal point for function $f$.
To prove this claim, we first need to show Fritz John necessary condition is satisfied; i.e. $F(f,\mathbf{x})$ and $FD(S,\mathbf{x_0})$ are disjoint.

For $\mathbf{x} = (0,0)$, constraints $g_2$ and $g_3$ are binding.
We have $\mathbf{d} \in F(f,\mathbf{x}) \cap G(\mathbf{g}, \mathbf{x})$ if following conditions are satisfied, simultaneously.

\begin{equation}
\begin{aligned}
2x_1 d_1 + 8x_2 d_2 &< 0\\
x_1 d_1 &< 0\\
x_2 d_2 &< 0\\
\end{aligned}
\label{eq25}
\end{equation}

However, since $x_1 = x_2 = 0$, none of the conditions in Eq. \ref{eq25} are satisfied and therefore, $F(f,\mathbf{x}) \cap G(\mathbf{g}, \mathbf{x}) = \emptyset$ for $x = (0,0)$.
Therefore we can continue with finding scalars $u_0$ and $u_i$ such that $u_0(\nabla f)_\mathbf{x} + \Sigma_{i=1}^{3} u_i (\nabla g_i)_\mathbf{x} = \mathbf{0}$.
Using Eq. \ref{eq24}, this condition can be rewritten as follows.

\begin{equation}
u_0 \begin{pmatrix} 2x_1\\ 8x_2\\ \end{pmatrix} + u_2 \begin{pmatrix} 1\\ 0\end{pmatrix} + u_3 \begin{pmatrix} 0\\ 1\end{pmatrix} = \begin{pmatrix}
0 \\ 0 \end{pmatrix}
\label{eq26}
\end{equation}

For Eq. \ref{eq26} to hold for $x = (0, 0)$, we should have $u_i = 0$ for all $i\in \{1,2,3\}$ and $u_0$ can be chosen as any positive number.
Since there is at least one positive scalar, all necessary conditions are satisfied for $\mathbf{x} = (0, 0)$ and $\mathbf{x}$ is proven to be the point of minimum for $f$.

\subsection*{Side Note}

In case the restrictions given in \ref{eq22} are changed to the following, the point of minimum of $f$ would be $\mathbf{x} = (5,2)$.

\begin{equation}
\begin{aligned}
5x_1 + 8x_2 - 41 &\geqslant 0,\\
x_1 &\geqslant 0,\\
x_2 &\geqslant 0.\\
\end{aligned}
\label{eq27}
\end{equation}

Choosing $\mathbf{x} = (5,2)$ will change the set of binding constraints to $\{g_1\}$.
Therefore, \ref{eq25} will change to Eq. \ref{eq28}.
In this case, $F(f,\mathbf{x}) \cap G(\mathbf{g}, \mathbf{x}) = \emptyset$ again, since no $d_1$ and $d_2$ exist to satisfy the following conditions simultaneously.

\begin{equation}
\begin{aligned}
10d_1 + 16d_2 &< 0,\\
5d_1 + 8d_2 &> 0\\
\end{aligned}
\label{eq28}
\end{equation}

Therefore, by showing there are $u_0$ and $u_i$ such that $u_0(\nabla f)_\mathbf{x} + \Sigma_{i=1}^{3} u_i (\nabla g_i)_\mathbf{x} = \mathbf{0}$, we can prove $\mathbf{x}(5,2)$ is really an optimal point.
The former is easy to show, using Eq. \ref{eq29}.

\begin{equation}
u_0 \begin{pmatrix} 2x_1\\ 8x_2\\ \end{pmatrix} + u_1 \begin{pmatrix} 5\\ 8\end{pmatrix} = \begin{pmatrix}
0 \\ 0 \end{pmatrix}
\label{eq29}
\end{equation}

And replacing $x_1 = 5$, $x_2 = 2$, Eq. \ref{eq29} holds by having $u_0 = u_1 = 0$ and choosing $u_2$ and $u_3$ as any arbitrary positive number.


\section{Conditional Expectation}
\begin{definition}
    Let $B$ be an event such that $\mathbb P(B)>0$ and let $X$ be a random variable, then we define
    $$\mathbb E[X|B]=\frac{\mathbb E[X\cdot 1_B]}{\mathbb P(B)}$$
\end{definition}
\begin{proposition}[Law of Total Expectation]
    Let $\Omega_n$ be a sequence of events that partitions $\Omega$, then
    $$\mathbb E[X]=\sum_n\mathbb E[X|\Omega_n]\mathbb P(\Omega_n)$$
\end{proposition}
\begin{proof}
    Write $X=\sum_nX\cdot1_{\Omega_n}$.
\end{proof}
\begin{definition}
    Let $X_1,\ldots,X_n$ be random variables, then the joint distribution is $\mathbb P(X_1=x_1,\ldots,X_n=x_n),x_i\in\omega_{X_i}$.
    Given such a joint distribution, the marginal distribution of $X_i$ is defined as
    $$\mathbb P(X_i=x_i)=\sum_{j\neq i,x_j\in\Omega_{X_j}}\mathbb P(X_1=x_1,\ldots,X_n=x_n)$$
\end{definition}
\begin{definition}
    Let $X,Y$ be random variables, then the conditional probability given $Y=y,y\in\Omega_Y$ is defined by
    $$\mathbb P(X=x|Y=y)=\mathbb P(X=x,Y=y)/\mathbb P(Y=y)$$
\end{definition}
Immediately
$$\mathbb P(X=x)=\sum_{y\in\Omega_Y}\mathbb P(X=x,Y=y)=\sum_{y\in\Omega_Y}\mathbb P(X=x|Y=y)\mathbb P(Y=y)$$
Note that if $X,Y$ are independent, then
\begin{align*}
    \mathbb P(X+Y=z)&=\sum_{y\in\Omega_Y}\mathbb P(X+Y=z|Y=y)\mathbb P(Y=y)\\
    &=\sum_{y\in\Omega_Y}\mathbb P(X=z-y|Y=y)\mathbb P(Y=y)\\
    &=\sum_{y\in\Omega_Y}\mathbb P(X=z-y)\mathbb P(Y=y)
\end{align*}
Similarly
$$\mathbb P(X+Y=z)=\sum_{x\in\Omega_X}\mathbb P(X=x)\mathbb P(Y=z-x)$$
\begin{example}
    Let $X\sim\operatorname{Pois}(\lambda),Y\sim\operatorname{Pois}(\mu)$, and $X,Y$ are independent, then
    $$\mathbb P(X+Y=n)=\sum_{r=0}^\infty \mathbb P(X=r)\mathbb P(X=n-r)=e^{-(\lambda+\mu)}\frac{(\lambda+\mu)^n}{n!}$$
\end{example}
\begin{definition}
    Let $X,Y$ be random variables,
    The conditional expectation of $X$ given $Y=y$ is defined to be the expectation of the conditional distribution of $X$ given $Y=y$, so
    $$\mathbb E[X|Y=y]=\frac{\mathbb E[X\cdot 1_{Y=y}]}{\mathbb P(Y=y)}=\sum_{x\in\Omega_X}x\mathbb P(X=x|Y=y)$$
\end{definition}
Note that $g(y)=\mathbb E[X|Y=y]$ is a function in $\Omega_Y\to\mathbb R$.
\begin{definition}
    The conditional expectation of $X$ given $Y$ is defined to be $\mathbb E[X|Y]=g(Y)$ which is a random variable as a function of $Y$.
\end{definition}
So obviously,
\begin{align*}
    \mathbb E[X|Y]&=g(Y)\\
    &=\sum_{y\in\Omega_Y}g(Y)\mathbb P(1_{Y=y})\\
    &=\sum_{y\in\Omega_Y}1_{Y=y}g(y)\\
    &=\sum_{y\in\Omega_Y}1_{Y=y}\mathbb E[X|Y=y]
\end{align*}
\begin{example}
    Toss a $p$-coin several times independently, so they produce a sequence of random variables $(X_i)_{i\in\mathbb N}\sim\operatorname{Bern}(p)$ and the number of heads are distributed in $Y_m=X_1+X_2+\cdots+X_m\sim\operatorname{Bin}(m,p)$
    We want to calculate $\mathbb E[X_i|Y_m]$.
    Note that $\mathbb E[X_i|Y_m=r]=\mathbb P(X_i=1|Y_m=r)=r/m$, which means
    $$\mathbb E[X_i|Y_m]=\frac{Y_m}{m}$$
\end{example}
\begin{proposition}
    1. $\forall c\in\mathbb R,\mathbb E[cX|Y]=c\mathbb E[X|Y],\mathbb E[c|Y]=c$.\\
    2.
    $$\mathbb E\left[\sum_{i=1}^nX_i\middle|Y\right]=\sum_{i=1}^n\mathbb E[X_i|Y]$$
    3. $\mathbb E[\mathbb E[X|Y]]=\mathbb E[X]$.
\end{proposition}
\begin{proof}
    1 and 2 are obvious.
    For 3,
    \begin{align*}
        \mathbb E[\mathbb E[X|Y]]&=\sum_{y\in\Omega_Y}\mathbb P(Y=y)\mathbb E[X|Y=y]\\
        &=\sum_{y\in\Omega_Y}\sum_{x\in\Omega_X}x\mathbb P(X=x|Y=y)\mathbb P(Y=y)\\
        &=\sum_{x\in\Omega_X}x\mathbb P(X=x)\\
        &=\mathbb E[X]
    \end{align*}
    As desired.
\end{proof}
Intuitively we also have the following:
\begin{proposition}\label{conditional_exp}
    1. If $X,Y$ are independent, then $\mathbb E[X|Y]=\mathbb E[X]$ which is constant.\\
    2. Suppose $Y,Z$ are independent, then $\mathbb E[\mathbb E[X|Y]|Z]=\mathbb E[X]$.\\
    3. Let $h:\mathbb R\to\mathbb R$, then $\mathbb E[h(Y)X|Y]=h(Y)\mathbb E[X|Y]$.
\end{proposition}
\begin{proof}
    1 is trivial.\\
    For 2, we have $\mathbb E[X|Y]$ is independent of $Z$, so $\mathbb E[\mathbb E[X|Y]|Z]=\mathbb E[\mathbb E[X|Y]]=\mathbb E[X]$ by 1.\\
    As for 3, we have $\mathbb E[h(Y)X|Y=y]=h(y)\mathbb E[X|Y=y]$, the identity follows.
\end{proof}
\begin{corollary}
    $\mathbb E[\mathbb E[X|Y]|Y]=\mathbb E[X|Y]$
\end{corollary}
\begin{proof}
    Take $h(y)=\mathbb E[X|Y=y]$ in Proposition \ref{conditional_exp}.3.
\end{proof}


\section*{Integration schemes}
Euler first order explicit
\begin{align}\label{eqn:euler}
    \begin{split}
        &v(t+\Delta{t}) = v(t) + a(t) * \Delta{t}\\
        &x(t+\Delta{t}) = x(t) + v(t) * \Delta{t}
    \end{split}
\end{align}
\par
The central difference scheme, also known as velocity Verlet is a very widely
used integration method of second order. This was initially proposed by Cundall
and Strack (1979) and adopted by several other authors. Velocities in the
upcoming time step $t + \Delta{t}/2 $ and positions at $t + \Delta{t}$ are
calculated as
\begin{align}\label{eqn:verlet}
    \begin{split}
        &v(t + \Delta{t}/2) = v(t + \Delta{t}/2) +a(t - \Delta{t}/2) * \Delta{t}\\
        &x(t + \Delta{t}) = x(t) +v(t + \Delta{t}/2) * \Delta{t}\\
    \end{split}
\end{align}
\par
predictor–corrector schemes very commonly used for molecular dynamics and
discrete element applications are Gear’s schemes. They are based on three
stages, whereas in addition to the predictor and corrector step known from the
Adams-method an evaluation step is added. Schemes considered here are the third
order Gear’s method (GPC3) and the fourth order Gear’s method (GPC4). In the
prediction step positions and their higher derivatives are calculated based on
Taylor series expansions as
\begin{equation}\label{eqn:gearP}
    \begin{split}
        c(t+\Delta{t}, p) =& c(t)\\
        b(t+\Delta{t}, p) =& b(t) + c(t) *\Delta{t}\\
        a(t+\Delta{t}, p) =& a(t) + b(t) *\Delta{t}^2 + \frac{1}{6} * c(t) *\Delta{t}^2\\
        v(t+\Delta{t}, p) =& v(t) + a(t) *\Delta{t} + \frac{1}{2} * b(t) *\Delta{t}^2 +\\
        &\frac{1}{6} * c(t) *\Delta{t}^3\\
        x(t+\Delta{t}, p) =& x(t) + v(t) * \Delta{t} + \frac{1}{2} * a(t) *\Delta{t}^2 +\\
        &\frac{1}{6} * b(t) *\Delta{t}^3 + \frac{1}{24} * c(t) *\Delta{t}^4\\
    \end{split}
\end{equation}
with the first and second derivative of the accelerations calculated as\par
for GPC3:
\begin{align}\label{eqn:gearJerk3}
    \begin{split}
        &b(t) = \frac{\Delta{a(t)}}{\Delta{t}}\\
        \\
        &c(t) = 0\\
    \end{split}
\end{align}\par
for GPC4:
\begin{align}\label{eqn:gearJerk4}
    \begin{split}
        &b(t) = \frac{\Delta{a(t)}}{\Delta{t}}\\
        \\
        &c(t) = \frac{\Delta{b(t)}}{\Delta{t}}\\
    \end{split}
\end{align}
\par
In the evaluation step the difference in the accelerations calculated based on
the acceleration $a(t+ \Delta{t}, p)$ and the acceleration $a(t+\Delta{t})$
calculated from positions $x(t+\Delta{t}, p)$ and velocities $v(t+\Delta{t}, p)$
is obtained by
\begin{align}\label{eqn:gearDa}
    \Delta{a} = a(t + \Delta{t}) - a(t + \Delta{t}, p)
\end{align}
\par
In the following, correction step positions and their higher derivatives are
calculated based on their values from the previous time step and the obtained
difference in acceleration as
\begin{align}\label{eqn:gearCorrector}
    \begin{split}
        &x(t+\Delta{t}) = x(t+\Delta{t}, p) + k1 * \Delta{a} * \Delta{t}^2\\
        &v(t+\Delta{t}) = v(t+\Delta{t}, p) + k2 * \Delta{a} * \Delta{t}\\
        &a(t+\Delta{t}) = a(t+\Delta{t}, p) + k3 * \Delta{a}\\
        &b(t+\Delta{t}) = b(t+\Delta{t}, p) + k4 * \frac{\Delta{a}}{\Delta{t}}\\
        &c(t+\Delta{t}) = c(t+\Delta{t}, p) + k5 * \frac{\Delta{a}}{\Delta{t}^2}\\
    \end{split}
\end{align}
\par
Gear’s scheme parameters k1-k5\par
for GPC3:
$k_1 = 1/12, k_2 = 5/12, k_3 = 1, k_4 = 1, k_5 = 0$\par
for GPC4:
$k_1 = 19/240, k_2 = 3/8, k_3 = 1, k_4 = 3/2, k_5 = 1$
\par
\newpage


\section{Merge Classification}

After generating the list of potential merge locations we extract a cubic region of interest around each.
We experimented with three different cube side lengths: $800 \textrm{nm}$, $1200 \textrm{nm}$, and $1600 \textrm{nm}$.
Side lengths of $1200 \textrm{nm}$ performed better on the training and validation data on our network.

\vspace{1cm}

\noindent
\textbf{Network Architecture}
We tested various architectures before deciding on the one we present in the paper.
Each architecture uses VGG-style blocks (i.e. two convolutions of size $3\times3\times3$ followed by a max-pooling layer)~\cite{chatfield2014return}.
For the first two layers the max-pooling is anisotropic with reduction only in the $x$ and $y$ dimensions.
The number of filters starts at 16 for the first block and doubles in each subsequent block.
Our architectures vary in the input size and number of layers.
In all instances we extract a \SI{1200}{\nano\meter^3} region of interest and map the extracted voxels to the given input size.
These input sizes correspond to specific output sizes from the last VGG block.
For training we use the mean squared error loss function and optimize with SGD with Nesterov momentum.

\begin{table}
	\scriptsize
	\centering
	\begin{tabular}{c c c c c c c}
		\hline
		\textbf{Depth} & \textbf{Input Size} & \textbf{No. Parameters} & \textbf{Output Size} & \textbf{Accuracy} & \textbf{Precision} & \textbf{Recall} \\ \hline
		      3        & (3, 18, 52, 52)     & 1,101,553               & (64, 3, 3, 3)        & 91.30             & 58.06              & 92.81 \\
		      3        & (3, 20, 60, 60)     & 2,313,969               & (64, 4, 4, 4)        & 92.41             & 61.70              & 92.41 \\
		      3        & (3, 22, 68, 68)     & 4,312,817               & (64, 5, 5, 5)        & 92.33             & 61.49              & 92.34 \\
		      3        & (3, 24, 76, 76)     & 7,294,705               & (64, 6, 6, 6)        & 93.51             & 65.78              & 93.13 \\
		      \textbf{3}        & \textbf{(3, 26, 84, 84)}     & \textbf{11,456,241}              & \textbf{(64, 7, 7, 7)}        & \textbf{95.38}             & \textbf{74.43}              & \textbf{92.34} \\
		      3        & (3, 28, 92, 92)     & 16,994,033              & (64, 8, 8, 8)        & 91.87             & 59.70              & 94.22 \\
		      3        & (3, 30, 100, 100)   & 24,104,689              & (64, 9, 9, 9)        & 92.01             & 60.24              & 93.75 \\
		      4        & (3, 28, 92, 92)     & 1,404,913               & (128, 2, 2, 2)       & 91.70             & 60.24             & 85.94 \\
		      4        & (3, 32, 108, 108)   & 2,650,097               & (128, 3, 3, 3)       & 92.80             & 64.28              & 86.88 \\\hline
	\end{tabular}
	\caption{The results of various network architectures trained on the Kasthuri data.}
	\label{table:input-size}
\end{table}

\noindent
\textbf{Inference Augmentation}
Augmenting the data for inference increases the precision by 3.79\% and the accuracy by 0.64\%.
Figure~\ref{fig:test-augmentation} shows the changes in the number of true positives, false positives, and false negatives as a function of the number of augmentations on the Kasthuri dataset.
The number of false positives decreases at first, falling below 200 after a second augmentation.
The gains become more gradual with the number of augmentations, leveling out around 175 false positives after 5 augmentations.

\begin{figure}[t]
	\centering
	\includegraphics[width=0.45\linewidth]{./figures/Kasthuri-test-augmentation.png}
	\caption{The number of false positives decreases with our data augmentation scheme. The benefit of augmentation gradually decreases with the number of random examples.}
	\label{fig:test-augmentation}
\end{figure}


We include some examples to demonstrate some of the uses of this package.

\section{Distinguishing groups}~

\begin{example}[Payne\_Grps]

We can use these functions to build groups from bilinear maps and distinguish
seemingly indistinguishable groups. In 2004, S. E. Payne asked if two elation
groups were isomorphic but suspected they were not \cite{Payne:elation-grps}.

The first group, $G_f$, is the elation group of the generalized quadrangle
$H(3,q^2)$, the Hermitian geometry. This group is defined as a Heisenberg group
whose bilinear map is the usual dot product.

\begin{code}
> p := 3;
> e := 4;
> q := p^e; // q = 3^e >= 27
> F := [KSpace(GF(q),2), KSpace(GF(q),2), KSpace(GF(q),1)];
>
> DotProd := function(x)
function>   return KSpace(GF(q),1)!(x[1]*Matrix(2,1,x[2]));
function> end function;
>
> DoubleForm := function(T)
function>   F := SystemOfForms(T)[1];
function>   K := BaseRing(F);
function>   n := Nrows(F);
function>   m := Ncols(F);
function>   MS := KMatrixSpace(K,n,m);
function>   Z := MS!0;
function>   M1 := HorizontalJoin(Z,-Transpose(F));
function>   M2 := HorizontalJoin(F,Z);
function>   D := VerticalJoin( M1, M2 );
function>   return Tensor( D, 2, 1 );
function> end function;
>
> f := DoubleForm( Tensor( F, DotProd ) );
> f;
Tensor of valence 2, U2 x U1 >-> U0
U2 : Full Vector space of degree 4 over GF(3^4)
U1 : Full Vector space of degree 4 over GF(3^4)
U0 : Full Vector space of degree 1 over GF(3^4)
>
> IsAlternating(f);
true
> Gf := HeisenbergGroup(f);
\end{code}

Now we define Payne's second group, $G_{\bar{f}}$, which is the elation group of
the Roman quadrangle with parameters $(q^2,q)$. In this example, $\bar{f}$ is a
biadditive map, but is bilinear over the prime field $\mathbb{F}_3$. Therefore,
we construct a vector space isomorphism from $\mathbb{F}_3^e$ to
$\mathbb{F}_{3^e}$ and the bilinear commutator map, induced by $\bar{f}$. Hence,
$G_{\bar{f}}$ is the Heisenberg group of this bilinear commutator map.

\begin{code}
> n := PrimitiveElement(GF(q)); // non-square
> MS := KMatrixSpace(GF(q),2,2);
> A := MS![-1,0,0,n];
> B := MS![0,1,1,0];
> C := MS![0,0,0,n^-1];
> F1 := Frame(f);
> F2 := [KSpace(GF(p),4*e), KSpace(GF(p),4*e),\
>   KSpace(GF(p),e)];
>
> // take 1/3^r root
> Root := function(v,r)
function>   k := Eltseq(v)[1];
function>   K := Parent(k);
function>   if k eq K!0 then return k; end if;
function>   R<x> := PolynomialRing(K);
function>   f := Factorization(x^(3^r)-k)[1][1];
function>   return K!(x-f);
function> end function;
>
> // biadditive map defining elation grp
> RomanGQ := function(x)
function>   u := Matrix(1,2,x[1]);
function>   v := Matrix(2,1,x[2]);
function>   M := [A,B,C];
function>   f := &+[Root(u*M[i]*v,i-1) : i in [1..3]];
function>   return KSpace(GF(q),1)![f];
function> end function;
>
> // vector space isomorphisms
> phi := map< F2[1] -> F1[1] | \
>   x :-> F1[1]![ GF(q)![ s : s in Eltseq(x)[i+1..e+i] ] : \
>     i in [0,e,2*e,3*e] ] >;
> gamma := map< F1[3] -> F2[3] | \
>   x :-> F2[3]!&cat[ Eltseq(s) : s in Eltseq(x) ] >;
>
> // bilinear commutator from RomanGQ
> RomanGQComm := function(x)
function>   x1 := Eltseq(x[1]@phi)[1..2];
function>   x2 := Eltseq(x[1]@phi)[3..4];
function>   y1 := Eltseq(x[2]@phi)[1..2];
function>   y2 := Eltseq(x[2]@phi)[3..4];
function>   comm := RomanGQ( <x2,y1> ) - RomanGQ( <y2,x1> );
function>   return comm @ gamma;
function> end function;
>
> f_bar := Tensor( F2, RomanGQComm );
> f_bar;
Tensor of valence 2, U2 x U1 >-> U0
U2 : Full Vector space of degree 16 over GF(3)
U1 : Full Vector space of degree 16 over GF(3)
U0 : Full Vector space of degree 4 over GF(3)
>
> IsAlternating(f_bar);
true
> Gfb := HeisenbergGroup(f_bar);
\end{code}

The groups $G_f$ and $G_{\bar{f}}$ have order $3^{20}$ and are class 2, exponent
3, and minimally generated by 16 elements. In other words, the groups $G_f$ and
$G_{\bar{f}}$ are central extensions of $\mathbb{Z}_3^{16}$ by
$\mathbb{Z}_3^{4}$ and have exponent $3$. Using standard heuristics, these
groups are indistinguishable. However, the invariants associated to their
exponent-$p$ central tensor are vastly different, and thus, they determine that
these groups are non-isomorphic. We show that the centroids of the tensors are
not isomorphic.

\begin{code}
> Tf := pCentralTensor(Gf,1,1);
> Tf;
Tensor of valence 2, U2 x U1 >-> U0
U2 : Full Vector space of degree 16 over GF(3)
U1 : Full Vector space of degree 16 over GF(3)
U0 : Full Vector space of degree 4 over GF(3)
>
> Tfb := pCentralTensor(Gfb,1,1);
> Tfb;
Tensor of valence 2, U2 x U1 >-> U0
U2 : Full Vector space of degree 16 over GF(3)
U1 : Full Vector space of degree 16 over GF(3)
U0 : Full Vector space of degree 4 over GF(3)
>
> Cf := Centroid(Tf);
> Cfb := Centroid(Tfb);
> Dimension(Cf) eq Dimension(Cfb);
false
\end{code}
\end{example}

\section{Simplifying automorphism group computations}~

\begin{example}[Ext\_Over\_Adj] We demonstrate how to to simplify the
automorphism group computation as discussed in \cite{BW:grps-tensor}. We
construct a class 2, exponent $p$, $p$-group $G$ which is a quotient of a
maximal unipotent subgroup of $\text{GL}(3,317^4)$.

\begin{code}
> p := 317;
> e := 4;
> H := ClassicalSylow( GL(3,p^e), p );
> U := UnipotentMatrixGroup(H);
> P := PCPresentation(U);
> Z := Center(P);
>
> N := sub< P | >;
> while #N lt p^2 do
while>   N := sub< P | Random(Z), N >;
while> end while;
>
> G := P/N;
> G;
GrpPC : G of order 10246902931634286779441449 = 317^10
PC-Relations:
    G.5^G.1 = G.5 * G.9^62 * G.10^133,
    G.5^G.2 = G.5 * G.9^312 * G.10^295,
    G.5^G.3 = G.5 * G.9^316,
    G.5^G.4 = G.5 * G.10^316,
    G.6^G.1 = G.6 * G.9^312 * G.10^295,
    G.6^G.2 = G.6 * G.9^316,
    G.6^G.3 = G.6 * G.10^316,
    G.6^G.4 = G.6 * G.9^138 * G.10^163,
    G.7^G.1 = G.7 * G.9^316,
    G.7^G.2 = G.7 * G.10^316,
    G.7^G.3 = G.7 * G.9^138 * G.10^163,
    G.7^G.4 = G.7 * G.9^188 * G.10^50,
    G.8^G.1 = G.8 * G.10^316,
    G.8^G.2 = G.8 * G.9^138 * G.10^163,
    G.8^G.3 = G.8 * G.9^188 * G.10^50,
    G.8^G.4 = G.8 * G.9^125 * G.10^151
\end{code}

We construct the exponent-$p$ central tensor of $G$ and compute its adjoint $*$-algebra $A$.

\begin{code}
> T := pCentralTensor(G,1,1);
> T;
Tensor of valence 2, U2 x U1 >-> U0
U2 : Full Vector space of degree 8 over GF(317)
U1 : Full Vector space of degree 8 over GF(317)
U0 : Full Vector space of degree 2 over GF(317)
>
> A := AdjointAlgebra(T);
> Dimension(A);
16
> star := Star(A);
\end{code}

If $V=G/\Phi(G)$ is the Frattini quotient of $G$, then our goal is to get the
cotensor space $V\wedge_A V$. Note that $\dim V\wedge V=28$, so standard methods
will compute a stabilizer of $\text{GL}(8,317)$ inside $V\wedge V$. We will
decrease the size of the ambient space resulting in an easier stabilizer
computation.

\begin{code}
> V := Domain(T)[1];
> E := ExteriorCotensorSpace(V,2);
> E;
Cotensor space of dimension 28 over GF(317) with valence 1
U2 : Full Vector space of degree 8 over GF(317)
U1 : Full Vector space of degree 8 over GF(317)
\end{code}

Now we create a sub cotensor space $S$ generated by all $(e_iX)\wedge e_j - e_i\wedge (e_jX)$ for $X\in A$,
and then quotient $V\wedge V$ by $S$. The result is a 4 dimensional space.

\begin{code}
> L := [];
> for E_gen in Generators(E) do
for>   F := SystemOfForms(E_gen)[1];
for>   for X in Basis(A) do
for|for>     L cat:= [E!Eltseq(X*F - F*Transpose(X@star))];
for|for>   end for;
for> end for;
>
> S := SubTensorSpace(E,L);
> S;
Cotensor space of dimension 24 over GF(317) with valence 1
U2 : Full Vector space of degree 8 over GF(317)
U1 : Full Vector space of degree 8 over GF(317)
>
> Q := E/S;
> Q;
Cotensor space of dimension 4 over GF(317) with valence 1
U2 : Full Vector space of degree 8 over GF(317)
U1 : Full Vector space of degree 8 over GF(317)
\end{code}
\end{example}


\chapter{Proofs by Contradiction}
\label{chapter:indirect-proofs}
\marginurl{%
  Proofs by Contradiction:\\\noindent
  Introduction to Mathematical Reasoning \#3
}{youtu.be/bWP0VYx75DI}
\section{Proving Negative Statements}
The direct method is not very convenient when we need to prove the negation of
a statement.

For example, we may try to prove that $78 n + 102 m = 11$ does not have integer
solutions. It is not clear how to prove it directly since we can not consider
all possible $n$ and $m$. Hence, we need another approach. Let us assume that
such a solution $n$, $m$ exists. Note that $78 n + 102 m$ is even, but $11$ is
odd. In other words, an odd number is equal to an even number, which is
impossible. Thus, the assumption was false.

Consider another example, let us prove that if $p^2$ is even, then
$p$ is also even ($p$ is an integer). Assume the opposite; i.e. that $p^2$ is
even but $p$ is not.\footnote{%
  Note that we use here the statement that an integer $n$ is not even iff it is
  odd, which, formally speaking, should be proven.
}
Let $p = 2b + 1$. Note that $p^2 = (2b + 1)^2 = 2(2b^2 + 2b) + 1$.
Hence, $p^2$ is odd which contradicts to the assumption that $p^2$ is even.

Using this idea we may prove much more complicated results e.g. one may show
that $\sqrt{2}$ is irrational. For the sake of contradiction, let us assume
that it is not true. In other words there are $p$ and $q$ such that
$\sqrt{2} = \frac{p}{q}$ and $\frac{p}{q}$ is an irreducible fraction.

Note that $\sqrt{2} q = p$, so $2q^2 = p^2$. Which implies that $p$ is even
and $4$ divides $p^2$. Therefore $4$ divides $2q^2$ and $q$ is also even. As
a result, we get a contradiction with the assumption that $\frac{p}{q}$ is an
irreducible fraction.

\begin{template}
  \textbf{Template for proving a statement by contradiction.} \\

  Assume, for the sake of contradiction, that \emph{the statement} is false.
  Then \emph{present some argument that leads to a contradiction}. Hence, the
  assumption is false and \emph{the statement} is true.
\end{template}

\begin{exercise}
  Show that $\sqrt{3}$ is irrational.
\end{exercise}

\begin{exercise}
  Let $a$ and $b$ be some integers. Show that $a^2 - 4b - 2 \neq 0$.
\end{exercise}
\begin{solution}
  Assume, for the sake of contradiction, that such $a$ and $b$ exist. Note that
  $a^2 = 4b + 2$, hence, $a$ is even but $a^2$ is not divisible for $4$ which is a
  contradiction.
\end{solution}

\section{Proving Implications by Contradiction}
This method works especially well when we need to prove an implication.
Since the implication $A \implies B$ is false only when $A$ is true but $B$ is
false, it is enough to derive a contradiction from the fact that $A$ is true
and $B$ is false.

We have already seen such examples in the previous section, we proved that
$p^2$ is even implies $p$ is even, for any integer $p$. Let us consider another
example. Let $a$ and $b$ be real numbers such that $a > b$. We need to show that
$(ac < bc) \implies c < 0$. So we may assume that $ac < bc$ but $c \ge 0$. By
the multiplicativity of the inequalities we know that if $(a > b)$ and $c > 0$,
then $ac > bc$ which contradicts to $ac < bc$.

A special case of such a proof is when we need to prove the implication
$A \implies B$, assume that $B$ is false and derive that $A$ is false which
contradicts to  $A$ (such proofs are called proofs by contraposition); note
that the previous proof is a proof in this form.

\section{Proof of ``OR'' Statements}
Another important case is when we need to prove that at least one of two
statements is true. For example, let us prove that $ab = 0$ iff $a = 0$ or
$b = 0$. We start from the implication from the right to the left. Since if
$a = 0$, then $ab = 0$ and the same is true for $b = 0$ this implication is
obvious.

The second part of the proof is the proof by contradiction. Assume $ab = 0$,
$a \neq 0$, and $b \neq 0$. Note that $b = \frac{ab}{a} = 0$,
hence $b = 0$ which is a contradiction to the assumption.

\begin{chapterendexercises}
    \exercise[recommended] Prove that if $n^2$ is odd, then $n$ is odd.
    \exercise  In Euclidean (standard) geometry, prove: If two lines share a
        common perpendicular, then the lines are parallel.
        \begin{solution}
          Let us denote by $AB$ the common perpendicular. Assume that the lines
          are not parallel (note that these lines are different) i.e. that there
          is an intersection $C$ of these lines.

          Note that the angles $CAB$ and $CBA$ are right, hence, the angle $ACB$
          is equal to $0$ degrees. So the lines are the same, which is a
          contradiction.

          Hence, the assumption was incorrect i.e. the lines are parallel.
        \end{solution}
    \exercise[recommended] Let us consider four-lines geometry, it is a theory with
        undefined terms: point, line, is on, and axioms:
        \begin{enumerate}
            \item there exist exactly four lines,
            \item any two distinct lines have exactly one point on both of them, and
            \item each point is on exactly two lines.
        \end{enumerate}

        Show that every line has exactly three points on it.
        \begin{solution}
          Let us assume the opposite; i.e. there is a line $\ell$ with four
          points $p_1, \dots, p_4$ on it. By axiom~3, for each of these points
          $p_i$ there is a line $\ell_i \neq \ell$ such that $p_i$ is on $\ell$.
          Since we have only $4$ lines and $\ell_i \neq \ell$, then there are $i
          \neq j$ such that $\ell_i = \ell_j$. As a result, $p_i$ and $p_j$ are
          on $\ell$ and $\ell_i$, it is contradicting to axiom~2.
        \end{solution}
    \exercise Let us consider group theory, it is a theory with undefined
        terms: group-element and times (if $a$ and $b$ are group elements,
        we denote $a$ times $b$ by $a \cdot b$), and axioms:
        \begin{enumerate}
          \item $(a \cdot b) \cdot c = a \cdot (b \cdot c)$
            for every group-elements $a$, $b$, and $c$;
          \item there is a unique group-element $e$ such that
            $e \cdot a = a = a \cdot e$ for every group-element $a$
            (we say that such an element is the identity element);
          \item for every group-element $a$ there is a group-element $b$
            such that $a \cdot b = e$, where $e$ is the identity element;
          \item for every group-element $a$ there is a group-element $b$
            such that $b \cdot a = e$, where $e$ is the identity element.
        \end{enumerate}

        Let $e$ be the identity element. Show the following statements
        \begin{itemize}
          \item if $b_0 \cdot a = b_1 \cdot a = e$, then $b_0 = b_1$, for every
            group-elements $a$, $b_0$, and $b_1$.
          \item if $a \cdot b_0 = a \cdot b_1 = e$, then $b_0 = b_1$, for every
            group-elements $a$, $b_0$, and $b_1$.
          \item if $a \cdot b_0 = b_1 \cdot a = e$, then $b_0 = b_1$, for every
            group-elements $a$, $b_0$, and $b_1$.
        \end{itemize}
    \exercise Let us consider three-points geometry, it is a theory with
        undefined terms: point, line, is on, and axioms:
        \begin{enumerate}
            \item There exist exactly three points.
            \item Two distinct points are on exactly one line.
            \item Not all the three points are collinear i.e. they do not lay on the
                same line.
            \item Two distinct lines are on at least one point i.e. there is at
              least one point such that it is on both lines.
        \end{enumerate}

        Show that there are exactly three lines.

        \begin{solution}
            Let us denote the points by $p_1$, $p_2$, and $p_3$ (they exist by
            Axiom~1). By Axiom~2, there are lines $l_{1, 2}$,
            $l_{1, 3}$, and $l_{2, 3}$ such that $p_i$ and $p_j$ are on
            $l_{i, j}$ ($i \neq j$).

            Note that the lines $l_{1, 2}$, $l_{1, 3}$, and $l_{2, 3}$ are different.
            Indeed, assume the opposite, i.e., without loss of generality that
            $l_{1, 2} = l_{1, 3}$. Note that $p_1$, $p_2$, and $p_3$ are on $l_{1, 2}$
            which contradicts Axiom~3.

            Let us now prove that there are no other lines. Assume the
            opposite i.e. that there is another line $l$. There is a
            point that is on $l$ and $l_{1, 2}$. Without loss of generality,
            this point is $p_1$. Additionally there is a point $p_i$
            ($i \neq 1$) that is on $l$ and  $l_{2, 3}$. However, it means that
            $p_1$ and $p_i$ are on $l$ which contradicts Axiom~2.
        \end{solution}
    \exercise Show that there are irrational numbers $a$ and $b$ such that
        $a^b$ is rational.
        \begin{solution}
          Assume that $a^b$ is irrational for all irrationals $a$ and $b$. Since
          $\sqrt{2}$ is irrational $\sqrt{2}^{\sqrt{2}}$ is also irrational.
          However, $(\sqrt{2}^{\sqrt{2}})^{\sqrt{2}} = \sqrt{2}^2 = 2$, which
          contradicts to the assumption.

          As a result, there are irrational $a$ and $b$ such that $a^b$ is
          rational.
        \end{solution}
    \exercise[recommended] Show that there does not exist the largest integer.

    \exercise Let us consider Young's geometry, it is a theory with undefined
        terms: point, line, is on, and axioms:
        \begin{enumerate}
            \item there exists at least one line,
            \item every line has exactly three points on it,
            \item not all points are on the same line,
            \item for two distinct points, there exists exactly one line on both of
              them,
            \item if a point does not lie on a given line, then there exists exactly
              one line on that point that does not intersect the given line.
        \end{enumerate}

        Show that for every point, there are exactly four lines on that point.
        \begin{solution}
          First, we prove that for every point, there is a line not on that
          point. Let $p$ be some point. By the first axiom, there is a line
          $\ell$. Assume that $p$ is on $\ell$ (otherwise we proved the
          statement). By axiom 2, there are two other points $p_1$ and $p_2$ on
          this line. By axiom 3, there is a point $q$ not on $\ell$. Finally, by
          axiom 4, there is a line $\ell'$ on $p_1$ and $q$. Note that $\ell'
          \neq \ell$, thus $p$ is not on $\ell'$.

          Now we are ready to prove that there are at least four lines. Let $p$
          be a point and $\ell$ be a line such that $p$ is not on $\ell$. By
          axiom 2, there are three points $p_1$, $p_2$, and $p_3$ on $\ell$. By
          axiom 4, there are lines $\ell_1$, $\ell_2$, and $\ell_3$ such that
          $p$ is on all of them and $p_i$ is on $\ell_i$ for $i \in \range{3}$.
          By axiom 5, there is a line $\ell_4$ contain $p$ but $p_1$, $p_2$,
          and $p_3$  are not on $\ell_4$. Thus, there are at least four lines
          through $p$.

          Let us now prove that there is no other line $\ell_5$ such that $p$ is
          on $\ell_5$. By axiom 5, there is a point $p_i$ such that $p_i$ is on
          both $\ell_5$ and $\ell$. But this contradicts to axiom 4, since $p_i$
          is also on $\ell_i$.
        \end{solution}
    \exercise Let us consider five-point geometry, it is a theory with undefined
      terms: point, line, is on, and axioms:
      \begin{enumerate}
        \item there exist exactly five points,
        \item each two distinct points have exactly one line on both of them, and
        \item each line has exactly two points.
      \end{enumerate}

      Show that each point has exactly four lines on it.
      \begin{solution}
        Let us consider some point $p$ and let $p_1$, \dots, $p_4$ be all other
        points (they exist by axiom~1). Note that there are lines $l_1$, \dots,
        $l_4$ such that $l_i$ goes throw $p$ and $p_i$. Note that $l_i \neq l_j$
        for $i \neq j$ by axiom~3 since $p_i$ is not on $l_j$ and there are
        already two points on $l_i$. Thus we proved that any point is on at
        least $4$ lines.

        Let us now prove that there are no other lines. Assume that $p$ is on a
        line $l$ and $l$ is not equal to $l_i$ for all $i$. However, by axiom 2,
        there is a point $p_j$ on $\ell$. Thus $l = l_j$ which is a contradiction.
      \end{solution}
\end{chapterendexercises}


\section{Homotopy, star-shaped regions}
As homology is a functor $H_\ast:\mathbf{Top}\to\mathbf{Ab}$, it preserves isomorphisms: homeomorphic spaces have isomorphic homology. However, homology is not always able to distinguish between non-homeomorphic spaces. We introduce the looser notion of homotopy, which is a central concept of algebraic topology, and later we will show that homology is a homotopy invariant.
\begin{definition}
Let $f_0,f_1:X\to Y$ be two maps. A \emph{homotopy} from $f_0$ to $f_1$ is a map $h:X\times I\to Y$ such that $h(x,0)=f_0(x)$ and $f(x,1)=f_1(x)$. We say that $f_0$ and $f_1$ are \emph{homotopic} and write $f_0\sim f_1$.  This notation is justified because it is indeed an equivalence relation (transitivity follows from the gluing lemma).
\end{definition}
\begin{figure}
	\centering
	\includegraphics[width=0.5\linewidth]{assets/L05/05-homotopy}
	\caption{A homotopy $h$ between $f_0,f_1:X\to Y$.}
	\label{fig:05-homotopy}
\end{figure}

We denote by $[X,Y]$ the set $\mathbf{Top}(X,Y)/\sim$.

Suppose we have a map $g: Y\to Z$ and homotopic maps $f_0,f_1:X\to Y$, with a homotopy $h:f_0\sim f_1$. Then $g\circ h$ gives a homotopy $g\circ f_0 \sim g\circ f_1$. Similarly, if $g:W\to X$ is a map and $f_0,f_1:X\to Y$ are homotopic, then $f_0\circ g\sim f_1\circ g$.

If $g_0\sim g_1:Y\to Z$ and $f_0\sim f_1: X\to Y$, then $g_0\circ f_0\sim g_0 \circ f_1\sim g_1 \circ f_1$. Hence we are able to compose homotopy classes, giving the dotted arrow below.
\begin{equation*}
\xymatrix{\mathbf{Top}(Y,Z)\times\mathbf{Top}(X,Y)\ar[d]\ar[r] & \mathbf{Top}(X,Z)\ar[d]\\
[Y,Z]\times[X,Y]\ar@{-->}[r] & [X,Z]}
\end{equation*}

\begin{definition}
The \emph{homotopy category of topological spaces} is $\mathrm{Ho}(\mathbf{Top})$ whose objects are topological spaces and $\mathrm{Ho}(\mathbf{Top})(X,Y)=[X,Y]=\mathbf{Top}(X,Y)/\sim$.
\end{definition}
\begin{definition}
	A map $f:X\to Y$ is a \emph{homotopy equivalence} if $[f]\in[X,Y]$ is an isomorphism in $\htop$. In other words, there is $g:Y\to X$ such that $fg\sim 1_Y$ and $gf\sim 1_X$.
\end{definition}
%This is an interesting category because it has \textit{terrible} categorical properties\todo{This sentence seems a bit random atm; give examples of why it's terrible? or just remove?}.

In Section \ref{lec:6-homotopy-invariance-of-homology} we will prove:
\begin{theorem}[Homotopy invariance of homology]
	If $f_0\sim f_1$, then $ H_\ast(f_0)= H_\ast(f_1)$.
\end{theorem}
This theorem states that the homology functor $H_\ast:\mathbf{Top}\to\mathbf{Ab}$ factors as $\mathbf{Top}\to\mathrm{Ho}(\mathbf{Top})\to\mathbf{Ab}$. In particular, it cannot distinguish between homotopy equivalent spaces. (Caution: spaces with isomorphic homology need not be homotopy equivalent.)
\begin{example}\label{exa:homotopy-equivalence-sphere}
The inclusion $S^{n-1}\subseteq \mathbf{R}^n-\{0\}$ is a homotopy equivalence. The homotopy inverse $p:\mathbf{R}^n-\{0\}\to S^{n-1}$ can be obtained by dividing a (always nonzero!) vector by its length. Clearly $p\circ i=1_{S^{n-1}}$. A homotopy $i\circ p\sim 1_{\mathbf{R}^n-\{0\}}$ is given by $(v,t)\mapsto tv+(1-t)\frac{v}{||v||}$. This example shows that homotopy equivalence does not preserve compactness.
\end{example}
\begin{definition}
A space $X$ is \emph{contractible} if the map $X\to\ast$ is a homotopy equivalence.
\end{definition}

\begin{definition}
	A \emph{star-shaped region} is a subspace $X$ of Euclidean space containing $\{0\}$, such that for all $x\in X$ and $t\in[0,1]$, $tx\in X$.
\end{definition}
\begin{figure}
	\centering
	\includegraphics[width=0.4\linewidth]{assets/L05/05-star-shaped-region}
	\caption{A star-shaped region.}
	\label{fig:05-star-shaped-region}
\end{figure}

For example, any convex region containing the origin is star-shaped. An argument similar to the one in Example \ref{exa:homotopy-equivalence-sphere} shows that the inclusion of $\{0\}$ into a star-shaped region is a homotopy equivalence. Thus star-shaped regions are contractible. Our goal now is to prove the following.
\begin{theorem}\label{thm:star-shaped-homology}
	Let $X$ be a star-shaped region. The augmentation map $\epsilon: H_\ast(X)\to \mathbf{Z}$ is an isomorphism, i.e., $ H_0(X)\cong\mathbf{Z}$ and $ H_i(X)\cong 0$ for $i>0$.
\end{theorem}
%The strategy of proof is that $\epsilon$ is induced by sending $X\to \ast$. We'll look at the chain map $S_\ast(x)\to\mathbf{Z}\to S_\ast(X)$. We'll show that this composite induces the same map in homology as the identity map, which means that the identity map factors through $\mathbf{Z}$, so we're done. (probably not necessary to include this now that it's been moved to this section, given that the proof follows shortly)
Before proving this, we will give a notion of homotopy in the category of chain complexes.
\begin{definition}
Let $C_\bullet,D_\bullet$ be chain complexes, and $f_0,f_1:C_\bullet\to D_\bullet$ be chain maps. A \emph{chain homotopy} $h:f_0\sim f_1$ is a collection of homomorphisms $h:C_n\to D_{n+1}$ such that $\partial h+h\partial=f_1-f_0$.
\end{definition}
			\begin{equation*}
			\xymatrix{C_{n+2}\ar[r]^{f_1-f_0}\ar[d]^\partial & D_{n+2}\ar[d]^\partial\\
			C_{n+1}\ar@{-->}[ur]^h\ar[r]^{f_1-f_0}\ar[d]^\partial & D_{n+2}\ar[d]^\partial\\
			C_n\ar@{-->}[ur]^h\ar[r]_{f_1-f_0} & D_n}
			\end{equation*}
The following lemma shows the significance of this condition.
\begin{lemma}
	If $f_0,f_1:C_\bullet\to D_\bullet$ are chain homotopic, then $f_{0,\ast}=f_{1,\ast}: H(C)\to H(D)$.
\end{lemma}
\begin{proof}
	We show that $(f_1-f_0)_\ast=0$. Let $c\in Z_n(C_\bullet)(C)$, so that $\partial c=0$. Then $(f_1-f_0)_\ast c=(\partial h+h\partial)c=\partial hc+h\partial c=\partial hc$ is a boundary, which is zero in homology.
\end{proof}
\begin{proof}[Proof of Theorem \ref{thm:star-shaped-homology}]
	The maps $\{0\}\to X$ and $X\to \{0\}$ induce $\mathbf{Z}\xrightarrow{\eta}S_\ast(X)$ and $S_\ast(X)\xrightarrow{\epsilon}\mathbf{Z}$ respectively. It is clear that $\epsilon\eta = 1:\mathbf{Z}\to\mathbf{Z}$. We now proceed to show that $\eta\epsilon\sim 1:S_\ast(X)\to S_\ast(X)$. Note that the composite $\eta \epsilon$ kills all chains in dimensions greater than zero, and on zero-chains we have $\eta\epsilon(\sum a_ix_i)=(\sum a_i)c_0$ where $c_0$ is the zero-simplex at the origin.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.8\linewidth]{assets/L05/05-star-shaped-line-homotopy-pf}
	\caption{The map $h$ illustrated on a 1-simplex.}
	\label{fig:05-star-shaped-line-homotopy-pf}
\end{figure}

	For $\sigma\in\Sin_q(X)$, define $h:\Sin_q(X)\to\Sin_{q+1}(X)$ as follows:
	$$h\sigma(t_0,\cdots,t_{q+1})=(1-t_0)\sigma\left(\frac{(t_0,\cdots,t_{q+1})}{1-t_0}\right).$$
	This extends by linearity to a map $h:S_q(X)\to S_{q+1}(X)$.
	Observe that $d_0 h \sigma = \sigma$, and if $q \geq 1$, $d_i h \sigma = h d_{i-1} \sigma$. Then, if $\sigma \in \Sin_q(X)$ with $q \geq 1$,
	\begin{align*}
		\partial h \sigma &= \sum_{i=0}^{q+1} (-1)^{i} d_i h\sigma\\
		&= \sigma - h \sum_{i=0}^q (-1)^i d_i \sigma\\
		&= \sigma - h\partial \sigma\\
		\partial h \sigma + h \partial \sigma &= \sigma.
	\end{align*}
	If $\sigma \in \Sin_0(X)$, then $d_1 h \sigma = c_0$ and we instead get $\partial h \sigma + h \partial \sigma = \sigma - c_0$. Thus $h:S_q(X)\to S_{q+1}(X)$ is a chain homotopy $\eta \epsilon \sim 1$ as desired.
\end{proof}
% Continue indenting like this.


\documentclass[11pt,twoside]{article}

\usepackage{amsmath,amsthm}
\usepackage{listings}
\usepackage[headings]{fullpage}
\usepackage[utopia]{mathdesign}
\usepackage{color}
\usepackage{graphicx}

\lstset{basicstyle=\footnotesize\ttfamily,language=Matlab}

\pagestyle{myheadings}
\markboth{Volume}{Volume}

\input{../fncextra}

\begin{document}

\begin{center}
  \bf Depths of despair
\end{center}

Numerical integration of a function of one variable is called quadrature. The analogous situation of integrating a function of two variables is sometimes called \emph{cubature}. In this project you will explore the extension of the trapezoid formula to this situation, and apply it to find the volume of water in a patch of the ocean.

Consider the problem $\iint_R f(x,y)\,dx\,dy$, where $R$ is the rectangle $[x_0,x_m] \times [y_0,y_n]$. We discretize each variable using the space steps $h$ and $k$, respectively, so that $x_i = x_0 + ih$ for $i=0,\ldots,n$, and $y_j=y_0+jk$ for $j=0,\ldots,m$. (This requires that $h=(x_m-x_0)/m$ and $k=(y_n-y_0)/n$.) The result is a decomposition of $R$ into rectangles with the nodes at the corners. The strategy is to compute a volume over each little rectangle and sum them over the whole domain. Here's an example of how the discretization process works in MATLAB:

\input{CubatureSetup}

At the corners of each rectangle we have values of $z$ according to $Z_{ij}=f(x_i,y_j)$. We can model the surface $z=f(x,y)$ over one of these rectangles using the function $L_{ij}(x,y)=a + b (x-x_i) + c(y-y_j) + d(x-x_i)(y-y_j)$, where $a,b,c,d$ are determined by interpolation conditions at the four corners of the rectangle. (These coefficients depend on $i$ and $j$, but that is left out to make the notation clearer.) We get a solid defined over the rectangle looking like this:

\input{CubatureSolid}

\subsection*{Objectives}
\label{sec:objectives}

Mathematical content:
\begin{enumerate}
\item Using a symbolic math package if you want, derive exact expressions for the interpolant $L_{ij}$ over the rectangle whose lower left corner is $(x_i,y_j)$, in terms of $h$, $k$, and four values $Z_{ij}$, $Z_{i+1,j}$, $Z_{i,j+1}$, $Z_{i+1,j+1}$. (Show the steps involved, whether you use a computer or not.)
\item Integrate the interpolant over the rectangle to get another expression in terms of the same quantities. This is $V_{ij}$, the volume used to approximate the integral of $f$ over the rectangle.
\item Show that if the $V_{ij}$ are added up over all $i$ and $j$, the result is identical to applying the trapezoid formula in each dimension sequentially over the domain (i.e., as an iterated integral).
\end{enumerate}

Computational content:
\begin{enumerate}
\item Download and install the GeoMapApp at \texttt{www.geomappapp.org}.
\item Start the app and agree to the license. You should get a window with a projected map of the world, in latitude-longitude corrdinates as measured in degrees of arc, and some GUI widgets. Use the magnifying glass tool to select a small rectangle over the ocean. You should try to get it to include about 1-2 degrees of latitiude (the $y$ axis).
\item Click on the icon that looks like a grid. After a few seconds another window should open with a histogram in it. Make sure the dropdown menu at the top of this window says ``GMRT Grid'' with some version number. Click on the floppy disk icon, select ``Grid: .XYZ (ascii format)'', and save the file to your computer. At this point you can close GeoMapApp.
\item You can import this data into MATLAB by double-clicking on it in the ``Current Folder'' tab of the MATLAB Desktop, and using the resulting dialog. What you will get is three columns of $x$, $y$, and $z$ data on a regular rectangular grid, where $x$ and $y$ are reported in degrees of arc, and $z$ will be negative to represent depths below sea level.
\item \textbf{After converting all the data into km units}, use it and the formula you derived above to estimate the amount of water in your patch of ocean.
\end{enumerate}

\subsection*{Submission}

Submit a function
\begin{verbatim}
function volume = ocean(x,y,z)
\end{verbatim}
that will compute an approximation to the volume using three vectors of depth data as described in the previous section.

Prepare a report that includes the following.
\begin{enumerate}
\item The required mathematical content.
\item Details needed to acquire the same raw data from the app and compute your volume result.
\item Some form of quantitative check on whether your answer is reasonable, in the sense of being at least the right order of magnitude.
\item A brief statement of the contributions of each team member to the project. \textbf{Be as specific as possible.}
\end{enumerate}
Your report should read like a document understandable to anyone else in the class. All of the mathematical expressions in your document should be typeset properly as mathematical notation. You have several options: Word, OpenOffice, \LaTeX, \texttt{texmacs.org}, Mathematica. Submit your report as a single PDF document, along with your M-file.

\end{document}